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