1// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 2// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf 3// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu 4// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu 5// expected-no-diagnostics 6 7#define CHECK_SIZE(name, size) \ 8 extern int name##_1[sizeof(name) == size ? 1 : -1]; 9 10 11struct __attribute__((packed)) { 12 int a; 13 int b : 4; 14 int c : 32; 15} s0; 16CHECK_SIZE(s0,9) 17 18#pragma pack (1) 19struct { 20 int a; 21 int b : 4; 22 int c : 32; 23} s1; 24CHECK_SIZE(s1,9) 25 26#pragma pack (2) 27struct { 28 int a; 29 int b : 4; 30 int c : 32; 31} s2; 32CHECK_SIZE(s2,10) 33 34#pragma pack (2) 35struct __attribute__((packed)) { 36 int a; 37 int b : 4; 38 int c : 32; 39} s3; 40CHECK_SIZE(s3,10) 41 42#pragma pack (4) 43struct __attribute__((packed)) { 44 int a; 45 int b : 4; 46 int c : 32; 47} s4; 48CHECK_SIZE(s4,12) 49 50#pragma pack (16) 51struct { 52 int a; 53 int __attribute__((packed)) b : 4; 54 int __attribute__((packed)) c : 32; 55} s41; 56CHECK_SIZE(s41,12) 57 58#pragma pack (16) 59struct { 60 int a; 61 int b : 4; 62 int c : 32; 63} s5; 64CHECK_SIZE(s5,12) 65 66#pragma pack (1) 67struct __attribute__((aligned(4))) { 68 int a; 69 int b : 4; 70 int c : 32; 71} s6; 72CHECK_SIZE(s6,12) 73 74#pragma pack (2) 75struct { 76 char a; 77 int b : 4; 78 int c : 32; 79 char s; 80} s7; 81CHECK_SIZE(s7,8) 82 83#pragma pack (1) 84struct { 85 char a; 86 int b : 4; 87 int c : 28; 88 char s; 89} s8; 90CHECK_SIZE(s8,6) 91 92#pragma pack (8) 93struct { 94 char a; 95 int b : 4; 96 int c : 28; 97 char s; 98} s9; 99CHECK_SIZE(s9,8) 100 101#pragma pack (8) 102struct { 103 char a; 104 char s; 105} s10; 106CHECK_SIZE(s10,2) 107 108#pragma pack(4) 109struct { 110 char a; 111 int b : 4; 112 int c : 28; 113 char s1; 114 char s2; 115 char s3; 116} s11; 117CHECK_SIZE(s11,8) 118 119#pragma pack(4) 120struct { 121 short s1; 122 int a1 : 17; 123 int a2 : 17; 124 int a3 : 30; 125 short s2; 126} s12; 127CHECK_SIZE(s12,12) 128 129#pragma pack(4) 130struct { 131 char c1; 132 int i1 : 17; 133 int i2 : 17; 134 int i3 : 30; 135 char c2; 136} s13; 137CHECK_SIZE(s13,12) 138 139#pragma pack(2) 140struct { 141 char a; 142 int s; 143} s14; 144CHECK_SIZE(s14,6) 145 146#pragma pack(4) 147struct { 148 char a; 149 short s; 150} s15; 151CHECK_SIZE(s15,4) 152 153#pragma pack(2) 154struct { 155 char a; 156 int b : 4; 157 int c : 28; 158 char s1; 159 char s2; 160 char s3; 161} s16; 162CHECK_SIZE(s16,8) 163 164#pragma pack (16) 165struct { 166 int __attribute__((packed)) a; 167 int __attribute__((packed)) b : 4; 168 int __attribute__((packed)) c : 32; 169} s17; 170CHECK_SIZE(s17,12) 171 172#pragma pack (16) 173struct { 174 int __attribute__((aligned(8))) a; 175 int __attribute__((aligned(8))) b : 4; 176 int __attribute__((aligned(8))) c : 32; 177} s18; 178CHECK_SIZE(s18,24) 179 180#pragma pack (16) 181struct { 182 int __attribute__((aligned(1))) a; 183 int __attribute__((aligned(1))) b : 4; 184 int __attribute__((aligned(1))) c : 32; 185} s19; 186CHECK_SIZE(s19,12) 187 188#pragma pack (1) 189struct __attribute__((aligned(8))) { 190 int a; 191 int b : 4; 192 int c : 32; 193} s20; 194CHECK_SIZE(s20,16) 195 196#pragma pack (2) 197struct { 198 int __attribute__((aligned(8))) a; 199 int __attribute__((aligned(8))) b : 4; 200 int __attribute__((aligned(8))) c : 32; 201} s21; 202CHECK_SIZE(s21,10) 203