[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [csmith-dev] Using safe math headers in csmith



Hi Karine, thanks for pointing this out.

I believe that we never used these features too much, so never noticed this.

Can I ask you to prepare a pull request fixing the easy parts, and then we'll look at whatever's left?

Thanks,

John



On 3/16/20 3:48 AM, Even Mendoza, Karine wrote:
Hi John


I was testing csmith the macro options; however, when running on a large population of seed, we got testcases with a different output when using macros.

I debugged it a bit, and it is due to 3 main issues: (1) safe condition checks are not always the same, (2) casting (between explicit C-like casting in the macros and implicit casting coming from the function signature), and last (3) brackets.

I can relatively easily fix 2+3, however (1) tends to be a bit more tricky.


For example:
The seed: 314862222 produces a different result when using macros due to differences in the conditions (the ternary operator) in rshift_func_int8_t_s_u.

I compile it and run it that way:
./src/csmith --seed 314862222 --bitfields --packed-struct >> temp_regular_5.c
clang -I../runtimeExp -DUSE_MATH_MACROS -w -O temp_regular_5.c -o temp_macros_5

The conditions:
((left < 0) || (((unsigned int)right) >= 32)) vs. (((int8_t)(left)) < ((int8_t)0)) || (((unsigned int)(right)) >= sizeof(int8_t)*CHAR_BIT)); these are evaluated to false vs. true for seed 314862222.


Please let me know if more examples of seeds could help. I have several examples.


Thanks much,

Karine

-----Original Message-----
From: csmith-dev-bounces@flux.utah.edu <csmith-dev-bounces@flux.utah.edu> On Behalf Of John Regehr
Sent: 24 February 2020 18:01
To: csmith-dev@flux.utah.edu
Subject: Re: [csmith-dev] Using safe math headers in csmith


*******************
This email originates from outside Imperial. Do not click on links and attachments unless you recognise the sender.
If you trust the sender, add them to your safe senders list https://spam.ic.ac.uk/SpamConsole/Senders.aspx to disable email stamping for this address.
*******************
Hi Karine, ok, I looked into this. Both of these alternative header files appear to work just fine. If you want to use the NOTMP versions, you need to pass Csmith the additional --math-notmp flag.

I ran this shell script a few times and both versions always produced the same checksum:

./src/csmith > foo.c
clang -O0 -w foo.c -I../runtime -o foo1
clang -O0 foo.c -I../runtime -DUSE_MATH_MACROS -w -o foo2 ulimit -t 2
./foo1
./foo2

Let us know if anything doesn't work as advertised.

John



On 2/24/20 8:20 AM, John Regehr wrote:
Hi Karine,

Well, I just tried to compile a program using -DUSE_MATH_MACROS_NOTMP
and it did not compile, so something must have gone wrong here. I
assume the same thing happened when you tried this?

I'll try to look into it soon.

John


On 2/24/20 2:28 AM, Even Mendoza, Karine wrote:
Hi,

I would like to know if the version of csmith using the header
safe_math_macros.h or safe_math_macros_notmp.c is working.

Can I use these headers instead of safe_math.h and expect the same
output for the generated programs?

Thanks much,

Karine