From: Keith Randall Date: Tue, 20 Sep 2016 23:34:30 +0000 (-0700) Subject: cmd/compile: fix type of static closure pointer X-Git-Tag: go1.8beta1~1192 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=88d2f9112a0a8afd3a29ac1479d4f17847f16803;p=gostls13.git cmd/compile: fix type of static closure pointer var x *X = ... defer x.foo() As part of the defer, we need to calculate &(*X).foo·f. This expression is the address of the static closure that will call (*X).foo when a pointer to that closure is used in a call/defer/go. This pointer is not currently properly typed in SSA. It is a pointer type, but the base type is nil, not a proper type. This turns out not to be a problem currently because we never use the type of these SSA values. But I'm trying to change that (to be able to spill them) in CL 28391. To fix, use uint8 as the fake type of the closure. Change-Id: Ieee388089c9af398ed772ee8c815122c347cb633 Reviewed-on: https://go-review.googlesource.com/29444 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index e0f6079837..a7a7de04c8 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -2788,9 +2788,15 @@ func (s *state) call(n *Node, k callKind) *ssa.Value { sym = fn.Sym break } + // Make a name n2 for the function. + // fn.Sym might be sync.(*Mutex).Unlock. + // Make a PFUNC node out of that, then evaluate it. + // We get back an SSA value representing &sync.(*Mutex).Unlock·f. + // We can then pass that to defer or go. n2 := newname(fn.Sym) n2.Class = PFUNC n2.Lineno = fn.Lineno + n2.Type = Types[TUINT8] // dummy type for a static closure. Could use runtime.funcval if we had it. closure = s.expr(n2) // Note: receiver is already assigned in n.List, so we don't // want to set it here. diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 53b0c9ad60..2c2e6ed1ef 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -1141,6 +1141,9 @@ func ptrto(t *Type) *Type { if Tptr == 0 { Fatalf("ptrto: no tptr") } + if t == nil { + Fatalf("ptrto: nil ptr") + } // Reduce allocations by pre-creating common cases. if !initPtrtoDone { initPtrto()