Search Issue Tracker
Fixed in 5.3.6
Votes
0
Found in
5.3.4f1
Issue ID
796224
Regression
No
Generated C++ code using IL2CPP ignores the order of code lines in C#
When generating the Windows Store app C++ project using IL2CPP, the compiler appears to be able to ignore the order of code lines in C#, and do optimizations which effectively break the execution of certain functionality. Specifically, the issue observed is that the compiler does NOT store the value of an array item before actually "nulling" it, thus a Pop method for a stack ends up always returning null (or default value). Basically it ignores the fact that the array item is stored in a local variable, before the item at that index in the array is nulled.
Reproducible on 5.3.4f1, 5.3.5f1, 5.4.0b18.
Repro steps:
a) Launch Unity and load IL2CPP_TESTS project attached
b) Switch platform to "Universal Windows 10"
c) Switch scripting backend in Player Settings to "IL2CPP"
d) Click "Build"
e) Open up the generated C++ project (inside /bin/) in e.g. Visual Studio
f) Navigate to "Bulk_Generics_0.cpp" (may vary?) file and find lines 808 to 822 (line numbers may vary?), marked in the scope "IL_0013" (may vary?). Basically, the implementation of the Pop method of the "TestStack" class.
g) Notice how the compiled C++ code sets the array item value, before getting it, while in C# code it is the reverse. Setting it before getting it in a Pop method is devastating, because it will always return null for reference types and the default value in case of value types. The following two lines are the issue:
(L_6)->SetAt(static_cast<il2cpp_array_size_t>(L_7), (Vector3_t465617797 )L_8);
return ((L_3)->GetAt(static_cast<il2cpp_array_size_t>(L_5)));
Thus, it must assign the result of GetAt to a local variable BEFORE it calls SetAt, which effectively changes the value returned by GetAt, so that it can return the reference or value desired to the caller.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- UI Toolkit 'background-size' property is not fully animatable
- Moving the Scrollbar via clicking no longer works after the first-click when page size is too small
- Elements in UI Builder Viewport are displayed incorrectly when Editor UI Scaling is set to 125%
- Prefab referencing a script is not shown in the Search window's Project tab when using "Find References In Project"
- Scroll view sensitivity remains unchanged when modifying the "--unity-metrics-single_line-height" value
Add comment