[csmith-dev] Alignment of struct members cause target dependent checksum
John Regehr
regehr at cs.utah.edu
Wed Jun 5 10:22:47 MDT 2013
Hi Kees,
It is not generally expected that Csmith programs will have the same
results across compilers or platforms except when those
compilers/platforms make the same choices for implementation-defined
characteristics such as alignment, integer width and representation, etc.
When creating Csmith we had a choice between generating more portable
code, which would permit differential testing across more platforms, and
less portable code, which (we think) finds more compiler bugs. We
decided to do the second one. Basically this means that you will need
to choose your compilers carefully when doing differential testing.
Most compiler bugs can be found simply by comparing different
optimization levels of the same compiler. We've seen a few bugs where a
compiler produces that same wrong result at all optimization levels, but
this is quite rare.
Hopefully this is helpful?
Thanks,
John
On 06/05/2013 06:27 AM, Kees Bakker wrote:
> Hi,
>
> Csmith can generate tests with unions and struct where the result
> is target dependent.
>
> Here is a small example.
>
> struct S1 {
> const volatile uint8_t f10;
> int32_t f11;
> };
>
> union U4 {
> const uint32_t f0;
> struct S1 f2;
> };
> static union U4 g_1126 = {4294967294UL};
>
> One of the tests I created was writing in g_1126.f2.f11 and reading
> from g_1126.f0 for the checksum.
>
> However, the struct member offset of f11 is not defined. For example GCC
> (i386)
> uses an offset 4, but other (compliant C99 compilers) may use offset 2
> or even 1.
> (And that is without specifying "pack".)
>
> In this case the checksum created with GCC (assuming GCC is correct) is not
> valid for all other compilers.
>
> What options do I have to let Csmith avoid such a construct?
>
> Kind regards,
> Kees Bakker
>
More information about the csmith-dev
mailing list