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>
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
}
--- /dev/null
+// 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 {
+ }
+}