From 4827c6d0778d93afeaee658a330d97b8f1b510a6 Mon Sep 17 00:00:00 2001 From: Todd Neal Date: Sun, 21 Feb 2016 20:21:23 -0600 Subject: [PATCH] [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 --- .../internal/gc/testdata/unsafe_ssa.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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() }