]>
Commit | Line | Data |
---|---|---|
4c7bd361 MS |
1 | /* PR c/87795 - Excessive alignment permitted for functions and labels |
2 | { dg-do compile } | |
3 | { dg-options "-Wno-pedantic" } */ | |
4 | ||
5 | /* The maximum alignment GCC can handle. */ | |
6 | #define ALIGN_MAX_HARD 0x10000000 | |
7 | ||
8 | /* Hardcode a few known values for testing the tight bounds. */ | |
9 | #if __hpux__ && __hppa__ && __LP64__ | |
10 | /* Maximum alignment for functions and objects with static storage | |
11 | duration that's expected to be accepted. */ | |
12 | # define ALIGN_MAX_STATIC 0x1000 | |
13 | /* Excessive alignment for functions and objects with static storage | |
14 | duration that's expected to trigger an error. */ | |
19bf83a9 IS |
15 | #elif __APPLE__ |
16 | # if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070 | |
17 | # define ALIGN_MAX_STATIC 0x8000 | |
18 | # else | |
19 | # define ALIGN_MAX_STATIC ALIGN_MAX_HARD | |
20 | # endif | |
4c7bd361 MS |
21 | #elif pdp11 |
22 | # define ALIGN_MAX_STATIC 2 | |
23 | /* Work around a pdp11 ICE (see PR target/87821). */ | |
24 | # define ALIGN_MAX_AUTO (ALIGN_MAX_HARD >> 14) | |
25 | #elif __powerpc64__ || __x86_64__ | |
26 | /* Is this processor- or operating-system specific? */ | |
27 | # define ALIGN_MAX_STATIC ALIGN_MAX_HARD | |
28 | #else | |
29 | /* Guaranteed to be accepted regardless of the target. */ | |
30 | # define ALIGN_MAX_STATIC __BIGGEST_ALIGNMENT__ | |
31 | /* Guaranteed to be rejected regardless of the target. */ | |
32 | # define ALIGN_TOO_BIG_OFILE (ALIGN_MAX_HARD << 1) | |
33 | #endif | |
34 | ||
35 | /* Maximum alignment for auto objects that's expected to be accepted. */ | |
36 | #ifndef ALIGN_MAX_AUTO | |
37 | # define ALIGN_MAX_AUTO ALIGN_MAX_HARD | |
38 | #endif | |
39 | ||
40 | #ifndef ALIGN_TOO_BIG_OFILE | |
41 | # define ALIGN_TOO_BIG_OFILE (ALIGN_MAX_STATIC << 1) | |
42 | #endif | |
43 | ||
44 | ||
45 | #define ALIGN(N) __attribute__ ((aligned (N))) | |
46 | ||
47 | ||
48 | /* Verify that types can be defined maximally overaligned using | |
49 | attribute aligned. */ | |
50 | typedef ALIGN (ALIGN_MAX_HARD) char CharAlignedMaxHard; | |
51 | typedef ALIGN (ALIGN_MAX_AUTO) char CharAlignedMaxAuto; | |
52 | typedef ALIGN (ALIGN_MAX_STATIC) char CharAlignedMaxStatic; | |
53 | ||
54 | #if ALIGN_TOO_BIG_OFILE < ALIGN_MAX_HARD | |
55 | /* Also verify that an alignment greater than MAX_OFILE_ALIGNMENT | |
56 | is accepted unless the constant is as large as GCC's maximum | |
57 | supported alignment in any context. */ | |
58 | typedef ALIGN (ALIGN_TOO_BIG_OFILE) char CharAlignedTooBig; | |
59 | #endif | |
60 | ||
61 | CharAlignedMaxStatic t_max; | |
62 | ||
63 | /* Verify that globals can be defined maximally overaligned using | |
64 | attribute aligned. */ | |
65 | ALIGN (ALIGN_MAX_STATIC) static const char aligned_sc_max = 0; | |
66 | ALIGN (ALIGN_MAX_STATIC) const char aligned_c_max = aligned_sc_max; | |
67 | ALIGN (ALIGN_MAX_STATIC) char aligned_v_max; | |
68 | ALIGN (ALIGN_MAX_STATIC) void aligned_f_max (void); | |
69 | ||
70 | _Static_assert (__alignof__ (aligned_sc_max) == ALIGN_MAX_STATIC); | |
71 | _Static_assert (__alignof__ (aligned_c_max) == ALIGN_MAX_STATIC); | |
72 | _Static_assert (__alignof__ (aligned_v_max) == ALIGN_MAX_STATIC); | |
73 | _Static_assert (__alignof__ (aligned_f_max) == ALIGN_MAX_STATIC); | |
74 | ||
75 | ||
76 | /* Verify that globals can be defined maximally overaligned using | |
77 | _Alignas. */ | |
78 | _Alignas (ALIGN_MAX_STATIC) static const char alignas_sc_max = 0; | |
79 | _Alignas (ALIGN_MAX_STATIC) const char alignas_c_max = alignas_sc_max; | |
80 | _Alignas (ALIGN_MAX_STATIC) char alignas_v_max; | |
81 | ||
82 | _Static_assert (__alignof__ (alignas_sc_max) == ALIGN_MAX_STATIC); | |
83 | _Static_assert (__alignof__ (alignas_c_max) == ALIGN_MAX_STATIC); | |
84 | _Static_assert (__alignof__ (alignas_v_max) == ALIGN_MAX_STATIC); | |
85 | ||
86 | ||
87 | /* Verify that auto and static local variables can be defined maximally | |
88 | overaligned. */ | |
89 | ||
90 | int accept_local_attribute_aligned (void) | |
91 | { | |
92 | #if ALIGN_TOO_BIG_OFILE < ALIGN_MAX_HARD | |
93 | /* Same as above. */ | |
94 | typedef ALIGN (ALIGN_TOO_BIG_OFILE) char LocalCharAlignedTooBig; | |
95 | LocalCharAlignedTooBig aligned_lt_too_big = 0; | |
96 | (void)&aligned_lt_too_big; | |
97 | #endif | |
98 | ||
99 | static CharAlignedMaxStatic aligned_st_max; | |
100 | _Static_assert (_Alignof (aligned_st_max) == ALIGN_MAX_STATIC); | |
101 | ||
102 | CharAlignedMaxAuto aligned_t_max; | |
103 | _Static_assert (_Alignof (aligned_t_max) == ALIGN_MAX_AUTO); | |
104 | ||
105 | ALIGN (ALIGN_MAX_STATIC) char aligned_s_max; | |
106 | _Static_assert (_Alignof (aligned_s_max) == ALIGN_MAX_STATIC); | |
107 | ||
108 | ALIGN (ALIGN_MAX_AUTO) char aligned_l_max; | |
109 | _Static_assert (_Alignof (aligned_l_max) == ALIGN_MAX_AUTO); | |
110 | ||
111 | return aligned_st_max++ + aligned_t_max++ + aligned_s_max++ + aligned_l_max++; | |
112 | } | |
113 | ||
114 | ||
115 | int accept_local_alignas (void) | |
116 | { | |
117 | _Alignas (ALIGN_MAX_STATIC) char alignas_s_max; | |
118 | _Static_assert (_Alignof (alignas_s_max) == ALIGN_MAX_STATIC); | |
119 | ||
120 | _Alignas (ALIGN_MAX_AUTO) char alignas_l_max; | |
121 | _Static_assert (_Alignof (alignas_l_max) == ALIGN_MAX_AUTO); | |
122 | ||
123 | return alignas_s_max++ + alignas_l_max++; | |
124 | } | |
125 | ||
126 | ||
127 | /* Verify that auto and static local variables are subject to the object | |
128 | file alignment limit. The "object file" part may not be mentioned if | |
129 | the object file maximum is the same as GCC's internal maximum. */ | |
130 | ||
131 | int reject_local_align (void) | |
132 | { | |
133 | /* Ironically, the errors below are on different lines for each | |
134 | of the two declarations if the aligned attribute is on a line | |
135 | of its own. */ | |
136 | ALIGN (ALIGN_TOO_BIG_OFILE) static char aligned_sl_max; /* { dg-error "requested alignment .\[0-9\]+. exceeds\( object file\)* maximum \[0-9\]+" } */ | |
137 | ||
138 | _Alignas (ALIGN_TOO_BIG_OFILE) static char alignas_sl_max; /* { dg-error "alignment" } */ | |
139 | ||
140 | return aligned_sl_max++ + alignas_sl_max++; | |
141 | } | |
142 | ||
143 | ||
144 | /* Verify that global variables are subject to the object file | |
145 | alignment limit. */ | |
146 | ||
147 | ALIGN (ALIGN_TOO_BIG_OFILE) char a_max_x_2; /* { dg-error "requested alignment .\[0-9\]+. exceeds\( object file\)* maximum \[0-9\]+" } */ | |
148 | ||
149 | _Alignas (ALIGN_TOO_BIG_OFILE) char a_max_x_2; /* { dg-error "alignment" } */ | |
150 | ||
151 | ALIGN (ALIGN_TOO_BIG_OFILE) void f_max_x_2 (void); /* { dg-error "requested alignment .\[0-9\]+. exceeds\( object file\)* maximum \[0-9\]+" } */ |