aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/reader.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-08-18 03:53:58 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-08-18 17:26:17 +0000
commit07cf24bdfe55dd3493e580c67b5437a114df7658 (patch)
tree2f419f1ce5b784763cf16b072369fec53c238b52 /src/cmd/compile/internal/noder/reader.go
parentb23d469e854f36e5ba8c0de9b7406a81e82d15c1 (diff)
downloadgo-07cf24bdfe55dd3493e580c67b5437a114df7658.tar.xz
cmd/compile/internal/noder: set ir.Name.DictIndex for unified IR
For local variables of derived type, Delve relies on ir.Name.DictIndex being set to the type's rtype index within the function's dictionary. This CL implements that functionality within unified IR. Manually double checked that Delve behaves correctly, at least as far as I can tell from casual use. Specifically, I confirmed that running the test program from TestDictIndex, stepping into testfn, and then running `print mapvar` prints `map[int]main.CustomInt []`, which matches the behavior under GOEXPERIMENT=nounified. (Also compare that when ir.Name.DictIndex is *not* set by unified IR, `print mapvar` instead prints `map[int]go.shape.int []`.) Fixes #54514. Change-Id: I90d443945895abfba04dc018f15e00217930091c Reviewed-on: https://go-review.googlesource.com/c/go/+/424735 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
-rw-r--r--src/cmd/compile/internal/noder/reader.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index 9280232fc9..1acc8c7fb6 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -1490,7 +1490,7 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
if name.Sym().Name == dictParamName {
r.dictParam = name
} else {
- if ctxt == ir.PAUTO {
+ if r.synthetic == nil {
r.Sync(pkgbits.SyncAddLocal)
if r.p.SyncMarkers() {
want := r.Int()
@@ -1498,12 +1498,10 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
base.FatalfAt(name.Pos(), "locals table has desynced")
}
}
+ r.varDictIndex(name)
}
r.locals = append(r.locals, name)
-
- // TODO(go.dev/issue/54514): Set name.DictIndex for variables of
- // derived type and enable cmd/link/internal/ld.TestDictIndex.
}
name.SetUsed(true)
@@ -3062,6 +3060,17 @@ func (r *reader) rtype0(pos src.XPos) (typ *types.Type, rtype ir.Node) {
return
}
+// varDictIndex populates name.DictIndex if name is a derived type.
+func (r *reader) varDictIndex(name *ir.Name) {
+ if r.Bool() {
+ idx := 1 + r.dict.rtypesOffset() + r.Len()
+ if int(uint16(idx)) != idx {
+ base.FatalfAt(name.Pos(), "DictIndex overflow for %v: %v", name, idx)
+ }
+ name.DictIndex = uint16(idx)
+ }
+}
+
func (r *reader) itab(pos src.XPos) (typ *types.Type, typRType ir.Node, iface *types.Type, ifaceRType ir.Node, itab ir.Node) {
if r.Bool() { // derived types
idx := r.Len()