aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2021-04-22 18:34:57 -0400
committerThan McIntosh <thanm@google.com>2021-04-23 01:16:19 +0000
commitcfac62a1cc021cae55c9c5e373ebe9c408b75a5d (patch)
tree9ab4415ffde640fa4f819f4983edf3de63218550 /test
parent14056d0d004489592ee0173e685ff86f241cfb4f (diff)
downloadgo-cfac62a1cc021cae55c9c5e373ebe9c408b75a5d.tar.gz
go-cfac62a1cc021cae55c9c5e373ebe9c408b75a5d.zip
cmd/compile: fix bug in defer wrapping
The defer wrapping feature added to the compiler's "order" phase creates temporaries into which it copies defer arguments. If one of these temps is large enough that we place it into the defer closure by address (as opposed to by value), then the temp in question can't be reused later on in the order phase, nor do we want a VARKILL annotation for it at the end of the current block scope. Test written by Cherry. Updates #40724. Change-Id: Iec7efd87ec5a3e3d7de41cdcc7f39c093ed1e815 Reviewed-on: https://go-review.googlesource.com/c/go/+/312869 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/abi/wrapdefer_largetmp.go37
-rw-r--r--test/abi/wrapdefer_largetmp.out1
2 files changed, 38 insertions, 0 deletions
diff --git a/test/abi/wrapdefer_largetmp.go b/test/abi/wrapdefer_largetmp.go
new file mode 100644
index 0000000000..fb6eebaaca
--- /dev/null
+++ b/test/abi/wrapdefer_largetmp.go
@@ -0,0 +1,37 @@
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// 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
+
+//go:noinline
+func F() {
+ b := g()
+ defer g2(b)
+ n := g()[20]
+ println(n)
+}
+
+type T [45]int
+
+var x = 0
+
+//go:noinline
+func g() T {
+ x++
+ return T{20: x}
+}
+
+//go:noinline
+func g2(t T) {
+ if t[20] != 1 {
+ println("FAIL", t[20])
+ }
+}
+
+func main() { F() }
diff --git a/test/abi/wrapdefer_largetmp.out b/test/abi/wrapdefer_largetmp.out
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/abi/wrapdefer_largetmp.out
@@ -0,0 +1 @@
+2