1 #include <stdint.h>
2 
3 int main(int argc, char const *argv[]) {
4   struct LargeBitsA {
5     unsigned int : 30, a : 20;
6   } lba;
7 
8   struct LargeBitsB {
9     unsigned int a : 1, : 11, : 12, b : 20;
10   } lbb;
11 
12   struct LargeBitsC {
13     unsigned int : 13, : 9, a : 1, b : 1, c : 5, d : 1, e : 20;
14   } lbc;
15 
16   struct LargeBitsD {
17     char arr[3];
18     unsigned int : 30, a : 20;
19   } lbd;
20 
21   // This case came up when debugging clang and models RecordDeclBits
22   struct BitExampleFromClangDeclContext {
23     class fields {
24       uint64_t : 13;
25       uint64_t : 9;
26 
27       uint64_t a: 1;
28       uint64_t b: 1;
29       uint64_t c: 1;
30       uint64_t d: 1;
31       uint64_t e: 1;
32       uint64_t f: 1;
33       uint64_t g: 1;
34       uint64_t h: 1;
35       uint64_t i: 1;
36       uint64_t j: 1;
37       uint64_t k: 1;
38 
39       // In order to reproduce the crash for this case we need the
40       // members of fields to stay private :-(
41       friend struct BitExampleFromClangDeclContext;
42     };
43 
44     union {
45       struct fields f;
46     };
47 
48     BitExampleFromClangDeclContext() {
49   f.a = 1;
50   f.b = 0;
51   f.c = 1;
52   f.d = 0;
53   f.e = 1;
54   f.f = 0;
55   f.g = 1;
56   f.h = 0;
57   f.i = 1;
58   f.j = 0;
59   f.k = 1;
60     }
61   } clang_example;
62 
63   class B {
64   public:
65     uint32_t b_a;
66   };
67 
68   class D : public B {
69   public:
70     uint32_t d_a : 1;
71   } derived;
72 
73   union union_with_bitfields {
74       unsigned int a : 8;
75       unsigned int b : 16;
76       unsigned int c : 32;
77       unsigned int x;
78   } uwbf;
79 
80   union union_with_unnamed_bitfield {
81    unsigned int : 16, a : 24;
82    unsigned int x;
83   } uwubf;
84 
85   lba.a = 2;
86 
87   lbb.a = 1;
88   lbb.b = 3;
89 
90   lbc.a = 1;
91   lbc.b = 0;
92   lbc.c = 4;
93   lbc.d = 1;
94   lbc.e = 20;
95 
96   lbd.arr[0] = 'a';
97   lbd.arr[1] = 'b';
98   lbd.arr[2] = '\0';
99   lbd.a = 5;
100 
101   derived.b_a = 2;
102   derived.d_a = 1;
103 
104   uwbf.x = 0xFFFFFFFF;
105   uwubf.x = 0xFFFFFFFF;
106 
107   struct BoolBits {
108     bool a : 1;
109     bool b : 1;
110     bool c : 2;
111     bool d : 2;
112   } bb;
113 
114   bb.a = 0b1;
115   bb.b = 0b0;
116   bb.c = 0b11;
117   bb.d = 0b01;
118 
119   return 0; // Set break point at this line.
120 }
121