Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / override-layout.c
blobf7f9aea14d01fe98f28a507e8819f31f3e07b23b
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
6 // If not explicitly disabled, set PACKED to the packed attribute.
7 #ifndef PACKED
8 # define PACKED __attribute__((packed))
9 #endif
11 // If not explicitly disabled, set ALIGNED16 to 16-byte alignment.
12 #ifndef ALIGNED16
13 # define ALIGNED16 __attribute__((aligned(16)))
14 #endif
16 // CHECK: Type: struct X0
17 struct X0 {
18 int x[6] PACKED;
21 void use_X0(void) { struct X0 x0; x0.x[5] = sizeof(struct X0); };
23 // CHECK: Type: struct X1
24 struct X1 {
25 char x[13];
26 struct X0 y;
27 } PACKED;
29 void use_X1(void) { struct X1 x1; x1.x[5] = sizeof(struct X1); };
31 // CHECK: Type: struct X2
32 struct PACKED X2 {
33 short x;
34 int y;
37 void use_X2(void) { struct X2 x2; x2.y = sizeof(struct X2); };
39 // CHECK: Type: struct X3
40 struct X3 {
41 short x PACKED;
42 int y;
45 void use_X3(void) { struct X3 x3; x3.y = sizeof(struct X3); };
47 #pragma pack(push,2)
48 // CHECK: Type: struct X4
49 struct X4 {
50 int x;
51 int y;
53 #pragma pack(pop)
55 void use_X4(void) { struct X4 x4; x4.y = sizeof(struct X4); };
57 // CHECK: Type: struct X5
58 struct PACKED X5 { double a[19]; signed char b; };
60 void use_X5(void) { struct X5 x5; x5.b = sizeof(struct X5); };
62 // CHECK: Type: struct X6
63 struct PACKED X6 { long double a; char b; };
65 void use_X6(void) { struct X6 x6; x6.b = sizeof(struct X6); };
67 // CHECK: Type: struct X7
68 struct X7 {
69 unsigned x;
70 unsigned char y;
71 } PACKED;
73 void use_X7(void) { struct X7 x7; x7.y = x7.x = sizeof(struct X7); }
75 // CHECK: Type: union X8
76 union X8 {
77 struct X7 x;
78 unsigned y;
79 } PACKED;
81 // CHECK: Type: struct X9
82 struct X9 {
83 unsigned int x[2] PACKED;
84 unsigned int y;
85 unsigned int z PACKED;
88 // CHECK: Type: struct X10
89 struct X10 {
90 unsigned int x[2] PACKED;
91 unsigned int y PACKED;
92 unsigned int z PACKED;
95 // CHECK: Type: struct X11
96 struct PACKED X11 {
97 unsigned int x[2];
98 unsigned int y;
99 unsigned int z;
102 // CHECK: Type: struct X12
103 struct PACKED X12 {
104 int x : 24;
107 // CHECK: Type: struct X13
108 struct PACKED X13 {
109 signed x : 10;
110 signed y : 10;
113 // CHECK: Type: union X14
114 union PACKED X14 {
115 unsigned long long x : 3;
118 // CHECK: Type: struct X15
119 struct X15 {
120 unsigned x : 16;
121 unsigned y : 28 PACKED;
124 // CHECK: Type: struct X16
125 struct ALIGNED16 X16 {
126 int a, b, c;
127 int x : 5;
128 int y : 29;
131 void 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;
137 struct X9 x9;
138 typedef int X9array[sizeof(struct X9)];
139 x9.y = sizeof(struct X9);
141 struct X10 x10;
142 typedef int X10array[sizeof(struct X10)];
143 x10.y = sizeof(struct X10);
145 struct X11 x11;
146 typedef int X11array[sizeof(struct X11)];
147 x11.y = sizeof(struct X11);
149 struct X12 x12;
150 x12.x = sizeof(struct X12);
152 struct X13 x13;
153 x13.x = sizeof(struct X13);
155 union X14 x14;
156 x14.x = sizeof(union X14);
158 struct X15 x15;
159 x15.x = sizeof(struct X15);
161 struct X16 x16;
162 x16.x = sizeof(struct X16);