[csmith-dev] Alignment of struct members cause target dependent checksum

John Regehr regehr at cs.utah.edu
Wed Jun 5 11:16:03 MDT 2013


> Incidentally, John, I was also surprised that Csmith would generate
> code that writes to a union member and then reads back from a
> different (and not even equivalent) member. On reflection I agree this
> might be useful, but shouldn't there at least be a command-line switch
> to prevent Csmith from generating undefined behavior? (If Kees
> described the problem correctly, the test program was definitely UB.)

This is one of those things that is technically undefined but common 
compilers (at least GCC and Clang, probably more) provide well-defined 
behavior that we wanted to test.  In other words, the GCC developers 
guarantee that type punning via union works "as expected."  In fact, 
there are optimization passes that propagate values through these sorts 
of type puns (I'm actually working on a blog post about this).

There are a few random union-related command line options, I'm not sure 
if the one you want is there, but if it's not I would imagine that we 
could add it.  We spent quite a bit of time on unions!

John



More information about the csmith-dev mailing list