Debian Codegraph @

gcc/testsuite/gcc.dg/builtins-68.c

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