aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-07-17 00:15:07 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-07-21 00:01:12 +0000
commitd5f6ba943c4e8f39d1bd20c79f4e9274ad10c103 (patch)
treeab9ee83c60796983f7303f41b4e8aec01608a678 /test
parent6a931673f0b655e7ca538826af21a54d3f958070 (diff)
downloadgo-d5f6ba943c4e8f39d1bd20c79f4e9274ad10c103.tar.gz
go-d5f6ba943c4e8f39d1bd20c79f4e9274ad10c103.zip
[dev.typeparams] test: add regression test for go/defer wrapper
CL 330330 moved logic for wrapping go/defer from order to esacpe analysis. It introduced a bug involves go/defer statement with ABI0 functions. Consider this following code: package p //go:cgo_unsafe_args func g(*int) (r1 struct{}) { return } func f() { defer g(new(int)) } g is a cgo-like generated function with ABI0. While compiling g, we set the offset per ABI0. The function f is rewritten into: func f() { _0, _1 := g, new(int) defer func() { _0(_1) }() } The temporary _0 hold function value with the same type as g, but with class PAUTO. Thus ssagen/ssa.go:state.call cannot handle it and use ABIDefault to set the offset, causes the offset of r1 changed CL 330332 intended to optimize code generated for wrapping function, by rewriting the wrapper function into: func f() { _0 := new(int) defer func() { g(_0) }() } So it fixed the bug unintentionally. This CL add regression test for this bug, and also add a comment to explain while not wrapping declared function is important. Updates #47227 Change-Id: I75c83d1d9cc7fd4699e6b218a295d0c0a10ef471 Reviewed-on: https://go-review.googlesource.com/c/go/+/334882 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue47227.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/fixedbugs/issue47227.go b/test/fixedbugs/issue47227.go
new file mode 100644
index 0000000000..a14efc9a68
--- /dev/null
+++ b/test/fixedbugs/issue47227.go
@@ -0,0 +1,23 @@
+// run fake-arg-to-force-use-of-go-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.
+
+//go:build cgo
+// +build cgo
+
+package main
+
+// void f(int *p) { *p = 0x12345678; }
+import "C"
+
+func main() {
+ var x C.int
+ func() {
+ defer C.f(&x)
+ }()
+ if x != 0x12345678 {
+ panic("FAIL")
+ }
+}