This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c/7741
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 9 Feb 2003 13:51:58 +0100
- Subject: [PATCH] Fix PR c/7741
Hi,
It's another ICE-after-error problem, again a regression from gcc 2.95.3,
because of a too agressive error recovery path.
Quoting Christian's analysis: "The problem is in duplicate_decls. When
duplicate_decls sees the second declaration for c with the initializer it
effectively replaces the first declaration by the second leading to the
equivalent of this code:
void foo(void)
{
int c = i;
int i;
}
with the exception that the now undeclared identifier i in the
initializer of c is not detected. This will cause the ICE later on."
Bootstrapped/regtested (c,c++,objc,f77 3.3 branch) on i586-redhat-linux-gnu.
Ok for mainline and 3.3 ? for 3.2 too ?
--
Eric Botcazou
2003-02-09 Eric Botcazou <ebotcazou@libertysurf.fr>
Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de>
PR c/7741
* c-decl.c (duplicate_decls): Discard the initializer of the new decl
when the types are conflicting.
2003-02-09 Eric Botcazou <ebotcazou@libertysurf.fr>
Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de>
* gcc.dg/decl-2.c: New test.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.356
diff -u -p -r1.356 c-decl.c
--- c-decl.c 13 Dec 2002 00:17:16 -0000 1.356
+++ c-decl.c 8 Feb 2003 17:31:58 -0000
@@ -1138,6 +1138,12 @@ duplicate_decls (newdecl, olddecl, diffe
}
}
error_with_decl (olddecl, "previous declaration of `%s'");
+
+ /* This is safer because the initializer might contain references
+ to variables that were declared between olddecl and newdecl. This
+ will make the initializer invalid for olddecl in case it gets
+ assigned to olddecl below. */
+ DECL_INITIAL (newdecl) = 0;
}
/* TLS cannot follow non-TLS declaration. */
else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
/* PR c/7411 */
/* Contributed by Christian Ehrhardt */
/* { dg-do compile } */
void foo(void)
{
char c; /* { dg-error "previous declaration" } */
int i;
int c = i; /* { dg-error "conflicting types" } */
}