Skip to content

Commit 738ea2b

Browse files
committed
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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]> Run-TryBot: Tim King <[email protected]>
1 parent 2ec4299 commit 738ea2b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

go/ssa/builder_generic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func TestInstructionString(t *testing.T) {
685685
//@ instrs("f12", "*ssa.MakeMap", "make map[P]bool 1:int")
686686
func f12[T any, P *struct{f T}](x T) map[P]bool { return map[P]bool{{}: true} }
687687
688-
//@ instrs("f13", "&v[0:int]")
688+
//@ instrs("f13", "*ssa.IndexAddr", "&v[0:int]")
689689
//@ instrs("f13", "*ssa.Store", "*t0 = 7:int", "*v = *new(A):A")
690690
func f13[A [3]int, PA *A](v PA) {
691691
*v = A{7}

go/ssa/emit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func emitTailCall(f *Function, call *Call) {
476476
// value of a field.
477477
func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos) Value {
478478
for _, index := range indices {
479-
if st, vptr := deptr(v.Type()); vptr {
479+
if st, vptr := deref(v.Type()); vptr {
480480
fld := fieldOf(st, index)
481481
instr := &FieldAddr{
482482
X: v,
@@ -486,7 +486,7 @@ func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos)
486486
instr.setType(types.NewPointer(fld.Type()))
487487
v = f.emit(instr)
488488
// Load the field's value iff indirectly embedded.
489-
if _, fldptr := deptr(fld.Type()); fldptr {
489+
if _, fldptr := deref(fld.Type()); fldptr {
490490
v = emitLoad(f, v)
491491
}
492492
} else {
@@ -510,7 +510,7 @@ func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos)
510510
// field's value.
511511
// Ident id is used for position and debug info.
512512
func emitFieldSelection(f *Function, v Value, index int, wantAddr bool, id *ast.Ident) Value {
513-
if st, vptr := deptr(v.Type()); vptr {
513+
if st, vptr := deref(v.Type()); vptr {
514514
fld := fieldOf(st, index)
515515
instr := &FieldAddr{
516516
X: v,

go/ssa/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ type Slice struct {
865865
type FieldAddr struct {
866866
register
867867
X Value // *struct
868-
Field int // field is typeparams.CoreType(X.Type().Underlying().(*types.Pointer).Elem()).(*types.Struct).Field(Field)
868+
Field int // index into CoreType(CoreType(X.Type()).(*types.Pointer).Elem()).(*types.Struct).Fields
869869
}
870870

871871
// The Field instruction yields the Field of struct X.
@@ -884,7 +884,7 @@ type FieldAddr struct {
884884
type Field struct {
885885
register
886886
X Value // struct
887-
Field int // index into typeparams.CoreType(X.Type()).(*types.Struct).Fields
887+
Field int // index into CoreType(X.Type()).(*types.Struct).Fields
888888
}
889889

890890
// The IndexAddr instruction yields the address of the element at

0 commit comments

Comments
 (0)