1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:10:21 -07:00

[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 <khr@golang.org>
This commit is contained in:
Todd Neal 2016-02-21 20:21:23 -06:00
parent 5949524fc4
commit 4827c6d077

View 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()
}