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