]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: keep autos whose address reaches a phi
authorMichael Munday <mike.munday@ibm.com>
Sat, 30 Jun 2018 09:14:49 +0000 (10:14 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 2 Jul 2018 19:43:07 +0000 (19:43 +0000)
If the address of an auto reaches a phi then any further stores to
the pointer represented by the phi probably need to be kept. This
is because stores to the other arguments to the phi may be visible
to the program.

Fixes #26153.

Change-Id: Ic506c6c543bf70d792e5b1a64bdde1e5fdf1126a
Reviewed-on: https://go-review.googlesource.com/121796
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
src/cmd/compile/internal/ssa/deadstore.go
test/fixedbugs/issue26153.go [new file with mode: 0644]

index 4b2f57dcd94caadbe60e94787a28bc1b70531ff0..e92521a79c13508d7103346dc93ea5d25bf22f11 100644 (file)
@@ -203,7 +203,8 @@ func elimDeadAutosGeneric(f *Func) {
 
                // If the address of the auto reaches a memory or control
                // operation not covered above then we probably need to keep it.
-               if v.Type.IsMemory() || v.Type.IsFlags() || (v.Op != OpPhi && v.MemoryArg() != nil) {
+               // We also need to keep autos if they reach Phis (issue #26153).
+               if v.Type.IsMemory() || v.Type.IsFlags() || v.Op == OpPhi || v.MemoryArg() != nil {
                        for _, a := range args {
                                if n, ok := addr[a]; ok {
                                        if !used[n] {
diff --git a/test/fixedbugs/issue26153.go b/test/fixedbugs/issue26153.go
new file mode 100644 (file)
index 0000000..53f53cf
--- /dev/null
@@ -0,0 +1,29 @@
+// run
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 26153. The write to ps was incorrectly
+// removed by the dead auto elimination pass.
+
+package main
+
+const hello = "hello world"
+
+func main() {
+       var s string
+       mangle(&s)
+       if s != hello {
+               panic("write incorrectly elided")
+       }
+}
+
+//go:noinline
+func mangle(ps *string) {
+       if ps == nil {
+               var s string
+               ps = &s
+       }
+       *ps = hello
+}