From 38cb4c096637c1b067a7a759646ab9f792a11fa9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 13 Jun 2014 17:12:28 -0400 Subject: [PATCH] go.tools/go/ssa: record ast.CallExpr.Rparen as Alloc.Pos() for varargs arrays. + pointer analysis test-case. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/108980043 --- go/pointer/testdata/func.go | 5 +++++ go/ssa/builder.go | 2 +- go/ssa/ssa.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/go/pointer/testdata/func.go b/go/pointer/testdata/func.go index 8ffb8c74865..c2ab58f8187 100644 --- a/go/pointer/testdata/func.go +++ b/go/pointer/testdata/func.go @@ -152,6 +152,10 @@ func func7() { // @calls main.func7 -> (main.D).f$thunk } +func func8(x ...int) { + print(&x[0]) // @pointsto varargs[*]@varargs:15 +} + func main() { func1() func2() @@ -160,6 +164,7 @@ func main() { func5() func6() func7() + func8(1, 2, 3) // @line varargs } // @calls -> main.main diff --git a/go/ssa/builder.go b/go/ssa/builder.go index 7f6f2c7b986..4007dc1c19e 100644 --- a/go/ssa/builder.go +++ b/go/ssa/builder.go @@ -854,8 +854,8 @@ func (b *builder) emitCallArgs(fn *Function, sig *types.Signature, e *ast.CallEx } else { // Replace a suffix of args with a slice containing it. at := types.NewArray(vt, int64(len(varargs))) - // Don't set pos for implicit Allocs. a := emitNew(fn, at, token.NoPos) + a.setPos(e.Rparen) a.Comment = "varargs" for i, arg := range varargs { iaddr := &IndexAddr{ diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go index ce23bbd54ad..404bf92eb3f 100644 --- a/go/ssa/ssa.go +++ b/go/ssa/ssa.go @@ -474,7 +474,7 @@ type Builtin struct { // instantiate these types. // // Pos() returns the ast.CompositeLit.Lbrace for a composite literal, -// or the ast.CallExpr.Lparen for a call to new() or for a call that +// or the ast.CallExpr.Rparen for a call to new() or for a call that // allocates a varargs slice. // // Example printed form: