Skip to content

Commit a3bb28e

Browse files
nimelehindanscales
authored andcommitted
cmd/compile: allow inlining of ORANGE
Updates #14768 Change-Id: I33831f616eae5eeb099033e2b9cf90fa70d6ca86 Reviewed-on: https://go-review.googlesource.com/c/go/+/356869 Run-TryBot: Alberto Donizetti <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dan Scales <[email protected]> Trust: Dan Scales <[email protected]> Trust: Alberto Donizetti <[email protected]>
1 parent 2ff1074 commit a3bb28e

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

src/cmd/compile/internal/inline/inl.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
358358
return true
359359
}
360360

361-
case ir.ORANGE,
362-
ir.OSELECT,
361+
case ir.OSELECT,
363362
ir.OGO,
364363
ir.ODEFER,
365364
ir.ODCLTYPE, // can't print yet

test/fixedbugs/issue49100b.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// run
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
func r(j int) {
10+
loop:
11+
for i, c := range "goclang" {
12+
if i == 2 {
13+
continue loop
14+
}
15+
println(string(c))
16+
}
17+
}
18+
19+
func main() {
20+
loop:
21+
for j := 0; j < 4; j++ {
22+
r(j)
23+
if j == 0 {
24+
break loop
25+
}
26+
}
27+
}

test/fixedbugs/issue49100b.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
g
2+
o
3+
l
4+
a
5+
n
6+
g

test/inline.go

+13
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ func switchType(x interface{}) int { // ERROR "can inline switchType" "x does no
160160
}
161161
}
162162

163+
func inlineRangeIntoMe(data []int) { // ERROR "can inline inlineRangeIntoMe" "data does not escape"
164+
rangeFunc(data, 12) // ERROR "inlining call to rangeFunc"
165+
}
166+
167+
func rangeFunc(xs []int, b int) int { // ERROR "can inline rangeFunc" "xs does not escape"
168+
for i, x := range xs {
169+
if x == b {
170+
return i
171+
}
172+
}
173+
return -1
174+
}
175+
163176
type T struct{}
164177

165178
func (T) meth(int, int) {} // ERROR "can inline T.meth"

test/linkname.dir/linkname1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package x
22

3-
func indexByte(xs []byte, b byte) int { // ERROR "xs does not escape"
3+
func indexByte(xs []byte, b byte) int { // ERROR "xs does not escape" "can inline indexByte"
44
for i, x := range xs {
55
if x == b {
66
return i

0 commit comments

Comments
 (0)