This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Fix handling of omitted expression in switch
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Fri, 28 Sep 2012 15:20:55 -0700
- Subject: Go patch committed: Fix handling of omitted expression in switch
In Go, if a switch statement omits the expression on which to switch, it
is taken to be the constant "true". I was simply testing that the cases
were boolean, which is not quite right, as it is valid to compare an
empty interface against "true". This patch to the Go frontend fixes the
problem. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.7 branch.
Ian
diff -r f2c5d044661e go/statements.cc
--- a/go/statements.cc Fri Sep 28 14:19:44 2012 -0700
+++ b/go/statements.cc Fri Sep 28 14:46:27 2012 -0700
@@ -3313,16 +3313,10 @@
p != this->cases_->end();
++p)
{
- Expression* this_cond;
- if (val_temp == NULL)
- this_cond = *p;
- else
- {
- Expression* ref = Expression::make_temporary_reference(val_temp,
- loc);
- this_cond = Expression::make_binary(OPERATOR_EQEQ, ref, *p, loc);
- }
-
+ Expression* ref = Expression::make_temporary_reference(val_temp,
+ loc);
+ Expression* this_cond = Expression::make_binary(OPERATOR_EQEQ, ref,
+ *p, loc);
if (cond == NULL)
cond = this_cond;
else
@@ -3866,15 +3860,12 @@
return Statement::make_statement(val, true);
}
- Temporary_statement* val_temp;
- if (this->val_ == NULL)
- val_temp = NULL;
- else
- {
- // var val_temp VAL_TYPE = VAL
- val_temp = Statement::make_temporary(NULL, this->val_, loc);
- b->add_statement(val_temp);
- }
+ // var val_temp VAL_TYPE = VAL
+ Expression* val = this->val_;
+ if (val == NULL)
+ val = Expression::make_boolean(true, loc);
+ Temporary_statement* val_temp = Statement::make_temporary(NULL, val, loc);
+ b->add_statement(val_temp);
this->clauses_->lower(b, val_temp, this->break_label());