1 // RUN: %clang_cc1 -fdump-record-layouts-simple %s > %t.layouts 2 // RUN: %clang_cc1 -fdump-record-layouts-simple %s > %t.before 3 // RUN: %clang_cc1 -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after 4 // RUN: diff -u %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 struct Empty1 { }; 13 struct Empty2 { }; 14 15 // CHECK: Type: struct X0 16 struct X0 : public Empty1 { 17 int x[6] PACKED; 18 }; 19 20 // CHECK: Type: struct X1 21 struct X1 : public X0, public Empty2 { 22 char x[13]; 23 struct X0 y; 24 } PACKED; 25 26 // CHECK: Type: struct X2 27 struct PACKED X2 : public X1, public X0, public Empty1 { 28 short x; 29 int y; 30 }; 31 32 // CHECK: Type: struct X3 33 struct PACKED X3 : virtual public X1, public X0 { 34 short x; 35 int y; 36 }; 37 38 // CHECK: Type: struct X4 39 struct PACKED X4 { 40 unsigned int a : 1; 41 unsigned int b : 1; 42 unsigned int c : 1; 43 unsigned int d : 1; 44 unsigned int e : 1; 45 unsigned int f : 1; 46 unsigned int g : 1; 47 unsigned int h : 1; 48 unsigned int i : 1; 49 unsigned int j : 1; 50 unsigned int k : 1; 51 unsigned int l : 1; 52 unsigned int m : 1; 53 unsigned int n : 1; 54 X4(); 55 }; 56 57 // CHECK: Type: struct X5 58 struct PACKED X5 { 59 union { 60 long a; 61 long b; 62 }; 63 short l; 64 short r; 65 }; 66 67 void use_structs() { 68 X0 x0s[sizeof(X0)]; 69 X1 x1s[sizeof(X1)]; 70 X2 x2s[sizeof(X2)]; 71 X3 x3s[sizeof(X3)]; 72 X4 x4s[sizeof(X4)]; 73 X5 x5s[sizeof(X5)]; 74 x4s[1].a = 1; 75 x5s[1].a = 17; 76 } 77 78