From 4c835f9169e2b1f98a9755724d1f46bf50566003 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 18 Jan 2021 09:42:53 +0700 Subject: [PATCH] [dev.regabi] cmd/compile: use LinksymOffsetExpr in TypePtr/ItabAddr Passes toolstash -cmp. Fixes #43737 Change-Id: I2d5228c0213b5f8742e3cea6fac9bc985b19d78c Reviewed-on: https://go-review.googlesource.com/c/go/+/284122 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Trust: Cuong Manh Le Reviewed-by: Matthew Dempsky --- .../compile/internal/reflectdata/reflect.go | 33 +++++-------------- src/cmd/compile/internal/staticinit/sched.go | 2 +- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index fe0bd269272..bd89b62ff5b 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -836,39 +836,22 @@ func TypeLinksym(t *types.Type) *obj.LSym { } func TypePtr(t *types.Type) *ir.AddrExpr { - s := TypeSym(t) - if s.Def == nil { - n := ir.NewNameAt(src.NoXPos, s) - n.SetType(types.Types[types.TUINT8]) - n.Class = ir.PEXTERN - n.SetTypecheck(1) - s.Def = n - } - - n := typecheck.NodAddr(ir.AsNode(s.Def)) - n.SetType(types.NewPtr(s.Def.Type())) - n.SetTypecheck(1) - return n + n := ir.NewLinksymExpr(base.Pos, TypeLinksym(t), types.Types[types.TUINT8]) + return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr) } func ITabAddr(t, itype *types.Type) *ir.AddrExpr { if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() || !itype.IsInterface() || itype.IsEmptyInterface() { base.Fatalf("ITabAddr(%v, %v)", t, itype) } - s := ir.Pkgs.Itab.Lookup(t.ShortString() + "," + itype.ShortString()) - if s.Def == nil { - n := typecheck.NewName(s) - n.SetType(types.Types[types.TUINT8]) - n.Class = ir.PEXTERN - n.SetTypecheck(1) - s.Def = n - itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: n.Linksym()}) + s, existed := ir.Pkgs.Itab.LookupOK(t.ShortString() + "," + itype.ShortString()) + if !existed { + itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: s.Linksym()}) } - n := typecheck.NodAddr(ir.AsNode(s.Def)) - n.SetType(types.NewPtr(s.Def.Type())) - n.SetTypecheck(1) - return n + lsym := s.Linksym() + n := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8]) + return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr) } // needkeyupdate reports whether map updates with t as a key diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go index cf1b4164627..f3ad82e7b60 100644 --- a/src/cmd/compile/internal/staticinit/sched.go +++ b/src/cmd/compile/internal/staticinit/sched.go @@ -344,7 +344,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty // Create a copy of l to modify while we emit data. // Emit itab, advance offset. - staticdata.InitAddr(l, loff, itab.X.(*ir.Name).Linksym()) + staticdata.InitAddr(l, loff, itab.X.(*ir.LinksymOffsetExpr).Linksym) // Emit data. if types.IsDirectIface(val.Type()) {