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