aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2005-05-11 07:33:31 +0000
committerRichard Henderson <rth@redhat.com>2005-05-11 07:33:31 +0000
commit1fbfb7c4752af0495cd9f5e6c9b151e1d1ef7734 (patch)
treee1b874c70f6faf84aed3125f9e65ab492e614198 /gcc/c-decl.c
parentb4bcc77c06563229c32df17a920a5639579b6fc2 (diff)
PR c/21502
* c-decl.c (finish_decl): Propagate the completed array type of a global variable into the binding. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@99563 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 0ca4500021e..6c9ab457510 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3275,11 +3275,13 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
/* Get the completed type made by complete_array_type. */
type = TREE_TYPE (decl);
- if (failure == 1)
- error ("%Jinitializer fails to determine size of %qD", decl, decl);
-
- else if (failure == 2)
+ switch (failure)
{
+ case 1:
+ error ("%Jinitializer fails to determine size of %qD", decl, decl);
+ break;
+
+ case 2:
if (do_default)
error ("%Jarray size missing in %qD", decl, decl);
/* If a `static' var's size isn't known,
@@ -3290,9 +3292,33 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
and it will get allocated. */
else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
DECL_EXTERNAL (decl) = 1;
+ break;
+
+ case 3:
+ error ("%Jzero or negative size array %qD", decl, decl);
+ break;
+
+ case 0:
+ /* For global variables, update the copy of the type that
+ exists in the binding. */
+ if (TREE_PUBLIC (decl))
+ {
+ struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
+ while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
+ b_ext = b_ext->shadowed;
+ if (b_ext)
+ {
+ if (b_ext->type)
+ b_ext->type = composite_type (b_ext->type, type);
+ else
+ b_ext->type = type;
+ }
+ }
+ break;
+
+ default:
+ gcc_unreachable ();
}
- else if (failure == 3)
- error ("%Jzero or negative size array %qD", decl, decl);
if (DECL_INITIAL (decl))
TREE_TYPE (DECL_INITIAL (decl)) = type;