File tree 3 files changed +49
-0
lines changed
regression/ansi-c/Struct_Padding7
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ #define CONCAT (a , b ) a##b
2
+ #define CONCAT2 (a , b ) CONCAT(a, b)
3
+
4
+ #define STATIC_ASSERT (condition ) \
5
+ int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
6
+
7
+ typedef struct S1
8
+ {
9
+ int x ;
10
+ } S1 ;
11
+
12
+ #ifdef __GNUC__
13
+ struct S2
14
+ {
15
+ struct S1 __attribute__((__aligned__ (((1L ) << 12 )))) s1 ;
16
+ };
17
+
18
+ struct foo
19
+ {
20
+ char a ;
21
+ int x [2 ] __attribute__((packed ));
22
+ };
23
+ #endif
24
+
25
+ int main ()
26
+ {
27
+ #ifdef __GNUC__
28
+ STATIC_ASSERT (sizeof (struct S1 ) == sizeof (int ));
29
+ STATIC_ASSERT (sizeof (struct S2 ) == (1L << 12 ));
30
+ STATIC_ASSERT (sizeof (struct foo ) == sizeof (char ) + 2 * sizeof (int ));
31
+ #endif
32
+ return 0 ;
33
+ }
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 @@ -761,6 +761,9 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
761
761
original_qualifiers.is_transparent_union ;
762
762
remove_qualifiers.write (type);
763
763
764
+ bool is_packed = type.get_bool (ID_C_packed);
765
+ irept alignment = type.find (ID_C_alignment);
766
+
764
767
if (type.find (ID_tag).is_nil ())
765
768
{
766
769
// Anonymous? Must come with body.
@@ -867,6 +870,11 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
867
870
type.swap (tag_type);
868
871
869
872
original_qualifiers.write (type);
873
+
874
+ if (is_packed)
875
+ type.set (ID_C_packed, true );
876
+ if (alignment.is_not_nil ())
877
+ type.set (ID_C_alignment, alignment);
870
878
}
871
879
872
880
void c_typecheck_baset::typecheck_compound_body (
You can’t perform that action at this time.
0 commit comments