[Issue 17220] invalid code with -m32 -inline and struct that's 4x the size of an assigned enum value

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 23 19:56:51 PST 2017


https://issues.dlang.org/show_bug.cgi?id=17220

Stefan Koch <uplink.coder at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |x86_64

--- Comment #1 from Stefan Koch <uplink.coder at gmail.com> ---
Happens on 64bit as well
Slightly modified:

void emitArithInstruction2(BCValue lhs)
{
    if (lhs.type != BCTypeEnum.i32) // type get's overwritten
        assert(0);
}

enum BCTypeEnum : ubyte
{
    Undef,
    i32 = 8, // value must be >= 8
}

struct BCValue // size must be size_t.sizeof x BCTypeEnum.i32
{
    BCTypeEnum type; // position doesn't matter
    ubyte[size_t.sizeof * BCTypeEnum.i32 - type.sizeof] more;
}
static assert(BCValue.sizeof == size_t.sizeof * BCTypeEnum.i32);

BCValue i32()
{
    BCValue result; // must be default 0 initialized
    result.type = BCTypeEnum.i32; // set value
    return result;
}

void main()
{
    auto val = i32();
    emitArithInstruction2(val);
}
CODE

--


More information about the Digitalmars-d-bugs mailing list