Skip to content

Commit f45c07e

Browse files
committed
cmd/compile: fix regression in DWARF inlined routine variable tracking
Fix a bug in the code that generates the pre-inlined variable declaration table used as raw material for emitting DWARF inline routine records. The fix for issue 23704 altered the recipe for assigning file/line/col to variables in one part of the compiler, but didn't update a similar recipe in the code for variable tracking. Added a new test that should catch problems of a similar nature. Fixes #24460. Change-Id: I255c036637f4151aa579c0e21d123fd413724d61 Reviewed-on: https://go-review.googlesource.com/101676 Reviewed-by: Alessandro Arzilli <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent ae10914 commit f45c07e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ func unversion(name string) string {
209209
// Given a function that was inlined as part of the compilation, dig
210210
// up the pre-inlining DCL list for the function and create a map that
211211
// supports lookup of pre-inline dcl index, based on variable
212-
// position/name.
212+
// position/name. NB: the recipe for computing variable pos/file/line
213+
// needs to be kept in sync with the similar code in gc.createSimpleVars
214+
// and related functions.
213215
func makePreinlineDclMap(fnsym *obj.LSym) map[varPos]int {
214216
dcl := preInliningDcls(fnsym)
215217
m := make(map[varPos]int)
@@ -218,8 +220,8 @@ func makePreinlineDclMap(fnsym *obj.LSym) map[varPos]int {
218220
pos := Ctxt.InnermostPos(n.Pos)
219221
vp := varPos{
220222
DeclName: unversion(n.Sym.Name),
221-
DeclFile: pos.Base().SymFilename(),
222-
DeclLine: pos.Line(),
223+
DeclFile: pos.RelFilename(),
224+
DeclLine: pos.RelLine(),
223225
DeclCol: pos.Col(),
224226
}
225227
if _, found := m[vp]; found {

src/cmd/link/internal/ld/dwarf_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,27 @@ func main() {
620620
t.Fatalf("can't locate origin DIE at off %v", ooff)
621621
}
622622

623+
// Walk the children of the abstract subroutine. We expect
624+
// to see child variables there, even if (perhaps due to
625+
// optimization) there are no references to them from the
626+
// inlined subroutine DIE.
627+
absFcnIdx := ex.idxFromOffset(ooff)
628+
absFcnChildDies := ex.Children(absFcnIdx)
629+
if len(absFcnChildDies) != 2 {
630+
t.Fatalf("expected abstract function: expected 2 children, got %d children", len(absFcnChildDies))
631+
}
632+
formalCount := 0
633+
for _, absChild := range absFcnChildDies {
634+
if absChild.Tag == dwarf.TagFormalParameter {
635+
formalCount += 1
636+
continue
637+
}
638+
t.Fatalf("abstract function child DIE: expected formal, got %v", absChild.Tag)
639+
}
640+
if formalCount != 2 {
641+
t.Fatalf("abstract function DIE: expected 2 formals, got %d", formalCount)
642+
}
643+
623644
if exCount >= len(expectedInl) {
624645
t.Fatalf("too many inlined subroutines found in main.main")
625646
}

0 commit comments

Comments
 (0)