aboutsummaryrefslogtreecommitdiff
path: root/test/inline.go
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2020-12-14 10:03:05 -0500
committerKatie Hockman <katie@golang.org>2020-12-14 10:06:13 -0500
commit0345ede87ee12698988973884cfc0fd3d499dffd (patch)
tree7123cff141ee5661208d2f5f437b8f5252ac7f6a /test/inline.go
parent4651d6b267818b0e0d128a5443289717c4bb8cbc (diff)
parent0a02371b0576964e81c3b40d328db9a3ef3b031b (diff)
downloadgo-0345ede87ee12698988973884cfc0fd3d499dffd.tar.xz
[dev.fuzz] all: merge master into dev.fuzz
Change-Id: I5d8c8329ccc9d747bd81ade6b1cb7cb8ae2e94b2
Diffstat (limited to 'test/inline.go')
-rw-r--r--test/inline.go72
1 files changed, 68 insertions, 4 deletions
diff --git a/test/inline.go b/test/inline.go
index 0b3ad55d46..d754f06e03 100644
--- a/test/inline.go
+++ b/test/inline.go
@@ -10,7 +10,6 @@
package foo
import (
- "errors"
"runtime"
"unsafe"
)
@@ -50,7 +49,13 @@ func j(x int) int { // ERROR "can inline j"
}
}
-var somethingWrong error = errors.New("something went wrong")
+func _() int { // ERROR "can inline _"
+ tmp1 := h
+ tmp2 := tmp1
+ return tmp2(0) // ERROR "inlining call to h"
+}
+
+var somethingWrong error
// local closures can be inlined
func l(x, y int) (int, int, error) {
@@ -59,6 +64,9 @@ func l(x, y int) (int, int, error) {
}
if x == y {
e(somethingWrong) // ERROR "inlining call to l.func1"
+ } else {
+ f := e
+ f(nil) // ERROR "inlining call to l.func1"
}
return y, x, nil
}
@@ -144,8 +152,7 @@ func switchBreak(x, y int) int {
return n
}
-// can't currently inline functions with a type switch
-func switchType(x interface{}) int { // ERROR "x does not escape"
+func switchType(x interface{}) int { // ERROR "can inline switchType" "x does not escape"
switch x.(type) {
case int:
return x.(int)
@@ -198,3 +205,60 @@ func gg(x int) { // ERROR "can inline gg"
func hh(x int) { // ERROR "can inline hh"
ff(x - 1) // ERROR "inlining call to ff" // ERROR "inlining call to gg"
}
+
+// Issue #14768 - make sure we can inline for loops.
+func for1(fn func() bool) { // ERROR "can inline for1" "fn does not escape"
+ for {
+ if fn() {
+ break
+ } else {
+ continue
+ }
+ }
+}
+
+// BAD: for2 should be inlineable too.
+func for2(fn func() bool) { // ERROR "fn does not escape"
+Loop:
+ for {
+ if fn() {
+ break Loop
+ } else {
+ continue Loop
+ }
+ }
+}
+
+// Issue #18493 - make sure we can do inlining of functions with a method value
+type T1 struct{}
+
+func (a T1) meth(val int) int { // ERROR "can inline T1.meth" "inlining call to T1.meth"
+ return val + 5
+}
+
+func getMeth(t1 T1) func(int) int { // ERROR "can inline getMeth"
+ return t1.meth // ERROR "t1.meth escapes to heap"
+}
+
+func ii() { // ERROR "can inline ii"
+ var t1 T1
+ f := getMeth(t1) // ERROR "inlining call to getMeth" "t1.meth does not escape"
+ _ = f(3)
+}
+
+// Issue #42194 - make sure that functions evaluated in
+// go and defer statements can be inlined.
+func gd1(int) {
+ defer gd1(gd2()) // ERROR "inlining call to gd2"
+ defer gd3()() // ERROR "inlining call to gd3"
+ go gd1(gd2()) // ERROR "inlining call to gd2"
+ go gd3()() // ERROR "inlining call to gd3"
+}
+
+func gd2() int { // ERROR "can inline gd2"
+ return 1
+}
+
+func gd3() func() { // ERROR "can inline gd3"
+ return ii
+}