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

login
register
mail settings
Submitter Ian Taylor
Date Nov. 11, 2010, 5:23 a.m.
Message ID <mcriq04tov9.fsf@google.com>
Download mbox | patch
Permalink /patch/70769/
State New
Headers show

Comments

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

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_)