aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2022-06-16 23:04:25 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2022-06-18 00:48:50 +0000
commit527ace0ffa81d59698d3a78ac3545de7295ea76b (patch)
tree9727ce930eff8ec76b657469e38dfd18abe15ce2 /test/typeparam
parentec58e3f3271de385cf976a805e611d3da09c3a0e (diff)
downloadgo-527ace0ffa81d59698d3a78ac3545de7295ea76b.tar.gz
go-527ace0ffa81d59698d3a78ac3545de7295ea76b.zip
cmd/compile: skip substituting closures in unsafe builtins arguments
For unsafe.{Alignof,Offsetof,Sizeof}, subster will transform them them to OLITERAL nodes, and discard their arguments. However, any closure in their children nodes were already processed and added to declaration queue. Thus, we lack of information for generating instantiation for the closure. To fix it, just skip substituting the closures if we are going to edit the children nodes of unsafe builtins. Fixes #53390 Change-Id: Ia815cd05af9dc0491f10faac4399f378ac53dec6 Reviewed-on: https://go-review.googlesource.com/c/go/+/412794 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/typeparam')
-rw-r--r--test/typeparam/issue53390.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/typeparam/issue53390.go b/test/typeparam/issue53390.go
new file mode 100644
index 0000000000..52098c520b
--- /dev/null
+++ b/test/typeparam/issue53390.go
@@ -0,0 +1,20 @@
+// compile
+
+// Copyright 2022 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 p
+
+import "unsafe"
+
+func F[T any](v T) uintptr {
+ return unsafe.Alignof(func() T {
+ func(any) {}(struct{ _ T }{})
+ return v
+ }())
+}
+
+func f() {
+ F(0)
+}