]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: keep call's args in elim dead auto pass
authorCherry Zhang <cherryyz@google.com>
Thu, 22 Apr 2021 15:36:29 +0000 (11:36 -0400)
committerCherry Zhang <cherryyz@google.com>
Thu, 22 Apr 2021 16:38:37 +0000 (16:38 +0000)
If the address of an auto is used in a Call, we need to keep it,
as we keep the Call itself.

Fixes #45693.

Change-Id: Ie548d6dffc95bf916868a8885d4ab4cf9e86355a
Reviewed-on: https://go-review.googlesource.com/c/go/+/312670
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/deadstore.go
test/fixedbugs/issue45693.go [new file with mode: 0644]

index 31d3f62d4e7cef68637d8c2552f22a7ad085122d..d694133ec3bb8dc17d67e61770026a585846bb62 100644 (file)
@@ -201,8 +201,9 @@ func elimDeadAutosGeneric(f *Func) {
                        panic("unhandled op with sym effect")
                }
 
-               if v.Uses == 0 && v.Op != OpNilCheck || len(args) == 0 {
+               if v.Uses == 0 && v.Op != OpNilCheck && !v.Op.IsCall() && !v.Op.HasSideEffects() || len(args) == 0 {
                        // Nil check has no use, but we need to keep it.
+                       // Also keep calls and values that have side effects.
                        return
                }
 
diff --git a/test/fixedbugs/issue45693.go b/test/fixedbugs/issue45693.go
new file mode 100644 (file)
index 0000000..20a0cec
--- /dev/null
@@ -0,0 +1,16 @@
+// compile
+
+// Copyright 2021 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 45693: ICE with register args.
+
+package p
+
+func f() {
+       var s string
+       s = s + "" + s + "" + s + ""
+       for {
+       }
+}