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