Put check for EOF in parse_for and parse_if, else it results in segmentation fault.
eg: (if (0) <eof> Not sure why it segfaults. I got following back-trace (in gdb): #0 _cpp_lex_direct (pfile=pfile@entry=0x66f560) at ../../src/libcpp/lex.c:2183 #1 0x000000000041d50c in _cpp_lex_token (pfile=pfile@entry=0x66f560) at ../../src/libcpp/lex.c:2067 #2 0x000000000041d630 in cpp_peek_token (pfile=pfile@entry=0x66f560, index=index@entry=0) at ../../src/libcpp/lex.c:1986 #3 0x000000000040e315 in peek (r=<optimized out>) at ../../src/gcc/genmatch.c:1820 #4 parse_if (r=r@entry=0x66f560, simplifiers=...) at ../../src/gcc/genmatch.c:2176 #5 0x000000000040de30 in parse_pattern (r=0x66f560, simplifiers=...) at ../../src/gcc/genmatch.c:2207 #6 0x0000000000407738 in main (argc=6747488, argv=0x68b350) at ../../src/gcc/genmatch.c:2275 This patch fixes the seg-fault by explicitly checking for EOF in parse_if and parse_for, however I am not sure if this is the right approach to fix it. I suppose parse_pattern should give an error here, since it expects CPP_OPEN_PAREN but receives CPP_EOF. * genmatch.c (parse_if): Put check for EOF. (parse_for): Likewise. Thanks, Prathamesh
Index: genmatch.c =================================================================== --- genmatch.c (revision 213752) +++ genmatch.c (working copy) @@ -2137,7 +2137,9 @@ parse_for (cpp_reader *r, source_locatio const cpp_token *token = peek (r); if (token->type == CPP_CLOSE_PAREN) break; - + else if (token->type == CPP_EOF) + fatal_at (token, "missing ending ')' in for"); + vec<simplify *> for_simplifiers = vNULL; parse_pattern (r, for_simplifiers); @@ -2174,6 +2176,8 @@ parse_if (cpp_reader *r, vec<simplify *> const cpp_token *token = peek (r); if (token->type == CPP_CLOSE_PAREN) break; + else if (token->type == CPP_EOF) + fatal_at (token, "missing ending ')' in if"); parse_pattern (r, simplifiers); }