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

Re: [csmith-dev] Unions with const and non const members

Not sure about C, but at least in C++ it's UB to write to one member, then read from another. But lots of code does it, so many compilers preserve the "expected" behavior here. If your compiler doesn't support that extension at all, you might have to tweak/configure csmith in some way (I don't know if it has a flag/feature/configuration for this extension) - but if it support it in the case of non-const members it seems pretty reasonable to me for it to support it for const members.

On Fri, Sep 25, 2015 at 4:24 PM, Anton Blanchard <anton@samba.org> wrote:

csmith creates unions with a mix of const and non const members, eg:

union U0 {
   int64_t  f0;
   const uint8_t  f1;
   uint64_t  f2;

static union U0 g_627 = {0x34L};

I'm chasing down a failing testcase on a vendor compiler where csmith
updates the non const members and then reads the const member. I don't
think that is valid c.

Unlike gcc, the vendor compiler propagates the constant 0x34 to all uses
of g_627.f1, such that it will never see a change if we write to the
other members.