aboutsummaryrefslogtreecommitdiff
path: root/go/ssa/interp/testdata/width32.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ssa/interp/testdata/width32.go')
-rw-r--r--go/ssa/interp/testdata/width32.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/go/ssa/interp/testdata/width32.go b/go/ssa/interp/testdata/width32.go
new file mode 100644
index 000000000..a032ba44c
--- /dev/null
+++ b/go/ssa/interp/testdata/width32.go
@@ -0,0 +1,42 @@
+// Copyright 2022 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.
+
+// Test interpretation on 32 bit widths.
+
+package main
+
+func main() {
+ mapSize()
+}
+
+func mapSize() {
+ // Tests for the size argument of make on a map type.
+ const tooBigFor32 = 1<<33 - 1
+ wantPanic(
+ func() {
+ _ = make(map[int]int, int64(tooBigFor32))
+ },
+ "runtime error: ssa.MakeMap.Reserve value 8589934591 does not fit in int",
+ )
+
+ // TODO: Enable the following if sizeof(int) can be different for host and target.
+ // _ = make(map[int]int, tooBigFor32)
+ //
+ // Second arg to make in `make(map[int]int, tooBigFor32)` is an untyped int and
+ // is converted into an int explicitly in ssa.
+ // This has a different value on 32 and 64 bit systems.
+}
+
+func wantPanic(fn func(), s string) {
+ defer func() {
+ err := recover()
+ if err == nil {
+ panic("expected panic")
+ }
+ if got := err.(error).Error(); got != s {
+ panic("expected panic " + s + " got " + got)
+ }
+ }()
+ fn()
+}