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