github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/cmd/compile/internal/ssa/writebarrier_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssa
     6  
     7  import "testing"
     8  
     9  func TestWriteBarrierStoreOrder(t *testing.T) {
    10  	// Make sure writebarrier phase works even StoreWB ops are not in dependency order
    11  	c := testConfig(t)
    12  	ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing
    13  	fun := Fun(c, "entry",
    14  		Bloc("entry",
    15  			Valu("start", OpInitMem, TypeMem, 0, nil),
    16  			Valu("sb", OpSB, TypeInvalid, 0, nil),
    17  			Valu("sp", OpSP, TypeInvalid, 0, nil),
    18  			Valu("v", OpConstNil, ptrType, 0, nil),
    19  			Valu("addr1", OpAddr, ptrType, 0, nil, "sb"),
    20  			Valu("wb2", OpStoreWB, TypeMem, 8, nil, "addr1", "v", "wb1"),
    21  			Valu("wb1", OpStoreWB, TypeMem, 8, nil, "addr1", "v", "start"), // wb1 and wb2 are out of order
    22  			Goto("exit")),
    23  		Bloc("exit",
    24  			Exit("wb2")))
    25  
    26  	CheckFunc(fun.f)
    27  	writebarrier(fun.f)
    28  	CheckFunc(fun.f)
    29  }