Skip to content

Commit d767064

Browse files
jakebaileygopherbot
authored andcommitted
cmd/compile: mark abi.PtrType.Elem sym as used
CL 700336 let the compiler see into the abi.PtrType.Elem field, but forgot the MarkTypeSymUsedInInterface to ensure that the symbol is marked as referenced. I am not sure how to write a test for this, but I noticed this when working on further optimizations where I "fixed" this issue and confusingly failed toolstash -cmp, with diffs like: @@ -70582,6 +70582,7 @@ reflect.groupAndSlotOf<1> STEXT size=696 args=0x20 locals=0x1e0 funcid=0x0 align rel 3+0 t=R_USEIFACE type:*reflect.rtype<0>+0 rel 3+0 t=R_USEIFACE type:*reflect.rtype<0>+0 rel 3+0 t=R_USEIFACE type:*uint64<0>+0 + rel 3+0 t=R_USEIFACE type:uint64<0>+0 rel 71+0 t=R_CALLIND +0 rel 92+4 t=R_PCREL go:itab.*reflect.rtype,reflect.Type<0>+0 rel 114+4 t=R_CALL reflect.(*rtype).ptrTo<1>+0 Updates golang#75203 Change-Id: Ib8de8a32aeb8a7ea6fcf5d728a2e4944ef227ab2 Reviewed-on: https://go-review.googlesource.com/c/go/+/701296 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 0b1eed0 commit d767064

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/cmd/compile/internal/ssa/_gen/generic.rules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,10 +2778,10 @@
27782778
(Load <typ.Uintptr> (ITab (IMake (Convert (Addr {s} sb) _) _)) _) && isFixedSym(s, 0) => (Addr {fixedSym(b.Func, s, 0)} sb)
27792779

27802780
// Loading constant values from abi.PtrType.Elem.
2781-
(Load <t> (OffPtr [off] (Addr {s} sb) ) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(s, off)} sb)
2782-
(Load <t> (OffPtr [off] (Convert (Addr {s} sb) _) ) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(s, off)} sb)
2783-
(Load <t> (OffPtr [off] (ITab (IMake (Addr {s} sb) _))) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(s, off)} sb)
2784-
(Load <t> (OffPtr [off] (ITab (IMake (Convert (Addr {s} sb) _) _))) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(s, off)} sb)
2781+
(Load <t> (OffPtr [off] (Addr {s} sb) ) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(b.Func, s, off)} sb)
2782+
(Load <t> (OffPtr [off] (Convert (Addr {s} sb) _) ) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(b.Func, s, off)} sb)
2783+
(Load <t> (OffPtr [off] (ITab (IMake (Addr {s} sb) _))) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(b.Func, s, off)} sb)
2784+
(Load <t> (OffPtr [off] (ITab (IMake (Convert (Addr {s} sb) _) _))) _) && t.IsPtr() && isPtrElem(s, off) => (Addr {ptrElem(b.Func, s, off)} sb)
27852785

27862786
// Loading constant values from runtime._type.hash.
27872787
(Load <t> (OffPtr [off] (Addr {sym} _) ) _) && t.IsInteger() && t.Size() == 4 && isFixed32(config, sym, off) => (Const32 [fixed32(config, sym, off)])

src/cmd/compile/internal/ssa/rewrite.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,14 +2029,16 @@ func isPtrElem(sym Sym, off int64) bool {
20292029
}
20302030
return false
20312031
}
2032-
func ptrElem(sym Sym, off int64) Sym {
2032+
func ptrElem(f *Func, sym Sym, off int64) Sym {
20332033
lsym := sym.(*obj.LSym)
20342034
if strings.HasPrefix(lsym.Name, "type:*") {
20352035
if ti, ok := (*lsym.Extra).(*obj.TypeInfo); ok {
20362036
t := ti.Type.(*types.Type)
20372037
if t.Kind() == types.TPTR {
20382038
if off == rttype.PtrType.OffsetOf("Elem") {
2039-
return reflectdata.TypeLinksym(t.Elem())
2039+
elemSym := reflectdata.TypeLinksym(t.Elem())
2040+
reflectdata.MarkTypeSymUsedInInterface(elemSym, f.fe.Func().Linksym())
2041+
return elemSym
20402042
}
20412043
}
20422044
}

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)