aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/compile/internal/inline/inl.go14
-rw-r--r--test/fixedbugs/issue49145.go27
-rw-r--r--test/fixedbugs/issue49145.out3
3 files changed, 40 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index fb6cf53155..1ae6a58de0 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -1285,18 +1285,24 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
ir.EditChildren(m, subst.edit)
if subst.newclofn == nil {
- // Translate any label on FOR or RANGE loops
- if m.Op() == ir.OFOR {
+ // Translate any label on FOR, RANGE loops or SWITCH
+ switch m.Op() {
+ case ir.OFOR:
m := m.(*ir.ForStmt)
m.Label = translateLabel(m.Label)
return m
- }
- if m.Op() == ir.ORANGE {
+ case ir.ORANGE:
m := m.(*ir.RangeStmt)
m.Label = translateLabel(m.Label)
return m
+
+ case ir.OSWITCH:
+ m := m.(*ir.SwitchStmt)
+ m.Label = translateLabel(m.Label)
+ return m
}
+
}
switch m := m.(type) {
diff --git a/test/fixedbugs/issue49145.go b/test/fixedbugs/issue49145.go
new file mode 100644
index 0000000000..d66668196e
--- /dev/null
+++ b/test/fixedbugs/issue49145.go
@@ -0,0 +1,27 @@
+// run
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func f(j int) {
+loop:
+ switch j {
+ case 1:
+ break loop
+ default:
+ println(j)
+ }
+}
+
+func main() {
+loop:
+ for j := 0; j < 5; j++ {
+ f(j)
+ if j == 3 {
+ break loop
+ }
+ }
+}
diff --git a/test/fixedbugs/issue49145.out b/test/fixedbugs/issue49145.out
new file mode 100644
index 0000000000..1556c06ea8
--- /dev/null
+++ b/test/fixedbugs/issue49145.out
@@ -0,0 +1,3 @@
+0
+2
+3