Skip to content

Commit

Permalink
JIT: fix some issues in fgIsThrowHlpBlk (dotnet#58510)
Browse files Browse the repository at this point in the history
We may see no return calls that are not the roots of their trees, so don't
assert that the last node must be a call.

Update the list of helpers we check for to reflect current practice.

Remove the unused SCK_PAUSE_EXEC.

Fixes dotnet#58372.
  • Loading branch information
AndyAyersMS authored Sep 2, 2021
1 parent d5f40ec commit 9a5baa9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
26 changes: 6 additions & 20 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2596,7 +2596,6 @@ inline Compiler::fgWalkResult Compiler::fgWalkTree(GenTree** pTree,
* argument exception (used by feature SIMD)
* argument range-check exception (used by feature SIMD)
* divide by zero exception (Not used on X86/X64)
* null reference exception (Not currently used)
* overflow exception
*/

Expand All @@ -2612,32 +2611,19 @@ inline bool Compiler::fgIsThrowHlpBlk(BasicBlock* block)
return false;
}

GenTree* call = block->lastNode();

#ifdef DEBUG
if (block->IsLIR())
{
LIR::Range& blockRange = LIR::AsRange(block);
for (LIR::Range::ReverseIterator node = blockRange.rbegin(), end = blockRange.rend(); node != end; ++node)
{
if (node->OperGet() == GT_CALL)
{
assert(*node == call);
assert(node == blockRange.rbegin());
break;
}
}
}
#endif
// Special check blocks will always end in a throw helper call.
//
GenTree* const call = block->lastNode();

if (!call || (call->gtOper != GT_CALL))
if ((call == nullptr) || (call->gtOper != GT_CALL))
{
return false;
}

if (!((call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_RNGCHKFAIL)) ||
(call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_THROWDIVZERO)) ||
(call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_THROWNULLREF)) ||
(call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_THROW_ARGUMENTEXCEPTION)) ||
(call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION)) ||
(call->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_OVERFLOW))))
{
return false;
Expand Down
19 changes: 6 additions & 13 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3632,13 +3632,12 @@ BasicBlock* Compiler::fgAddCodeRef(BasicBlock* srcBlk, unsigned refData, Special
}

const static BBjumpKinds jumpKinds[] = {
BBJ_NONE, // SCK_NONE
BBJ_THROW, // SCK_RNGCHK_FAIL
BBJ_ALWAYS, // SCK_PAUSE_EXEC
BBJ_THROW, // SCK_DIV_BY_ZERO
BBJ_THROW, // SCK_ARITH_EXCP, SCK_OVERFLOW
BBJ_THROW, // SCK_ARG_EXCPN
BBJ_THROW, // SCK_ARG_RNG_EXCPN
BBJ_NONE, // SCK_NONE
BBJ_THROW, // SCK_RNGCHK_FAIL
BBJ_THROW, // SCK_DIV_BY_ZERO
BBJ_THROW, // SCK_ARITH_EXCP, SCK_OVERFLOW
BBJ_THROW, // SCK_ARG_EXCPN
BBJ_THROW, // SCK_ARG_RNG_EXCPN
};

noway_assert(sizeof(jumpKinds) == SCK_COUNT); // sanity check
Expand Down Expand Up @@ -3702,9 +3701,6 @@ BasicBlock* Compiler::fgAddCodeRef(BasicBlock* srcBlk, unsigned refData, Special
case SCK_RNGCHK_FAIL:
msg = " for RNGCHK_FAIL";
break;
case SCK_PAUSE_EXEC:
msg = " for PAUSE_EXEC";
break;
case SCK_DIV_BY_ZERO:
msg = " for DIV_BY_ZERO";
break;
Expand Down Expand Up @@ -3765,9 +3761,6 @@ BasicBlock* Compiler::fgAddCodeRef(BasicBlock* srcBlk, unsigned refData, Special
helper = CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION;
break;

// case SCK_PAUSE_EXEC:
// noway_assert(!"add code to pause exec");

default:
noway_assert(!"unexpected code addition kind");
return nullptr;
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// GenTreeOps nodes, for which codegen will generate the branch
// - it will use the appropriate kind based on the opcode, though it's not
// clear why SCK_OVERFLOW == SCK_ARITH_EXCPN
// SCK_PAUSE_EXEC is not currently used.
//
enum SpecialCodeKind
{
SCK_NONE,
SCK_RNGCHK_FAIL, // target when range check fails
SCK_PAUSE_EXEC, // target to stop (e.g. to allow GC)
SCK_DIV_BY_ZERO, // target for divide by zero (Not used on X86/X64)
SCK_ARITH_EXCPN, // target on arithmetic exception
SCK_OVERFLOW = SCK_ARITH_EXCPN, // target on overflow
Expand Down

0 comments on commit 9a5baa9

Please sign in to comment.