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