Skip to content

Commit

Permalink
cmd/compile: make sure ascompatee walk lhs init statements
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
cuonglm committed Apr 23, 2021
1 parent d4bfe00 commit 8c66669
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/walk/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions test/fixedbugs/issue45706.go
Original file line number Diff line number Diff line change
@@ -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{} {
}
}

0 comments on commit 8c66669

Please sign in to comment.