diff --git a/regression/ansi-c/Struct_Padding7/main.c b/regression/ansi-c/Struct_Padding7/main.c new file mode 100644 index 00000000000..5f9095abea4 --- /dev/null +++ b/regression/ansi-c/Struct_Padding7/main.c @@ -0,0 +1,33 @@ +#define CONCAT(a, b) a##b +#define CONCAT2(a, b) CONCAT(a, b) + +#define STATIC_ASSERT(condition) \ + int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1] + +typedef struct S1 +{ + int x; +} S1; + +#ifdef __GNUC__ +struct S2 +{ + struct S1 __attribute__((__aligned__(((1L) << 12)))) s1; +}; + +struct foo +{ + char a; + int x[2] __attribute__((packed)); +}; +#endif + +int main() +{ +#ifdef __GNUC__ + STATIC_ASSERT(sizeof(struct S1) == sizeof(int)); + STATIC_ASSERT(sizeof(struct S2) == (1L << 12)); + STATIC_ASSERT(sizeof(struct foo) == sizeof(char) + 2 * sizeof(int)); +#endif + return 0; +} diff --git a/regression/ansi-c/Struct_Padding7/test.desc b/regression/ansi-c/Struct_Padding7/test.desc new file mode 100644 index 00000000000..466da18b2b5 --- /dev/null +++ b/regression/ansi-c/Struct_Padding7/test.desc @@ -0,0 +1,8 @@ +CORE +main.c + +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring +^CONVERSION ERROR$ diff --git a/src/ansi-c/c_typecheck_type.cpp b/src/ansi-c/c_typecheck_type.cpp index a7e6f8c8ebd..ea57e4edaa3 100644 --- a/src/ansi-c/c_typecheck_type.cpp +++ b/src/ansi-c/c_typecheck_type.cpp @@ -761,6 +761,9 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type) original_qualifiers.is_transparent_union; remove_qualifiers.write(type); + bool is_packed = type.get_bool(ID_C_packed); + irept alignment = type.find(ID_C_alignment); + if(type.find(ID_tag).is_nil()) { // Anonymous? Must come with body. @@ -867,6 +870,11 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type) type.swap(tag_type); original_qualifiers.write(type); + + if(is_packed) + type.set(ID_C_packed, true); + if(alignment.is_not_nil()) + type.set(ID_C_alignment, alignment); } void c_typecheck_baset::typecheck_compound_body(