compiler: implement unsafe.Alignof and unsafe.Sizeof for generic code

For some reason, these aren't lowered when a generic function is
instantiated by the SSA package.

I've left unsafe.Offsetof to be implemented later, it's a bit difficult
to do correctly the way the code is currently structured.
This commit is contained in:
Ayke van Laethem
2022-07-28 14:14:23 +02:00
committed by Ron Evans
parent 70c52ef1b4
commit 7b1e5f6f99
3 changed files with 26 additions and 0 deletions
+6
View File
@@ -1,5 +1,7 @@
package main
import "unsafe"
type Coord interface {
int | float32
}
@@ -9,6 +11,8 @@ type Point[T Coord] struct {
}
func Add[T Coord](a, b Point[T]) Point[T] {
checkSize(unsafe.Alignof(a))
checkSize(unsafe.Sizeof(a))
return Point[T]{
X: a.X + b.X,
Y: a.Y + b.Y,
@@ -22,3 +26,5 @@ func main() {
var ai, bi Point[int]
Add(ai, bi)
}
func checkSize(uintptr)