diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-04-23 12:18:59 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-04-23 20:57:54 +0000 |
commit | 691e1b84c11d038060807f9c79107996ca2f19ae (patch) | |
tree | f8f31ea29406493f4cd1640cd6f9271c3b66a318 /src/cmd/compile/internal/walk | |
parent | 768a39975d8851f1c309b163a8eb4b7a5388aa24 (diff) | |
download | go-691e1b84c11d038060807f9c79107996ca2f19ae.tar.gz go-691e1b84c11d038060807f9c79107996ca2f19ae.zip |
cmd/compile: generalize fix for lvalue-init evaluation
The previous fix to ensure early evaluation of lvalue-init statements
(CL 312632) added it after we'd already peeled away any array-OINDEX
expressions. But those might have init statements too, so we need to
do this earlier actually and perhaps more than once.
Longer term, lvalue expressions shouldn't have init statements anyway.
But rsc and I both spent a while looking into this earlier in the dev
cycle and couldn't come up with anything reasonable.
Fixes #45706.
Change-Id: I2d19c5ba421b3f019c62eec45774c84cf04b30ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/313011
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/walk')
-rw-r--r-- | src/cmd/compile/internal/walk/assign.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index 3abf2a060c..6d697a53ae 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -322,6 +322,13 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node { // Save subexpressions needed on left side. // Drill through non-dereferences. for { + // If an expression has init statements, they must be evaluated + // before any of its saved sub-operands (#45706). + // TODO(mdempsky): Disallow init statements on lvalues. + init := ir.TakeInit(l) + walkStmtList(init) + early.Append(init...) + switch ll := l.(type) { case *ir.IndexExpr: if ll.X.Type().IsArray() { @@ -341,9 +348,6 @@ 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: |