Commit 88d2f911 authored by Keith Randall's avatar Keith Randall

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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent d586aae1
...@@ -2788,9 +2788,15 @@ func (s *state) call(n *Node, k callKind) *ssa.Value { ...@@ -2788,9 +2788,15 @@ func (s *state) call(n *Node, k callKind) *ssa.Value {
sym = fn.Sym sym = fn.Sym
break 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 := newname(fn.Sym)
n2.Class = PFUNC n2.Class = PFUNC
n2.Lineno = fn.Lineno 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) closure = s.expr(n2)
// Note: receiver is already assigned in n.List, so we don't // Note: receiver is already assigned in n.List, so we don't
// want to set it here. // want to set it here.
......
...@@ -1141,6 +1141,9 @@ func ptrto(t *Type) *Type { ...@@ -1141,6 +1141,9 @@ func ptrto(t *Type) *Type {
if Tptr == 0 { if Tptr == 0 {
Fatalf("ptrto: no tptr") Fatalf("ptrto: no tptr")
} }
if t == nil {
Fatalf("ptrto: nil ptr")
}
// Reduce allocations by pre-creating common cases. // Reduce allocations by pre-creating common cases.
if !initPtrtoDone { if !initPtrtoDone {
initPtrto() initPtrto()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment