You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Change the condition of unnecessary packed warning
Summary:
Change the condition of this unnecessary packed warning. The packed is unnecessary when
1. the alignment of the struct/class won't alter.
2. the size is unchanged.
3. the offset of each field is the same.
Remove all field-level warning.
Reviewers: chh, akyrtzi, rtrieu
Reviewed By: chh
Subscribers: rsmith, srhines, cfe-commits, xazax.hun
Differential Revision: https://reviews.llvm.org/D34114
llvm-svn: 309750
Copy file name to clipboardExpand all lines: clang/test/CodeGenCXX/warn-padded-packed.cpp
+85-8Lines changed: 85 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ struct S3 {
17
17
} __attribute__((packed));
18
18
19
19
structS4 {
20
-
int i;// expected-warning {{packed attribute is unnecessary for 'i'}}
20
+
int i;
21
21
char c;
22
22
} __attribute__((packed));
23
23
@@ -46,18 +46,18 @@ struct S8 : B {
46
46
int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
47
47
};
48
48
49
-
structS9 {// 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'}}
49
+
structS9 {
50
+
int x;
51
+
int y;
52
52
} __attribute__((packed));
53
53
54
-
structS10 {// expected-warning {{packed attribute is unnecessary for 'S10'}}
55
-
int x;// expected-warning {{packed attribute is unnecessary for 'x'}}
54
+
structS10 {
55
+
int x;
56
56
char a,b,c,d;
57
57
} __attribute__((packed));
58
58
59
59
60
-
structS11 {
60
+
structS11 {// expected-warning {{packed attribute is unnecessary for 'S11'}}
61
61
bool x;
62
62
char a,b,c,d;
63
63
} __attribute__((packed));
@@ -72,5 +72,82 @@ struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignmen
72
72
bool b : 10;
73
73
};
74
74
75
+
structS14 { // expected-warning {{packed attribute is unnecessary for 'S14'}}
76
+
char a,b,c,d;
77
+
} __attribute__((packed));
78
+
79
+
structS15 { // expected-warning {{packed attribute is unnecessary for 'S15'}}
80
+
structS14 s;
81
+
char a;
82
+
} __attribute__((packed));
83
+
84
+
structS16 { // expected-warning {{padding size of 'S16' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S16'}}
85
+
char a,b;
86
+
} __attribute__((packed, aligned(4)));
87
+
88
+
structS17 {
89
+
structS16 s;
90
+
char a,b;
91
+
} __attribute__((packed, aligned(2)));
92
+
93
+
structS18 { // expected-warning {{padding size of 'S18' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S18'}}
94
+
structS16 s;
95
+
char a,b;
96
+
} __attribute__((packed, aligned(4)));
97
+
98
+
structS19 { // expected-warning {{packed attribute is unnecessary for 'S19'}}
99
+
bool b;
100
+
char a;
101
+
} __attribute__((packed, aligned(1)));
102
+
103
+
structS20 {
104
+
int i;
105
+
char a;
106
+
} __attribute__((packed, aligned(1)));
107
+
108
+
structS21 { // expected-warning {{padding size of 'S21' with 4 bits to alignment boundary}}
109
+
unsignedchar a : 6;
110
+
unsignedchar b : 6;
111
+
} __attribute__((packed, aligned(1)));
112
+
113
+
structS22 { // expected-warning {{packed attribute is unnecessary for 'S22'}}
114
+
unsignedchar a : 4;
115
+
unsignedchar b : 4;
116
+
} __attribute__((packed));
117
+
118
+
structS23 { // expected-warning {{padding size of 'S23' with 4 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S23'}}
119
+
unsignedchar a : 2;
120
+
unsignedchar b : 2;
121
+
} __attribute__((packed));
122
+
123
+
structS24 {
124
+
unsignedchar a : 6;
125
+
unsignedchar b : 6;
126
+
unsignedchar c : 6;
127
+
unsignedchar d : 6;
128
+
unsignedchar e : 6;
129
+
unsignedchar f : 6;
130
+
unsignedchar g : 6;
131
+
unsignedchar h : 6;
132
+
} __attribute__((packed));
133
+
134
+
structS25 { // expected-warning {{padding size of 'S25' with 7 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S25'}}
135
+
unsignedchar a;
136
+
unsignedchar b : 1;
137
+
} __attribute__((packed));
138
+
139
+
structS26 { // expected-warning {{packed attribute is unnecessary for 'S26'}}
140
+
unsignedchar a : 1;
141
+
unsignedchar b; //expected-warning {{padding struct 'S26' with 7 bits to align 'b'}}
142
+
} __attribute__((packed));
143
+
144
+
structS27 { // expected-warning {{padding size of 'S27' with 7 bits to alignment boundary}}
145
+
unsignedchar a : 1;
146
+
unsignedchar b : 8;
147
+
} __attribute__((packed));
148
+
149
+
75
150
// The warnings are emitted when the layout of the structs is computed, so we have to use them.
0 commit comments