]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make sure ascompatee walk lhs init statements
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 23 Apr 2021 05:53:51 +0000 (12:53 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 23 Apr 2021 17:36:11 +0000 (17:36 +0000)
CL 281152 improved ascompatee by removing the call to safeExpr on lhs.
But we forgot that lhs int statements, if any, must be walked prior
saving subexpressions, which cause the bug in #45706.

Fixes #45706

Change-Id: I0064315056ef4ca92ebf3c332c2e3a9bb2b26f68
Reviewed-on: https://go-review.googlesource.com/c/go/+/312632
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/walk/assign.go
test/fixedbugs/issue45706.go [new file with mode: 0644]

index c8342b4fa432d833f858dd2470a53bd9b56bb0c2..3abf2a060c8a03b672a4a3b3fc66a3225e392f04 100644 (file)
@@ -341,6 +341,9 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
                        break
                }
 
+               walkStmtList(l.Init())
+               early.Append(ir.TakeInit(l)...)
+
                var name *ir.Name
                switch l.Op() {
                default:
diff --git a/test/fixedbugs/issue45706.go b/test/fixedbugs/issue45706.go
new file mode 100644 (file)
index 0000000..facf488
--- /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.
+
+package p
+
+var i int
+var arr []*int
+var f func() int
+
+func g() {
+       for i, *(arr[f()]) = range []int{} {
+       }
+}