1
0
mirror of https://github.com/golang/go synced 2024-11-26 13:08:08 -07:00

cmd/compile: deal with call.Use correctly for noder2, allow inlining of stenciled functions

The setting of n.Use for a call node in transformCall() (and previously
in Call()), was not corrrect, since it was trying to use the number of
results of the call, rather than whether the call result was actually
used. We are already setting n.Use to ir.CallUseStmt if the call node is
directly a statement, so we just need to initialize n.Use to
ir.CallExprStmt in Call(), which will get changed to ir.CallUseStmt at
the statement level if it's used as a statement.

Enable inlining of stenciled functions (just disabled for testing,
easier debugging). The above n.Use fix was required for the inlining
to work for two cases.

Change-Id: Ie4ef6cd53fd4b20a4f3be31e629280909a545b7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/305913
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Dan Scales 2021-03-30 16:03:26 -07:00
parent f2717b31b5
commit 6d2a557a4d
3 changed files with 3 additions and 7 deletions

View File

@ -87,6 +87,9 @@ func Binary(pos src.XPos, op ir.Op, typ *types.Type, x, y ir.Node) ir.Node {
func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool) ir.Node {
n := ir.NewCallExpr(pos, ir.OCALL, fun, args)
n.IsDDD = dots
// n.Use will be changed to ir.CallUseStmt in g.stmt() if this call is
// just a statement (any return values are ignored).
n.Use = ir.CallUseExpr
if fun.Op() == ir.OTYPE {
// Actually a type conversion, not a function call.

View File

@ -303,8 +303,6 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, targs []ir.No
ir.MarkFunc(newf.Nname)
newf.SetTypecheck(1)
newf.Nname.SetTypecheck(1)
// TODO(danscales) - remove later, but avoid confusion for now.
newf.Pragma = ir.Noinline
// Make sure name/type of newf is set before substituting the body.
newf.Body = subst.list(gf.Body)

View File

@ -143,11 +143,6 @@ func transformCall(n *ir.CallExpr) {
}
typecheckaste(ir.OCALL, n.X, n.IsDDD, t.Params(), n.Args)
if t.NumResults() == 0 {
n.Use = ir.CallUseStmt
return
}
n.Use = ir.CallUseExpr
if t.NumResults() == 1 {
n.SetType(l.Type().Results().Field(0).Type)