Debian Codegraph @

go/ssa/interp/testdata/width32.go

raw symbols SCIP
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Test interpretation on 32 bit widths.
6
7 package main
8
9 func main() {
10 mapSize()
11 }
12
13 func mapSize() {
14 // Tests for the size argument of make on a map type.
15 const tooBigFor32 = 1<<33 - 1
16 wantPanic(
17 func() {
18 _ = make(map[int]int, int64(tooBigFor32))
19 },
20 "runtime error: ssa.MakeMap.Reserve value 8589934591 does not fit in int",
21 )
22
23 // TODO: Enable the following if sizeof(int) can be different for host and target.
24 // _ = make(map[int]int, tooBigFor32)
25 //
26 // Second arg to make in `make(map[int]int, tooBigFor32)` is an untyped int and
27 // is converted into an int explicitly in ssa.
28 // This has a different value on 32 and 64 bit systems.
29 }
30
31 func wantPanic(fn func(), s string) {
32 defer func() {
33 err := recover()
34 if err == nil {
35 panic("expected panic")
36 }
37 if got := err.(error).Error(); got != s {
38 panic("expected panic " + s + " got " + got)
39 }
40 }()
41 fn()
42 }