[gccgo] Fix type switches with multiple types in a case

Submitted by Ian Taylor on Nov. 11, 2010, 5:23 a.m.

Details

Message ID mcriq04tov9.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Nov. 11, 2010, 5:23 a.m.
I ran into a gccgo but in the handling of type switches in which there
are multiple types in a case but the case has no statements.  The code
was accidentally falling through into the next case even though there
was no fallthrough statement.  This patch fixes the problem.  Committed
to gccgo branch.

Ian

Patch hide | download patch | download mbox

diff -r ad0e2fe0513d go/statements.cc
--- a/go/statements.cc	Wed Nov 10 17:53:27 2010 -0800
+++ b/go/statements.cc	Wed Nov 10 21:09:59 2010 -0800
@@ -3649,19 +3649,24 @@ 
       b->add_statement(s);
     }
 
-  if (this->statements_ != NULL)
+  if (this->statements_ != NULL
+      || (!this->is_fallthrough_
+	  && stmts_label != NULL
+	  && *stmts_label != NULL))
     {
       gcc_assert(!this->is_fallthrough_);
       if (stmts_label != NULL && *stmts_label != NULL)
 	{
 	  gcc_assert(!this->is_default_);
-	  (*stmts_label)->set_location(this->statements_->start_location());
+	  if (this->statements_ != NULL)
+	    (*stmts_label)->set_location(this->statements_->start_location());
 	  Statement* s = Statement::make_unnamed_label_statement(*stmts_label);
 	  b->add_statement(s);
 	  *stmts_label = NULL;
 	}
-      b->add_statement(Statement::make_block_statement(this->statements_,
-						       loc));
+      if (this->statements_ != NULL)
+	b->add_statement(Statement::make_block_statement(this->statements_,
+							 loc));
     }
 
   if (this->is_fallthrough_)