From: Todd Neal Date: Mon, 22 Feb 2016 02:21:23 +0000 (-0600) Subject: [dev.ssa] test: add test of pointer aliasing X-Git-Tag: go1.7beta1~1623^2^2~36 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4827c6d0778d93afeaee658a330d97b8f1b510a6;p=gostls13.git [dev.ssa] test: add test of pointer aliasing 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 --- diff --git a/src/cmd/compile/internal/gc/testdata/unsafe_ssa.go b/src/cmd/compile/internal/gc/testdata/unsafe_ssa.go index bc292828d5..d074eb1d5e 100644 --- a/src/cmd/compile/internal/gc/testdata/unsafe_ssa.go +++ b/src/cmd/compile/internal/gc/testdata/unsafe_ssa.go @@ -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() }