-
Notifications
You must be signed in to change notification settings - Fork 509
CppCodeGen: AV in Enum.ToString() #4558
Comments
Without ToString(): using System;
internal class Program
{
enum State { On, Off }
private static void Main(string[] args)
=> Console.WriteLine(State.On);
} The stacktrace looks bit different: 0000000000000000() Unknown Non-user code
reproNativeCpp.exe!System_Runtime_Extensions::System::IO::TextWriter::WriteLine_12(System_Runtime_Extensions::System::IO::TextWriter * ___this, System_Private_CoreLib::System::Object * value) Line 430 C++ Symbols loaded.
reproNativeCpp.exe!System_Console::System::IO::SyncTextWriter::WriteLine_12(System_Console::System::IO::SyncTextWriter * ___this, System_Private_CoreLib::System::Object * value) Line 289 C++ Symbols loaded.
reproNativeCpp.exe!System_Console::System::Console::WriteLine_11(System_Private_CoreLib::System::Object * value) Line 555 C++ Symbols loaded.
reproNativeCpp.exe!repro::Program::Main(__Array_A_::System_Private_CoreLib::System::String_V_ * args) Line 11 C++ Symbols loaded.
reproNativeCpp.exe!repro::_Module_::MainMethodWrapper(__Array_A_::System_Private_CoreLib::System::String_V_ * _a0) C++ Non-user code. Symbols loaded.
reproNativeCpp.exe!repro::_Module_::StartupCodeMain(int _a0, __int64 _a1) C++ Non-user code. Symbols loaded.
reproNativeCpp.exe!__managed__Main(int _a0, __int64 _a1) Line 16707570 C++ Symbols loaded.
reproNativeCpp.exe!wmain(int argc, wchar_t * * argv) Line 332 C++ Symbols loaded.
reproNativeCpp.exe!invoke_main() Line 91 C++ Non-user code. Symbols loaded.
reproNativeCpp.exe!__scrt_common_main_seh() Line 283 C++ Non-user code. Symbols loaded.
reproNativeCpp.exe!__scrt_common_main() Line 326 C++ Non-user code. Symbols loaded.
reproNativeCpp.exe!wmainCRTStartup() Line 17 C++ Non-user code. Symbols loaded.
kernel32.dll!BaseThreadInitThunk�() Unknown Non-user code. Symbols loaded.
ntdll.dll!RtlUserThreadStart�() Unknown Non-user code. Symbols loaded. I assume this is because @hippiehunter, this second case might be related to #4556. |
The second failure appears to be something interacting poorly between boxed enum types and interface methods. The call to FindInterfaceMethodImplementationTarget appears to be returning 0 for the requested function pointer. |
@jkotas |
@hippiehunter, I tested corert/src/Runtime.Base/src/System/Runtime/TypeCast.cs Lines 156 to 169 in 0fa150c
while debugging reproNativeCpp.vcxproj. Except for the first time it hits this breakpoint (different code path from initial module loader), it throws invalid cast exception from line 169 as It also throws same exception with constant int ToString(): using System;
internal class Program
{
private static void Main(string[] args)
=> Console.WriteLine(42.ToString());
} |
It looks like I cut my test down to far and was only really testing the boxing interface call portion of this issue. It looks like the failure happens with just this
|
@jkotas
Only works if the module has NativeFormatModuleInfo, otherwise it will throw when it attempts to cast. So basically the path that is supposed to return false and cause RuntimeNoMetadataNamedTypeInfo to be created, itself fails because there is no guard against the requested module being just a plain ModuleInfo instance. I don't see a way to tell from the TypeManagerHandle if the type is going to be good or not. The header of GetModuleInfoByHandle is pretty clear that it only works for NativeFormatModuleInfo and it makes no attempt to guard against improper access. Is that wrong or is there some way to tell before we get into GetModuleInfoByHandle that there isn't going to be a NativeFormatModuleInfo result? |
when i hard code IsReflectionBlocked => true, we fail anyway because ToString of an Enum looks like it requires at least FieldInfo level reflection in order to work
|
Fix this by using TryGetModuleInfoByHandle instead?
Yes, the enum.ToString is still expected to fail. int.ToString should work. |
I didn't even think to look for a Try method. Anyway that works for the int case and I've made #4571, does the github bot run a larger set of the coreclr tests? Given this is a common area I would really like to not break the world again. |
#6423 has more current discussion about |
The runtime transpiled code in C++ for ToString looks like this:
Given the following code:
we get access violation when the getslot function tries to dereference
((RawEEType **)pThis)
, this part:(*((RawEEType **)pThis) + 1)
.Stacktrace:
The text was updated successfully, but these errors were encountered: