Commit 2ad1815d by Eric Botcazou Committed by Eric Botcazou

re PR c/9262 (ICE on false case label)

	PR c/9262
	* c-typeck.c (do_case): Attach the first case label to the SWITCH_BODY.
	(c_finish_case): Rechain the next statements to the SWITCH_STMT.

From-SVN: r63783
parent e2483ef7
2003-03-04 Eric Botcazou <ebotcazou@libertysurf.fr>
PR c/9262
* c-typeck.c (do_case): Attach the first case label to the SWITCH_BODY.
(c_finish_case): Rechain the next statements to the SWITCH_STMT.
Tue Mar 4 11:30:04 CET 2003 Jan Hubicka <jh@suse.cz> Tue Mar 4 11:30:04 CET 2003 Jan Hubicka <jh@suse.cz>
* doc/invoke.texi: Document that unit-at-a-time is enabled for -O3 * doc/invoke.texi: Document that unit-at-a-time is enabled for -O3
......
...@@ -7184,11 +7184,19 @@ do_case (low_value, high_value) ...@@ -7184,11 +7184,19 @@ do_case (low_value, high_value)
if (switch_stack) if (switch_stack)
{ {
bool switch_was_empty_p = (SWITCH_BODY (switch_stack->switch_stmt) == NULL_TREE);
label = c_add_case_label (switch_stack->cases, label = c_add_case_label (switch_stack->cases,
SWITCH_COND (switch_stack->switch_stmt), SWITCH_COND (switch_stack->switch_stmt),
low_value, high_value); low_value, high_value);
if (label == error_mark_node) if (label == error_mark_node)
label = NULL_TREE; label = NULL_TREE;
else if (switch_was_empty_p)
{
/* Attach the first case label to the SWITCH_BODY. */
SWITCH_BODY (switch_stack->switch_stmt) = TREE_CHAIN (switch_stack->switch_stmt);
TREE_CHAIN (switch_stack->switch_stmt) = NULL_TREE;
}
} }
else if (low_value) else if (low_value)
error ("case label not within a switch statement"); error ("case label not within a switch statement");
...@@ -7205,7 +7213,8 @@ c_finish_case () ...@@ -7205,7 +7213,8 @@ c_finish_case ()
{ {
struct c_switch *cs = switch_stack; struct c_switch *cs = switch_stack;
RECHAIN_STMTS (cs->switch_stmt, SWITCH_BODY (cs->switch_stmt)); /* Rechain the next statements to the SWITCH_STMT. */
last_tree = cs->switch_stmt;
/* Pop the stack. */ /* Pop the stack. */
switch_stack = switch_stack->next; switch_stack = switch_stack->next;
......
2003-03-04 Eric Botcazou <ebotcazou@libertysurf.fr>
* gcc.dg/switch-2.c: New test.
* gcc.dg/switch-3.c: New test.
* gcc.dg/Wswitch.c: Adjust line numbers.
* gcc.dg/Wswitch-default.c: Likewise.
* gcc.dg/Wswitch-enum.c: Likewise.
2003-03-04 Alexandre Oliva <aoliva@redhat.com> 2003-03-04 Alexandre Oliva <aoliva@redhat.com>
* gcc.c-torture/execute/20030222-1.c: New test. * gcc.c-torture/execute/20030222-1.c: New test.
......
...@@ -18,8 +18,8 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el, ...@@ -18,8 +18,8 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
case 4: return 3; case 4: return 3;
default: break; default: break;
} }
switch (ei) switch (ei) /* { dg-warning "switch missing default case" } */
{ /* { dg-warning "switch missing default case" } */ {
} }
switch (ej) switch (ej)
{ {
......
...@@ -19,9 +19,9 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el, ...@@ -19,9 +19,9 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
case 4: return 3; case 4: return 3;
default: break; default: break;
} }
switch (ei) switch (ei) /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" } */
{ /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" } */ { /* { dg-warning "enumeration value `e2' not handled in switch" "enum e2" { target *-*-* } 22 } */
} /* { dg-warning "enumeration value `e2' not handled in switch" "enum e2" { target *-*-* } 23 } */ }
switch (ej) switch (ej)
{ /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" { target *-*-* } 28 } */ { /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" { target *-*-* } 28 } */
default: break; default: break;
......
...@@ -19,9 +19,9 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el, ...@@ -19,9 +19,9 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
case 4: return 3; case 4: return 3;
default: break; default: break;
} }
switch (ei) switch (ei) /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" } */
{ /* { dg-warning "enumeration value `e1' not handled in switch" "enum e1" } */ { /*{ dg-warning "enumeration value `e2' not handled in switch" "enum e2" { target *-*-* } 22 } */
} /* { dg-warning "enumeration value `e2' not handled in switch" "enum e2" { target *-*-* } 23 } */ }
switch (ej) switch (ej)
{ {
default: break; default: break;
......
/* PR c/9262 */
/* Originator: Rasmus Hahn <rassahah@neofonie.de> */
/* { dg-do compile } */
int foo(int i)
{
switch (i)
case 3:
return 1,
} /* { dg-error "(parse|syntax) error" } */
/* PR c/9262 */
/* Originator: Rasmus Hahn <rassahah@neofonie.de> */
/* { dg-do compile } */
int foo(int i)
{
switch (i)
case 3:
return 1;
case 4: /* { dg-error "not within a switch statement" } */
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment