cmd/compile: "simd" types have non-constant sizeof
This is for the simd aka "midway" types whose size is
determined at run time.
diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go
index 82c6e9c..f130020 100644
--- a/src/cmd/compile/internal/types2/builtins.go
+++ b/src/cmd/compile/internal/types2/builtins.go
@@ -1034,6 +1034,11 @@
t.unpack()
varSize := check.hasVarSize(t.rhs())
+ // Special case for portable simd types that rewrite to unknown sizes.
+ if o := t.Obj(); o != nil && o.Pkg() != nil && o.Pkg().Name() == "simd" && o.Name() == "_simd" {
+ varSize = true
+ }
+
t.mu.Lock()
defer t.mu.Unlock()
diff --git a/src/simd/sizeof_test.go b/src/simd/sizeof_test.go
new file mode 100644
index 0000000..497d715
--- /dev/null
+++ b/src/simd/sizeof_test.go
@@ -0,0 +1,33 @@
+// Copyright 2026 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 goexperiment.simd
+
+package simd_test
+
+import (
+ "simd"
+ "simd/testdata"
+ "testing"
+ "unsafe"
+)
+
+var v simd.Float32s
+
+func TestSizeof(t *testing.T) {
+ var f float32
+ sv0 := int(unsafe.Sizeof(v))
+ sv1 := v.Len() * int(unsafe.Sizeof(f))
+ sV := int(unsafe.Sizeof(testdata.V))
+ sF := int(unsafe.Sizeof(testdata.F()))
+ if sv0 != sv1 {
+ t.Errorf("Expected sv0=%d and sv1=%d are equal, but not", sv0, sv1)
+ }
+ if sF != sv1 {
+ t.Errorf("Expected sF=%d and sv1=%d are equal, but not", sF, sv1)
+ }
+ if sV != sv1 {
+ t.Errorf("Expected sV=%d and sv1=%d are equal, but not", sV, sv1)
+ }
+}
diff --git a/src/simd/testdata/v.go b/src/simd/testdata/v.go
new file mode 100644
index 0000000..4f1710fa
--- /dev/null
+++ b/src/simd/testdata/v.go
@@ -0,0 +1,18 @@
+// Copyright 2026 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 goexperiment.simd
+
+package testdata
+
+import (
+ "simd"
+)
+
+var V simd.Float32s
+
+func F() simd.Float32s {
+ var x simd.Float32s
+ return x
+}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Seems ok but you need to also fix go/types by calling go generate in that directory.
check.push(t.obj)maybe here:
```
obj := t.obj
check.push(obj)
```
and then below (line 1038):
```
if pkg := obj.pkg; pkg != nil && ...
```
if o := t.Obj(); o != nil && o.Pkg() != nil && o.Pkg().Name() == "simd" && o.Name() == "_simd" {You should be able to leave away o != nil. All *Named types must have an object (which is where their name is).
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |