aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/redecl-18.c17
4 files changed, 35 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 1450d65..9bb8351 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2019-02-06 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/88584
+ * c-decl.c (finish_decl): Do not complete array types for arrays
+ with external linkage not at file scope.
+
2019-02-05 Richard Biener <rguenther@suse.de>
PR c/88606
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 65aee4d..b658eb1 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5099,10 +5099,15 @@ finish_decl (tree decl, location_t init_loc, tree init,
type = TREE_TYPE (decl);
- /* Deduce size of array from initialization, if not already known. */
+ /* Deduce size of array from initialization, if not already known.
+ This is only needed for an initialization in the current scope;
+ it must not be done for a file-scope initialization of a
+ declaration with external linkage, redeclared in an inner scope
+ with the outer declaration shadowed in an intermediate scope. */
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE
- && TREE_CODE (decl) != TYPE_DECL)
+ && TREE_CODE (decl) != TYPE_DECL
+ && !(TREE_PUBLIC (decl) && current_scope != file_scope))
{
bool do_default
= (TREE_STATIC (decl)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ac70c72..2c6d0e4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-06 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/88584
+ * gcc.dg/redecl-18.c: New test.
+
2019-02-05 Jakub Jelinek <jakub@redhat.com>
PR c++/89187
diff --git a/gcc/testsuite/gcc.dg/redecl-18.c b/gcc/testsuite/gcc.dg/redecl-18.c
new file mode 100644
index 0000000..f96bbe7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-18.c
@@ -0,0 +1,17 @@
+/* Test redeclaration in an inner scope, with an incomplete type, of a
+ file-scope initialized array shadowed in an intermediate scope (bug
+ 88584). */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int a[1] = { 0 };
+
+void
+f (void)
+{
+ int a;
+ {
+ extern int a[];
+ sizeof (a); /* { dg-error "incomplete" } */
+ }
+}