Skip to content

Commit 41eabc0

Browse files
randall77mvdan
authored andcommitted
cmd/compile: fix merge rules for panic calls
Use entire inlining call stack to decide whether two panic calls can be merged. We used to merge panic calls when only the leaf line numbers matched, but that leads to places higher up the call stack being merged incorrectly. Fixes #22083 Change-Id: Ia41400a80de4b6ecf3e5089abce0c42b65e9b38a Reviewed-on: https://go-review.googlesource.com/67632 Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent d851f10 commit 41eabc0

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/cmd/compile/internal/gc/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ type state struct {
277277

278278
type funcLine struct {
279279
f *obj.LSym
280-
file string
280+
base *src.PosBase
281281
line uint
282282
}
283283

@@ -3464,7 +3464,7 @@ func (s *state) check(cmp *ssa.Value, fn *obj.LSym) {
34643464
bNext := s.f.NewBlock(ssa.BlockPlain)
34653465
line := s.peekPos()
34663466
pos := Ctxt.PosTable.Pos(line)
3467-
fl := funcLine{f: fn, file: pos.Filename(), line: pos.Line()}
3467+
fl := funcLine{f: fn, base: pos.Base(), line: pos.Line()}
34683468
bPanic := s.panics[fl]
34693469
if bPanic == nil {
34703470
bPanic = s.f.NewBlock(ssa.BlockPlain)

test/fixedbugs/issue22083.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// run
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// The compiler was panicking on the wrong line number, where
8+
// the panic was occurring in an inlined call.
9+
10+
package main
11+
12+
import (
13+
"runtime/debug"
14+
"strings"
15+
)
16+
17+
type Wrapper struct {
18+
a []int
19+
}
20+
21+
func (w Wrapper) Get(i int) int {
22+
return w.a[i]
23+
}
24+
25+
func main() {
26+
defer func() {
27+
e := recover()
28+
if e == nil {
29+
panic("bounds check didn't fail")
30+
}
31+
stk := string(debug.Stack())
32+
if !strings.Contains(stk, "issue22083.go:40") {
33+
panic("wrong stack trace: " + stk)
34+
}
35+
}()
36+
foo := Wrapper{a: []int{0, 1, 2}}
37+
_ = foo.Get(0)
38+
_ = foo.Get(1)
39+
_ = foo.Get(2)
40+
_ = foo.Get(3) // stack trace should mention this line
41+
}

0 commit comments

Comments
 (0)