]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: simplify dwarfgen.declPos
authorMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 10:23:48 +0000 (02:23 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 11:30:20 +0000 (11:30 +0000)
The previous code was way overcomplicating things. To find out if a
variable is a closure pseudo-variable, one only needs to check
IsClosureVar. Checking Captured and Byval are only meant to be used by
closure conversion.

Passes toolstash -cmp.

Change-Id: I22622cba36ba7f60b3275d17999a8b6bb7c6719a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280995
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

index 42c83b1f239e50cd3e292a45fdb02832ffb5d0f3..6eac9d547e4e6b3a41e8aee28ad9554e93bb9fee 100644 (file)
@@ -127,22 +127,8 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
 }
 
 func declPos(decl *ir.Name) src.XPos {
-       if decl.Defn != nil && (decl.Captured() || decl.Byval()) {
-               // It's not clear which position is correct for captured variables here:
-               // * decl.Pos is the wrong position for captured variables, in the inner
-               //   function, but it is the right position in the outer function.
-               // * decl.Name.Defn is nil for captured variables that were arguments
-               //   on the outer function, however the decl.Pos for those seems to be
-               //   correct.
-               // * decl.Name.Defn is the "wrong" thing for variables declared in the
-               //   header of a type switch, it's their position in the header, rather
-               //   than the position of the case statement. In principle this is the
-               //   right thing, but here we prefer the latter because it makes each
-               //   instance of the header variable local to the lexical block of its
-               //   case statement.
-               // This code is probably wrong for type switch variables that are also
-               // captured.
-               return decl.Defn.Pos()
+       if decl.IsClosureVar() {
+               decl = decl.Defn.(*ir.Name)
        }
        return decl.Pos()
 }