Commit c08b01ec authored by David Chase's avatar David Chase

cmd/compile: fix panic-okay-to-inline change; adjust tests

This line of the inlining tuning experiment
https://go-review.googlesource.com/c/go/+/109918/1/src/cmd/compile/internal/gc/inl.go#347
was incorrectly rewritten in a later patch to use the call
cost, not the panic cost, and thus the inlining of panic
didn't occur when it should.  I discovered this when I
realized that tests should have failed, but didn't.

Fix is to make the correct change, and also to modify the
tests that this causes to fail.  One test now asserts the
new normal, the other calls "ppanic" instead which is
designed to behave like panic but not be inlined.

Change-Id: I423bb7f08bd66a70d999826dd9b87027abf34cdf
Reviewed-on: https://go-review.googlesource.com/116656
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent d09d7627
...@@ -352,7 +352,7 @@ func (v *hairyVisitor) visit(n *Node) bool { ...@@ -352,7 +352,7 @@ func (v *hairyVisitor) visit(n *Node) bool {
v.budget -= v.extraCallCost v.budget -= v.extraCallCost
case OPANIC: case OPANIC:
v.budget -= v.extraCallCost v.budget -= inlineExtraPanicCost
case ORECOVER: case ORECOVER:
// recover matches the argument frame pointer to find // recover matches the argument frame pointer to find
......
...@@ -538,7 +538,7 @@ func TestGdbPanic(t *testing.T) { ...@@ -538,7 +538,7 @@ func TestGdbPanic(t *testing.T) {
`main`, `main`,
} }
for _, name := range bt { for _, name := range bt {
s := fmt.Sprintf("#.* .* in main\\.%v", name) s := fmt.Sprintf("(#.* .* in )?main\\.%v", name)
re := regexp.MustCompile(s) re := regexp.MustCompile(s)
if found := re.Find(got) != nil; !found { if found := re.Find(got) != nil; !found {
t.Errorf("could not find '%v' in backtrace", s) t.Errorf("could not find '%v' in backtrace", s)
......
...@@ -15,12 +15,12 @@ func main() { ...@@ -15,12 +15,12 @@ func main() {
if x := func() int { // ERROR "can inline main.func1" if x := func() int { // ERROR "can inline main.func1"
return 1 return 1
}(); x != 1 { // ERROR "inlining call to main.func1" }(); x != 1 { // ERROR "inlining call to main.func1"
panic("x != 1") ppanic("x != 1")
} }
if x := func() int { // ERROR "can inline main.func2" "func literal does not escape" if x := func() int { // ERROR "can inline main.func2" "func literal does not escape"
return 1 return 1
}; x() != 1 { // ERROR "inlining call to main.func2" }; x() != 1 { // ERROR "inlining call to main.func2"
panic("x() != 1") ppanic("x() != 1")
} }
} }
...@@ -28,12 +28,12 @@ func main() { ...@@ -28,12 +28,12 @@ func main() {
if y := func(x int) int { // ERROR "can inline main.func3" if y := func(x int) int { // ERROR "can inline main.func3"
return x + 2 return x + 2
}(40); y != 42 { // ERROR "inlining call to main.func3" }(40); y != 42 { // ERROR "inlining call to main.func3"
panic("y != 42") ppanic("y != 42")
} }
if y := func(x int) int { // ERROR "can inline main.func4" "func literal does not escape" if y := func(x int) int { // ERROR "can inline main.func4" "func literal does not escape"
return x + 2 return x + 2
}; y(40) != 42 { // ERROR "inlining call to main.func4" }; y(40) != 42 { // ERROR "inlining call to main.func4"
panic("y(40) != 42") ppanic("y(40) != 42")
} }
} }
...@@ -45,7 +45,7 @@ func main() { ...@@ -45,7 +45,7 @@ func main() {
return x + 1 return x + 1
} }
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
} }
...@@ -58,7 +58,7 @@ func main() { ...@@ -58,7 +58,7 @@ func main() {
return x + 1 return x + 1
} }
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
}() }()
} }
...@@ -71,7 +71,7 @@ func main() { ...@@ -71,7 +71,7 @@ func main() {
return x + 1 return x + 1
}, 42 }, 42
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
} }
...@@ -84,7 +84,7 @@ func main() { ...@@ -84,7 +84,7 @@ func main() {
return x + 1 return x + 1
}, 42 }, 42
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
}() }()
} }
...@@ -93,13 +93,13 @@ func main() { ...@@ -93,13 +93,13 @@ func main() {
y := func(x int) int { // ERROR "can inline main.func11" "func literal does not escape" y := func(x int) int { // ERROR "can inline main.func11" "func literal does not escape"
return x + 2 return x + 2
} }
y, sink = func() (func(int)int, int) { // ERROR "func literal does not escape" y, sink = func() (func(int) int, int) { // ERROR "func literal does not escape"
return func(x int) int { // ERROR "can inline main.func12" "func literal escapes" return func(x int) int { // ERROR "can inline main.func12" "func literal escapes"
return x + 1 return x + 1
}, 42 }, 42
}() }()
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
} }
...@@ -114,7 +114,7 @@ func main() { ...@@ -114,7 +114,7 @@ func main() {
}, 42 }, 42
}() }()
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
}() }()
} }
...@@ -123,11 +123,11 @@ func main() { ...@@ -123,11 +123,11 @@ func main() {
y := func(x int) int { // ERROR "can inline main.func14" "func literal does not escape" y := func(x int) int { // ERROR "can inline main.func14" "func literal does not escape"
return x + 2 return x + 2
} }
y, ok = map[int]func(int)int { // ERROR "does not escape" y, ok = map[int]func(int) int{ // ERROR "does not escape"
0: func (x int) int { return x + 1 }, // ERROR "can inline main.func15" "func literal escapes" 0: func(x int) int { return x + 1 }, // ERROR "can inline main.func15" "func literal escapes"
}[0] }[0]
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
} }
...@@ -136,11 +136,11 @@ func main() { ...@@ -136,11 +136,11 @@ func main() {
y := func(x int) int { // ERROR "can inline main.func16.1" "func literal does not escape" y := func(x int) int { // ERROR "can inline main.func16.1" "func literal does not escape"
return x + 2 return x + 2
} }
y, ok = map[int]func(int) int{// ERROR "does not escape" y, ok = map[int]func(int) int{ // ERROR "does not escape"
0: func(x int) int { return x + 1 }, // ERROR "can inline main.func16.2" "func literal escapes" 0: func(x int) int { return x + 1 }, // ERROR "can inline main.func16.2" "func literal escapes"
}[0] }[0]
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
}() }()
} }
...@@ -149,11 +149,11 @@ func main() { ...@@ -149,11 +149,11 @@ func main() {
y := func(x int) int { // ERROR "can inline main.func17" "func literal does not escape" y := func(x int) int { // ERROR "can inline main.func17" "func literal does not escape"
return x + 2 return x + 2
} }
y, ok = interface{}(func (x int) int { // ERROR "can inline main.func18" "does not escape" y, ok = interface{}(func(x int) int { // ERROR "can inline main.func18" "does not escape"
return x + 1 return x + 1
}).(func(int)int) }).(func(int) int)
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
} }
...@@ -166,7 +166,7 @@ func main() { ...@@ -166,7 +166,7 @@ func main() {
return x + 1 return x + 1
}).(func(int) int) }).(func(int) int)
if y(40) != 41 { if y(40) != 41 {
panic("y(40) != 41") ppanic("y(40) != 41")
} }
}() }()
} }
...@@ -176,12 +176,12 @@ func main() { ...@@ -176,12 +176,12 @@ func main() {
if y := func() int { // ERROR "can inline main.func20" if y := func() int { // ERROR "can inline main.func20"
return x return x
}(); y != 42 { // ERROR "inlining call to main.func20" }(); y != 42 { // ERROR "inlining call to main.func20"
panic("y != 42") ppanic("y != 42")
} }
if y := func() int { // ERROR "can inline main.func21" "func literal does not escape" if y := func() int { // ERROR "can inline main.func21" "func literal does not escape"
return x return x
}; y() != 42 { // ERROR "inlining call to main.func21" }; y() != 42 { // ERROR "inlining call to main.func21"
panic("y() != 42") ppanic("y() != 42")
} }
} }
...@@ -192,14 +192,14 @@ func main() { ...@@ -192,14 +192,14 @@ func main() {
return x + y return x + y
}() // ERROR "inlining call to main.func22.1" }() // ERROR "inlining call to main.func22.1"
}(1); z != 43 { }(1); z != 43 {
panic("z != 43") ppanic("z != 43")
} }
if z := func(y int) int { // ERROR "func literal does not escape" if z := func(y int) int { // ERROR "func literal does not escape"
return func() int { // ERROR "can inline main.func23.1" return func() int { // ERROR "can inline main.func23.1"
return x + y return x + y
}() // ERROR "inlining call to main.func23.1" }() // ERROR "inlining call to main.func23.1"
}; z(1) != 43 { }; z(1) != 43 {
panic("z(1) != 43") ppanic("z(1) != 43")
} }
} }
...@@ -211,7 +211,7 @@ func main() { ...@@ -211,7 +211,7 @@ func main() {
}() // ERROR "inlining call to main.func24" "&a does not escape" }() // ERROR "inlining call to main.func24" "&a does not escape"
}() }()
if a != 2 { if a != 2 {
panic("a != 2") ppanic("a != 2")
} }
} }
...@@ -222,11 +222,11 @@ func main() { ...@@ -222,11 +222,11 @@ func main() {
b = 3 b = 3
}() // ERROR "inlining call to main.func25.1" "&b does not escape" }() // ERROR "inlining call to main.func25.1" "&b does not escape"
if b != 3 { if b != 3 {
panic("b != 3") ppanic("b != 3")
} }
}(b) }(b)
if b != 2 { if b != 2 {
panic("b != 2") ppanic("b != 2")
} }
} }
...@@ -236,12 +236,12 @@ func main() { ...@@ -236,12 +236,12 @@ func main() {
c = 4 c = 4
func() { // ERROR "func literal does not escape" func() { // ERROR "func literal does not escape"
if c != 4 { if c != 4 {
panic("c != 4") ppanic("c != 4")
} }
}() }()
}() }()
if c != 4 { if c != 4 {
panic("c != 4") ppanic("c != 4")
} }
} }
...@@ -256,7 +256,7 @@ func main() { ...@@ -256,7 +256,7 @@ func main() {
}(10) // ERROR "inlining call to main.func27.1.1" }(10) // ERROR "inlining call to main.func27.1.1"
}(100) }(100)
}(1000); r != 2350 { }(1000); r != 2350 {
panic("r != 2350") ppanic("r != 2350")
} }
} }
...@@ -274,10 +274,15 @@ func main() { ...@@ -274,10 +274,15 @@ func main() {
return a + c return a + c
}(100) + b }(100) + b
}(1000); r != 2350 { }(1000); r != 2350 {
panic("r != 2350") ppanic("r != 2350")
} }
if a != 2000 { if a != 2000 {
panic("a != 2000") ppanic("a != 2000")
} }
} }
} }
//go:noinline
func ppanic(s string) { // ERROR "leaking param: s"
panic(s)
}
...@@ -34,8 +34,8 @@ func f1() { ...@@ -34,8 +34,8 @@ func f1() {
func f2() {} // ERROR "can inline f2" func f2() {} // ERROR "can inline f2"
// No inline for panic, recover. // No inline for recover; panic now allowed to inline.
func f3() { panic(1) } func f3() { panic(1) } // ERROR "can inline f3"
func f4() { recover() } func f4() { recover() }
func f5() *byte { func f5() *byte {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment