Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / warn-all-padded-packed-packed-non-pod.cpp
blob2a75498d87197a486888c58c4365ed3966c5164e
1 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
2 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
3 // -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
4 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s -emit-llvm-only
5 // -Wall should not emit the "packed attribute is unnecessary" warnings without -Wpacked.
6 // RUN: %clang_cc1 -triple=x86_64-none-none -Wall -verify=top %s -emit-llvm-only
9 struct S1 {
10 char c;
11 short s; // expected-warning {{padding struct 'S1' with 1 byte to align 's'}}
12 long l; // expected-warning {{padding struct 'S1' with 4 bytes to align 'l'}}
15 struct S2 { // expected-warning {{padding size of 'S2' with 3 bytes to alignment boundary}}
16 int i;
17 char c;
20 struct S3 {
21 char c;
22 int i;
23 } __attribute__((packed));
25 struct S4 {
26 int i;
27 char c;
28 } __attribute__((packed));
30 struct S5 {
31 char c;
32 union {
33 char c;
34 int i;
35 } u; // expected-warning {{padding struct 'S5' with 3 bytes to align 'u'}}
38 struct S6 { // expected-warning {{padding size of 'S6' with 30 bits to alignment boundary}}
39 int i : 2;
42 struct S7 { // expected-warning {{padding size of 'S7' with 7 bytes to alignment boundary}}
43 char c;
44 virtual void m();
47 struct B {
48 char c;
51 struct S8 : B {
52 int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
55 struct S9 {
56 int x;
57 int y;
58 } __attribute__((packed));
60 struct S10 {
61 int x;
62 char a,b,c,d;
63 } __attribute__((packed));
66 struct S11 { // expected-warning {{packed attribute is unnecessary for 'S11'}}
67 bool x;
68 char a,b,c,d;
69 } __attribute__((packed));
71 struct S12 {
72 bool b : 1;
73 char c; // expected-warning {{padding struct 'S12' with 7 bits to align 'c'}}
76 struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}
77 char c;
78 bool b : 10;
81 struct S14 { // expected-warning {{packed attribute is unnecessary for 'S14'}}
82 char a,b,c,d;
83 } __attribute__((packed));
85 struct S15 { // expected-warning {{packed attribute is unnecessary for 'S15'}}
86 struct S14 s;
87 char a;
88 } __attribute__((packed));
90 struct S16 { // expected-warning {{padding size of 'S16' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S16'}}
91 char a,b;
92 } __attribute__((packed, aligned(4)));
94 struct S17 {
95 struct S16 s;
96 char a,b;
97 } __attribute__((packed, aligned(2)));
99 struct S18 { // expected-warning {{padding size of 'S18' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S18'}}
100 struct S16 s;
101 char a,b;
102 } __attribute__((packed, aligned(4)));
104 struct S19 { // expected-warning {{packed attribute is unnecessary for 'S19'}}
105 bool b;
106 char a;
107 } __attribute__((packed, aligned(1)));
109 struct S20 {
110 int i;
111 char a;
112 } __attribute__((packed, aligned(1)));
114 struct S21 { // expected-warning {{padding size of 'S21' with 4 bits to alignment boundary}}
115 unsigned char a : 6;
116 unsigned char b : 6;
117 } __attribute__((packed, aligned(1)));
119 struct S22 { // expected-warning {{packed attribute is unnecessary for 'S22'}}
120 unsigned char a : 4;
121 unsigned char b : 4;
122 } __attribute__((packed));
124 struct S23 { // expected-warning {{padding size of 'S23' with 4 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S23'}}
125 unsigned char a : 2;
126 unsigned char b : 2;
127 } __attribute__((packed));
129 struct S24 {
130 unsigned char a : 6;
131 unsigned char b : 6;
132 unsigned char c : 6;
133 unsigned char d : 6;
134 unsigned char e : 6;
135 unsigned char f : 6;
136 unsigned char g : 6;
137 unsigned char h : 6;
138 } __attribute__((packed));
140 struct S25 { // expected-warning {{padding size of 'S25' with 7 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S25'}}
141 unsigned char a;
142 unsigned char b : 1;
143 } __attribute__((packed));
145 struct S26 { // expected-warning {{packed attribute is unnecessary for 'S26'}}
146 unsigned char a : 1;
147 unsigned char b; //expected-warning {{padding struct 'S26' with 7 bits to align 'b'}}
148 } __attribute__((packed));
150 struct S27 { // expected-warning {{padding size of 'S27' with 7 bits to alignment boundary}}
151 unsigned char a : 1;
152 unsigned char b : 8;
153 } __attribute__((packed));
155 struct S28_non_pod {
156 protected:
157 int i;
159 struct S28 {
160 char c1;
161 short s1;
162 char c2;
163 S28_non_pod p1; // top-warning {{not packing field 'p1' as it is non-POD for the purposes of layout}}
164 } __attribute__((packed));
166 struct S29_non_pod_align_1 {
167 protected:
168 char c;
170 struct S29 {
171 S29_non_pod_align_1 p1;
172 int i;
173 } __attribute__((packed)); // no warning
174 static_assert(alignof(S29) == 1, "");
176 struct S30 {
177 protected:
178 short s;
179 } __attribute__((packed)); // no warning
180 struct S30_use { // abi15-warning {{packed attribute is unnecessary for 'S30_use'}}
181 char c;
182 S30 u;
183 } __attribute__((packed));
184 static_assert(sizeof(S30_use) == 3, "");
186 // The warnings are emitted when the layout of the structs is computed, so we have to use them.
187 void f(S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13,
188 S14, S15, S16, S17, S18, S19, S20, S21, S22, S23, S24, S25,
189 S26, S27, S28, S29){}