File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed
regression/ansi-c/Struct_Padding6 Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 1+ #define STATIC_ASSERT (condition ) \
2+ int some_array##__LINE__[(condition) ? 1 : -1]
3+
4+ #pragma pack(4)
5+
6+ typedef unsigned short domid_t ;
7+ typedef unsigned evtchn_port_t ;
8+ struct evtchn_status {
9+ domid_t dom ;
10+ evtchn_port_t port ;
11+ unsigned status ;
12+ unsigned vcpu ;
13+ union {
14+ struct {
15+ domid_t dom ;
16+ } unbound ;
17+ struct {
18+ domid_t dom ;
19+ evtchn_port_t port ;
20+ } interdomain ;
21+ unsigned pirq ;
22+ unsigned virq ;
23+ } u ;
24+ char a ;
25+ };
26+
27+ int main ()
28+ {
29+ STATIC_ASSERT (__builtin_offsetof (struct evtchn_status ,u .interdomain .port )== 20 );
30+ STATIC_ASSERT (sizeof (struct evtchn_status )== 28 );
31+ return 0 ;
32+ };
Original file line number Diff line number Diff line change 1+ CORE
2+ main.c
3+
4+ ^EXIT=0$
5+ ^SIGNAL=0$
6+ --
7+ ^warning: ignoring
8+ ^CONVERSION ERROR$
Original file line number Diff line number Diff line change @@ -188,8 +188,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
188188 }
189189 }
190190
191- // Is the struct packed?
192- if (type.get_bool (ID_C_packed))
191+ // Is the struct packed, without any alignment specification?
192+ if (type.get_bool (ID_C_packed) &&
193+ type.find (ID_C_alignment).is_nil ())
193194 return ; // done
194195
195196 mp_integer offset=0 ;
@@ -291,6 +292,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
291292 max_alignment=tmp_i;
292293 }
293294 }
295+ // Is the struct packed, without any alignment specification?
296+ else if (type.get_bool (ID_C_packed))
297+ return ; // done
294298
295299 // There may be a need for 'end of struct' padding.
296300 // We use 'max_alignment'.
You can’t perform that action at this time.
0 commit comments