This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 */
+/* { dg-do compile } */
+
+void f (void)
+{
+  case (0) { /* { dg-error "expected" } */
+    switch 0: { } /* { dg-error "expected" } */
+  }
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]