This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Fix C error-recovery (PR c/91192)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Jul 2019 09:22:00 +0200
- Subject: [C PATCH] Fix C error-recovery (PR c/91192)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Neither c_expr_sizeof_expr nor c_expr_sizeof_type bother with filling up
the locations in c_expr struct they return. Normally, this isn't a problem,
as the sole caller of those calls set_c_expr_source_range. It doesn't call
it though if we reach CPP_EOF while parsing the sizeof expression.
Later on when the callers access the location info, it can randomly segfault
during error-recovery. The testcase is too obscure with too many errors to
include IMHO though, and as it only ICEs randomly, I'm not including it.
The fix is simple, just initialize the locations to something, doesn't
matter much exactly to what, this patch uses a range from start to start.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2019-07-30 Jakub Jelinek <jakub@redhat.com>
PR c/91192
* c-parser.c (c_parser_sizeof_expression): Call set_c_expr_source_range
even if finish is UNKNOWN_LOCATION, just use start as finish in that
case.
--- gcc/c/c-parser.c.jj 2019-07-19 20:53:42.121228422 +0200
+++ gcc/c/c-parser.c 2019-07-29 16:54:43.046562282 +0200
@@ -7477,8 +7477,9 @@ c_parser_sizeof_expression (c_parser *pa
error_at (expr_loc, "%<sizeof%> applied to a bit-field");
result = c_expr_sizeof_expr (expr_loc, expr);
}
- if (finish != UNKNOWN_LOCATION)
- set_c_expr_source_range (&result, start, finish);
+ if (finish == UNKNOWN_LOCATION)
+ finish = start;
+ set_c_expr_source_range (&result, start, finish);
return result;
}
Jakub