go/pointer: fix two crashes caused by 'print()'.

+ Test.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/173540043
This commit is contained in:
Alan Donovan 2014-11-20 13:33:20 -05:00
parent 4f9827a99d
commit ce7df396da
3 changed files with 7 additions and 2 deletions

View File

@ -525,7 +525,9 @@ func (a *analysis) genBuiltinCall(instr ssa.CallInstruction, cgn *cgnode) {
case "print": case "print":
// In the tests, the probe might be the sole reference // In the tests, the probe might be the sole reference
// to its arg, so make sure we create nodes for it. // 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": case "ssa:wrapnilchk":
a.copy(a.valueNode(instr.Value()), a.valueNode(call.Args[0]), 1) a.copy(a.valueNode(instr.Value()), a.valueNode(call.Args[0]), 1)

View File

@ -191,7 +191,8 @@ func doOneInput(input, filename string) bool {
for _, b := range fn.Blocks { for _, b := range fn.Blocks {
for _, instr := range b.Instrs { for _, instr := range b.Instrs {
if instr, ok := instr.(ssa.CallInstruction); ok { 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 probes[instr.Common()] = true
} }
} }

View File

@ -31,4 +31,6 @@ func main() {
// labels, even though it may contain pointers that do. // 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) // @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(i.(func(int) int)) // @pointsto main.incr
print() // regression test for crash
} }