diff mbox series

[C] Fix C error-recovery (PR c/91192)

Message ID 20190730072200.GK15878@tucnak
State New
Headers show
Series [C] Fix C error-recovery (PR c/91192) | expand

Commit Message

Jakub Jelinek July 30, 2019, 7:22 a.m. UTC
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.


	Jakub

Comments

Marek Polacek July 31, 2019, 2:26 p.m. UTC | #1
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  <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;
>  }

Marek
diff mbox series

Patch

--- 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;
 }