1 /* PR middle-end/69780 - [4.9/5/6 Regression] ICE on
2 __builtin_alloca_with_align with small alignment */
3 /* { dg-do compile } */
4 /* { dg-require-effective-target alloca } */
5 /* { dg-options "-Wno-long-long" } */
7 #define CHAR_BIT __CHAR_BIT__
8 #define SIZE_MAX __SIZE_MAX__
9 #define UINT_MAX (__INT_MAX__ + 1U)
11 /* The largest valid alignment is undocumented and subject to change
12 but for the purposes of white box testing we rely on knowing that
13 it happens to be defined to (UINT_MAX >> 1) + 1. */
14 #define ALIGN_MAX ((UINT_MAX >> 1) + 1)
16 #if UINT_MAX < SIZE_MAX
17 /* Define a constant to exercise an alignment that is valid a power
18 of 2 in excess of the maximum. */
19 # define MAX_X_2 (ALIGN_MAX << 1)
21 /* For targets where UINT_MAX is the same as SIZE_MAX, use an invalid
22 alignment that's less than the maximum to elicit the same errors. */
23 # define MAX_X_2 (ALIGN_MAX + 1)
28 /* Verify that valid __builtin_alloca_with_align expressions are accepted. */
29 void test_valid (int n
)
40 /* Valid alignments are power of 2 positive multiples of CHAR_BIT. */
41 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 1);
42 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 2);
43 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 4);
44 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 8);
45 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 16);
46 p
= __builtin_alloca_with_align (n
, CHAR_BIT
* 32);
48 p
= __builtin_alloca_with_align (n
, A1
);
49 p
= __builtin_alloca_with_align (n
, A2
);
50 p
= __builtin_alloca_with_align (n
, A4
);
51 p
= __builtin_alloca_with_align (n
, A8
);
52 p
= __builtin_alloca_with_align (n
, A16
);
53 p
= __builtin_alloca_with_align (n
, A32
);
56 /* Non-integer alignments must be rejected. */
57 void test_arg2_non_int (int n
)
59 /* Verify the full text of the diagnostic just once. */
60 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 " } */
62 /* Disable diagnostic complaining about converting void* to int that
63 preempts the "constant integer expression" error. */
64 #pragma GCC diagnostic push
65 #pragma GCC diagnostic ignored "-Wint-conversion"
67 p
= __builtin_alloca_with_align (n
, (void*)0); /* { dg-error "must be a constant integer" } */
68 p
= __builtin_alloca_with_align (n
, ""); /* { dg-error "must be a constant integer" } */
69 p
= __builtin_alloca_with_align (n
, L
""); /* { dg-error "must be a constant integer" } */
71 #pragma GCC diagnostic pop
75 /* Integer alignment that's not a constant expression must be rejected. */
76 void test_arg2_non_const (int n
, int a1
)
79 static const int a3
= CHAR_BIT
;
80 static volatile const int a4
= CHAR_BIT
;
82 p
= __builtin_alloca_with_align (n
, a1
); /* { dg-error "must be a constant integer" } */
83 p
= __builtin_alloca_with_align (n
, a2
); /* { dg-error "must be a constant integer" } */
84 p
= __builtin_alloca_with_align (n
, a3
); /* { dg-error "must be a constant integer" } */
85 p
= __builtin_alloca_with_align (n
, a4
); /* { dg-error "must be a constant integer" } */
88 /* Constant integer alignment that's not a power of 2 positive multiple
89 of CHAR_BIT less than (1LLU << 32) must be rejected. */
90 void test_arg2_non_pow2 (int n
)
92 p
= __builtin_alloca_with_align (n
, 0); /* { dg-error "must be a constant integer" } */
93 p
= __builtin_alloca_with_align (n
, 1); /* { dg-error "must be a constant integer" } */
94 p
= __builtin_alloca_with_align (n
, 2); /* { dg-error "must be a constant integer" } */
95 p
= __builtin_alloca_with_align (n
, 3); /* { dg-error "must be a constant integer" } */
96 p
= __builtin_alloca_with_align (n
, 4); /* { dg-error "must be a constant integer" } */
97 p
= __builtin_alloca_with_align (n
, 5); /* { dg-error "must be a constant integer" } */
98 p
= __builtin_alloca_with_align (n
, 6); /* { dg-error "must be a constant integer" } */
99 p
= __builtin_alloca_with_align (n
, 7); /* { dg-error "must be a constant integer" } */
100 p
= __builtin_alloca_with_align (n
, 9); /* { dg-error "must be a constant integer" } */
101 p
= __builtin_alloca_with_align (n
, 10); /* { dg-error "must be a constant integer" } */
102 p
= __builtin_alloca_with_align (n
, 11); /* { dg-error "must be a constant integer" } */
103 p
= __builtin_alloca_with_align (n
, 12); /* { dg-error "must be a constant integer" } */
104 p
= __builtin_alloca_with_align (n
, 13); /* { dg-error "must be a constant integer" } */
105 p
= __builtin_alloca_with_align (n
, 14); /* { dg-error "must be a constant integer" } */
106 p
= __builtin_alloca_with_align (n
, 15); /* { dg-error "must be a constant integer" } */
107 p
= __builtin_alloca_with_align (n
, 17); /* { dg-error "must be a constant integer" } */
108 p
= __builtin_alloca_with_align (n
, 31); /* { dg-error "must be a constant integer" } */
109 p
= __builtin_alloca_with_align (n
, 33); /* { dg-error "must be a constant integer" } */
110 p
= __builtin_alloca_with_align (n
, 63); /* { dg-error "must be a constant integer" } */
111 p
= __builtin_alloca_with_align (n
, 65); /* { dg-error "must be a constant integer" } */
112 p
= __builtin_alloca_with_align (n
, SIZE_MAX
); /* { dg-error "must be a constant integer" } */
113 p
= __builtin_alloca_with_align (n
, MAX_X_2
); /* { dg-error "must be a constant integer" } */