This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4 only] PR c/22458: Segfault in finish_fname_decls
- From: Richard Sandiford <richard at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: gdr at integrable-solutions dot net
- Date: Fri, 29 Jul 2005 11:57:48 +0100
- Subject: [3.4 only] PR c/22458: Segfault in finish_fname_decls
This patch fixes a minor 3.4-only regression from 3.3. Given:
void foo()
{
__PRETTY_FUNCTION__;
we'll complain about the missing '}' and then segfault in
finish_fname_decls:
/* They were called into existence, so add to statement tree. Add
the DECL_STMTs inside the outermost scope. */
tree *p = &DECL_SAVED_TREE (current_function_decl);
/* Skip the dummy EXPR_STMT and any EH_SPEC_BLOCK. */
while (TREE_CODE (*p) != COMPOUND_STMT)
...
p = &COMPOUND_BODY (*p);
---> if (TREE_CODE (*p) == SCOPE_STMT)
p = &TREE_CHAIN (*p);
because the function's body is a COMPOUND_STMT with a null COMPOUND_BODY.
This wasn't a problem in 3.3 because 3.3 only called finish_fname_decls
after a successful parse:
program: /* empty */
...
| extdefs
{
...
finish_fname_decls ();
...
}
However, as a result of the inter-module patches, 3.4 calls it from
c_parse_file() instead. This changed again in 4.0 after Zack's big
binding patch, making the bug a 3.4-only problem.
The patch below fixes the PR by getting c_begin_compound_stmt to
initialize the body of the statement to error_mark_node rather than
NULL. This won't affect successful parses because COMPOUND_BODY will
be overwritten later.
Bootstrapped & regression tested on i686-pc-linux-gnu. OK for 3.4?
The test passes as-is on 4.0, and also passes on mainline with a
tweak to the expected error message. I'll apply the appropriate
testcase versions to 4.0 and mainline if the patch is OK for 3.4.
Richard
PR c/22458
* c-decl.c (c_begin_compound_stmt): Set the initial body to
error_mark_node, not NULL.
testsuite/
PR c/22458
* gcc.dg/pr22458-1.c: New test.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.470.4.21
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.470.4.21 c-decl.c
--- c-decl.c 28 Jul 2005 23:01:12 -0000 1.470.4.21
+++ c-decl.c 29 Jul 2005 10:23:24 -0000
@@ -6410,7 +6410,7 @@ c_begin_compound_stmt (void)
tree stmt;
/* Create the COMPOUND_STMT. */
- stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE));
+ stmt = add_stmt (build_stmt (COMPOUND_STMT, error_mark_node));
return stmt;
}
diff -u /dev/null testsuite/gcc.dg/pr22458-1.c
--- /dev/null 2005-06-16 22:49:09.000000000 +0100
+++ testsuite/gcc.dg/pr22458-1.c 2005-07-29 11:22:26.000000000 +0100
@@ -0,0 +1,4 @@
+/* { dg-error "(parse|syntax) error" "" { target *-*-* } 0 } */
+void foo()
+{
+ __PRETTY_FUNCTION__;