]> Cypherpunks repositories - gostls13.git/commitdiff
test: use go:noinline consistently
authorTodd Neal <todd@tneal.org>
Fri, 30 Oct 2015 02:45:19 +0000 (21:45 -0500)
committerTodd Neal <todd@tneal.org>
Tue, 3 Nov 2015 02:01:34 +0000 (02:01 +0000)
Replace various implementations of inlining prevention with
"go:noinline"

Change-Id: Iac90895c3a62d6f4b7a6c72e11e165d15a0abfa4
Reviewed-on: https://go-review.googlesource.com/16510
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

14 files changed:
src/runtime/gc_test.go
src/runtime/pprof/mprof_test.go
src/runtime/race/testdata/mop_test.go
src/runtime/race/testdata/regression_test.go
test/fixedbugs/bug401.go
test/fixedbugs/bug484.go
test/fixedbugs/issue10441.go
test/fixedbugs/issue12133.go
test/fixedbugs/issue4518.go
test/fixedbugs/issue4964.dir/a.go
test/fixedbugs/issue7995b.dir/x1.go
test/fixedbugs/issue8036.go
test/func8.go
test/reorder2.go

index 61bbc1494545dd7343ee2f31e5543d8a7404a683..ce61059e85fd1f5f4a7d1883ec7ab2d15fc51444 100644 (file)
@@ -511,9 +511,11 @@ func TestAssertE2T2Liveness(t *testing.T) {
        testIfaceEqual(io.EOF)
 }
 
+var a bool
+
+//go:noinline
 func testIfaceEqual(x interface{}) {
        if x == "abc" {
-               // Prevent inlining
-               panic("")
+               a = true
        }
 }
index ebf53dd66bdc562fb727282a94c9247667d0a904..d14fb5888ee1ed6d82e43203250d4dfdb5b44006 100644 (file)
@@ -22,11 +22,8 @@ func allocateTransient1M() {
        }
 }
 
+//go:noinline
 func allocateTransient2M() {
-       // prevent inlining
-       if memSink == nil {
-               panic("bad")
-       }
        memSink = make([]byte, 2<<20)
 }
 
@@ -76,18 +73,18 @@ func TestMemoryProfiler(t *testing.T) {
 
        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),
        }
 
index d7cbc98f95a2fce6ff22922849fbd053d0f8bcc8..c96acb9021309fecac67106e5ecb6340691f1844 100644 (file)
@@ -1356,14 +1356,8 @@ type InterImpl struct {
        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
index d461269d98225d3bf0471e7979399d3e52cde7cd..6a7802fb021d2bab34bf47758603b1fb289d3aaa 100644 (file)
@@ -65,10 +65,8 @@ type Image struct {
        min, max Rect
 }
 
+//go:noinline
 func NewImage() Image {
-       var pleaseDoNotInlineMe stack
-       pleaseDoNotInlineMe.push(1)
-       _ = pleaseDoNotInlineMe.pop()
        return Image{}
 }
 
@@ -113,11 +111,8 @@ type RpcChan struct {
 
 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
index 5589b5b1bb0a7f560aba44dc127e28bb8ac3bf29..c58e1ca40042eef7f25f8db42e4288ebfe8166de 100644 (file)
@@ -9,9 +9,8 @@ package main
 
 type T struct{}
 
+//go:noinline
 func (T) cplx() complex128 {
-       for false {
-       } // avoid inlining
        return complex(1, 0)
 }
 
index c664b83af313638969fab480ac4f09ebdb7696c9..7025affc2dc1ebff8e3c0b13077906845cc67164 100644 (file)
@@ -23,20 +23,14 @@ package main
 
 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()
@@ -47,31 +41,25 @@ func g() {
        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() {
@@ -85,6 +73,6 @@ func main() {
 
 func big(x int) {
        if x >= 0 {
-               big(x-1)
+               big(x - 1)
        }
 }
index 25832fac450f1b924c97ff730ddfd1ff6a760b77..9bc4948b15b2881f703389d68e1288f396814608 100644 (file)
@@ -11,7 +11,7 @@ func bar() {
        foo(&f)
 }
 
+//go:noinline
 func foo(f *func()) func() {
-       defer func() {}() // prevent inlining of foo
        return *f
 }
index 0b66c56a5164dc84b7ec77ef28afdc847d86b60c..7b02a47c7259381a563fc3e8e7df7a4a910e0c52 100644 (file)
@@ -19,8 +19,8 @@ func main() {
                panic("bad")
        }
 }
+
+//go:noinline
 func f1(v1 uint) uint {
-       switch {
-       } // prevent inlining
        return v1 >> ((1 >> v1) + (1 >> v1))
 }
index e64b069bb9915d6cc65279b5290177300f604f93..5c3a1782be149e12401a364b92278308a5e4b9ed 100644 (file)
 
 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
 }
 
index 2b9e44e351afb76c618f73758f5b7f2eb3f94e29..216f352ca959e5fb4e30744b2e8839154665c89f 100644 (file)
@@ -10,16 +10,14 @@ type T struct {
        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 {
index 075911b921c878b7817be7d654ceb420128c584e..bafecf52a9ce0d71db4f0cc9f52aa78a1344da72 100644 (file)
@@ -4,12 +4,8 @@ import "fmt"
 
 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)
index f32fde84ab334a33aca32e95159f9ebd9ca6ce44..f052cf9e5c80183e294210eaa0de6560abb43e73 100644 (file)
@@ -18,19 +18,19 @@ type T struct {
 
 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
 }
 
index 13051802ecdcdae043aad275a7096b85297263bd..09ca02081416fd44a00cd84c5c7de6fa52851ca8 100644 (file)
@@ -21,16 +21,14 @@ func g() int {
 
 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"
 }
index e56be2bc8017892f97b6c127f1292bbb917e80d3..3e87998ffe7445894db8c0a667910b41509f0d02 100644 (file)
@@ -58,9 +58,8 @@ func f(x, y string) {
        log += "f(" + x + ", " + y + ")"
 }
 
+//go:noinline
 func ff(x, y string) {
-       for false {
-       } // prevent inl
        log += "ff(" + x + ", " + y + ")"
 }
 
@@ -69,9 +68,8 @@ func h(x string) string {
        return x
 }
 
+//go:noinline
 func g(x string) string {
-       for false {
-       } // prevent inl
        log += "g(" + x + ")"
        return x
 }
@@ -167,7 +165,7 @@ func main() {
                err++
        }
        log = ""
-       
+
        x := 0
        switch x {
        case 0:
@@ -176,7 +174,7 @@ func main() {
                        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++
@@ -194,7 +192,7 @@ func main() {
                }
                log = ""
        }
-       
+
        c := make(chan int, 1)
        c <- 1
        select {
@@ -206,7 +204,7 @@ func main() {
                        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++
@@ -233,7 +231,7 @@ func main() {
                        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++
@@ -255,14 +253,14 @@ func main() {
        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++
@@ -290,7 +288,7 @@ func main() {
                        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++
@@ -318,7 +316,7 @@ func main() {
                        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++