[csmith-dev] Alignment of struct members cause target dependent checksum
Kees Bakker
kees.bakker at altium.nl
Wed Jun 12 03:46:47 MDT 2013
Hi John,
Thank you for the explanation. We're grateful for the tool, so for sure we don't
want to complain too much :-)
We're using GCC4.7 as a reference to generate the checksum. The compilers
that we test are very diverse. And alignment of structure members can be
different from GCC-x86. When we hit a problem we first look at the checksum
of a few other compilers. When the difference is caused by structure alignment
it may be that 4 out of 5 give the same checksum. Then one might conclude that
the fifth compiler has a bug. And in the end you find out that it wasn't a problem.
Analyzing bugs in Csmith programs can be time consuming. And Creduce isn't always
helpful.
Kind regards,
Kees Bakker
On 05-06-13 18:22, John Regehr wrote:
> 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