[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[csmith-dev] Pragma pack clang/gcc difference
Hello,
the generation of pragma pack directives in Csmith programs
recently became active by default. I am not asking how to
deactivate it (I can only re-iterate here that I find Csmith
really easy to use for what it does). But together with unions,
programs may be generated that test the same thing as
this reduced program:
#pragma pack(push)
#pragma pack(1)
struct S0 {
unsigned f0 : 5;
unsigned : 0;
unsigned f1 : 5;
};
#pragma pack(pop)
main(){
return (sizeof(struct S0));
}
Generated programs do not use sizeof (that I know of)
but an union containing struct S0 allows to observe the
layout chosen by the compiler.
Clang and GCC have different layouts when using #pragma pack
together with size 0 bitfields!
~ $ clang t.c
t.c:10:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main(){
^
1 diagnostic generated.
~ $ ./a.out
~ $ echo $?
2
~ $ gcc t.c
~ $ ./a.out
~ $ echo $?
5
One does not seem more "right" than the other
(although 5 is surprising to me).
Does anyone know how to make GCC behave like clang, or the
opposite, and whether someone might like to know about this
(this may break some ABIs, although anyone using :0 bitfields
in packed structs in ABI definitions is basically asking for it).
Pascal