aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkhr@golang.org <khr@golang.org>2024-02-20 10:32:26 -0800
committerGopher Robot <gobot@golang.org>2024-02-29 21:29:41 +0000
commite93041333150e6b74f931119036156938dcd0925 (patch)
tree3e323e5e1e2eb61fc11a87d5ab35d584f5197301 /test
parent4e7bd20f8fdccdb2f0f30b051e3ea3fffb449367 (diff)
downloadgo-e93041333150e6b74f931119036156938dcd0925.tar.gz
go-e93041333150e6b74f931119036156938dcd0925.zip
cmd/compile: soften type matching when allocating stack slots
Currently we use pointer equality on types when deciding whether we can reuse a stack slot. That's too strict, as we don't guarantee pointer equality for the same type. In particular, it can vary based on whether PtrTo has been called in the frontend or not. Instead, use the type's LinkString, which is guaranteed to both be unique for a type, and to not vary given two different type structures describing the same type. Update #65783 Change-Id: I64f55138475f04bfa30cfb819b786b7cc06aebe4 Reviewed-on: https://go-review.googlesource.com/c/go/+/565436 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/codegen/stack.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/codegen/stack.go b/test/codegen/stack.go
index eebbbf1677..65c9868d67 100644
--- a/test/codegen/stack.go
+++ b/test/codegen/stack.go
@@ -113,3 +113,32 @@ func Defer() {
// amd64:`CALL\truntime\.deferprocStack`
defer func() {}()
}
+
+// Check that stack slots are shared among values of the same
+// type, but not pointer-identical types. See issue 65783.
+
+func spillSlotReuse() {
+ // The return values of getp1 and getp2 need to be
+ // spilled around the calls to nopInt. Make sure that
+ // spill slot gets reused.
+
+ //arm64:`.*autotmp_2-8\(SP\)`
+ getp1()[nopInt()] = 0
+ //arm64:`.*autotmp_2-8\(SP\)`
+ getp2()[nopInt()] = 0
+}
+
+//go:noinline
+func nopInt() int {
+ return 0
+}
+
+//go:noinline
+func getp1() *[4]int {
+ return nil
+}
+
+//go:noinline
+func getp2() *[4]int {
+ return nil
+}