This is the mail archive of the
mailing list for the GCC project.
Re: [C PATCH] Fix C error-recovery (PR c/91192)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 31 Jul 2019 10:26:29 -0400
- Subject: Re: [C PATCH] Fix C error-recovery (PR c/91192)
- References: <20190730072200.GK15878@tucnak>
On Tue, Jul 30, 2019 at 09:22:00AM +0200, Jakub Jelinek wrote:
> 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 <email@example.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
> --- 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;