From 70692d3c5feb2dd71b19393c21d0746c21cec5e9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 13 Nov 2013 09:13:42 -0500 Subject: [PATCH] go.tools/pointer: fix constraint generation bug in *ssa.Select. The previous code assumed that each channel item contained one field. + regression test. R=crawshaw CC=golang-dev https://golang.org/cl/25480044 --- pointer/gen.go | 2 +- pointer/testdata/channels.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pointer/gen.go b/pointer/gen.go index 5a995342..89143c93 100644 --- a/pointer/gen.go +++ b/pointer/gen.go @@ -994,7 +994,7 @@ func (a *analysis) genInstr(cgn *cgnode, instr ssa.Instruction) { switch st.Dir { case ast.RECV: a.genLoad(cgn, recv, st.Chan, 0, elemSize) - recv++ + recv += nodeid(elemSize) case ast.SEND: a.genStore(cgn, st.Chan, a.valueNode(st.Send), 0, elemSize) diff --git a/pointer/testdata/channels.go b/pointer/testdata/channels.go index 001d7d23..db427d0b 100644 --- a/pointer/testdata/channels.go +++ b/pointer/testdata/channels.go @@ -90,9 +90,29 @@ func chan4() { } } +// Multi-word channel value in select with multiple receive cases. +// (Regtest for a crash.) +func chan5() { + type T struct { + x *int + y interface{} + } + ch := make(chan T) + ch <- T{new(int), incr} // @line ch5new + select { + case a := <-ch: + print(a.x) // @pointsto new@ch5new:13 + print(a.y) // @types func(x int) int + case b := <-ch: + print(b.x) // @pointsto new@ch5new:13 + print(b.y) // @types func(x int) int + } +} + func main() { chan1() chan2() chan3() chan4() + chan5() }