From e683e998f9e269bf4dba98dd0e1805fb2f0ca846 Mon Sep 17 00:00:00 2001 From: Aman Khalid Date: Tue, 12 Dec 2023 18:20:59 -0500 Subject: [PATCH] JIT: Fix BBJ_COND-related assert in OptIfConversionDsc::IfConvertDump (#95934) In #95773, I incorrectly assumed m_startBlock would always be a BBJ_COND in OptIfConversionDsc::IfConvertDump, but it can be converted to a BBJ_ALWAYS before being dumped, thus hitting an assert when m_startBlock->GetTrueTarget() is called. This is fixed by calling the correct target accessor method depending on the type of m_startBlock. (Note that IfConvertDump is only called if dumps are enabled, hence why this assert wasn't initially hit in CI.) --- src/coreclr/jit/ifconversion.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/ifconversion.cpp b/src/coreclr/jit/ifconversion.cpp index 5c52e5c31a2d1..2883eeae5d603 100644 --- a/src/coreclr/jit/ifconversion.cpp +++ b/src/coreclr/jit/ifconversion.cpp @@ -381,15 +381,15 @@ void OptIfConversionDsc::IfConvertDump() { assert(m_startBlock != nullptr); m_comp->fgDumpBlock(m_startBlock); - for (BasicBlock* dumpBlock = m_startBlock->Next(); dumpBlock != m_finalBlock; - dumpBlock = dumpBlock->GetUniqueSucc()) + BasicBlock* dumpBlock = m_startBlock->KindIs(BBJ_COND) ? m_startBlock->GetFalseTarget() : m_startBlock->Next(); + for (; dumpBlock != m_finalBlock; dumpBlock = dumpBlock->GetUniqueSucc()) { m_comp->fgDumpBlock(dumpBlock); } if (m_doElseConversion) { - for (BasicBlock* dumpBlock = m_startBlock->GetTrueTarget(); dumpBlock != m_finalBlock; - dumpBlock = dumpBlock->GetUniqueSucc()) + dumpBlock = m_startBlock->KindIs(BBJ_COND) ? m_startBlock->GetTrueTarget() : m_startBlock->GetTarget(); + for (; dumpBlock != m_finalBlock; dumpBlock = dumpBlock->GetUniqueSucc()) { m_comp->fgDumpBlock(dumpBlock); }