This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
patch gcj front end bug (switch without default)
- From: Per Bothner <per at bothner dot com>
- To: tromey at redhat dot com
- Cc: Java Discuss List <java at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Sun, 09 Dec 2001 20:29:05 -0800
- Subject: patch gcj front end bug (switch without default)
- References: <87wuzx9ies.fsf@creche.redhat.com>
Tom Tromey found a bug in the define assignment code, where we
did not properly handle a switch statement without an explicit
default handler. This should fix it. I've checked it into the
trunk.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
2001-12-09 Per Bothner <per@bothner.com>
* check-init.c (current_switch_has_default): New static field.
(check_init): Case DEFAULT_EXPR: Set current_switch_has_default.
Case SWITCH_EXPR: Save/restore current_switch_has_default. If no
DEFAULT_EXPR seen, simulate a default alternative that copies state.
Index: check-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/check-init.c,v
retrieving revision 1.38
diff -u -p -r1.38 check-init.c
--- check-init.c 2001/12/09 23:43:19 1.38
+++ check-init.c 2001/12/10 04:15:20
@@ -429,6 +429,9 @@ struct alternatives
struct alternatives * alternatives = NULL;
+/* True if we've seen a DEFAULT_EXPR for the current SWITCH_EXPR. */
+static int current_switch_has_default;
+
/* Begin handling a control flow branch.
BEFORE is the state of [un]assigned variables on entry.
CURRENT is a struct alt to manage the branch alternatives. */
@@ -686,7 +689,9 @@ check_init (exp, before)
case SWITCH_EXPR:
{
struct alternatives alt;
+ int saved_current_switch_has_default = current_switch_has_default;
word buf[2];
+ current_switch_has_default = 0;
check_init (TREE_OPERAND (exp, 0), before);
BEGIN_ALTERNATIVES (before, alt);
alt.saved = ALLOC_BUFFER(buf, num_current_words);
@@ -694,12 +699,19 @@ check_init (exp, before)
alt.block = exp;
check_init (TREE_OPERAND (exp, 1), before);
done_alternative (before, &alt);
+ if (! current_switch_has_default)
+ {
+ done_alternative (alt.saved, &alt);
+ }
FREE_BUFFER(alt.saved, buf);
END_ALTERNATIVES (before, alt);
+ current_switch_has_default = saved_current_switch_has_default;
return;
}
- case CASE_EXPR:
case DEFAULT_EXPR:
+ current_switch_has_default = 1;
+ /* .. then fall through ... */
+ case CASE_EXPR:
{
int i;
struct alternatives *alt = alternatives;