diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e8250cd56dd029..ee75064919f81b 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -15970,6 +15970,9 @@ void Compiler::impImportBlockCode(BasicBlock* block) } op1 = gtNewHelperCallNode(helper, TYP_VOID, gtNewCallArgs(op2, op1)); + // In this case helper call is a fallback to throw an exception. + op1->AsCall()->gtCallMoreFlags |= GTF_CALL_M_DOES_NOT_RETURN; + op1 = new (this, GT_COLON) GenTreeColon(TYP_VOID, gtNewNothingNode(), op1); op1 = gtNewQmarkNode(TYP_VOID, condBox, op1); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 433750b37f262f..d55929f03d8d62 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -18034,6 +18034,12 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) } Statement* trueStmt = fgNewStmtFromTree(trueExpr, stmt->GetILOffsetX()); fgInsertStmtAtEnd(thenBlock, trueStmt); + + // Convert the whole block to BBJ_THROW if trueExpr is a no-return call + if (trueExpr->IsCall() && trueExpr->AsCall()->IsNoReturn()) + { + fgConvertBBToThrowBB(thenBlock); + } } // Assign the falseExpr into the dst or tmp, insert in elseBlock @@ -18045,6 +18051,12 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) } Statement* falseStmt = fgNewStmtFromTree(falseExpr, stmt->GetILOffsetX()); fgInsertStmtAtEnd(elseBlock, falseStmt); + + // Convert the whole block to BBJ_THROW if falseExpr is a no-return call + if (falseExpr->IsCall() && falseExpr->AsCall()->IsNoReturn()) + { + fgConvertBBToThrowBB(elseBlock); + } } #ifdef DEBUG