This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: gcc's C parser bitten by error recovery changes in bison 1.50
>>>>> "Zack" == Zack Weinberg <zack@codesourcery.com> writes:
>> Wow... I do hope that you don't care :( But if you really do want
>> to do that, you want to apply a patch similar to the reverse of:
Zack> Um, I think you misunderstand. Assuming that we care, I don't
Zack> want to change bison.simple. I want to adjust the rules in
Zack> GCC's .y file so that it behaves the same way under both error
Zack> recovery schemes.
Ah, yes, I misunderstood, sorry.
Well, I don't know. I suppose the best means to ``fix'' this is to
introduce another error recovery rule. I managed to get the
following:
gcc/build/gcc % ./cc1 /tmp/foo.c nostromo 13:18
a_translate
/tmp/foo.c: Dans la fonction «a_translate»:
/tmp/foo.c:7: error: erreur d'analyse syntaxique before '{' token
/tmp/foo.c:11: error: `p_addr' undeclared (first use in this function)
/tmp/foo.c:11: error: (Each undeclared identifier is reported only once
/tmp/foo.c:11: error: for each function it appears in.)
Temps d'exécution (secondes)
parser : 0.01 (100%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
TOTAL : 0.01 0.01 0.25
gcc/build/gcc % LC_ALL=C ./cc1 /tmp/foo.c nostromo Err 1
a_translate
/tmp/foo.c: In function `a_translate':
/tmp/foo.c:7: error: parse error before '{' token
/tmp/foo.c:11: error: `p_addr' undeclared (first use in this function)
/tmp/foo.c:11: error: (Each undeclared identifier is reported only once
/tmp/foo.c:11: error: for each function it appears in.)
Execution times (seconds)
parser : 0.01 (50%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
TOTAL : 0.02 0.00 0.25
with the following code. Obviously, the code of my action is quire
random: I tried to use $$ = error_mark_node, but the compiler rejects
it later. So I copied the real code from do-while:
--- /tmp/c-parse.in.orig 2002-10-16 13:20:51.000000000 +0200
+++ c-parse.in 2002-10-16 13:17:58.000000000 +0200
@@ -2232,6 +2232,18 @@
c99_block_lineno_labeled_stmt WHILE
{ $$ = $<ttype>2;
RECHAIN_STMTS ($$, DO_BODY ($$)); }
+ |
+ DO error WHILE
+ { stmt_count++;
+ compstmt_count++;
+ $<ttype>$
+ = add_stmt (build_stmt (DO_STMT, NULL_TREE,
+ NULL_TREE));
+ /* In the event that a parse error prevents
+ parsing the complete do-statement, set the
+ condition now. Otherwise, we can get crashes at
+ RTL-generation time. */
+ DO_COND ($<ttype>$) = error_mark_node; }
;
/* The forced readahead in here is because we might be at the end of a