]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix evaluation order for OASOP
authorMatthew Dempsky <mdempsky@google.com>
Tue, 29 Aug 2017 22:40:32 +0000 (15:40 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 5 Sep 2017 18:10:17 +0000 (18:10 +0000)
commit34db5f0c4d80b8fe3fb4b5be90efd9ee92bd1d4d
tree5ce79ac2fa1a6bd6a07a5d2c8a16124f87786ba8
parentd349fa25dfe2a86c01620f8b049c5e78e46759f3
cmd/compile: fix evaluation order for OASOP

Currently, we handle "x op= y" by rewriting as "x = x op y", while
ensuring that any calls or receive operations in 'x' are only
evaluated once. Notably, pointer indirection, indexing operations,
etc. are left alone as it's typically safe to re-evaluate those.

However, those operations were interleaved with evaluating 'y', which
could include function calls that might cause re-evaluation to yield
different memory addresses.

As a fix, simply ensure that we order side-effecting operations in 'y'
before either evaluation of 'x'.

Fixes #21687.

Change-Id: Ib14e77760fda9c828e394e8e362dc9e5319a84b2
Reviewed-on: https://go-review.googlesource.com/60091
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/gc/order.go
test/fixedbugs/issue21687.go [new file with mode: 0644]