On Tue, Jul 30, 2019 at 09:22:00AM +0200, Jakub Jelinek wrote: > 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.
Makes sense. > 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? Ok, thanks. > 2019-07-30 Jakub Jelinek <ja...@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; > } Marek