This is the mail archive of the gcc-bugs@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]

Re: c/7741: [<3.2,3.3> regression] ICE on conflicting types (make_decl_rtl at varasm.c:834)


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7741

Hi,

this PR is about the following illegal code triggering an ICE, I analyzed why:
int main() {
	char c;
	int i;
	int c = i;
}

The problem is in duplicate_decls. When duplicate_decl sees the second
declaration for c with the initializer it effectivly replaces the
first declaration with the second leading to the equivilent of this code:
int main ()
{
	int c = i;
	int i;
}

with the exception that the now undeclared identifier i in the
initialization auf c is not detected. This will cause the ICE later on.
I suggest that we replace unconditionally set DECL_INITIAL to NULL
in duplicate_decls and possibly print an additional warning if the
initializer like this:


--- gcc-cvs/gcc/gcc/c-decl.c.orig	Thu Dec 12 17:59:13 2002
+++ gcc-cvs/gcc/gcc/c-decl.c	Thu Dec 12 18:03:34 2002
@@ -1554,7 +1554,7 @@
     return 0;
 
   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
-     But preserve OLDDECL's DECL_UID.  */
+     But preserve OLDDECL's DECL_UID and drop the initializer.  */
   {
     unsigned olddecl_uid = DECL_UID (olddecl);
 
@@ -1562,6 +1562,10 @@
 	    (char *) newdecl + sizeof (struct tree_common),
 	    sizeof (struct tree_decl) - sizeof (struct tree_common));
     DECL_UID (olddecl) = olddecl_uid;
+    /* This is necessary because the initializer might contain references
+       to varialbes that were declared between olddecl and newdecl. This
+       will make the initializer invalid for olddecl. */
+    DECL_INITIAL (olddecl) = NULL;
   }
 
   /* NEWDECL contains the merged attribute lists.

   regards   Christian

-- 
THAT'S ALL FOLKS!


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