Repository: dotnet/runtime
File: src/coreclr/jit/flowgraph.cpp (C++)

Code before:
    {
        fgInsertStmtAtEnd(block, fgNewStmtFromTree(tree));
    }
    else
    {
        LIR::Range     range     = LIR::SeqTree(this, tree);
        GenTree* const firstNode = range.FirstNode();
        GenTree* const lastNode  = range.LastNode();
        LIR::AsRange(block).InsertAtEnd(std::move(range));
        LIR::ReadOnlyRange blockRange(firstNode, lastNode);
        m_pLowering->LowerRange(block, blockRange);
    }
}

//------------------------------------------------------------------------
// fgGetExcptnTarget: finds the block to jump to that will throw a given kind of exception
//
// Arguments:
//    kind -- kind of exception to throw
//    fromBlock -- block that will jump to the throw helper
//    createIfNeeded -- create the block if it does not already exist
//
// Return Value:
//    Code descriptor for the appropriate throw helper block.
//    When createIfNeeded is false, this can return an AddCodeDsc where acdBlk is nullptr.
//    If createIfNeeded is true, acdBlk will be non-null.
//
Compiler::AddCodeDsc* Compiler::fgGetExcptnTarget(SpecialCodeKind kind, BasicBlock* fromBlock, bool createIfNeeded)
{
    assert(fgUseThrowHelperBlocks() || (kind == SCK_FAIL_FAST));
    AddCodeDsc*          add = nullptr;
    AddCodeDscMap* const map = fgGetAddCodeDscMap();
    AddCodeDscKey        key(kind, fromBlock, this);
    map->Lookup(key, &add);

    if (add == nullptr)
    {
        add = fgCreateAddCodeDsc(fromBlock, kind);

        // Create the block...
        //
        if (createIfNeeded)
        {
            fgCreateThrowHelperBlock(add);
        }
    }

    return add;
}

//------------------------------------------------------------------------

Review comment (bug):
The comment refers to `acdBlk`, but the field name is `acdDstBlk`. Updating the comment would avoid confusion when reasoning about when the throw-helper block is actually created.
```suggestion
//    When createIfNeeded is false, this can return an AddCodeDsc where acdDstBlk is nullptr.
//    If createIfNeeded is true, acdDstBlk will be non-null.
```

Code after:
    {
        fgInsertStmtAtEnd(block, fgNewStmtFromTree(tree));
    }
    else
    {
        LIR::Range     range     = LIR::SeqTree(this, tree);
        GenTree* const firstNode = range.FirstNode();
        GenTree* const lastNode  = range.LastNode();
        LIR::AsRange(block).InsertAtEnd(std::move(range));
        LIR::ReadOnlyRange blockRange(firstNode, lastNode);
        m_pLowering->LowerRange(block, blockRange);
    }
}

//------------------------------------------------------------------------
// fgGetExcptnTarget: finds the block to jump to that will throw a given kind of exception
//
// Arguments:
//    kind -- kind of exception to throw
//    fromBlock -- block that will jump to the throw helper
//    createIfNeeded -- create the block if it does not already exist
//
// Return Value:
//    Code descriptor for the appropriate throw helper block.
//    When createIfNeeded is false, this can return an AddCodeDsc where acdDstBlk is nullptr.
//    If createIfNeeded is true, acdDstBlk will be non-null.
//
Compiler::AddCodeDsc* Compiler::fgGetExcptnTarget(SpecialCodeKind kind, BasicBlock* fromBlock, bool createIfNeeded)
{
    assert(fgUseThrowHelperBlocks() || (kind == SCK_FAIL_FAST));
    AddCodeDsc*          add = nullptr;
    AddCodeDscMap* const map = fgGetAddCodeDscMap();
    AddCodeDscKey        key(kind, fromBlock, this);
    map->Lookup(key, &add);

    if (add == nullptr)
    {
        add = fgCreateAddCodeDsc(fromBlock, kind);

        // Create the block...
        //
        if (createIfNeeded)
        {
            fgCreateThrowHelperBlock(add);
        }
    }

    return add;
}

//------------------------------------------------------------------------