This patch by Cherry Zhang adds a break label when lowering a select
statement with one or two cases.  The earlier change
https://golang.org/cl/184998
(https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00322.html) added
optimizations for one- and two-case select statements.  But it didn't
handle break statement in the select case correctly.  Specifically, it
didn't add the label definition, so it could result in a dangling
goto.  This patch fixes this, by adding the label definition.  A test
case is https://golang.org/cl/185520.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 273307)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-7a8e10be0ddb8909ce25a264d03b24cee4df60cc
+170ecdf6b2eab8aac2b8c852fa95d3c36d6bf604
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/statements.cc
===================================================================
--- gcc/go/gofrontend/statements.cc     (revision 273307)
+++ gcc/go/gofrontend/statements.cc     (working copy)
@@ -5855,6 +5855,10 @@ Select_statement::lower_one_case(Block*
     Statement::make_block_statement(scase.statements(), scase.location());
   b->add_statement(bs);
 
+  Statement* label =
+    Statement::make_unnamed_label_statement(this->break_label());
+  b->add_statement(label);
+
   this->is_lowered_ = true;
   return Statement::make_block_statement(b, loc);
 }
@@ -5958,6 +5962,10 @@ Select_statement::lower_two_case(Block*
     Statement::make_if_statement(call, bchan, defcase.statements(), loc);
   b->add_statement(ifs);
 
+  Statement* label =
+    Statement::make_unnamed_label_statement(this->break_label());
+  b->add_statement(label);
+
   this->is_lowered_ = true;
   return Statement::make_block_statement(b, loc);
 }

Reply via email to