aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfumiyanokesinn <shindori238@gmail.com>2026-01-25 23:59:25 +0900
committerGopher Robot <gobot@golang.org>2026-01-26 18:28:40 -0800
commitcf0c42c2ca04c3ae9fa20ce9dd4f6bce301bd37b (patch)
treef7906d370423297fe9913fb13eddd732160f78f3
parentbb221e8954b639e8790fd1d4a8cd35ff3a9340aa (diff)
downloadgo-cf0c42c2ca04c3ae9fa20ce9dd4f6bce301bd37b.tar.xz
cmd/compile/internal/reflectdata: fix divide by zero for zero-size array elements
When generating equality signatures for arrays with zero-size ASPECIAL elements (e.g., [3]struct{_ [0]float64}), the compiler crashed with a divide by zero error when computing the loop unroll factor. Skip comparison code generation for zero-size elements since they need no comparison. Fixes #77303 Change-Id: Ib432cfece22b1cb714de4f0a0b0d1a2d89bb0d33 Reviewed-on: https://go-review.googlesource.com/c/go/+/738841 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
-rw-r--r--src/cmd/compile/internal/reflectdata/alg.go3
-rw-r--r--test/fixedbugs/issue77303.go19
2 files changed, 22 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go
index eb46ed84aa..f74a42eac1 100644
--- a/src/cmd/compile/internal/reflectdata/alg.go
+++ b/src/cmd/compile/internal/reflectdata/alg.go
@@ -785,6 +785,9 @@ func (e *eqSigBuilder) build(t *types.Type) {
// The generated loops are kind of inefficient as well,
// so unroll the loop a bit.
const unrollSize = 32 // make loop body compare around this many bytes
+ if et.Size() == 0 {
+ break // zero-size elements need no comparison
+ }
unroll := max(1, unrollSize/et.Size())
// Do partial loops directly.
for n%unroll != 0 {
diff --git a/test/fixedbugs/issue77303.go b/test/fixedbugs/issue77303.go
new file mode 100644
index 0000000000..995e73b034
--- /dev/null
+++ b/test/fixedbugs/issue77303.go
@@ -0,0 +1,19 @@
+// 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.
+
+// Issue 77303: compiler crash on array of zero-size ASPECIAL elements.
+
+package p
+
+type zeroSizeSpecial struct {
+ _ [0]float64
+}
+
+var x [3]zeroSizeSpecial
+
+func f() bool {
+ return x == x
+}