1 //===-- main.c --------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <string.h>
11 
12 int main (int argc, char const *argv[])
13 {
14     struct Bits
15     {
16         uint32_t    : 1, // Unnamed bitfield
17                     b1 : 1,
18                     b2 : 2,
19                     : 2, // Unnamed bitfield
20                     b3 : 3,
21                     : 2, // Unnamed bitfield (this will get removed)
22                     b4 __attribute__ ((aligned(16))),
23                     b5 : 5,
24                     b6 : 6,
25                     b7 : 7,
26                     four : 4;
27     };
28 
29     printf("%lu", sizeof(struct Bits));
30 
31     struct Bits bits;
32     int i;
33     for (i=0; i<(1<<1); i++)
34         bits.b1 = i;        //// break $source:$line
35     for (i=0; i<(1<<2); i++)
36         bits.b2 = i;        //// break $source:$line
37     for (i=0; i<(1<<3); i++)
38         bits.b3 = i;        //// break $source:$line
39     for (i=0; i<(1<<4); i++)
40         bits.b4 = i;        //// break $source:$line
41     for (i=0; i<(1<<5); i++)
42         bits.b5 = i;        //// break $source:$line
43     for (i=0; i<(1<<6); i++)
44         bits.b6 = i;        //// break $source:$line
45     for (i=0; i<(1<<7); i++)
46         bits.b7 = i;        //// break $source:$line
47     for (i=0; i<(1<<4); i++)
48         bits.four = i;      //// break $source:$line
49 
50     struct MoreBits
51     {
52         uint32_t    a : 3;
53         uint8_t       : 1;
54         uint8_t     b : 1;
55         uint8_t     c : 1;
56         uint8_t     d : 1;
57     };
58 
59     struct MoreBits more_bits;
60 
61     more_bits.a = 3;
62     more_bits.b = 0;
63     more_bits.c = 1;
64     more_bits.d = 0;
65 
66     struct EvenMoreBits
67     {
68         uint8_t b1  : 1, b2  : 1, b3  : 1, b4  : 1, b5  : 1, b6  : 1,
69                 b7  : 1, b8  : 1, b9  : 1, b10 : 1, b11 : 1, b12 : 1,
70                 b13 : 1, b14 : 1, b15 : 1, b16 : 1, b17 : 1;
71     };
72 
73     struct EvenMoreBits even_more_bits;
74     memset(&even_more_bits, 0, sizeof(even_more_bits));
75     even_more_bits.b1 = 1;
76     even_more_bits.b5 = 1;
77     even_more_bits.b7 = 1;
78     even_more_bits.b13 = 1;
79 
80 #pragma pack(1)
81     struct PackedBits
82     {
83         char a;
84     	uint32_t b : 5,
85                  c : 27;
86     };
87 #pragma pack()
88     struct PackedBits packed;
89     packed.a = 'a';
90     packed.b = 10;
91     packed.c = 0x7112233;
92 
93     struct LargePackedBits {
94         uint64_t a: 36;
95         uint64_t b: 36;
96     } __attribute__((packed));
97 
98     struct LargePackedBits large_packed =
99       (struct LargePackedBits){ 0xcbbbbaaaa, 0xdffffeeee };
100 
101     return 0;               //// Set break point at this line.
102 
103 }
104