diff --git a/go/pointer/gen.go b/go/pointer/gen.go index 9d8e2c1513c..ee680f6b1d2 100644 --- a/go/pointer/gen.go +++ b/go/pointer/gen.go @@ -1102,9 +1102,7 @@ func (a *analysis) makeCGNode(fn *ssa.Function, obj nodeid, callersite *callsite // or a library. // func (a *analysis) genRootCalls() *cgnode { - r := ssa.NewFunction("", new(types.Signature), "root of callgraph") - r.Prog = a.prog // hack. - r.String() // (asserts that it doesn't crash) + r := a.prog.NewFunction("", new(types.Signature), "root of callgraph") root := a.makeCGNode(r, 0, nil) // TODO(adonovan): make an ssa utility to construct an actual diff --git a/go/ssa/func.go b/go/ssa/func.go index 1bd24ec0bc9..5de5b61fc92 100644 --- a/go/ssa/func.go +++ b/go/ssa/func.go @@ -640,11 +640,11 @@ func (f *Function) newBasicBlock(comment string) *BasicBlock { return b } -// NewFunction returns a new synthetic Function instance with its name -// and signature fields set as specified. +// NewFunction returns a new synthetic Function instance belonging to +// prog, with its name and signature fields set as specified. // // The caller is responsible for initializing the remaining fields of -// the function object, e.g. Pkg, Prog, Params, Blocks. +// the function object, e.g. Pkg, Params, Blocks. // // It is practically impossible for clients to construct well-formed // SSA functions/packages/programs directly, so we assume this is the @@ -655,8 +655,8 @@ func (f *Function) newBasicBlock(comment string) *BasicBlock { // // TODO(adonovan): think harder about the API here. // -func NewFunction(name string, sig *types.Signature, provenance string) *Function { - return &Function{name: name, Signature: sig, Synthetic: provenance} +func (prog *Program) NewFunction(name string, sig *types.Signature, provenance string) *Function { + return &Function{Prog: prog, name: name, Signature: sig, Synthetic: provenance} } type extentNode [2]token.Pos diff --git a/go/ssa/interp/reflect.go b/go/ssa/interp/reflect.go index 53bc614ae7e..91a0b301599 100644 --- a/go/ssa/interp/reflect.go +++ b/go/ssa/interp/reflect.go @@ -491,9 +491,8 @@ func newMethod(pkg *ssa.Package, recvType types.Type, name string) *ssa.Function // now, we'll set it to always be false since we're only // concerned with rtype. Encapsulate this better. sig := types.NewSignature(nil, types.NewVar(token.NoPos, nil, "recv", recvType), nil, nil, false) - fn := ssa.NewFunction(name, sig, "fake reflect method") + fn := pkg.Prog.NewFunction(name, sig, "fake reflect method") fn.Pkg = pkg - fn.Prog = pkg.Prog return fn }