]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: do not use special literal assignment if LHS is address-taken
authorCherry Mui <cherryyz@google.com>
Wed, 18 May 2022 15:58:53 +0000 (11:58 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 18 May 2022 18:24:59 +0000 (18:24 +0000)
commit1c77137d4fdfbb3e7e8d9efaab3bab5ee736a19d
tree1b1f711dd4edc9a823eda2188fe34b36fbe5d590
parent4ba114ec05c6090708b51db5f7a196e95bce64e0
cmd/compile: do not use special literal assignment if LHS is address-taken

A composite literal assignment

x = T{field: v}

may be compiled to

x = T{}
x.field = v

We already do not use this form is RHS uses LHS. If LHS is
address-taken, RHS may uses LHS implicitly, e.g.

v = &x.field
x = T{field: *v}

The lowering above would change the value of RHS (*v).

Fixes #52953.

Change-Id: I3f798e00598aaa550b8c17182c7472fef440d483
Reviewed-on: https://go-review.googlesource.com/c/go/+/407014
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/walk/complit.go
test/fixedbugs/issue52953.go [new file with mode: 0644]