Jim Grosbach | f794705 | 2012-07-09 18:34:21 +0000 | [diff] [blame] | 1 | // REQUIRES: arm-registered-target |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -target-abi apcs-gnu -triple armv7-apple-darwin10 %s -verify |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 3 | // expected-no-diagnostics |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 4 | // |
| 5 | // Note: gcc forces the alignment to 4 bytes, regardless of the type of the |
| 6 | // zero length bitfield. |
| 7 | // rdar://9859156 |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 8 | |
| 9 | #include <stddef.h> |
| 10 | |
| 11 | struct t1 |
| 12 | { |
| 13 | int foo : 1; |
| 14 | char : 0; |
| 15 | char bar; |
| 16 | }; |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 17 | static int arr1_offset[(offsetof(struct t1, bar) == 4) ? 0 : -1]; |
| 18 | static int arr1_sizeof[(sizeof(struct t1) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 19 | |
| 20 | struct t2 |
| 21 | { |
| 22 | int foo : 1; |
| 23 | short : 0; |
| 24 | char bar; |
| 25 | }; |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 26 | static int arr2_offset[(offsetof(struct t2, bar) == 4) ? 0 : -1]; |
| 27 | static int arr2_sizeof[(sizeof(struct t2) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 28 | |
| 29 | struct t3 |
| 30 | { |
| 31 | int foo : 1; |
| 32 | int : 0; |
| 33 | char bar; |
| 34 | }; |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 35 | static int arr3_offset[(offsetof(struct t3, bar) == 4) ? 0 : -1]; |
| 36 | static int arr3_sizeof[(sizeof(struct t3) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 37 | |
| 38 | struct t4 |
| 39 | { |
| 40 | int foo : 1; |
| 41 | long : 0; |
| 42 | char bar; |
| 43 | }; |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 44 | static int arr4_offset[(offsetof(struct t4, bar) == 4) ? 0 : -1]; |
| 45 | static int arr4_sizeof[(sizeof(struct t4) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 46 | |
| 47 | struct t5 |
| 48 | { |
| 49 | int foo : 1; |
| 50 | long long : 0; |
| 51 | char bar; |
| 52 | }; |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 53 | static int arr5_offset[(offsetof(struct t5, bar) == 4) ? 0 : -1]; |
| 54 | static int arr5_sizeof[(sizeof(struct t5) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 55 | |
| 56 | struct t6 |
| 57 | { |
| 58 | int foo : 1; |
| 59 | char : 0; |
| 60 | char bar : 1; |
| 61 | char bar2; |
| 62 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 63 | static int arr6_offset[(offsetof(struct t6, bar2) == 5) ? 0 : -1]; |
| 64 | static int arr6_sizeof[(sizeof(struct t6) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 65 | |
| 66 | struct t7 |
| 67 | { |
| 68 | int foo : 1; |
| 69 | short : 0; |
| 70 | char bar1 : 1; |
| 71 | char bar2; |
| 72 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 73 | static int arr7_offset[(offsetof(struct t7, bar2) == 5) ? 0 : -1]; |
| 74 | static int arr7_sizeof[(sizeof(struct t7) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 75 | |
| 76 | struct t8 |
| 77 | { |
| 78 | int foo : 1; |
| 79 | int : 0; |
| 80 | char bar1 : 1; |
| 81 | char bar2; |
| 82 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 83 | static int arr8_offset[(offsetof(struct t8, bar2) == 5) ? 0 : -1]; |
| 84 | static int arr8_sizeof[(sizeof(struct t8) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 85 | |
| 86 | struct t9 |
| 87 | { |
| 88 | int foo : 1; |
| 89 | long : 0; |
| 90 | char bar1 : 1; |
| 91 | char bar2; |
| 92 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 93 | static int arr9_offset[(offsetof(struct t9, bar2) == 5) ? 0 : -1]; |
| 94 | static int arr9_sizeof[(sizeof(struct t9) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 95 | |
| 96 | struct t10 |
| 97 | { |
| 98 | int foo : 1; |
| 99 | long long : 0; |
| 100 | char bar1 : 1; |
| 101 | char bar2; |
| 102 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 103 | static int arr10_offset[(offsetof(struct t10, bar2) == 5) ? 0 : -1]; |
| 104 | static int arr10_sizeof[(sizeof(struct t10) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 105 | |
| 106 | struct t11 |
| 107 | { |
| 108 | int foo : 1; |
| 109 | long long : 0; |
| 110 | char : 0; |
| 111 | char bar1 : 1; |
| 112 | char bar2; |
| 113 | }; |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 114 | static int arr11_offset[(offsetof(struct t11, bar2) == 5) ? 0 : -1]; |
| 115 | static int arr11_sizeof[(sizeof(struct t11) == 8) ? 0 : -1]; |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 116 | |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 117 | struct t12 |
| 118 | { |
| 119 | int foo : 1; |
| 120 | char : 0; |
| 121 | long long : 0; |
| 122 | char : 0; |
| 123 | char bar; |
| 124 | }; |
| 125 | static int arr12_offset[(offsetof(struct t12, bar) == 4) ? 0 : -1]; |
| 126 | static int arr12_sizeof[(sizeof(struct t12) == 8) ? 0 : -1]; |
| 127 | |
Chad Rosier | b8fca90 | 2011-08-05 22:38:04 +0000 | [diff] [blame] | 128 | struct t13 |
| 129 | { |
| 130 | char foo; |
| 131 | long : 0; |
| 132 | char bar; |
| 133 | }; |
| 134 | static int arr13_offset[(offsetof(struct t13, bar) == 4) ? 0 : -1]; |
| 135 | static int arr13_sizeof[(sizeof(struct t13) == 8) ? 0 : -1]; |
| 136 | |
| 137 | struct t14 |
| 138 | { |
| 139 | char foo1; |
| 140 | int : 0; |
| 141 | char foo2 : 1; |
| 142 | short foo3 : 16; |
| 143 | char : 0; |
| 144 | short foo4 : 16; |
| 145 | char bar1; |
| 146 | int : 0; |
| 147 | char bar2; |
| 148 | }; |
| 149 | static int arr14_bar1_offset[(offsetof(struct t14, bar1) == 10) ? 0 : -1]; |
| 150 | static int arr14_bar2_offset[(offsetof(struct t14, bar2) == 12) ? 0 : -1]; |
| 151 | static int arr14_sizeof[(sizeof(struct t14) == 16) ? 0 : -1]; |
| 152 | |
| 153 | struct t15 |
| 154 | { |
| 155 | char foo; |
| 156 | char : 0; |
| 157 | int : 0; |
| 158 | char bar; |
| 159 | long : 0; |
| 160 | char : 0; |
| 161 | }; |
| 162 | static int arr15_offset[(offsetof(struct t15, bar) == 4) ? 0 : -1]; |
| 163 | static int arr15_sizeof[(sizeof(struct t15) == 8) ? 0 : -1]; |
| 164 | |
| 165 | struct t16 |
| 166 | { |
| 167 | long : 0; |
| 168 | char bar; |
| 169 | }; |
| 170 | static int arr16_offset[(offsetof(struct t16, bar) == 0) ? 0 : -1]; |
| 171 | static int arr16_sizeof[(sizeof(struct t16) == 4) ? 0 : -1]; |
| 172 | |
| 173 | struct t17 |
| 174 | { |
| 175 | char foo; |
| 176 | long : 0; |
| 177 | long : 0; |
| 178 | char : 0; |
| 179 | char bar; |
| 180 | }; |
| 181 | static int arr17_offset[(offsetof(struct t17, bar) == 4) ? 0 : -1]; |
| 182 | static int arr17_sizeof[(sizeof(struct t17) == 8) ? 0 : -1]; |
| 183 | |
| 184 | struct t18 |
| 185 | { |
| 186 | long : 0; |
| 187 | long : 0; |
| 188 | char : 0; |
| 189 | }; |
| 190 | static int arr18_sizeof[(sizeof(struct t18) == 0) ? 0 : -1]; |
| 191 | |
| 192 | struct t19 |
| 193 | { |
| 194 | char foo1; |
| 195 | long foo2 : 1; |
| 196 | char : 0; |
| 197 | long foo3 : 32; |
| 198 | char bar; |
| 199 | }; |
| 200 | static int arr19_offset[(offsetof(struct t19, bar) == 8) ? 0 : -1]; |
| 201 | static int arr19_sizeof[(sizeof(struct t19) == 12) ? 0 : -1]; |
| 202 | |
| 203 | struct t20 |
| 204 | { |
| 205 | short : 0; |
| 206 | int foo : 1; |
| 207 | long : 0; |
| 208 | char bar; |
| 209 | }; |
| 210 | static int arr20_offset[(offsetof(struct t20, bar) == 4) ? 0 : -1]; |
| 211 | static int arr20_sizeof[(sizeof(struct t20) == 8) ? 0 : -1]; |
| 212 | |
| 213 | struct t21 |
| 214 | { |
| 215 | short : 0; |
| 216 | int foo1 : 1; |
| 217 | char : 0; |
| 218 | int foo2 : 16; |
| 219 | long : 0; |
| 220 | char bar1; |
| 221 | int bar2; |
| 222 | long bar3; |
| 223 | char foo3 : 8; |
| 224 | char : 0; |
| 225 | long : 0; |
| 226 | int foo4 : 32; |
| 227 | short foo5: 1; |
| 228 | long bar4; |
| 229 | short foo6: 16; |
| 230 | short foo7: 16; |
| 231 | short foo8: 16; |
| 232 | }; |
| 233 | static int arr21_bar1_offset[(offsetof(struct t21, bar1) == 8) ? 0 : -1]; |
| 234 | static int arr21_bar2_offset[(offsetof(struct t21, bar2) == 12) ? 0 : -1]; |
| 235 | static int arr21_bar3_offset[(offsetof(struct t21, bar3) == 16) ? 0 : -1]; |
| 236 | static int arr21_bar4_offset[(offsetof(struct t21, bar4) == 32) ? 0 : -1]; |
| 237 | static int arr21_sizeof[(sizeof(struct t21) == 44) ? 0 : -1]; |
| 238 | |
Chad Rosier | 4ab0024 | 2011-08-04 00:19:13 +0000 | [diff] [blame] | 239 | int main() { |
| 240 | return 0; |
| 241 | } |
| 242 | |