From eb7322c21594903f2973674af622408f8e485ed2 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 22 Nov 2024 11:32:03 +0200 Subject: [PATCH 1/2] [mono][aot] Fix stack state when emitting type load throw Method compilation was continuing and we ended up failing with invalid IL. --- src/mono/mono/mini/method-to-ir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 33916b9c104db..7c26ffe935d4f 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -12111,14 +12111,13 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b break; case MONO_CEE_INITOBJ: klass = mini_get_class (method, token, generic_context); + --sp; if (CLASS_HAS_FAILURE (klass)) { HANDLE_TYPELOAD_ERROR (cfg, klass); inline_costs += 10; break; // reached only in AOT } - --sp; - if (mini_class_is_reference (klass)) MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STORE_MEMBASE_IMM, sp [0]->dreg, 0, 0); else From 11375fe614e6551f1d7282fac572063a3be38ebe Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 22 Nov 2024 11:33:42 +0200 Subject: [PATCH 2/2] [mono][aot] Mark clauses as dead when replacing method code with exception throw In the final stages of method compilation, when trying to compute clause ranges, we were asserting because the clause bblocks haven't been reached for compilation. --- src/mono/mono/mini/method-to-ir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 7c26ffe935d4f..879d98dfc673e 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -6262,6 +6262,9 @@ method_make_alwaysthrow_typeloadfailure (MonoCompile* cfg, MonoClass* klass) mono_link_bblock (cfg, bb, cfg->bb_exit); cfg->disable_inline = TRUE; + + for (guint i = 0; i < cfg->header->num_clauses; i++) + cfg->clause_is_dead [i] = TRUE; } typedef union _MonoOpcodeParameter {