Skip to content

Commit fce2a94

Browse files
committed
cmd/compile: fix buglet in inlined info abstract function dwarf-gen
When generating DWARF inlined info records, it's possible to have a local function whose only callsites are inlined away, meaning that we emit an abstract function DIE but no regular subprogram DIE. When emitting DWARF scope info we need to handle this case (specifically when scoping PCs, check for the case that the func in question has been entirely deleted). Fixes #44344. Change-Id: I9f5bc692f225aa4c5c23f7bd2e50bcf7fe4fc5f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/293309 TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Russ Cox <[email protected]> Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]>
1 parent 7764ee5 commit fce2a94

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cmd/compile/internal/dwarfgen/scope.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func assembleScopes(fnsym *obj.LSym, fn *ir.Func, dwarfVars []*dwarf.Var, varSco
3737
}
3838

3939
scopeVariables(dwarfVars, varScopes, dwarfScopes)
40-
scopePCs(fnsym, fn.Marks, dwarfScopes)
40+
if fnsym.Func().Text != nil {
41+
scopePCs(fnsym, fn.Marks, dwarfScopes)
42+
}
4143
return compactScopes(dwarfScopes)
4244
}
4345

test/fixedbugs/issue44344.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile
2+
3+
// Copyright 2021 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+
// Issue #44344: a crash in DWARF scope generation (trying to
8+
// scope the PCs of a function that was inlined away).
9+
10+
package main
11+
12+
func main() {
13+
pv := []int{3, 4, 5}
14+
if pv[1] != 9 {
15+
pv = append(pv, 9)
16+
}
17+
tryit := func() bool {
18+
lpv := len(pv)
19+
if lpv == 101 {
20+
return false
21+
}
22+
if worst := pv[pv[1]&1]; worst != 101 {
23+
return true
24+
}
25+
return false
26+
}()
27+
if tryit {
28+
println(pv[0])
29+
}
30+
}

0 commit comments

Comments
 (0)