xref: /llvm-project/clang/test/CodeGen/ms_struct-pack.c (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1 // RUN: %clang_cc1 -emit-llvm-only  -triple i386-apple-darwin9 -fdump-record-layouts %s | FileCheck %s
2 
3 #pragma pack(1)
4 struct _one_ms {
5         short m:9;      // size is 2
6         int q:27;       // size is 6
7         short w:13;     // size is 8
8         short e:3;      // size is 8
9         char r:4;       // size is 9
10         char t:7;       // size is 10
11         short y:16;     // size is 12
12         short u:1;      // size is 14
13         char i:2;       // size is 15
14         int a;          // size is 19
15         char o:6;       // size is 20
16         char s:2;       // size is 20
17         short d:10;     // size is 22
18         short f:4;      // size is 22
19         char b;         // size is 23
20         char g:1;       // size is 24
21         short h:13;     // size is 26
22         char j:8;       // size is 27
23         char k:5;       // size is 28
24         char c;         // size is 29
25         int l:28;       // size is 33
26         char z:7;       // size is 34
27         int x:20;       // size is 38
28 } __attribute__((__ms_struct__));
29 typedef struct _one_ms one_ms;
30 
31 static int a1[(sizeof(one_ms) == 38) - 1];
32 
33 #pragma pack(2)
34 struct _two_ms {
35         short m:9;
36         int q:27;
37         short w:13;
38         short e:3;
39         char r:4;
40         char t:7;
41         short y:16;
42         short u:1;
43         char i:2;
44         int a;
45         char o:6;
46         char s:2;
47         short d:10;
48         short f:4;
49         char b;
50         char g:1;
51         short h:13;
52         char j:8;
53         char k:5;
54         char c;
55         int l:28;
56         char z:7;
57         int x:20;
58 } __attribute__((__ms_struct__));
59 
60 typedef struct _two_ms two_ms;
61 
62 static int a2[(sizeof(two_ms) == 42) - 1];
63 
64 #pragma pack(4)
65 struct _four_ms {
66         short m:9;
67         int q:27;
68         short w:13;
69         short e:3;
70         char r:4;
71         char t:7;
72         short y:16;
73         short u:1;
74         char i:2;
75         int a;
76         char o:6;
77         char s:2;
78         short d:10;
79         short f:4;
80         char b;
81         char g:1;
82         short h:13;
83         char j:8;
84         char k:5;
85         char c;
86         int l:28;
87         char z:7;
88         int x:20;
89 } __attribute__((__ms_struct__));
90 typedef struct _four_ms four_ms;
91 
92 static int a4[(sizeof(four_ms) == 48) - 1];
93 
94 #pragma pack(8)
95 struct _eight_ms {
96         short m:9;
97         int q:27;
98         short w:13;
99         short e:3;
100         char r:4;
101         char t:7;
102         short y:16;
103         short u:1;
104         char i:2;
105         int a;
106         char o:6;
107         char s:2;
108         short d:10;
109         short f:4;
110         char b;
111         char g:1;
112         short h:13;
113         char j:8;
114         char k:5;
115         char c;
116         int l:28;
117         char z:7;
118         int x:20;
119 } __attribute__((__ms_struct__));
120 
121 typedef struct _eight_ms eight_ms;
122 
123 static int a8[(sizeof(eight_ms) == 48) - 1];
124 
125 #pragma pack(2)
126 struct test0 {
127   unsigned long a : 8;
128   unsigned long b : 8;
129   unsigned long c : 8;
130   unsigned long d : 10;
131   unsigned long e : 1;
132 } __attribute__((__ms_struct__));
133 
134 // CHECK:             0 | struct test0
135 // CHECK-NEXT:    0:0-7 |   unsigned long a
136 // CHECK-NEXT:    1:0-7 |   unsigned long b
137 // CHECK-NEXT:    2:0-7 |   unsigned long c
138 // CHECK-NEXT:    4:0-9 |   unsigned long d
139 // CHECK-NEXT:    5:2-2 |   unsigned long e
140 // CHECK-NEXT:          | [sizeof=8, align=2]
141 
142 static int test0[(sizeof(struct test0) == 8) ? 1 : -1];
143