blob: d432885c584845c2f7e3f8934327a56e1ce31b44 [file] [log] [blame]
Douglas Gregor453dbcb2012-01-26 07:55:45 +00001// RUN: %clang_cc1 -fdump-record-layouts-simple %s 2> %t.layouts
2// RUN: %clang_cc1 -fdump-record-layouts-simple %s > %t.before 2>&1
3// RUN: %clang_cc1 -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
12struct Empty1 { };
13struct Empty2 { };
14
15// CHECK: Type: struct X0
16struct X0 : public Empty1 {
17 int x[6] PACKED;
18};
19
20// CHECK: Type: struct X1
21struct X1 : public X0, public Empty2 {
22 char x[13];
23 struct X0 y;
24} PACKED;
25
26// CHECK: Type: struct X2
27struct PACKED X2 : public X1, public X0, public Empty1 {
28 short x;
29 int y;
30};
31
32// CHECK: Type: struct X3
33struct PACKED X3 : virtual public X1, public X0 {
34 short x;
35 int y;
36};
37
Douglas Gregor285c6072012-02-03 19:31:51 +000038// CHECK: Type: struct X4
39struct 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
Douglas Gregor453dbcb2012-01-26 07:55:45 +000057void use_structs() {
Douglas Gregor285c6072012-02-03 19:31:51 +000058 X0 x0s[sizeof(X0)];
59 X1 x1s[sizeof(X1)];
60 X2 x2s[sizeof(X2)];
61 X3 x3s[sizeof(X3)];
62 X4 x4s[sizeof(X4)];
63 x4s[1].a = 1;
Douglas Gregor453dbcb2012-01-26 07:55:45 +000064}