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
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
Add comment