-
Notifications
You must be signed in to change notification settings - Fork 509
[CppCodeGen] Simple test with enum fails on Linux x64 #2884
Comments
This is likely caused by missing generator of unboxing stub in CppCodeGen. It is not Linux specific - same crash will happen on Windows too. The CppCodeGen is not as far as the RyuJIT CodeeGen (list of issues CodeGen-Cpp ). This test works fine with RyuJIT, so the alternative is to start bringing up the RyuJIT backend. |
@jkotas Just had a look at this issue, though struggled to translate the approach RyuJIT took to the CPP generator. Is there any documentation that would allow me to better understand the work needed here (corert seems less will documented than coreclr unfortunately). Do you think another of the open CPP issues would be better to try and get an understanding of the code? |
@benpye Welcome back Ben! Even simpler repro - interface method calls on boxed value types do not work:
Here is how to start debugging it:
FindInterfaceMethodImplementationTarget finds the pointer to the method to call, and the next line calls it. The crash means that FindInterfaceMethodImplementationTarget have not found the interface method implementation. The interface method implementation is pretty similar between CoreCLR and CoreRT.: https://github.com/dotnet/coreclr/blob/master/Documentation/botr/virtual-stub-dispatch.md The low level assembly tricks and encoding of the dispatch maps are different, but the overall scheme is the same. The crash is likely caused by bad dispatch map emitted by the compiler. InterfaceDispatchMapNode is what holds the dispatch map in the compiler.
I think this issue is a good one to start with. |
#3670 fixed the example given by @jkotas above, however the original and a simplified version are still broken. using System;
namespace EnumTest
{
internal class Program
{
enum Test { A }
private static void Main()
{
Console.WriteLine(Convert.ToInt32(Test.A));
}
}
} As in the PR, EDIT: So far as I can tell this is occurring exclusively for enums. Does RyuJIT take any additional steps for enums? The method table for enum types is full of the non-unboxing methods, whilst other value types get given (correctly) the unboxing stubs. |
I do not think so. Looks like a bug in the CppCodeGen - using underlying enum type instead of actual enum type, or something similar. |
Hm, alright. At a quick glance it looks like CppCodeGen doesn't do much differently for enums compared to other value types, aside from a little different name mangling. Will have another look over the weekend. |
It appears to me that with the latest code on the master branch, the bug does not repro anymore (with all the code snippets above). Closing this issue for now. Feel free to re-open if this is not the case for you @sergign60 @jkotas @benpye |
The following test fails on x64 Linux with the latest version of corert
the listing of the execution in gdb
I commented #line generation in the file src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs and added "-g" in /src/BuildIntegration/Microsoft.NETCore.Native.Unix.props
The text was updated successfully, but these errors were encountered: