]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] test: add test of pointer aliasing
authorTodd Neal <todd@tneal.org>
Mon, 22 Feb 2016 02:21:23 +0000 (20:21 -0600)
committerTodd Neal <todd@tneal.org>
Mon, 22 Feb 2016 03:40:16 +0000 (03:40 +0000)
This adds a test case with aliased pointers to ensure modifications to
dse don't remove valid stores.

Change-Id: I143653250f46a403835218ec685bcd336d5087ef
Reviewed-on: https://go-review.googlesource.com/19795
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/testdata/unsafe_ssa.go

index bc292828d5f9a0ee5982480990ade43db73233c0..d074eb1d5eaf8a9dd5f41fe072e1350539d337bf 100644 (file)
@@ -123,7 +123,26 @@ func testg() {
        }
 }
 
+func alias_ssa(ui64 *uint64, ui32 *uint32) uint32 {
+       *ui32 = 0xffffffff
+       *ui64 = 0                  // store
+       ret := *ui32               // load from same address, should be zero
+       *ui64 = 0xffffffffffffffff // store
+       return ret
+}
+func testdse() {
+       x := int64(-1)
+       // construct two pointers that alias one another
+       ui64 := (*uint64)(unsafe.Pointer(&x))
+       ui32 := (*uint32)(unsafe.Pointer(&x))
+       if want, got := uint32(0), alias_ssa(ui64, ui32); got != want {
+               fmt.Printf("alias_ssa: wanted %d, got %d\n", want, got)
+               panic("alias_ssa")
+       }
+}
+
 func main() {
        testf()
        testg()
+       testdse()
 }