compiler: add break label in 1,2-case select statement lowering
CL 184998 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 CL fixes this, by
adding the label definition.
A test case is CL 185520.
Change-Id: I98d30f599f1c4c71b91724ac394b8761d1b70b7d
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/185519
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/statements.cc b/go/statements.cc
index 1e88fab..b0b576f 100644
--- a/go/statements.cc
+++ b/go/statements.cc
@@ -5855,6 +5855,10 @@
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 @@
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);
}