blob: a3c4bb446caaf9779a1ac420d7cc317707b6626c [file] [log] [blame]
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001// RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.layouts
2// RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.before
3// RUN: %clang_cc1 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after
Douglas Gregorf5967602012-10-26 22:31:14 +00004// RUN: diff -u %t.before %t.after
Douglas Gregor453dbcb2012-01-26 07:55:45 +00005// 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 Gregorf5967602012-10-26 22:31:14 +000057// CHECK: Type: struct X5
58struct PACKED X5 {
59 union {
60 long a;
61 long b;
62 };
63 short l;
64 short r;
65};
66
Douglas Gregor453dbcb2012-01-26 07:55:45 +000067void use_structs() {
Douglas Gregor285c6072012-02-03 19:31:51 +000068 X0 x0s[sizeof(X0)];
69 X1 x1s[sizeof(X1)];
70 X2 x2s[sizeof(X2)];
71 X3 x3s[sizeof(X3)];
72 X4 x4s[sizeof(X4)];
Douglas Gregorf5967602012-10-26 22:31:14 +000073 X5 x5s[sizeof(X5)];
Douglas Gregor285c6072012-02-03 19:31:51 +000074 x4s[1].a = 1;
Douglas Gregorf5967602012-10-26 22:31:14 +000075 x5s[1].a = 17;
Douglas Gregor453dbcb2012-01-26 07:55:45 +000076}
Douglas Gregorf5967602012-10-26 22:31:14 +000077