hc
2023-12-06 d38611ca164021d018c1b23eee65bbebc09c63e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 
/*
 * BTF-to-C dumper tests for bitfield.
 *
 * Copyright (c) 2019 Facebook
 */
#include <stdbool.h>
 
/* ----- START-EXPECTED-OUTPUT ----- */
/*
 *struct bitfields_only_mixed_types {
 *    int a: 3;
 *    long int b: 2;
 *    _Bool c: 1;
 *    enum {
 *        A = 0,
 *        B = 1,
 *    } d: 1;
 *    short e: 5;
 *    int: 20;
 *    unsigned int f: 30;
 *};
 *
 */
/* ------ END-EXPECTED-OUTPUT ------ */
 
struct bitfields_only_mixed_types {
   int a: 3;
   long int b: 2;
   bool c: 1; /* it's really a _Bool type */
   enum {
       A, /* A = 0, dumper is very explicit */
       B, /* B = 1, same */
   } d: 1;
   short e: 5;
   /* 20-bit padding here */
   unsigned f: 30; /* this gets aligned on 4-byte boundary */
};
 
/* ----- START-EXPECTED-OUTPUT ----- */
/*
 *struct bitfield_mixed_with_others {
 *    char: 4;
 *    int a: 4;
 *    short b;
 *    long int c;
 *    long int d: 8;
 *    int e;
 *    int f;
 *};
 *
 */
/* ------ END-EXPECTED-OUTPUT ------ */
struct bitfield_mixed_with_others {
   long: 4; /* char is enough as a backing field */
   int a: 4;
   /* 8-bit implicit padding */
   short b; /* combined with previous bitfield */
   /* 4 more bytes of implicit padding */
   long c;
   long d: 8;
   /* 24 bits implicit padding */
   int e; /* combined with previous bitfield */
   int f;
   /* 4 bytes of padding */
};
 
/* ----- START-EXPECTED-OUTPUT ----- */
/*
 *struct bitfield_flushed {
 *    int a: 4;
 *    long: 60;
 *    long int b: 16;
 *};
 *
 */
/* ------ END-EXPECTED-OUTPUT ------ */
struct bitfield_flushed {
   int a: 4;
   long: 0; /* flush until next natural alignment boundary */
   long b: 16;
};
 
int f(struct {
   struct bitfields_only_mixed_types _1;
   struct bitfield_mixed_with_others _2;
   struct bitfield_flushed _3;
} *_)
{
   return 0;
}