Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -9409,15 +9409,41 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
MonoInst *vtable_arg = NULL;

cmethod = mini_get_method (cfg, method, token, NULL, generic_context);
/*
* In AOT mode, a type-load failure while resolving the constructor (e.g. an
* invalid covariant override on the declaring type) should turn the method
* into one that throws TypeLoadException at runtime, matching the JIT
* behavior, instead of aborting compilation. Aborting would exclude the
* method from the AOT image, and calling it under full-AOT would surface a
* confusing 'JIT compile while running in aot-only mode' error instead.
*/
if (cfg->compile_aot && !is_ok (cfg->error) && mono_error_get_error_code (cfg->error) == MONO_ERROR_TYPE_LOAD) {
clear_cfg_error (cfg);
INLINE_FAILURE ("type load error");
method_make_alwaysthrow_typeloadfailure (cfg, cmethod ? cmethod->klass : NULL);
goto all_bbs_done;
}
CHECK_CFG_ERROR;

fsig = mono_method_get_signature_checked (cmethod, image, token, generic_context, cfg->error);
CHECK_CFG_ERROR;

mono_save_token_info (cfg, image, token, cmethod);

if (mono_class_has_failure (cmethod->klass) || !mono_class_init_internal (cmethod->klass))
TYPE_LOAD_ERROR (cmethod->klass);
if (mono_class_has_failure (cmethod->klass) || !mono_class_init_internal (cmethod->klass)) {
if (!cfg->compile_aot)
TYPE_LOAD_ERROR (cmethod->klass);
/*
* In AOT mode, rather than aborting compilation of the whole method
* (which would exclude it from the AOT image and make a full-AOT call
* site throw a confusing 'JIT compile while running in aot-only mode'
* error), turn the method into one that throws the TypeLoadException at
* runtime, matching the JIT behavior.
*/
INLINE_FAILURE ("type load error");
method_make_alwaysthrow_typeloadfailure (cfg, cmethod->klass);
goto all_bbs_done;
}

context_used = mini_method_check_context_used (cfg, cmethod);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,6 @@
01 00 00 00
)
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ActiveIssueAttribute::.ctor(string, class [mscorlib]System.Type, string[]) = {string('Tests that expect TypeLoadException') type([TestLibrary]TestLibrary.Utilities) string[1] ('IsNativeAot') }
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ActiveIssueAttribute::.ctor(string, valuetype [Microsoft.DotNet.XUnitExtensions]Xunit.TestRuntimes) = {
string('https://github.com/dotnet/runtime/issues/129508')
int32(0x2) // Mono
}
.entrypoint
.maxstack 2
.locals init ( bool result )
Expand Down
Loading