brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · f7f9aea Raw
164 lines · c
1// RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.layouts2// RUN: %clang_cc1 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after3// RUN: diff %t.layouts %t.after4// RUN: FileCheck %s < %t.after5 6// If not explicitly disabled, set PACKED to the packed attribute.7#ifndef PACKED8#  define PACKED __attribute__((packed))9#endif10 11// If not explicitly disabled, set ALIGNED16 to 16-byte alignment.12#ifndef ALIGNED1613#  define ALIGNED16 __attribute__((aligned(16)))14#endif15 16// CHECK: Type: struct X017struct X0 { 18  int x[6] PACKED; 19};20 21void use_X0(void) { struct X0 x0; x0.x[5] = sizeof(struct X0); };22 23// CHECK: Type: struct X124struct X1 { 25  char x[13]; 26  struct X0 y; 27} PACKED;28 29void use_X1(void) { struct X1 x1; x1.x[5] = sizeof(struct X1); };30 31// CHECK: Type: struct X232struct PACKED X2 {33  short x;34  int y;35};36 37void use_X2(void) { struct X2 x2; x2.y = sizeof(struct X2); };38 39// CHECK: Type: struct X340struct X3 {41  short x PACKED;42  int y;43};44 45void use_X3(void) { struct X3 x3; x3.y = sizeof(struct X3); };46 47#pragma pack(push,2)48// CHECK: Type: struct X449struct X4 {50  int x;51  int y;52};53#pragma pack(pop)54 55void use_X4(void) { struct X4 x4; x4.y = sizeof(struct X4); };56 57// CHECK: Type: struct X558struct PACKED X5 { double a[19];  signed char b; };59 60void use_X5(void) { struct X5 x5; x5.b = sizeof(struct X5); };61 62// CHECK: Type: struct X663struct PACKED X6 { long double a; char b; };64 65void use_X6(void) { struct X6 x6; x6.b = sizeof(struct X6); };66 67// CHECK: Type: struct X768struct X7 {69        unsigned x;70        unsigned char y;71} PACKED;72 73void use_X7(void) { struct X7 x7; x7.y = x7.x = sizeof(struct X7); }74 75// CHECK: Type: union X876union X8 {77  struct X7 x;78  unsigned y;79} PACKED;80 81// CHECK: Type: struct X982struct X9 {83  unsigned int x[2] PACKED;84  unsigned int y;85  unsigned int z PACKED;86};87 88// CHECK: Type: struct X1089struct X10 {90  unsigned int x[2] PACKED;91  unsigned int y PACKED;92  unsigned int z PACKED;93};94 95// CHECK: Type: struct X1196struct PACKED X11 {97  unsigned int x[2];98  unsigned int y;99  unsigned int z;100};101 102// CHECK: Type: struct X12103struct PACKED X12 {104  int x : 24;105};106 107// CHECK: Type: struct X13108struct PACKED X13 {109  signed x : 10;110  signed y : 10;111};112 113// CHECK: Type: union X14114union PACKED X14 {115  unsigned long long x : 3;116};117 118// CHECK: Type: struct X15119struct X15 {120  unsigned x : 16;121  unsigned y : 28 PACKED;122};123 124// CHECK: Type: struct X16125struct ALIGNED16 X16 {126  int a, b, c;127  int x : 5;128  int y : 29;129};130 131void use_structs(void) {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