aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgulmix <egorpoddelkov1@gmail.com>2026-03-28 01:23:58 +0300
committerGopher Robot <gobot@golang.org>2026-04-06 19:36:35 -0700
commit3b5954c6349d31465dca409b45ab6597e0942d9f (patch)
tree600faf5ebf65fb8c1f70b0e8dd0d06d9092f9275
parenta93560b70a65821ba8403b66261a3c23c93176c5 (diff)
downloadgo-3b5954c6349d31465dca409b45ab6597e0942d9f.tar.xz
cmd/compile: report error instead of ICE for oversized map element
When a map element or key type is 2GB or larger, the compiler crashed with "internal compiler error: map elem too big" in reflectdata.ZeroAddr. Add a size check in types.CalcSize for TMAP, similar to the existing check for channel element types, so that oversized map elements are reported as a normal error before reaching ZeroAddr. Fixes #78355 Change-Id: I281a5f0ec7dda6dac084787859156d4409dc860c Reviewed-on: https://go-review.googlesource.com/c/go/+/760600 Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--src/cmd/compile/internal/types/size.go6
-rw-r--r--src/cmd/compile/internal/types2/stdlib_test.go1
-rw-r--r--src/go/types/stdlib_test.go1
-rw-r--r--test/fixedbugs/issue78355.go17
4 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types/size.go b/src/cmd/compile/internal/types/size.go
index 1acb041e35..4d64c7f8d2 100644
--- a/src/cmd/compile/internal/types/size.go
+++ b/src/cmd/compile/internal/types/size.go
@@ -366,6 +366,12 @@ func CalcSize(t *Type) {
t.intRegs = 1
CheckSize(t.Elem())
CheckSize(t.Key())
+ if t.Elem().width >= 1<<31 {
+ base.Errorf("map element type too large")
+ }
+ if t.Key().width >= 1<<31 {
+ base.Errorf("map key type too large")
+ }
t.setAlg(ANOEQ)
t.ptrBytes = int64(PtrSize)
diff --git a/src/cmd/compile/internal/types2/stdlib_test.go b/src/cmd/compile/internal/types2/stdlib_test.go
index 924b7b841f..6108155fc7 100644
--- a/src/cmd/compile/internal/types2/stdlib_test.go
+++ b/src/cmd/compile/internal/types2/stdlib_test.go
@@ -328,6 +328,7 @@ func TestStdFixed(t *testing.T) {
"issue48230.go", // go/types doesn't check validity of //go:xxx directives
"issue49767.go", // go/types does not have constraints on channel element size
"issue49814.go", // go/types does not have constraints on array size
+ "issue78355.go", // types2 does not have constraints on map element size
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
"issue52697.go", // types2 does not have constraints on stack size
diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go
index 7830029fb2..8d4cba6625 100644
--- a/src/go/types/stdlib_test.go
+++ b/src/go/types/stdlib_test.go
@@ -330,6 +330,7 @@ func TestStdFixed(t *testing.T) {
"issue48230.go", // go/types doesn't check validity of //go:xxx directives
"issue49767.go", // go/types does not have constraints on channel element size
"issue49814.go", // go/types does not have constraints on array size
+ "issue78355.go", // go/types does not have constraints on map element size
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
"issue52697.go", // go/types does not have constraints on stack size
diff --git a/test/fixedbugs/issue78355.go b/test/fixedbugs/issue78355.go
new file mode 100644
index 0000000000..092d659f03
--- /dev/null
+++ b/test/fixedbugs/issue78355.go
@@ -0,0 +1,17 @@
+// errorcheck
+
+// 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 amd64 || arm64
+
+// Issue 78355: map element or key type too large should not cause ICE.
+
+package p
+
+type T [1 << 31]byte
+
+func F(m map[int]T) { // ERROR "map element type too large"
+ _ = m[0]
+}