Debian Codegraph @

go/ssa/interp/testdata/fixedbugs/issue69929.go

raw symbols SCIP
1 package main
2
3 // This is a regression test for a bug (#69929) in
4 // the SSA interpreter in which it would not execute phis in parallel.
5 //
6 // The insert function below has interdependent phi nodes:
7 //
8 // entry:
9 // t0 = *root // t0 is x or y before loop
10 // jump test
11 // body:
12 // print(t5) // t5 is x at loop entry
13 // t3 = t5.Child // t3 is x after loop
14 // jump test
15 // test:
16 // t5 = phi(t0, t3) // t5 is x at loop entry
17 // t6 = phi(t0, t5) // t6 is y at loop entry
18 // if t5 != nil goto body else done
19 // done:
20 // print(t6)
21 // return
22 //
23 // The two phis:
24 //
25 // t5 = phi(t0, t3)
26 // t6 = phi(t0, t5)
27 //
28 // must be executed in parallel as if they were written in Go
29 // as:
30 //
31 // t5, t6 = phi(t0, t3), phi(t0, t5)
32 //
33 // with the second phi node observing the original, not
34 // updated, value of t5. (In more complex examples, the phi
35 // nodes may be mutually recursive, breaking partial solutions
36 // based on simple reordering of the phi instructions. See the
37 // Briggs paper for detail.)
38 //
39 // The correct behavior is print(1, root); print(2, root); print(3, root).
40 // The previous incorrect behavior had print(2, nil).
41
42 func main() {
43 insert()
44 print(3, root)
45 }
46
47 var root = new(node)
48
49 type node struct{ child *node }
50
51 func insert() {
52 x := root
53 y := x
54 for x != nil {
55 y = x
56 print(1, y)
57 x = x.child
58 }
59 print(2, y)
60 }
61
62 func print(order int, ptr *node) {
63 println(order, ptr)
64 if ptr != root {
65 panic(ptr)
66 }
67 }