xref: /llvm-project/clang/test/CodeGenCXX/warn-padded-bitfields.cpp (revision 43feb3eeb1ba4de920d6eaa12b7a5c21f6dd6229)
1 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded-bitfield -verify=expected %s -emit-llvm-only
2 
3 struct S1 {
4   unsigned a : 1;
5   unsigned long long : 0; // expected-warning {{padding struct 'S1' with 63 bits to align anonymous bit-field}}
6 };
7 
8 struct S2 {
9   unsigned a : 1;
10   unsigned long long b : 64; // expected-warning {{padding struct 'S2' with 63 bits to align 'b'}}
11 };
12 
13 struct S3 {
14   char a : 1;
15   short b : 16; // expected-warning {{padding struct 'S3' with 15 bits to align 'b'}}
16 };
17 
18 struct [[gnu::packed]] S4 {
19   char a : 1;
20   short b : 16;
21 };
22 
23 struct S5 {
24   unsigned a : 1;
25   unsigned long long b : 63;
26 };
27 
28 struct S6 {
29   unsigned a : 1;
30   unsigned long long b;
31 };
32 
33 struct S7 {
34   int word;
35   struct {
36     int filler __attribute__ ((aligned (8)));
37   };
38 };
39 
40 // The warnings are emitted when the layout of the structs is computed, so we have to use them.
f(S1,S2,S3,S4,S5,S6,S7)41 void f(S1, S2, S3, S4, S5, S6, S7){}
42