warn-padded-packed.cpp revision 78a916ec5ff5b66adec3c499e1b9af7b87668309
1// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify %s -emit-llvm -o %t
2
3struct S1 {
4  char c;
5  short s; // expected-warning {{padding struct 'S1' with 1 byte to align 's'}}
6  long l; // expected-warning {{padding struct 'S1' with 4 bytes to align 'l'}}
7};
8
9struct S2 { // expected-warning {{padding size of 'S2' with 3 bytes to alignment boundary}}
10  int i;
11  char c;
12};
13
14struct S3 {
15  char c;
16  int i;
17} __attribute__((packed));
18
19struct S4 {
20  int i; // expected-warning {{packed attribute is unnecessary for 'i'}}
21  char c;
22} __attribute__((packed));
23
24struct S5 {
25  char c;
26  union {
27    char c;
28    int i;
29  } u; // expected-warning {{padding struct 'S5' with 3 bytes to align 'u'}}
30};
31
32struct S6 { // expected-warning {{padding size of 'S6' with 30 bits to alignment boundary}}
33  int i : 2;
34};
35
36struct S7 { // expected-warning {{padding size of 'S7' with 7 bytes to alignment boundary}}
37  char c;
38  virtual void m();
39};
40
41struct B {
42  char c;
43};
44
45struct S8 : B {
46  int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
47};
48
49struct S9 { // expected-warning {{packed attribute is unnecessary for 'S9'}}
50  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
51  int y; // expected-warning {{packed attribute is unnecessary for 'y'}}
52} __attribute__((packed));
53
54struct S10 { // expected-warning {{packed attribute is unnecessary for 'S10'}}
55  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
56  char a,b,c,d;
57} __attribute__((packed));
58
59
60struct S11 {
61  bool x;
62  char a,b,c,d;
63} __attribute__((packed));
64
65struct S12 {
66  bool b : 1;
67  char c; // expected-warning {{padding struct 'S12' with 7 bits to align 'c'}}
68};
69
70struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}
71  char c;
72  bool b : 10; // expected-warning {{size of bit-field 'b' (10 bits) exceeds the size of its type}}
73};
74
75// The warnings are emitted when the layout of the structs is computed, so we have to use them.
76void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*) { }
77