Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
0002 
0003 /*
0004  * BTF-to-C dumper tests for bitfield.
0005  *
0006  * Copyright (c) 2019 Facebook
0007  */
0008 #include <stdbool.h>
0009 
0010 /* ----- START-EXPECTED-OUTPUT ----- */
0011 /*
0012  *struct bitfields_only_mixed_types {
0013  *  int a: 3;
0014  *  long b: 2;
0015  *  _Bool c: 1;
0016  *  enum {
0017  *      A = 0,
0018  *      B = 1,
0019  *  } d: 1;
0020  *  short e: 5;
0021  *  int: 20;
0022  *  unsigned int f: 30;
0023  *};
0024  *
0025  */
0026 /* ------ END-EXPECTED-OUTPUT ------ */
0027 
0028 struct bitfields_only_mixed_types {
0029     int a: 3;
0030     long b: 2;
0031     bool c: 1; /* it's really a _Bool type */
0032     enum {
0033         A, /* A = 0, dumper is very explicit */
0034         B, /* B = 1, same */
0035     } d: 1;
0036     short e: 5;
0037     /* 20-bit padding here */
0038     unsigned f: 30; /* this gets aligned on 4-byte boundary */
0039 };
0040 
0041 /* ----- START-EXPECTED-OUTPUT ----- */
0042 /*
0043  *struct bitfield_mixed_with_others {
0044  *  char: 4;
0045  *  int a: 4;
0046  *  short b;
0047  *  long c;
0048  *  long d: 8;
0049  *  int e;
0050  *  int f;
0051  *};
0052  *
0053  */
0054 /* ------ END-EXPECTED-OUTPUT ------ */
0055 struct bitfield_mixed_with_others {
0056     long: 4; /* char is enough as a backing field */
0057     int a: 4;
0058     /* 8-bit implicit padding */
0059     short b; /* combined with previous bitfield */
0060     /* 4 more bytes of implicit padding */
0061     long c;
0062     long d: 8;
0063     /* 24 bits implicit padding */
0064     int e; /* combined with previous bitfield */
0065     int f;
0066     /* 4 bytes of padding */
0067 };
0068 
0069 /* ----- START-EXPECTED-OUTPUT ----- */
0070 /*
0071  *struct bitfield_flushed {
0072  *  int a: 4;
0073  *  long: 60;
0074  *  long b: 16;
0075  *};
0076  *
0077  */
0078 /* ------ END-EXPECTED-OUTPUT ------ */
0079 struct bitfield_flushed {
0080     int a: 4;
0081     long: 0; /* flush until next natural alignment boundary */
0082     long b: 16;
0083 };
0084 
0085 int f(struct {
0086     struct bitfields_only_mixed_types _1;
0087     struct bitfield_mixed_with_others _2;
0088     struct bitfield_flushed _3;
0089 } *_)
0090 {
0091     return 0;
0092 }