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
- [OpenGLES][XR] Zooming in on the camera's URP opaque texture causes "double vision" on Quest in OpenGLES3
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
Add comment