Skip to content

Commit 68a98d5

Browse files
committed
cmd/compile: better handling for PAUTOHEAP in DWARF inline gen
When generating DWARF inline info records, the post-SSA code looks through the original "pre-inline" dcl list for the function so as to handle situations where formal params are promoted or optimized away. This code was not properly handling the case where an output parameter was promoted to the heap -- in this case the param node is converted in place from class PPARAMOUT to class PAUTOHEAP. This caused inconsistencies later on, since the variable entry in the abstract subprogram DIE wound up as a local and not an output parameter. Fixes #30908. Change-Id: Ia70b89f0cf7f9b16246d95df17ad6e307228b8c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/168818 Reviewed-by: Cherry Zhang <cherryyz@google.com>
1 parent 9eef964 commit 68a98d5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls {
127127
DeclLine: v.DeclLine,
128128
DeclCol: v.DeclCol,
129129
}
130-
synthesized := strings.HasPrefix(v.Name, "~r") || canonName == "_"
130+
synthesized := strings.HasPrefix(v.Name, "~r") || canonName == "_" || strings.HasPrefix(v.Name, "~b")
131131
if idx, found := m[vp]; found {
132132
v.ChildIndex = int32(idx)
133133
v.IsInAbstract = !synthesized

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,22 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
593593
typename := dwarf.InfoPrefix + typesymname(n.Type)
594594
decls = append(decls, n)
595595
abbrev := dwarf.DW_ABRV_AUTO_LOCLIST
596+
isReturnValue := (n.Class() == PPARAMOUT)
596597
if n.Class() == PPARAM || n.Class() == PPARAMOUT {
597598
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
599+
} else if n.Class() == PAUTOHEAP {
600+
// If dcl in question has been promoted to heap, do a bit
601+
// of extra work to recover original class (auto or param);
602+
// see issue 30908. This insures that we get the proper
603+
// signature in the abstract function DIE, but leaves a
604+
// misleading location for the param (we want pointer-to-heap
605+
// and not stack).
606+
// TODO(thanm): generate a better location expression
607+
stackcopy := n.Name.Param.Stackcopy
608+
if stackcopy != nil && (stackcopy.Class() == PPARAM || stackcopy.Class() == PPARAMOUT) {
609+
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
610+
isReturnValue = (stackcopy.Class() == PPARAMOUT)
611+
}
598612
}
599613
inlIndex := 0
600614
if genDwarfInline > 1 {
@@ -608,7 +622,7 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
608622
declpos := Ctxt.InnermostPos(n.Pos)
609623
vars = append(vars, &dwarf.Var{
610624
Name: n.Sym.Name,
611-
IsReturnValue: n.Class() == PPARAMOUT,
625+
IsReturnValue: isReturnValue,
612626
Abbrev: abbrev,
613627
StackOffset: int32(n.Xoffset),
614628
Type: Ctxt.Lookup(typename),

0 commit comments

Comments
 (0)