Search Unity

IL2CPP generates bad code in 2019.2.6 (bad casting)

Discussion in 'Scripting' started by MFG-jkhoo, Oct 4, 2019.

  1. MFG-jkhoo

    MFG-jkhoo

    Joined:
    Jul 15, 2016
    Posts:
    19
    There's a new IL2CPP bug introduced in 2019.2.6. (Bug did not exist in 2019.2.5)

    Code (CSharp):
    1. double foo = 2147483649;
    2. 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.
     
    MNNoxMortem and jawad_ahmad like this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    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:

    Code (csharp):
    1.     double V_0 = 0.0;
    2.     uint32_t V_1 = 0;
    3.     {
    4.         V_0 = (2147483649.0);
    5.         double L_0 = V_0;
    6.         V_1 = (((int32_t)((uint32_t)L_0)));
    7.         uint32_t L_1 = V_1;
    8.         return L_1;
    9.     }
    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.
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Please file a bug report for this issue - we will gladly investigate it.
     
  4. MFG-jkhoo

    MFG-jkhoo

    Joined:
    Jul 15, 2016
    Posts:
    19
    MNNoxMortem likes this.
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    MFG-jkhoo likes this.