This improves cse and works correctly now that divide by zero is checked
explicitly.
Change-Id: If54fbe403ed5230b897afc5def644ba9f0056dfd
Reviewed-on: https://go-review.googlesource.com/16454
Run-TryBot: Todd Neal <todd@tneal.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
switch n.Class {
case PEXTERN:
// global variable
- aux := &ssa.ExternSymbol{n.Type, n.Sym}
+ aux := s.lookupSymbol(n, &ssa.ExternSymbol{n.Type, n.Sym})
v := s.entryNewValue1A(ssa.OpAddr, t, aux, s.sb)
// TODO: Make OpAddr use AuxInt as well as Aux.
if n.Xoffset != 0 {
}
}
+var b int
+
+// testDeadStorePanic_ssa ensures that we don't optimize away stores
+// that could be read by after recover(). Modeled after fixedbugs/issue1304.
+func testDeadStorePanic_ssa(a int) (r int) {
+ switch {
+ }
+ defer func() {
+ recover()
+ r = a
+ }()
+ a = 2 // store
+ b := a - a // optimized to zero
+ c := 4
+ a = c / b // store, but panics
+ a = 3 // store
+ r = a
+ return
+}
+
+func testDeadStorePanic() {
+ if want, got := 2, testDeadStorePanic_ssa(1); want != got {
+ fmt.Println("testDeadStorePanic failed. want =", want, ", got =", got)
+ failed = true
+ }
+}
+
func main() {
testLoadStoreOrder()
testStoreSize()
testExtStore()
+ testDeadStorePanic()
if failed {
panic("failed")