]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile/internal/ssa: reuse Aux values for PEXTERN
authorTodd Neal <todd@tneal.org>
Wed, 28 Oct 2015 02:35:48 +0000 (21:35 -0500)
committerTodd Neal <todd@tneal.org>
Wed, 28 Oct 2015 23:12:28 +0000 (23:12 +0000)
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>

src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/testdata/loadstore_ssa.go

index 4b4dc09f11172e25a36ed5bdf648ea88ea09821c..b96661d15ede0f8593b28cbd713d56d273dd99c5 100644 (file)
@@ -2265,7 +2265,7 @@ func (s *state) addr(n *Node, bounded bool) *ssa.Value {
                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 {
index e986f53bc666b139d9d3bc406dbd015bdc9128e0..e0b0b4dfab2c42cd3e8d75e69cd82ea84dbf3ed0 100644 (file)
@@ -77,11 +77,39 @@ func testExtStore() {
        }
 }
 
+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")