diff mbox

C PATCH for c/71853 (ICE with uninitialized memory on invalid)

Message ID 20160727215056.GB7007@redhat.com
State New
Headers show

Commit Message

Marek Polacek July 27, 2016, 9:50 p.m. UTC
This testcase was breaking because we were using uninitialized memory
coming from c_expr in c_parser_switch_statement.  There, in case we hadn't
seen '(' after switch, we called c_finish_case with uninitialized CE.
Fixed thus.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-07-27  Marek Polacek  <polacek@redhat.com>

	PR c/71853
	* c-parser.c (c_parser_switch_statement): Initialize ce.original_type
	to error node for invalid code.

	* gcc.dg/noncompile/pr71853.c: New test.


	Marek

Comments

Marek Polacek July 28, 2016, 10:17 a.m. UTC | #1
On Wed, Jul 27, 2016 at 11:50:56PM +0200, Marek Polacek wrote:
> This testcase was breaking because we were using uninitialized memory
> coming from c_expr in c_parser_switch_statement.  There, in case we hadn't
> seen '(' after switch, we called c_finish_case with uninitialized CE.
> Fixed thus.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2016-07-27  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/71853
> 	* c-parser.c (c_parser_switch_statement): Initialize ce.original_type
> 	to error node for invalid code.
> 
> 	* gcc.dg/noncompile/pr71853.c: New test.
> 
> diff --git gcc/c/c-parser.c gcc/c/c-parser.c
> index 8952bca..3679654 100644
> --- gcc/c/c-parser.c
> +++ gcc/c/c-parser.c
> @@ -5661,6 +5661,7 @@ c_parser_switch_statement (c_parser *parser, bool *if_p)
>      {
>        switch_cond_loc = UNKNOWN_LOCATION;
>        expr = error_mark_node;
> +      ce.original_type = error_mark_node;
>      }
>    c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
>    save_break = c_break_label;
> diff --git gcc/testsuite/gcc.dg/noncompile/pr71853.c gcc/testsuite/gcc.dg/noncompile/pr71853.c
> index e69de29..e049c8e 100644
> --- gcc/testsuite/gcc.dg/noncompile/pr71853.c
> +++ gcc/testsuite/gcc.dg/noncompile/pr71853.c
> @@ -0,0 +1,9 @@
> +/* PR c/71426 */

Bad PR number.  Fixed in my local copy.

	Marek
Jeff Law July 29, 2016, 3:36 p.m. UTC | #2
On 07/27/2016 03:50 PM, Marek Polacek wrote:
> This testcase was breaking because we were using uninitialized memory
> coming from c_expr in c_parser_switch_statement.  There, in case we hadn't
> seen '(' after switch, we called c_finish_case with uninitialized CE.
> Fixed thus.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-07-27  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/71853
> 	* c-parser.c (c_parser_switch_statement): Initialize ce.original_type
> 	to error node for invalid code.
>
> 	* gcc.dg/noncompile/pr71853.c: New test.
OK.
jeff
diff mbox

Patch

diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 8952bca..3679654 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -5661,6 +5661,7 @@  c_parser_switch_statement (c_parser *parser, bool *if_p)
     {
       switch_cond_loc = UNKNOWN_LOCATION;
       expr = error_mark_node;
+      ce.original_type = error_mark_node;
     }
   c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
   save_break = c_break_label;
diff --git gcc/testsuite/gcc.dg/noncompile/pr71853.c gcc/testsuite/gcc.dg/noncompile/pr71853.c
index e69de29..e049c8e 100644
--- gcc/testsuite/gcc.dg/noncompile/pr71853.c
+++ gcc/testsuite/gcc.dg/noncompile/pr71853.c
@@ -0,0 +1,9 @@ 
+/* PR c/71426 */
+/* { dg-do compile } */
+
+void f (void)
+{
+  case (0) { /* { dg-error "expected" } */
+    switch 0: { } /* { dg-error "expected" } */
+  }
+}