1
0
mirror of https://github.com/golang/go synced 2024-11-11 20:40:21 -07:00

test: use go:noinline consistently

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>
This commit is contained in:
Todd Neal 2015-10-29 21:45:19 -05:00
parent ebafc80eba
commit e3e0122ae2
14 changed files with 44 additions and 81 deletions

View 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
}
}

View 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),
}

View 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

View 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

View File

@ -9,9 +9,8 @@ package main
type T struct{}
//go:noinline
func (T) cplx() complex128 {
for false {
} // avoid inlining
return complex(1, 0)
}

View 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)
}
}

View File

@ -11,7 +11,7 @@ func bar() {
foo(&f)
}
//go:noinline
func foo(f *func()) func() {
defer func() {}() // prevent inlining of foo
return *f
}

View 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))
}

View File

@ -10,15 +10,13 @@
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
}

View 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 {

View 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)

View 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
}

View 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"
}

View 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++