testIfaceEqual(io.EOF)
}
+var a bool
+
+//go:noinline
func testIfaceEqual(x interface{}) {
if x == "abc" {
- // Prevent inlining
- panic("")
+ a = true
}
}
}
}
+//go:noinline
func allocateTransient2M() {
- // prevent inlining
- if memSink == nil {
- panic("bad")
- }
memSink = make([]byte, 2<<20)
}
tests := []string{
fmt.Sprintf(`%v: %v \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-# 0x[0-9,a-f]+ runtime/pprof_test\.allocatePersistent1K\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:43
-# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:66
+# 0x[0-9,a-f]+ runtime/pprof_test\.allocatePersistent1K\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:40
+# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test\.go:63
`, 32*memoryProfilerRun, 1024*memoryProfilerRun, 32*memoryProfilerRun, 1024*memoryProfilerRun),
fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
# 0x[0-9,a-f]+ runtime/pprof_test\.allocateTransient1M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:21
-# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:64
+# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:61
`, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-# 0x[0-9,a-f]+ runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:30
-# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:65
+# 0x[0-9,a-f]+ runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:27
+# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:62
`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
}
x, y int
}
+//go:noinline
func (p InterImpl) Foo(x int) {
- // prevent inlining
- z := 42
- x = 85
- y := x / z
- z = y * z
- x = z * y
- _, _, _ = x, y, z
}
type InterImpl2 InterImpl
min, max Rect
}
+//go:noinline
func NewImage() Image {
- var pleaseDoNotInlineMe stack
- pleaseDoNotInlineMe.push(1)
- _ = pleaseDoNotInlineMe.pop()
return Image{}
}
var makeChanCalls int
+//go:noinline
func makeChan() *RpcChan {
- var pleaseDoNotInlineMe stack
- pleaseDoNotInlineMe.push(1)
- _ = pleaseDoNotInlineMe.pop()
-
makeChanCalls++
c := &RpcChan{make(chan bool, 1)}
c.c <- true
type T struct{}
+//go:noinline
func (T) cplx() complex128 {
- for false {
- } // avoid inlining
return complex(1, 0)
}
import "runtime"
-var c bool
-
+//go:noinline
func f() interface{} {
- if c { // disable inlining
- f()
- }
runtime.GC()
return nil
}
+//go:noinline
func g() {
- if c { // disable inlining
- g()
- }
var s interface{}
_ = func() {
s := f()
useiface(s)
}
+//go:noinline
func useiface(x interface{}) {
- if c { // disable inlining
- useiface(x)
- }
}
+//go:noinline
func h() {
- if c { // disable inlining
- h()
- }
var x [16]uintptr
for i := range x {
x[i] = 1
}
-
+
useint(x[0])
useint(x[1])
useint(x[2])
useint(x[3])
}
+//go:noinline
func useint(x uintptr) {
- if c { // disable inlining
- useint(x)
- }
}
func main() {
func big(x int) {
if x >= 0 {
- big(x-1)
+ big(x - 1)
}
}
foo(&f)
}
+//go:noinline
func foo(f *func()) func() {
- defer func() {}() // prevent inlining of foo
return *f
}
panic("bad")
}
}
+
+//go:noinline
func f1(v1 uint) uint {
- switch {
- } // prevent inlining
return v1 >> ((1 >> v1) + (1 >> v1))
}
package main
-func DontInline() {}
-
+//go:noinline
func F(e interface{}) (int, int) {
- DontInline()
return 3, 7
}
+//go:noinline
func G() (int, int) {
- DontInline()
return 3, 7
}
Pointer *int
}
-func dontinline() {}
-
+//go:noinline
func Store(t *T) {
global = t.Pointer
- dontinline()
}
+//go:noinline
func Store2(t *T) {
global2 = t.Pointer
- dontinline()
}
func Get() *int {
var P int
-var b bool
-
+//go:noinline
func F(x *int) string {
- if b { // avoid inlining
- F(x)
- }
P = 50
*x = 100
return fmt.Sprintln(P, *x)
type TI [3]uintptr
+//go:noinline
func G() (t TI) {
t[0] = 1
t[1] = 2
t[2] = 3
- runtime.GC() // prevent inlining
return
}
+//go:noinline
func F() (t T) {
t.X = newint()
t.Y = t.X
t.Z = t.Y
- runtime.GC() // prevent inlining
return
}
var xy string
+//go:noinline
func x() bool {
- for false {
- } // no inlining
xy += "x"
return false
}
+//go:noinline
func y() string {
- for false {
- } // no inlining
xy += "y"
return "abc"
}
log += "f(" + x + ", " + y + ")"
}
+//go:noinline
func ff(x, y string) {
- for false {
- } // prevent inl
log += "ff(" + x + ", " + y + ")"
}
return x
}
+//go:noinline
func g(x string) string {
- for false {
- } // prevent inl
log += "g(" + x + ")"
return x
}
err++
}
log = ""
-
+
x := 0
switch x {
case 0:
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in switch, expecting a(1)b(2)a(2), got ", log)
err++
}
log = ""
}
-
+
c := make(chan int, 1)
c <- 1
select {
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in select1, expecting a(1)b(2)a(2), got ", log)
err++
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in select2, expecting a(1)b(2)a(2), got ", log)
err++
c <- 1
select {
default:
- case c<-1:
+ case c <- 1:
case <-c:
if a("1")("2")("3"); log != "a(1)a(2)a(3)" {
println("in select3, expecting a(1)a(2)a(3) , got ", log)
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in select3, expecting a(1)b(2)a(2), got ", log)
err++
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in select4, expecting a(1)b(2)a(2), got ", log)
err++
err++
}
log = ""
-
+
if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
println("in select5, expecting a(1)b(2)a(2), got ", log)
err++