Skip to content

Commit 2560a2c

Browse files
committed
update
Change-Id: I47372cc2a2f18fb843572757902b1730dd963bde
1 parent 372c5bb commit 2560a2c

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

src/cmd/compile/internal/base/debug.go

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type DebugFlags struct {
7575
WrapGlobalMapDbg int `help:"debug trace output for global map init wrapping"`
7676
WrapGlobalMapCtl int `help:"global map init wrap control (0 => default, 1 => off, 2 => stress mode, no size cutoff)"`
7777
ZeroCopy int `help:"enable zero-copy string->[]byte conversions" concurrent:"ok"`
78-
Testing int `help:"enable zero-copy string->[]byte conversions" concurrent:"ok"`
7978

8079
ConcurrentOk bool // true if only concurrentOk flags seen
8180
}

src/cmd/compile/internal/devirtualize/devirtualize.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ func StaticCall(call *ir.CallExpr) {
127127
// v.A()
128128
// v = &Impl{}
129129
//
130-
// Here in the devirtualizer, we determine the concrete type of v as beeing an *Impl, but
131-
// in can still be a nil interface, but we have not detected that. It is not a huge problem as
132-
// the v.(*Impl) type assertion that we make here would also have failed, but with a different
130+
// Here in the devirtualizer, we determine the concrete type of v as beeing an *Impl,
131+
// but in can still be a nil interface, we have not detected that. The v.(*Impl)
132+
// type assertion that we make here would also have failed, but with a different
133133
// panic "pkg.Iface is nil, not *pkg.Impl", where previously we would get a nil panic.
134134
// We fix this, by introducing an additional nilcheck on the itab.
135-
nilCheck := ir.NewUnaryExpr(call.Pos(), ir.OCHECKNIL, ir.NewUnaryExpr(call.Pos(), ir.OITAB, sel.X))
136-
dt.PtrInit().Append(typecheck.Stmt(nilCheck))
135+
dt.EmitItabNilCheck = true
136+
dt.SetPos(call.Pos())
137137
}
138138

139139
x := typecheck.XDotMethod(sel.Pos(), dt, sel.Sel, true)
@@ -174,14 +174,12 @@ func StaticCall(call *ir.CallExpr) {
174174
typecheck.FixMethodCall(call)
175175
}
176176

177-
// const concreteTypeDebug = false
178-
var concreteTypeDebug = false
177+
const concreteTypeDebug = false
179178

180179
// concreteType determines the concrete type of n, following OCONVIFACEs and type asserts.
181180
// Returns nil when the concrete type could not be determined, or when there are multiple
182181
// (different) types assigned to an interface.
183182
func concreteType(n ir.Node) (typ *types.Type) {
184-
concreteTypeDebug = base.Debug.Testing != 0
185183
return concreteType1(n, make(map[*ir.Name]*types.Type))
186184
}
187185

src/cmd/compile/internal/ir/expr.go

+3
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ type TypeAssertExpr struct {
677677

678678
// An internal/abi.TypeAssert descriptor to pass to the runtime.
679679
Descriptor *obj.LSym
680+
681+
// Emit a nilcheck on the Itab of X.
682+
EmitItabNilCheck bool
680683
}
681684

682685
func NewTypeAssertExpr(pos src.XPos, x Node, typ *types.Type) *TypeAssertExpr {

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

+11
Original file line numberDiff line numberDiff line change
@@ -5625,6 +5625,17 @@ func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Val
56255625
if n.ITab != nil {
56265626
targetItab = s.expr(n.ITab)
56275627
}
5628+
5629+
if n.EmitItabNilCheck {
5630+
typs := s.f.Config.Types
5631+
iface = s.newValue2(
5632+
ssa.OpIMake,
5633+
iface.Type,
5634+
s.nilCheck(s.newValue1(ssa.OpITab, typs.BytePtr, iface)),
5635+
s.newValue1(ssa.OpIData, typs.BytePtr, iface),
5636+
)
5637+
}
5638+
56285639
return s.dottype1(n.Pos(), n.X.Type(), n.Type(), iface, nil, target, targetItab, commaok, n.Descriptor)
56295640
}
56305641

0 commit comments

Comments
 (0)