3 // Copyright 2013 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
20 if unsafe.Sizeof(t) == 8 {
21 // Test mem > maxAlloc
24 // Test elem.size*cap overflow
32 // Test elem.size*cap overflow
38 func shouldPanic(str string, f func()) {
42 panic("did not panic")
44 s := err.(error).Error()
45 if !strings.Contains(s, str) {
46 panic("got panic " + s + ", want " + str)
53 func testInts(n uint64) {
56 testMakeInAppendInts(n)
59 func testBytes(n uint64) {
62 testMakeInAppendBytes(n)
65 // Test make panics for given length or capacity n.
66 func testMakeInts(n uint64) {
68 shouldPanic("len out of range", func() { _ = make(T, int(n)) })
69 shouldPanic("cap out of range", func() { _ = make(T, 0, int(n)) })
70 shouldPanic("len out of range", func() { _ = make(T, uint(n)) })
71 shouldPanic("cap out of range", func() { _ = make(T, 0, uint(n)) })
72 shouldPanic("len out of range", func() { _ = make(T, int64(n)) })
73 shouldPanic("cap out of range", func() { _ = make(T, 0, int64(n)) })
74 shouldPanic("len out of range", func() { _ = make(T, uint64(n)) })
75 shouldPanic("cap out of range", func() { _ = make(T, 0, uint64(n)) })
78 func testMakeBytes(n uint64) {
80 shouldPanic("len out of range", func() { _ = make(T, int(n)) })
81 shouldPanic("cap out of range", func() { _ = make(T, 0, int(n)) })
82 shouldPanic("len out of range", func() { _ = make(T, uint(n)) })
83 shouldPanic("cap out of range", func() { _ = make(T, 0, uint(n)) })
84 shouldPanic("len out of range", func() { _ = make(T, int64(n)) })
85 shouldPanic("cap out of range", func() { _ = make(T, 0, int64(n)) })
86 shouldPanic("len out of range", func() { _ = make(T, uint64(n)) })
87 shouldPanic("cap out of range", func() { _ = make(T, 0, uint64(n)) })
90 // Test make+copy panics since the gc compiler optimizes these
91 // to runtime.makeslicecopy calls.
92 func testMakeCopyInts(n uint64) {
95 shouldPanic("len out of range", func() { x := make(T, int(n)); copy(x, c) })
96 shouldPanic("cap out of range", func() { x := make(T, 0, int(n)); copy(x, c) })
97 shouldPanic("len out of range", func() { x := make(T, uint(n)); copy(x, c) })
98 shouldPanic("cap out of range", func() { x := make(T, 0, uint(n)); copy(x, c) })
99 shouldPanic("len out of range", func() { x := make(T, int64(n)); copy(x, c) })
100 shouldPanic("cap out of range", func() { x := make(T, 0, int64(n)); copy(x, c) })
101 shouldPanic("len out of range", func() { x := make(T, uint64(n)); copy(x, c) })
102 shouldPanic("cap out of range", func() { x := make(T, 0, uint64(n)); copy(x, c) })
105 func testMakeCopyBytes(n uint64) {
108 shouldPanic("len out of range", func() { x := make(T, int(n)); copy(x, c) })
109 shouldPanic("cap out of range", func() { x := make(T, 0, int(n)); copy(x, c) })
110 shouldPanic("len out of range", func() { x := make(T, uint(n)); copy(x, c) })
111 shouldPanic("cap out of range", func() { x := make(T, 0, uint(n)); copy(x, c) })
112 shouldPanic("len out of range", func() { x := make(T, int64(n)); copy(x, c) })
113 shouldPanic("cap out of range", func() { x := make(T, 0, int64(n)); copy(x, c) })
114 shouldPanic("len out of range", func() { x := make(T, uint64(n)); copy(x, c) })
115 shouldPanic("cap out of range", func() { x := make(T, 0, uint64(n)); copy(x, c) })
118 // Test make in append panics for int slices since the gc compiler optimizes makes in appends.
119 func testMakeInAppendInts(n uint64) {
121 for _, length := range []int{0, 1} {
123 shouldPanic("len out of range", func() { _ = append(t, make(T, int(n))...) })
124 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, int(n))...) })
125 shouldPanic("len out of range", func() { _ = append(t, make(T, int64(n))...) })
126 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, int64(n))...) })
127 shouldPanic("len out of range", func() { _ = append(t, make(T, uint64(n))...) })
128 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, uint64(n))...) })
129 shouldPanic("len out of range", func() { _ = append(t, make(T, int(n))...) })
130 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, int(n))...) })
131 shouldPanic("len out of range", func() { _ = append(t, make(T, uint(n))...) })
132 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, uint(n))...) })
136 func testMakeInAppendBytes(n uint64) {
138 for _, length := range []int{0, 1} {
140 shouldPanic("len out of range", func() { _ = append(t, make(T, int(n))...) })
141 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, int(n))...) })
142 shouldPanic("len out of range", func() { _ = append(t, make(T, uint(n))...) })
143 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, uint(n))...) })
144 shouldPanic("len out of range", func() { _ = append(t, make(T, int64(n))...) })
145 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, int64(n))...) })
146 shouldPanic("len out of range", func() { _ = append(t, make(T, uint64(n))...) })
147 shouldPanic("cap out of range", func() { _ = append(t, make(T, 0, uint64(n))...) })