1 #include <stdint.h>
2
3 struct LargeBitsA {
4 unsigned int : 30, a : 20;
5 } lba;
6
7 struct LargeBitsB {
8 unsigned int a : 1, : 11, : 12, b : 20;
9 } lbb;
10
11 struct LargeBitsC {
12 unsigned int : 13, : 9, a : 1, b : 1, c : 5, d : 1, e : 20;
13 } lbc;
14
15 struct LargeBitsD {
16 char arr[3];
17 unsigned int : 30, a : 20;
18 } lbd;
19
20 struct BitfieldsInStructInUnion {
21 class fields {
22 uint64_t : 13;
23 uint64_t : 9;
24
25 uint64_t a : 1;
26 uint64_t b : 1;
27 uint64_t c : 1;
28 uint64_t d : 1;
29 uint64_t e : 1;
30 uint64_t f : 1;
31 uint64_t g : 1;
32 uint64_t h : 1;
33 uint64_t i : 1;
34 uint64_t j : 1;
35 uint64_t k : 1;
36
37 // In order to reproduce the crash for this case we need the
38 // members of fields to stay private :-(
39 friend struct BitfieldsInStructInUnion;
40 };
41
42 union {
43 struct fields f;
44 };
45
BitfieldsInStructInUnionBitfieldsInStructInUnion46 BitfieldsInStructInUnion() {
47 f.a = 1;
48 f.b = 0;
49 f.c = 1;
50 f.d = 0;
51 f.e = 1;
52 f.f = 0;
53 f.g = 1;
54 f.h = 0;
55 f.i = 1;
56 f.j = 0;
57 f.k = 1;
58 }
59 } bitfields_in_struct_in_union;
60
61 class Base {
62 public:
63 uint32_t b_a;
64 };
65
66 class Derived : public Base {
67 public:
68 uint32_t d_a : 1;
69 } derived;
70
71 union UnionWithBitfields {
72 unsigned int a : 8;
73 unsigned int b : 16;
74 unsigned int c : 32;
75 unsigned int x;
76 } uwbf;
77
78 union UnionWithUnnamedBitfield {
79 unsigned int : 16, a : 24;
80 unsigned int x;
81 } uwubf;
82
83 struct BoolBits {
84 bool a : 1;
85 bool b : 1;
86 bool c : 2;
87 bool d : 2;
88 };
89
90 struct WithVTable {
~WithVTableWithVTable91 virtual ~WithVTable() {}
92 unsigned a : 4;
93 unsigned b : 4;
94 unsigned c : 4;
95 };
96 WithVTable with_vtable;
97
98 struct WithVTableAndUnnamed {
~WithVTableAndUnnamedWithVTableAndUnnamed99 virtual ~WithVTableAndUnnamed() {}
100 unsigned : 4;
101 unsigned b : 4;
102 unsigned c : 4;
103 };
104 WithVTableAndUnnamed with_vtable_and_unnamed;
105
106 struct BaseWithVTable {
~BaseWithVTableBaseWithVTable107 virtual ~BaseWithVTable() {}
108 };
109 struct HasBaseWithVTable : BaseWithVTable {
110 unsigned a : 4;
111 unsigned b : 4;
112 unsigned c : 4;
113 };
114 HasBaseWithVTable base_with_vtable;
115
main(int argc,char const * argv[])116 int main(int argc, char const *argv[]) {
117 lba.a = 2;
118
119 lbb.a = 1;
120 lbb.b = 3;
121
122 lbc.a = 1;
123 lbc.b = 0;
124 lbc.c = 4;
125 lbc.d = 1;
126 lbc.e = 20;
127
128 lbd.arr[0] = 'a';
129 lbd.arr[1] = 'b';
130 lbd.arr[2] = '\0';
131 lbd.a = 5;
132
133 derived.b_a = 2;
134 derived.d_a = 1;
135
136 uwbf.x = 0xFFFFFFFF;
137 uwubf.x = 0xFFFFFFFF;
138
139 BoolBits bb;
140 bb.a = 0b1;
141 bb.b = 0b0;
142 bb.c = 0b11;
143 bb.d = 0b01;
144
145 with_vtable.a = 5;
146 with_vtable.b = 0;
147 with_vtable.c = 5;
148
149 with_vtable_and_unnamed.b = 0;
150 with_vtable_and_unnamed.c = 5;
151
152 base_with_vtable.a = 5;
153 base_with_vtable.b = 0;
154 base_with_vtable.c = 5;
155
156 return 0; // break here
157 }
158