1 // RUN: %clang_cc1 -w -fdump-record-layouts %s > %t.layouts 2 // RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.before 3 // RUN: %clang_cc1 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after 4 // RUN: diff %t.before %t.after 5 // RUN: FileCheck %s < %t.after 6 7 // If not explicitly disabled, set PACKED to the packed attribute. 8 #ifndef PACKED 9 # define PACKED __attribute__((packed)) 10 #endif 11 12 // If not explicitly disabled, set ALIGNED16 to 16-byte alignment. 13 #ifndef ALIGNED16 14 # define ALIGNED16 __attribute__((aligned(16))) 15 #endif 16 17 // CHECK: Type: struct X0 18 struct X0 { 19 int x[6] PACKED; 20 }; 21 22 void use_X0() { struct X0 x0; x0.x[5] = sizeof(struct X0); }; 23 24 // CHECK: Type: struct X1 25 struct X1 { 26 char x[13]; 27 struct X0 y; 28 } PACKED; 29 30 void use_X1() { struct X1 x1; x1.x[5] = sizeof(struct X1); }; 31 32 // CHECK: Type: struct X2 33 struct PACKED X2 { 34 short x; 35 int y; 36 }; 37 38 void use_X2() { struct X2 x2; x2.y = sizeof(struct X2); }; 39 40 // CHECK: Type: struct X3 41 struct X3 { 42 short x PACKED; 43 int y; 44 }; 45 46 void use_X3() { struct X3 x3; x3.y = sizeof(struct X3); }; 47 48 #pragma pack(push,2) 49 // CHECK: Type: struct X4 50 struct X4 { 51 int x; 52 int y; 53 }; 54 #pragma pack(pop) 55 56 void use_X4() { struct X4 x4; x4.y = sizeof(struct X4); }; 57 58 // CHECK: Type: struct X5 59 struct PACKED X5 { double a[19]; signed char b; }; 60 61 void use_X5() { struct X5 x5; x5.b = sizeof(struct X5); }; 62 63 // CHECK: Type: struct X6 64 struct PACKED X6 { long double a; char b; }; 65 66 void use_X6() { struct X6 x6; x6.b = sizeof(struct X6); }; 67 68 // CHECK: Type: struct X7 69 struct X7 { 70 unsigned x; 71 unsigned char y; 72 } PACKED; 73 74 void use_X7() { struct X7 x7; x7.y = x7.x = sizeof(struct X7); } 75 76 // CHECK: Type: union X8 77 union X8 { 78 struct X7 x; 79 unsigned y; 80 } PACKED; 81 82 // CHECK: Type: struct X9 83 struct X9 { 84 unsigned int x[2] PACKED; 85 unsigned int y; 86 unsigned int z PACKED; 87 }; 88 89 // CHECK: Type: struct X10 90 struct X10 { 91 unsigned int x[2] PACKED; 92 unsigned int y PACKED; 93 unsigned int z PACKED; 94 }; 95 96 // CHECK: Type: struct X11 97 struct PACKED X11 { 98 unsigned int x[2]; 99 unsigned int y; 100 unsigned int z; 101 }; 102 103 // CHECK: Type: struct X12 104 struct PACKED X12 { 105 int x : 24; 106 }; 107 108 // CHECK: Type: struct X13 109 struct PACKED X13 { 110 signed x : 10; 111 signed y : 10; 112 }; 113 114 // CHECK: Type: union X14 115 union PACKED X14 { 116 unsigned long long x : 3; 117 }; 118 119 // CHECK: Type: struct X15 120 struct X15 { 121 unsigned x : 16; 122 unsigned y : 28 PACKED; 123 }; 124 125 // CHECK: Type: struct X16 126 struct ALIGNED16 X16 { 127 int a, b, c; 128 int x : 5; 129 int y : 29; 130 }; 131 132 void use_structs() { 133 union X8 x8; 134 typedef int X8array[sizeof(union X8)]; 135 x8.y = sizeof(union X8); 136 x8.x.x = x8.y; 137 138 struct X9 x9; 139 typedef int X9array[sizeof(struct X9)]; 140 x9.y = sizeof(struct X9); 141 142 struct X10 x10; 143 typedef int X10array[sizeof(struct X10)]; 144 x10.y = sizeof(struct X10); 145 146 struct X11 x11; 147 typedef int X11array[sizeof(struct X11)]; 148 x11.y = sizeof(struct X11); 149 150 struct X12 x12; 151 x12.x = sizeof(struct X12); 152 153 struct X13 x13; 154 x13.x = sizeof(struct X13); 155 156 union X14 x14; 157 x14.x = sizeof(union X14); 158 159 struct X15 x15; 160 x15.x = sizeof(struct X15); 161 162 struct X16 x16; 163 x16.x = sizeof(struct X16); 164 } 165