]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: for non-SSA-typed params, emit simple vars.
authorDavid Chase <drchase@google.com>
Tue, 20 Nov 2018 21:33:33 +0000 (16:33 -0500)
committerDavid Chase <drchase@google.com>
Wed, 21 Nov 2018 21:16:23 +0000 (21:16 +0000)
This case was missed entirely and caused such params to be
unprintable.  This change gives them stack addresses
for the entire function (which is correct).

Change-Id: Ia4f706450219e48bce65b6395d3d9792df142fb5
Reviewed-on: https://go-review.googlesource.com/c/150657
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
src/cmd/compile/internal/gc/pgen.go

index d567cfe14989b9885825cd43f99d8121a14bb1d2..bdc66f3e275a01f1d9bb5b2100a21d2b1a27f0fd 100644 (file)
@@ -441,55 +441,60 @@ func createSimpleVars(automDecls []*Node) ([]*Node, []*dwarf.Var, map[*Node]bool
                if n.IsAutoTmp() {
                        continue
                }
-               var abbrev int
-               offs := n.Xoffset
 
-               switch n.Class() {
-               case PAUTO:
-                       abbrev = dwarf.DW_ABRV_AUTO
-                       if Ctxt.FixedFrameSize() == 0 {
-                               offs -= int64(Widthptr)
-                       }
-                       if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) || objabi.GOARCH == "arm64" {
-                               // There is a word space for FP on ARM64 even if the frame pointer is disabled
-                               offs -= int64(Widthptr)
-                       }
+               decls = append(decls, n)
+               vars = append(vars, createSimpleVar(n))
+               selected[n] = true
+       }
+       return decls, vars, selected
+}
 
-               case PPARAM, PPARAMOUT:
-                       abbrev = dwarf.DW_ABRV_PARAM
-                       offs += Ctxt.FixedFrameSize()
-               default:
-                       Fatalf("createSimpleVars unexpected type %v for node %v", n.Class(), n)
+func createSimpleVar(n *Node) *dwarf.Var {
+       var abbrev int
+       offs := n.Xoffset
+
+       switch n.Class() {
+       case PAUTO:
+               abbrev = dwarf.DW_ABRV_AUTO
+               if Ctxt.FixedFrameSize() == 0 {
+                       offs -= int64(Widthptr)
+               }
+               if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) || objabi.GOARCH == "arm64" {
+                       // There is a word space for FP on ARM64 even if the frame pointer is disabled
+                       offs -= int64(Widthptr)
                }
 
-               selected[n] = true
-               typename := dwarf.InfoPrefix + typesymname(n.Type)
-               decls = append(decls, n)
-               inlIndex := 0
-               if genDwarfInline > 1 {
-                       if n.InlFormal() || n.InlLocal() {
-                               inlIndex = posInlIndex(n.Pos) + 1
-                               if n.InlFormal() {
-                                       abbrev = dwarf.DW_ABRV_PARAM
-                               }
+       case PPARAM, PPARAMOUT:
+               abbrev = dwarf.DW_ABRV_PARAM
+               offs += Ctxt.FixedFrameSize()
+       default:
+               Fatalf("createSimpleVar unexpected class %v for node %v", n.Class(), n)
+       }
+
+       typename := dwarf.InfoPrefix + typesymname(n.Type)
+       inlIndex := 0
+       if genDwarfInline > 1 {
+               if n.InlFormal() || n.InlLocal() {
+                       inlIndex = posInlIndex(n.Pos) + 1
+                       if n.InlFormal() {
+                               abbrev = dwarf.DW_ABRV_PARAM
                        }
                }
-               declpos := Ctxt.InnermostPos(n.Pos)
-               vars = append(vars, &dwarf.Var{
-                       Name:          n.Sym.Name,
-                       IsReturnValue: n.Class() == PPARAMOUT,
-                       IsInlFormal:   n.InlFormal(),
-                       Abbrev:        abbrev,
-                       StackOffset:   int32(offs),
-                       Type:          Ctxt.Lookup(typename),
-                       DeclFile:      declpos.RelFilename(),
-                       DeclLine:      declpos.RelLine(),
-                       DeclCol:       declpos.Col(),
-                       InlIndex:      int32(inlIndex),
-                       ChildIndex:    -1,
-               })
        }
-       return decls, vars, selected
+       declpos := Ctxt.InnermostPos(n.Pos)
+       return &dwarf.Var{
+               Name:          n.Sym.Name,
+               IsReturnValue: n.Class() == PPARAMOUT,
+               IsInlFormal:   n.InlFormal(),
+               Abbrev:        abbrev,
+               StackOffset:   int32(offs),
+               Type:          Ctxt.Lookup(typename),
+               DeclFile:      declpos.RelFilename(),
+               DeclLine:      declpos.RelLine(),
+               DeclCol:       declpos.Col(),
+               InlIndex:      int32(inlIndex),
+               ChildIndex:    -1,
+       }
 }
 
 // createComplexVars creates recomposed DWARF vars with location lists,
@@ -541,12 +546,15 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
        // If optimization is enabled, the list above will typically be
        // missing some of the original pre-optimization variables in the
        // function (they may have been promoted to registers, folded into
-       // constants, dead-coded away, etc). Here we add back in entries
+       // constants, dead-coded away, etc).  Input arguments not eligible
+       // for SSA optimization are also missing.  Here we add back in entries
        // for selected missing vars. Note that the recipe below creates a
        // conservative location. The idea here is that we want to
        // communicate to the user that "yes, there is a variable named X
        // in this function, but no, I don't have enough information to
        // reliably report its contents."
+       // For non-SSA-able arguments, however, the correct information
+       // is known -- they have a single home on the stack.
        for _, n := range dcl {
                if _, found := selected[n]; found {
                        continue
@@ -555,6 +563,18 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
                if c == '.' || n.Type.IsUntyped() {
                        continue
                }
+               if n.Class() == PPARAM && !canSSAType(n.Type) {
+                       // SSA-able args get location lists, and may move in and
+                       // out of registers, so those are handled elsewhere.
+                       // Autos and named output params seem to get handled
+                       // with VARDEF, which creates location lists.
+                       // Args not of SSA-able type are treated here; they
+                       // are homed on the stack in a single place for the
+                       // entire call.
+                       vars = append(vars, createSimpleVar(n))
+                       decls = append(decls, n)
+                       continue
+               }
                typename := dwarf.InfoPrefix + typesymname(n.Type)
                decls = append(decls, n)
                abbrev := dwarf.DW_ABRV_AUTO_LOCLIST