This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] fix c/21502


On Tue, May 10, 2005 at 10:33:36PM +0000, Joseph S. Myers wrote:
> Yes (as a quality-of-implementation matter, not a standard requirement).  
> It does in 3.4.  It ought to do so immediately after my patch for bug 
> 21342 as well but I don't have a build tree with that patch around.

Hum, yes.  The following update seems to do what you want.  It 
doesn't do your number 2 test; I have no idea what you'd want 
for that.

Seem ok?  Or good enough at least?  This is fixing a bootstrap
failure after all...


r~


	* c-decl.c (finish_decl): After complete_array_type on an external
	decl, store the composite back into the binding.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.630.6.10
diff -u -p -d -r1.630.6.10 c-decl.c
--- c-decl.c	10 May 2005 12:41:06 -0000	1.630.6.10
+++ c-decl.c	10 May 2005 22:49:35 -0000
@@ -3285,11 +3285,13 @@ finish_decl (tree decl, tree init, 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,
@@ -3300,9 +3302,33 @@ finish_decl (tree decl, tree init, 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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]