IL2CPP generates bad code in 2019.2.6 (bad casting)

There’s a new IL2CPP bug introduced in 2019.2.6. (Bug did not exist in 2019.2.5)

double foo = 2147483649;
uint fooAsUint = (uint)foo;

In 2019.2.6 IL2CPP, fooAsUint is 2147483648.
When using the Mono runtime or using 2019.2.5 IL2CPP, fooAsUint is 2147483649.

This affects all platforms. I also tested on 2019.2.8, 2019.3.0b5, and 2020.1.0a7. The same bug exists in those Unity versions as well.

2 Likes

Have you looked at the generated IL2CPP in each case?

I just took a quick peek in an older Unity 5.6.6f2 targeting iOS and got this C codelet:

    double V_0 = 0.0;
    uint32_t V_1 = 0;
    {
        V_0 = (2147483649.0);
        double L_0 = V_0;
        V_1 = (((int32_t)((uint32_t)L_0)));
        uint32_t L_1 = V_1;
        return L_1;
    }

I don’t have newer versions handy with me right now but I can check tomorrow. I’m curious because if you found a real bug, absolutely file it. Unity does fix a ton of bugs based on bug reports, and the smaller and simpler the repro steps the better.

Please file a bug report for this issue - we will gladly investigate it.

@Kurt-Dekker , thanks, I just checked the C++ output and with 2019.2.6 it’s performing an extra cast:

V_1 = (((int32_t)((uint32_t)(int32_t)L_0)));

@JoshPeterson : I did submit a bug report two weeks ago, but I haven’t heard any response or follow-up:
https://fogbugz.unity3d.com/default.asp?1186125_3dopatk59vmsmb67

1 Like

Thanks! The bug report has just come through our QA team - we will investigate it.

1 Like