annotate gcc/testsuite/g++.dg/ext/builtin_alloca.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // PR middle-end/69780 - [4.9/5/6 Regression] ICE on
kono
parents:
diff changeset
2 // __builtin_alloca_with_align with small alignment
kono
parents:
diff changeset
3 // { dg-do compile }
kono
parents:
diff changeset
4 // { dg-require-effective-target alloca }
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 #define CHAR_BIT __CHAR_BIT__
kono
parents:
diff changeset
7 #define SIZE_MAX __SIZE_MAX__
kono
parents:
diff changeset
8 #define UINT_MAX (__INT_MAX__ + 1U)
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 /* The largest valid alignment is undocumented and subject to change
kono
parents:
diff changeset
11 but for the purposes of white box testing we rely on knowing that
kono
parents:
diff changeset
12 it happens to be defined to (UINT_MAX >> 1) + 1. */
kono
parents:
diff changeset
13 #define ALIGN_MAX ((UINT_MAX >> 1) + 1)
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 #if UINT_MAX < SIZE_MAX
kono
parents:
diff changeset
16 /* Define a constant to exercise an alignment that is valid a power
kono
parents:
diff changeset
17 of 2 in excess of the maximum. */
kono
parents:
diff changeset
18 # define MAX_X_2 (ALIGN_MAX << 1)
kono
parents:
diff changeset
19 #else
kono
parents:
diff changeset
20 /* For targets where UINT_MAX is the same as SIZE_MAX, use an invalid
kono
parents:
diff changeset
21 alignment that's less than the maximum to elicit the same errors. */
kono
parents:
diff changeset
22 # define MAX_X_2 (ALIGN_MAX + 1)
kono
parents:
diff changeset
23 #endif
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 static void* p;
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 // Verify that valid __builtin_alloca_with_align expressions are accepted.
kono
parents:
diff changeset
28 void test_valid (int n)
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 enum {
kono
parents:
diff changeset
31 A1 = CHAR_BIT * 1,
kono
parents:
diff changeset
32 A2 = CHAR_BIT * 2,
kono
parents:
diff changeset
33 A4 = CHAR_BIT * 4,
kono
parents:
diff changeset
34 A8 = CHAR_BIT * 8,
kono
parents:
diff changeset
35 A16 = CHAR_BIT * 16,
kono
parents:
diff changeset
36 A32 = CHAR_BIT * 32
kono
parents:
diff changeset
37 };
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 const int a1 = A1;
kono
parents:
diff changeset
40 const int a2 = A2;
kono
parents:
diff changeset
41 const int a4 = A4;
kono
parents:
diff changeset
42 const int a8 = A8;
kono
parents:
diff changeset
43 const int a16 = A16;
kono
parents:
diff changeset
44 const int a32 = A32;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 // Valid alignments are power of 2 positive multiples of CHAR_BIT.
kono
parents:
diff changeset
47 p = __builtin_alloca_with_align (n, CHAR_BIT * 1);
kono
parents:
diff changeset
48 p = __builtin_alloca_with_align (n, CHAR_BIT * 2);
kono
parents:
diff changeset
49 p = __builtin_alloca_with_align (n, CHAR_BIT * 4);
kono
parents:
diff changeset
50 p = __builtin_alloca_with_align (n, CHAR_BIT * 8);
kono
parents:
diff changeset
51 p = __builtin_alloca_with_align (n, CHAR_BIT * 16);
kono
parents:
diff changeset
52 p = __builtin_alloca_with_align (n, CHAR_BIT * 32);
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 p = __builtin_alloca_with_align (n, A1);
kono
parents:
diff changeset
55 p = __builtin_alloca_with_align (n, A2);
kono
parents:
diff changeset
56 p = __builtin_alloca_with_align (n, A4);
kono
parents:
diff changeset
57 p = __builtin_alloca_with_align (n, A8);
kono
parents:
diff changeset
58 p = __builtin_alloca_with_align (n, A16);
kono
parents:
diff changeset
59 p = __builtin_alloca_with_align (n, A32);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 p = __builtin_alloca_with_align (n, a1);
kono
parents:
diff changeset
62 p = __builtin_alloca_with_align (n, a2);
kono
parents:
diff changeset
63 p = __builtin_alloca_with_align (n, a4);
kono
parents:
diff changeset
64 p = __builtin_alloca_with_align (n, a8);
kono
parents:
diff changeset
65 p = __builtin_alloca_with_align (n, a16);
kono
parents:
diff changeset
66 p = __builtin_alloca_with_align (n, a32);
kono
parents:
diff changeset
67 }
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 template <int A> struct X { enum { Align = A }; };
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 template <int A>
kono
parents:
diff changeset
72 void test_valid_template (int n)
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 // Valid alignments are power of 2 positive multiples of CHAR_BIT.
kono
parents:
diff changeset
75 p = __builtin_alloca_with_align (n, A);
kono
parents:
diff changeset
76 }
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 template void test_valid_template<CHAR_BIT>(int);
kono
parents:
diff changeset
79 template void test_valid_template<CHAR_BIT * 2>(int);
kono
parents:
diff changeset
80 template void test_valid_template<CHAR_BIT * 4>(int);
kono
parents:
diff changeset
81 template void test_valid_template<CHAR_BIT * 8>(int);
kono
parents:
diff changeset
82 template void test_valid_template<CHAR_BIT * 16>(int);
kono
parents:
diff changeset
83 template void test_valid_template<CHAR_BIT * 32>(int);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 // Exercise the alignment in a dependent context.
kono
parents:
diff changeset
86 template <int A>
kono
parents:
diff changeset
87 void test_valid_template_dep (int n)
kono
parents:
diff changeset
88 {
kono
parents:
diff changeset
89 // Valid alignments are power of 2 positive multiples of CHAR_BIT.
kono
parents:
diff changeset
90 p = __builtin_alloca_with_align (n, X<A>::Align);
kono
parents:
diff changeset
91 }
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 template void test_valid_template_dep<CHAR_BIT>(int);
kono
parents:
diff changeset
94 template void test_valid_template_dep<CHAR_BIT * 2>(int);
kono
parents:
diff changeset
95 template void test_valid_template_dep<CHAR_BIT * 4>(int);
kono
parents:
diff changeset
96 template void test_valid_template_dep<CHAR_BIT * 8>(int);
kono
parents:
diff changeset
97 template void test_valid_template_dep<CHAR_BIT * 16>(int);
kono
parents:
diff changeset
98 template void test_valid_template_dep<CHAR_BIT * 32>(int);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 // Invalid size must be rejected (and not cause an ICE).
kono
parents:
diff changeset
101 void test_arg1_non_int (int n)
kono
parents:
diff changeset
102 {
kono
parents:
diff changeset
103 extern void f ();
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 p = __builtin_alloca_with_align ((void*)0, 32); // { dg-error "invalid conversion" }
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 p = __builtin_alloca_with_align ("", 32); // { dg-error "invalid conversion" }
kono
parents:
diff changeset
108 p = __builtin_alloca_with_align (L"", 32); // { dg-error "invalid conversion" }
kono
parents:
diff changeset
109 p = __builtin_alloca_with_align (f, 32); // { dg-error "invalid conversion" }
kono
parents:
diff changeset
110 }
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 // Non-integer alignment must be rejected.
kono
parents:
diff changeset
113 void test_arg2_non_int (int n)
kono
parents:
diff changeset
114 {
kono
parents:
diff changeset
115 // Verify the full text of the diagnostic just once.
kono
parents:
diff changeset
116 p = __builtin_alloca_with_align (n, 0.0); // { dg-error "second argument to function .__builtin_alloca_with_align. must be a constant integer power of 2 between .8. and " }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 p = __builtin_alloca_with_align (n, (void*)0); // { dg-error "invalid conversion|must be a constant integer" }
kono
parents:
diff changeset
119 p = __builtin_alloca_with_align (n, ""); // { dg-error "invalid conversion|must be a constant integer" }
kono
parents:
diff changeset
120 p = __builtin_alloca_with_align (n, L""); // { dg-error "invalid conversion|must be a constant integer" }
kono
parents:
diff changeset
121 }
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 // Integer alignment that's not a constant expression must be rejected.
kono
parents:
diff changeset
124 void test_arg2_non_const (int n, int a1)
kono
parents:
diff changeset
125 {
kono
parents:
diff changeset
126 extern const int a2;
kono
parents:
diff changeset
127 static volatile const int a3 = CHAR_BIT;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 p = __builtin_alloca_with_align (n, a1); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
130 p = __builtin_alloca_with_align (n, a2); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
131 p = __builtin_alloca_with_align (n, a3); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
132 }
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 // Constant integer alignment that's not a power of 2 positive multiple
kono
parents:
diff changeset
135 // of CHAR_BIT must be rejected.
kono
parents:
diff changeset
136 void test_arg2_non_pow2 (int n)
kono
parents:
diff changeset
137 {
kono
parents:
diff changeset
138 p = __builtin_alloca_with_align (n, 0); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
139 p = __builtin_alloca_with_align (n, 1); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
140 p = __builtin_alloca_with_align (n, 2); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
141 p = __builtin_alloca_with_align (n, 3); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
142 p = __builtin_alloca_with_align (n, 4); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
143 p = __builtin_alloca_with_align (n, 5); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
144 p = __builtin_alloca_with_align (n, 6); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
145 p = __builtin_alloca_with_align (n, 7); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
146 p = __builtin_alloca_with_align (n, 9); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
147 p = __builtin_alloca_with_align (n, 10); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
148 p = __builtin_alloca_with_align (n, 11); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
149 p = __builtin_alloca_with_align (n, 12); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
150 p = __builtin_alloca_with_align (n, 13); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
151 p = __builtin_alloca_with_align (n, 14); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
152 p = __builtin_alloca_with_align (n, 15); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
153 p = __builtin_alloca_with_align (n, 17); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
154 p = __builtin_alloca_with_align (n, 31); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
155 p = __builtin_alloca_with_align (n, 33); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
156 p = __builtin_alloca_with_align (n, 63); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
157 p = __builtin_alloca_with_align (n, 65); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
158 p = __builtin_alloca_with_align (n, SIZE_MAX); /* { dg-error "must be a constant integer" } */
kono
parents:
diff changeset
159 p = __builtin_alloca_with_align (n, MAX_X_2); /* { dg-error "must be a constant integer" } */
kono
parents:
diff changeset
160 }
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 // Exercise invalid alignment specified by a template argument.
kono
parents:
diff changeset
163 template <int A>
kono
parents:
diff changeset
164 void test_invalid_template_1 (int n)
kono
parents:
diff changeset
165 {
kono
parents:
diff changeset
166 // Valid alignments are power of 2 positive multiples of CHAR_BIT.
kono
parents:
diff changeset
167 p = __builtin_alloca_with_align (n, A); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
168 }
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 template void test_invalid_template_1<1>(int);
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 template <int A>
kono
parents:
diff changeset
173 void test_invalid_template_7 (int n)
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 p = __builtin_alloca_with_align (n, A); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 template void test_invalid_template_7<7>(int);
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 template <int A>
kono
parents:
diff changeset
181 void test_invalid_template_9 (int n)
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 p = __builtin_alloca_with_align (n, A); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 template void test_invalid_template_9<9>(int);
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 // Exercise invalid alignment specified by a template dependent argument.
kono
parents:
diff changeset
189 template <int A>
kono
parents:
diff changeset
190 void test_invalid_template_dep_1 (int n)
kono
parents:
diff changeset
191 {
kono
parents:
diff changeset
192 p = __builtin_alloca_with_align (n, X<A>::Align); // { dg-error "must be a constant integer" }
kono
parents:
diff changeset
193 }
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 template void test_invalid_template_dep_1<1>(int);