]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix type of static closure pointer
authorKeith Randall <khr@golang.org>
Tue, 20 Sep 2016 23:34:30 +0000 (16:34 -0700)
committerKeith Randall <khr@golang.org>
Thu, 22 Sep 2016 21:50:32 +0000 (21:50 +0000)
  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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/subr.go

index e0f60798373be9de7b540f9d140ccad03c17ccb1..a7a7de04c84947f24e0597397706e3400d8e84c3 100644 (file)
@@ -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.
index 53b0c9ad603b6cc94e85bed7cd688cf375628bc7..2c2e6ed1efbd6d547962eec2c9b9e79fc96f5e45 100644 (file)
@@ -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()