1
2
3
4
5 package ssacompile
6
7 import (
8 "testing"
9
10 "cmd/compile/internal/ssa/ssaop"
11 "cmd/compile/internal/types"
12 )
13
14 func TestWriteBarrierStoreOrder(t *testing.T) {
15
16 c := testConfig(t)
17 ptrType := c.config.Types.BytePtr
18 fun := c.Fun("entry",
19 Bloc("entry",
20 Valu("start", ssaop.OpInitMem, types.TypeMem, 0, nil),
21 Valu("sb", ssaop.OpSB, c.config.Types.Uintptr, 0, nil),
22 Valu("sp", ssaop.OpSP, c.config.Types.Uintptr, 0, nil),
23 Valu("v", ssaop.OpConstNil, ptrType, 0, nil),
24 Valu("addr1", ssaop.OpAddr, ptrType, 0, nil, "sb"),
25 Valu("wb2", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr1", "v", "wb1"),
26 Valu("wb1", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr1", "v", "start"),
27 Goto("exit")),
28 Bloc("exit",
29 Exit("wb2")))
30
31 CheckFunc(fun.f)
32 writebarrier(fun.f)
33 CheckFunc(fun.f)
34 }
35
36 func TestWriteBarrierPhi(t *testing.T) {
37
38
39
40 c := testConfig(t)
41 ptrType := c.config.Types.BytePtr
42 fun := c.Fun("entry",
43 Bloc("entry",
44 Valu("start", ssaop.OpInitMem, types.TypeMem, 0, nil),
45 Valu("sb", ssaop.OpSB, c.config.Types.Uintptr, 0, nil),
46 Valu("sp", ssaop.OpSP, c.config.Types.Uintptr, 0, nil),
47 Goto("loop")),
48 Bloc("loop",
49 Valu("phi", ssaop.OpPhi, types.TypeMem, 0, nil, "start", "wb"),
50 Valu("v", ssaop.OpConstNil, ptrType, 0, nil),
51 Valu("addr", ssaop.OpAddr, ptrType, 0, nil, "sb"),
52 Valu("wb", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr", "v", "phi"),
53 Goto("loop")))
54
55 CheckFunc(fun.f)
56 writebarrier(fun.f)
57 CheckFunc(fun.f)
58 }
59
View as plain text