]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.19] cmd/compile: avoid using destination pointer base type in...
authorKeith Randall <khr@golang.org>
Sat, 17 Sep 2022 22:52:35 +0000 (18:52 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 21 Sep 2022 20:24:34 +0000 (20:24 +0000)
commit4b0e03da0e0c096b8e695d9e564a8ceac99f2d76
tree4ffd361c642ea2196e7d21578ac9ea4386d49139
parent225bcec98b53ddceeb6998614ad566c11ef27620
[release-branch.go1.19] cmd/compile: avoid using destination pointer base type in memmove optimization

The type of the source and destination of a memmove call isn't
always accurate. It will always be a pointer (or an unsafe.Pointer), but
the base type might not be accurate. This comes about because multiple
copies of a pointer with different base types are coalesced into a single value.

In the failing example, the IData selector of the input argument is a
*[32]byte in one branch of the type switch, and a *[]byte in the other branch.
During the expand_calls pass both IDatas become just copies of the input
register. Those copies are deduped and an arbitrary one wins (in this case,
*[]byte is the unfortunate winner).

Generally an op v can rely on v.Type during rewrite rules. But relying
on v.Args[i].Type is discouraged.

Fixes #55124

Change-Id: I348fd9accf2058a87cd191eec01d39cda612f120
Reviewed-on: https://go-review.googlesource.com/c/go/+/431496
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit e283473ebbebf4a80db166e7e852d03c5cff1a61)
Reviewed-on: https://go-review.googlesource.com/c/go/+/431917
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
test/fixedbugs/issue55122.go [new file with mode: 0644]
test/fixedbugs/issue55122b.go [new file with mode: 0644]