diff options
author | Keith Randall <khr@golang.org> | 2021-01-07 14:57:53 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-01-08 05:00:06 +0000 |
commit | 304f769ffc68e64244266b3aadbf91e6738c0064 (patch) | |
tree | fe443868201a208fac12c485149f7922416d4c57 /test | |
parent | ae9771713383c1ee01a544cd50cfdbc22841380a (diff) | |
download | go-304f769ffc68e64244266b3aadbf91e6738c0064.tar.gz go-304f769ffc68e64244266b3aadbf91e6738c0064.zip |
cmd/compile: don't short-circuit copies whose source is volatile
Current optimization: When we copy a->b and then b->c, we might as well
copy a->c instead of b->c (then b might be dead and go away).
*Except* if a is a volatile location (might be clobbered by a call).
In that case, we really do want to copy a immediately, because there
might be a call before we can do the a->c copy.
User calls can't happen in between, because the rule matches up the
memory states. But calls inserted for memory barriers, particularly
runtime.typedmemmove, can.
(I guess we could introduce a register-calling-convention version
of runtime.typedmemmove, but that seems a bigger change than this one.)
Fixes #43570
Change-Id: Ifa518bb1a6f3a8dd46c352d4fd54ea9713b3eb1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/282492
Trust: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue43570.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/fixedbugs/issue43570.go b/test/fixedbugs/issue43570.go new file mode 100644 index 0000000000..d073fde5f6 --- /dev/null +++ b/test/fixedbugs/issue43570.go @@ -0,0 +1,40 @@ +// run + +// 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 main + +import "fmt" + +type T [8]*int + +//go:noinline +func f(x int) T { + return T{} +} + +//go:noinline +func g(x int, t T) { + if t != (T{}) { + panic(fmt.Sprintf("bad: %v", t)) + } +} + +func main() { + const N = 10000 + var q T + func() { + for i := 0; i < N; i++ { + q = f(0) + g(0, q) + sink = make([]byte, 1024) + } + }() + // Note that the closure is a trick to get the write to q to be a + // write to a pointer that is known to be non-nil and requires + // a write barrier. +} + +var sink []byte |