go/pointer: fix two crashes caused by 'print()'. + Test. LGTM=crawshaw R=crawshaw CC=golang-codereviews https://golang.org/cl/173540043
diff --git a/go/pointer/gen.go b/go/pointer/gen.go index 12f4d79..48ca368 100644 --- a/go/pointer/gen.go +++ b/go/pointer/gen.go
@@ -525,7 +525,9 @@ case "print": // In the tests, the probe might be the sole reference // to its arg, so make sure we create nodes for it. - a.valueNode(call.Args[0]) + if len(call.Args) > 0 { + a.valueNode(call.Args[0]) + } case "ssa:wrapnilchk": a.copy(a.valueNode(instr.Value()), a.valueNode(call.Args[0]), 1)
diff --git a/go/pointer/pointer_test.go b/go/pointer/pointer_test.go index aeffb5c..ed3ebb0 100644 --- a/go/pointer/pointer_test.go +++ b/go/pointer/pointer_test.go
@@ -191,7 +191,8 @@ for _, b := range fn.Blocks { for _, instr := range b.Instrs { if instr, ok := instr.(ssa.CallInstruction); ok { - if b, ok := instr.Common().Value.(*ssa.Builtin); ok && b.Name() == "print" { + call := instr.Common() + if b, ok := call.Value.(*ssa.Builtin); ok && b.Name() == "print" && len(call.Args) == 1 { probes[instr.Common()] = true } }
diff --git a/go/pointer/testdata/another.go b/go/pointer/testdata/another.go index 443c94d..12ed690 100644 --- a/go/pointer/testdata/another.go +++ b/go/pointer/testdata/another.go
@@ -31,4 +31,6 @@ // labels, even though it may contain pointers that do. print(i) // @pointsto makeinterface:func(x int) int | makeinterface:func(x int, y int) | makeinterface:func(int, int) | makeinterface:int | makeinterface:main.S print(i.(func(int) int)) // @pointsto main.incr + + print() // regression test for crash }