cmd/compile: fix internal compiler error: bad write barrier type
This change fixes an issue where the compiler panics with 'bad
write barrier type' for zero-sized arrays. The loops in
storeTypeScalars and storeTypePtrs erroneously processed
zero-sized arrays causing invalid operations. This ignores them.
Fixes #77815
diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go
index 5c4826f..5d54a61 100644
--- a/src/cmd/compile/internal/ssagen/ssa.go
+++ b/src/cmd/compile/internal/ssagen/ssa.go
@@ -5673,6 +5673,8 @@
}
case t.IsArray() && t.NumElem() == 0:
// nothing
+ case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):
+ // nothing
case t.IsArray() && t.NumElem() == 1:
s.storeTypeScalars(t.Elem(), left, s.newValue1I(ssa.OpArraySelect, t.Elem(), 0, right), 0)
default:
@@ -5711,7 +5713,7 @@
val := s.newValue1I(ssa.OpStructSelect, ft, int64(i), right)
s.storeTypePtrs(ft, addr, val)
}
- case t.IsArray() && t.NumElem() == 0:
+ case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):
// nothing
case t.IsArray() && t.NumElem() == 1:
s.storeTypePtrs(t.Elem(), left, s.newValue1I(ssa.OpArraySelect, t.Elem(), 0, right))
diff --git a/test/fixedbugs/issue77815.go b/test/fixedbugs/issue77815.go
new file mode 100644
index 0000000..64feffe
--- /dev/null
+++ b/test/fixedbugs/issue77815.go
@@ -0,0 +1,17 @@
+// compile
+
+// 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.
+
+package p
+
+type S struct {
+ a [4]struct{}
+ c chan int
+}
+
+func f(x int, m map[int]S) {
+ var s S
+ m[x] = s
+}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):```suggestion
case t.IsArray() && t.Size() == 0:
```
Isn't the `NumElem` redundant now?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
package p
type S struct {
a [4]struct{}
c chan int
}
func f(x int, m map[int]S) {
var s S
m[x] = s
}```suggestion
package p
type S struct {
a [4]struct{}
f chan int
}func f(p *S) {
var s S// Memory write that requires a write barrier should work
// with structs having zero-sized arrays of non-zero elements.
*p = s
}
```
This bug is not related to maps, we could avoid the confusion and a bit of comment can help, since not that complex to explain the issue.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):```suggestion
case t.IsArray() && t.Size() == 0:
```
Isn't the `NumElem` redundant now?
Probably even better to just put t.Size() == 0 as the first case. (Like zeroVal.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
package p
type S struct {
a [4]struct{}
c chan int
}
func f(x int, m map[int]S) {
var s S
m[x] = s
}```suggestion
package p
type S struct {
a [4]struct{}
f chan int
}func f(p *S) {
var s S// Memory write that requires a write barrier should work
// with structs having zero-sized arrays of non-zero elements.
*p = s
}
```
This bug is not related to maps, we could avoid the confusion and a bit of comment can help, since not that complex to explain the issue.
Thank you for the quick reply, I will fix this issue as soon as possible.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):Keith Randall```suggestion
case t.IsArray() && t.Size() == 0:
```Isn't the `NumElem` redundant now?
Probably even better to just put t.Size() == 0 as the first case. (Like zeroVal.)
Fix applied.
package p
type S struct {
a [4]struct{}
c chan int
}
func f(x int, m map[int]S) {
var s S
m[x] = s
}Francisco Ferraz```suggestion
package ptype S struct {
a [4]struct{}
f chan int
}func f(p *S) {
var s S// Memory write that requires a write barrier should work
// with structs having zero-sized arrays of non-zero elements.
*p = s
}
```
This bug is not related to maps, we could avoid the confusion and a bit of comment can help, since not that complex to explain the issue.
Thank you for the quick reply, I will fix this issue as soon as possible.
Fix applied.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):also here
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I don't see a new patchset?
Check again please, i retried the submission.
case t.IsArray() && (t.NumElem() == 0 || t.Size() == 0):Francisco Ferrazalso here
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |