// errorcheckwithauto -0 -m -d=inlfuncswithclosures=1
+//go:build !goexperiment.newinliner
+
// Copyright 2015 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.
return foo() // ERROR "inlining call to q.func1"
}
+func r(z int) int {
+ foo := func(x int) int { // ERROR "can inline r.func1" "func literal does not escape"
+ return x + z
+ }
+ bar := func(x int) int { // ERROR "func literal does not escape" "can inline r.func2"
+ return x + func(y int) int { // ERROR "can inline r.func2.1" "can inline r.r.func2.func3"
+ return 2*y + x*z
+ }(x) // ERROR "inlining call to r.func2.1"
+ }
+ return foo(42) + bar(42) // ERROR "inlining call to r.func1" "inlining call to r.func2" "inlining call to r.r.func2.func3"
+}
+
func s0(x int) int { // ERROR "can inline s0"
foo := func() { // ERROR "can inline s0.func1" "func literal does not escape"
x = x + 1
return "oh nose!"
}
}
+func switchConst4() { // ERROR "can inline switchConst4"
+ const intSize = 32 << (^uint(0) >> 63)
+ want := func() string { // ERROR "can inline switchConst4.func1"
+ switch intSize {
+ case 32:
+ return "32"
+ case 64:
+ return "64"
+ default:
+ panic("unreachable")
+ }
+ }() // ERROR "inlining call to switchConst4.func1"
+ _ = want
+}
func inlineRangeIntoMe(data []int) { // ERROR "can inline inlineRangeIntoMe" "data does not escape"
rangeFunc(data, 12) // ERROR "inlining call to rangeFunc"
if x < 0 {
return
}
- gg(x - 1)
+ gg(x - 1) // ERROR "inlining call to gg" "inlining call to hh"
}
func gg(x int) { // ERROR "can inline gg"
- hh(x - 1)
+ hh(x - 1) // ERROR "inlining call to hh" "inlining call to ff"
}
func hh(x int) { // ERROR "can inline hh"
- ff(x - 1) // ERROR "inlining call to ff" // ERROR "inlining call to gg"
+ ff(x - 1) // ERROR "inlining call to ff" "inlining call to gg"
}
// Issue #14768 - make sure we can inline for loops.
select2(x, y) // ERROR "inlining call to select2"
}
}
+
+// Issue #62211: inlining a function with unreachable "return"
+// statements could trip up phi insertion.
+func issue62211(x bool) { // ERROR "can inline issue62211"
+ if issue62211F(x) { // ERROR "inlining call to issue62211F"
+ }
+ if issue62211G(x) { // ERROR "inlining call to issue62211G"
+ }
+
+ // Initial fix CL caused a "non-monotonic scope positions" failure
+ // on code like this.
+ if z := 0; false {
+ panic(z)
+ }
+}
+
+func issue62211F(x bool) bool { // ERROR "can inline issue62211F"
+ if x || true {
+ return true
+ }
+ return true
+}
+
+func issue62211G(x bool) bool { // ERROR "can inline issue62211G"
+ if x || true {
+ return true
+ } else {
+ return true
+ }
+}