]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/85056 ([nvptx] wrong declaration of external arrays)
authorCesar Philippidis <cesar@codesourcery.com>
Fri, 30 Mar 2018 15:47:23 +0000 (08:47 -0700)
committerCesar Philippidis <cesar@gcc.gnu.org>
Fri, 30 Mar 2018 15:47:23 +0000 (08:47 -0700)
PR target/85056

Backport from mainline
2018-03-27  Cesar Philippidis  <cesar@codesourcery.com>

PR target/85056

gcc/
* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Add '[]' to
extern array declarations.

gcc/testsuite/
* testsuite/gcc.target/nvptx/pr85056.c: New test.
* testsuite/gcc.target/nvptx/pr85056a.c: New test.

From-SVN: r258978

gcc/ChangeLog
gcc/config/nvptx/nvptx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/nvptx/pr85056.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/pr85056a.c [new file with mode: 0644]

index e9233eb5a05318d56565bcd11589c94fd5b649d9..9cf73205757dad76075c1a0acac8ec2f69e67e09 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-30  Cesar Philippidis  <cesar@codesourcery.com>
+
+       Backport from mainline
+       2018-03-27  Cesar Philippidis  <cesar@codesourcery.com>
+
+       PR target/85056
+       * config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Add '[]' to
+       extern array declarations.
+
 2018-03-29  Sudakshina Das  <sudi.das@arm.com>
 
        Backport from mainline
index 16e80421f6906971b95a67fd6697ccb70a09eb95..8eb230973461818c448363845616b5b3a00d37e0 100644 (file)
@@ -1616,6 +1616,9 @@ static void
 nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section,
                           const_tree type, HOST_WIDE_INT size, unsigned align)
 {
+  bool atype = (TREE_CODE (type) == ARRAY_TYPE)
+    && (TYPE_DOMAIN (type) == NULL_TREE);
+
   while (TREE_CODE (type) == ARRAY_TYPE)
     type = TREE_TYPE (type);
 
@@ -1655,6 +1658,8 @@ nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section,
     /* We make everything an array, to simplify any initialization
        emission.  */
     fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]", init_frag.remaining);
+  else if (atype)
+    fprintf (file, "[]");
 }
 
 /* Called when the initializer for a decl has been completely output through
index 248686961f8ee2b0098e8ad178812983faca9c92..896abe33ee7a1a0bfe0691bec61fea72d7fde619 100644 (file)
@@ -1,3 +1,11 @@
+2018-03-30  Cesar Philippidis  <cesar@codesourcery.com>
+
+       Backport from mainline
+       2018-03-27  Cesar Philippidis  <cesar@codesourcery.com>
+
+       * testsuite/gcc.target/nvptx/pr85056.c: New test.
+       * testsuite/gcc.target/nvptx/pr85056a.c: New test.
+
 2018-03-29  Sudakshina Das  <sudi.das@arm.com>
 
        * gcc.target/arm/pr84826.c: Change dg-option to -fstack-check.
diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056.c b/gcc/testsuite/gcc.target/nvptx/pr85056.c
new file mode 100644 (file)
index 0000000..fe7f8af
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-additional-sources "pr85056a.c" } */
+
+extern void abort ();
+
+extern int a[];
+
+int
+main ()
+{
+  int i, sum;
+
+  for (i = 0; i < 10; i++)
+    sum += a[i];
+
+  if (sum != 55)
+    abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056a.c b/gcc/testsuite/gcc.target/nvptx/pr85056a.c
new file mode 100644 (file)
index 0000000..a45a5f2
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-skip-if "" { *-*-* } } */
+
+int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };