go/ssa: use core type for field accesses
Change Field and FieldAddr to consistently use the core type
instead of the underlying type to determine if the address is a pointer
or not.
Change-Id: I9a5e31497c1ff4ca733848d7f2a51e5e83ace7e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/496215
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Tim King <taking@google.com>
diff --git a/go/ssa/builder_generic_test.go b/go/ssa/builder_generic_test.go
index 77de326..c86da0c 100644
--- a/go/ssa/builder_generic_test.go
+++ b/go/ssa/builder_generic_test.go
@@ -685,7 +685,7 @@
//@ instrs("f12", "*ssa.MakeMap", "make map[P]bool 1:int")
func f12[T any, P *struct{f T}](x T) map[P]bool { return map[P]bool{{}: true} }
- //@ instrs("f13", "&v[0:int]")
+ //@ instrs("f13", "*ssa.IndexAddr", "&v[0:int]")
//@ instrs("f13", "*ssa.Store", "*t0 = 7:int", "*v = *new(A):A")
func f13[A [3]int, PA *A](v PA) {
*v = A{7}
diff --git a/go/ssa/emit.go b/go/ssa/emit.go
index 80e30b6..fe2f6f0 100644
--- a/go/ssa/emit.go
+++ b/go/ssa/emit.go
@@ -476,7 +476,7 @@
// value of a field.
func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos) Value {
for _, index := range indices {
- if st, vptr := deptr(v.Type()); vptr {
+ if st, vptr := deref(v.Type()); vptr {
fld := fieldOf(st, index)
instr := &FieldAddr{
X: v,
@@ -486,7 +486,7 @@
instr.setType(types.NewPointer(fld.Type()))
v = f.emit(instr)
// Load the field's value iff indirectly embedded.
- if _, fldptr := deptr(fld.Type()); fldptr {
+ if _, fldptr := deref(fld.Type()); fldptr {
v = emitLoad(f, v)
}
} else {
@@ -510,7 +510,7 @@
// field's value.
// Ident id is used for position and debug info.
func emitFieldSelection(f *Function, v Value, index int, wantAddr bool, id *ast.Ident) Value {
- if st, vptr := deptr(v.Type()); vptr {
+ if st, vptr := deref(v.Type()); vptr {
fld := fieldOf(st, index)
instr := &FieldAddr{
X: v,
diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go
index eeb9681..313146d 100644
--- a/go/ssa/ssa.go
+++ b/go/ssa/ssa.go
@@ -865,7 +865,7 @@
type FieldAddr struct {
register
X Value // *struct
- Field int // field is typeparams.CoreType(X.Type().Underlying().(*types.Pointer).Elem()).(*types.Struct).Field(Field)
+ Field int // index into CoreType(CoreType(X.Type()).(*types.Pointer).Elem()).(*types.Struct).Fields
}
// The Field instruction yields the Field of struct X.
@@ -884,7 +884,7 @@
type Field struct {
register
X Value // struct
- Field int // index into typeparams.CoreType(X.Type()).(*types.Struct).Fields
+ Field int // index into CoreType(X.Type()).(*types.Struct).Fields
}
// The IndexAddr instruction yields the address of the element at