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