GoPLS Viewer

Home|gopls/go/ssa/interp/testdata/width32.go
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
7package main
8
9func main() {
10    mapSize()
11}
12
13func 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]intint64(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
31func 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}
43
MembersX
mapSize
Members
X