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 lba.a = 2; 64 65 lbb.a = 1; 66 lbb.b = 3; 67 68 lbc.a = 1; 69 lbc.b = 0; 70 lbc.c = 4; 71 lbc.d = 1; 72 lbc.e = 20; 73 74 lbd.arr[0] = 'a'; 75 lbd.arr[1] = 'b'; 76 lbd.arr[2] = '\0'; 77 lbd.a = 5; 78 79 80 return 0; // Set break point at this line. 81 } 82