summaryrefslogtreecommitdiff
path: root/test/typeparam/issue48094.dir
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-08-31 09:31:56 -0700
committerKeith Randall <khr@golang.org>2021-08-31 17:21:38 +0000
commitf27d6a23b0b9d2cb41441a5dd2bd6d65dd94acf0 (patch)
treee96aa2ccd24c0abb8fc89288478bd383371e6bcb /test/typeparam/issue48094.dir
parent68152359fdd45e8d51aaaec64075aad4ff8f68b2 (diff)
downloadgo-git-f27d6a23b0b9d2cb41441a5dd2bd6d65dd94acf0.tar.gz
cmd/compile: builtins may be in the unsafe package
Now that unsafe.Sizeof and friends can operate on generic parameters, and evaluate to non-constants, we need to export/import them correctly. Fixes #48094 Change-Id: If3ebf77255385cd5462e13fb7ced8b157ba3cf5b Reviewed-on: https://go-review.googlesource.com/c/go/+/346469 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'test/typeparam/issue48094.dir')
-rw-r--r--test/typeparam/issue48094.dir/a.go26
-rw-r--r--test/typeparam/issue48094.dir/main.go20
2 files changed, 46 insertions, 0 deletions
diff --git a/test/typeparam/issue48094.dir/a.go b/test/typeparam/issue48094.dir/a.go
new file mode 100644
index 0000000000..dd8c16f3ae
--- /dev/null
+++ b/test/typeparam/issue48094.dir/a.go
@@ -0,0 +1,26 @@
+// 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 a
+
+import "unsafe"
+
+func F[T any]() uintptr {
+ var t T
+ return unsafe.Sizeof(t)
+}
+
+func G[T any]() uintptr {
+ var t T
+ return unsafe.Alignof(t)
+}
+
+//func H[T any]() uintptr {
+// type S struct {
+// a T
+// b T
+// }
+// var s S
+// return unsafe.Offsetof(s.b)
+//}
diff --git a/test/typeparam/issue48094.dir/main.go b/test/typeparam/issue48094.dir/main.go
new file mode 100644
index 0000000000..eb1ddbe231
--- /dev/null
+++ b/test/typeparam/issue48094.dir/main.go
@@ -0,0 +1,20 @@
+// 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 "a"
+
+func main() {
+ if a.F[int64]() != 8 {
+ panic("bad")
+ }
+ if a.G[int8]() != 1 {
+ panic("bad")
+ }
+ // TODO: enable once 47631 is fixed.
+ //if a.H[int64]() != 8 {
+ // panic("bad")
+ //}
+}