Skip to content

Commit 81d18ad

Browse files
authored
[NFC][DebugInfo] Make some block-start-position methods return iterators (#124287)
As part of the "RemoveDIs" work to eliminate debug intrinsics, we're replacing methods that use Instruction*'s as positions with iterators. A number of these (such as getFirstNonPHIOrDbg) are sufficiently infrequently used that we can just replace the pointer-returning version with an iterator-returning version, hopefully without much/any disruption. Thus this patch has getFirstNonPHIOrDbg and getFirstNonPHIOrDbgOrLifetime return an iterator, and updates all call-sites. There are no concerns about the iterators returned being converted to Instruction*'s and losing the debug-info bit: because the methods skip debug intrinsics, the iterator head bit is always false anyway.
1 parent 5f5cdf4 commit 81d18ad

File tree

19 files changed

+74
-50
lines changed

19 files changed

+74
-50
lines changed

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static llvm::Value *FindEntryInstruction(llvm::Function *function) {
6666
if (function->empty())
6767
return nullptr;
6868

69-
return function->getEntryBlock().getFirstNonPHIOrDbg();
69+
return &*function->getEntryBlock().getFirstNonPHIOrDbg();
7070
}
7171

7272
IRForTarget::IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map,
@@ -361,7 +361,7 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
361361
// there's nothing to put into its equivalent persistent variable.
362362

363363
BasicBlock &entry_block(llvm_function.getEntryBlock());
364-
Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
364+
Instruction *first_entry_instruction(&*entry_block.getFirstNonPHIOrDbg());
365365

366366
if (!first_entry_instruction)
367367
return false;
@@ -1505,7 +1505,7 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) {
15051505
LLDB_LOG(log, "Arg: \"{0}\"", PrintValue(argument));
15061506

15071507
BasicBlock &entry_block(llvm_function.getEntryBlock());
1508-
Instruction *FirstEntryInstruction(entry_block.getFirstNonPHIOrDbg());
1508+
Instruction *FirstEntryInstruction(&*entry_block.getFirstNonPHIOrDbg());
15091509

15101510
if (!FirstEntryInstruction) {
15111511
m_error_stream.Printf("Internal error [IRForTarget]: Couldn't find the "

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,24 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
299299
/// Returns a pointer to the first instruction in this block that is not a
300300
/// PHINode or a debug intrinsic, or any pseudo operation if \c SkipPseudoOp
301301
/// is true.
302-
const Instruction *getFirstNonPHIOrDbg(bool SkipPseudoOp = true) const;
303-
Instruction *getFirstNonPHIOrDbg(bool SkipPseudoOp = true) {
304-
return const_cast<Instruction *>(
305-
static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbg(
306-
SkipPseudoOp));
302+
InstListType::const_iterator
303+
getFirstNonPHIOrDbg(bool SkipPseudoOp = true) const;
304+
InstListType::iterator getFirstNonPHIOrDbg(bool SkipPseudoOp = true) {
305+
return static_cast<const BasicBlock *>(this)
306+
->getFirstNonPHIOrDbg(SkipPseudoOp)
307+
.getNonConst();
307308
}
308309

309310
/// Returns a pointer to the first instruction in this block that is not a
310311
/// PHINode, a debug intrinsic, or a lifetime intrinsic, or any pseudo
311312
/// operation if \c SkipPseudoOp is true.
312-
const Instruction *
313+
InstListType::const_iterator
313314
getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp = true) const;
314-
Instruction *getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp = true) {
315-
return const_cast<Instruction *>(
316-
static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbgOrLifetime(
317-
SkipPseudoOp));
315+
InstListType::iterator
316+
getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp = true) {
317+
return static_cast<const BasicBlock *>(this)
318+
->getFirstNonPHIOrDbgOrLifetime(SkipPseudoOp)
319+
.getNonConst();
318320
}
319321

320322
/// Returns an iterator to the first instruction in this block that is

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
990990
isa<IndirectBrInst>(Pred->getTerminator())))
991991
return true;
992992

993-
if (BB->getTerminator() != BB->getFirstNonPHIOrDbg())
993+
if (BB->getTerminator() != &*BB->getFirstNonPHIOrDbg())
994994
return true;
995995

996996
// We use a simple cost heuristic which determine skipping merging is

llvm/lib/IR/BasicBlock.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,25 @@ BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const {
383383
return It;
384384
}
385385

386-
const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
386+
BasicBlock::const_iterator
387+
BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
387388
for (const Instruction &I : *this) {
388389
if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
389390
continue;
390391

391392
if (SkipPseudoOp && isa<PseudoProbeInst>(I))
392393
continue;
393394

394-
return &I;
395+
BasicBlock::const_iterator It = I.getIterator();
396+
// This position comes after any debug records, the head bit should remain
397+
// unset.
398+
assert(!It.getHeadBit());
399+
return It;
395400
}
396-
return nullptr;
401+
return end();
397402
}
398403

399-
const Instruction *
404+
BasicBlock::const_iterator
400405
BasicBlock::getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp) const {
401406
for (const Instruction &I : *this) {
402407
if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
@@ -408,9 +413,14 @@ BasicBlock::getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp) const {
408413
if (SkipPseudoOp && isa<PseudoProbeInst>(I))
409414
continue;
410415

411-
return &I;
416+
BasicBlock::const_iterator It = I.getIterator();
417+
// This position comes after any debug records, the head bit should remain
418+
// unset.
419+
assert(!It.getHeadBit());
420+
421+
return It;
412422
}
413-
return nullptr;
423+
return end();
414424
}
415425

416426
BasicBlock::const_iterator BasicBlock::getFirstInsertionPt() const {
@@ -428,11 +438,10 @@ BasicBlock::const_iterator BasicBlock::getFirstInsertionPt() const {
428438
}
429439

430440
BasicBlock::const_iterator BasicBlock::getFirstNonPHIOrDbgOrAlloca() const {
431-
const Instruction *FirstNonPHI = getFirstNonPHI();
432-
if (!FirstNonPHI)
441+
const_iterator InsertPt = getFirstNonPHIIt();
442+
if (InsertPt == end())
433443
return end();
434444

435-
const_iterator InsertPt = FirstNonPHI->getIterator();
436445
if (InsertPt->isEHPad())
437446
++InsertPt;
438447

@@ -448,6 +457,9 @@ BasicBlock::const_iterator BasicBlock::getFirstNonPHIOrDbgOrAlloca() const {
448457
++InsertPt;
449458
}
450459
}
460+
461+
// Signal that this comes after any debug records.
462+
InsertPt.setHeadBit(false);
451463
return InsertPt;
452464
}
453465

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ static std::optional<Instruction *> instCombineDMB(InstCombiner &IC,
21882188
NI = NI->getNextNonDebugInstruction();
21892189
if (!NI) {
21902190
if (auto *SuccBB = NIBB->getUniqueSuccessor())
2191-
NI = SuccBB->getFirstNonPHIOrDbgOrLifetime();
2191+
NI = &*SuccBB->getFirstNonPHIOrDbgOrLifetime();
21922192
else
21932193
break;
21942194
}

llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Value *SIAnnotateControlFlow::handleLoopCondition(
232232
} else if (L->contains(Inst)) {
233233
Insert = Term;
234234
} else {
235-
Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
235+
Insert = &*L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
236236
}
237237

238238
return CreateBreak(Insert);
@@ -247,7 +247,7 @@ Value *SIAnnotateControlFlow::handleLoopCondition(
247247
}
248248

249249
if (isa<Argument>(Cond)) {
250-
Instruction *Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
250+
Instruction *Insert = &*L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
251251
return CreateBreak(Insert);
252252
}
253253

llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool GenericToNVVM::runOnModule(Module &M) {
8686
if (F.isDeclaration()) {
8787
continue;
8888
}
89-
IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg());
89+
IRBuilder<> Builder(&*F.getEntryBlock().getFirstNonPHIOrDbg());
9090
for (BasicBlock &BB : F) {
9191
for (Instruction &II : BB) {
9292
for (unsigned i = 0, e = II.getNumOperands(); i < e; ++i) {

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,8 @@ static void eliminateSwiftErrorAlloca(Function &F, AllocaInst *Alloca,
16971697
static void eliminateSwiftErrorArgument(Function &F, Argument &Arg,
16981698
coro::Shape &Shape,
16991699
SmallVectorImpl<AllocaInst*> &AllocasToPromote) {
1700-
IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg());
1700+
IRBuilder<> Builder(&F.getEntryBlock(),
1701+
F.getEntryBlock().getFirstNonPHIOrDbg());
17011702

17021703
auto ArgTy = cast<PointerType>(Arg.getType());
17031704
auto ValueTy = PointerType::getUnqual(F.getContext());

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ static void replaceSwiftErrorOps(Function &F, coro::Shape &Shape,
597597
}
598598

599599
// Create a swifterror alloca.
600-
IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg());
600+
IRBuilder<> Builder(&F.getEntryBlock(),
601+
F.getEntryBlock().getFirstNonPHIOrDbg());
601602
auto Alloca = Builder.CreateAlloca(ValueTy);
602603
Alloca->setSwiftError(true);
603604

@@ -828,7 +829,7 @@ static void updateScopeLine(Instruction *ActiveSuspend,
828829
// instructions are not in the same BB.
829830
if (auto *Branch = dyn_cast_or_null<BranchInst>(Successor);
830831
Branch && Branch->isUnconditional())
831-
Successor = Branch->getSuccessor(0)->getFirstNonPHIOrDbg();
832+
Successor = &*Branch->getSuccessor(0)->getFirstNonPHIOrDbg();
832833

833834
// Find the first successor of ActiveSuspend with a non-zero line location.
834835
// If that matches the file of ActiveSuspend, use it.

llvm/lib/Transforms/IPO/IROutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Value *OutlinableRegion::findCorrespondingValueIn(const OutlinableRegion &Other,
197197
BasicBlock *
198198
OutlinableRegion::findCorrespondingBlockIn(const OutlinableRegion &Other,
199199
BasicBlock *BB) {
200-
Instruction *FirstNonPHI = BB->getFirstNonPHIOrDbg();
200+
Instruction *FirstNonPHI = &*BB->getFirstNonPHIOrDbg();
201201
assert(FirstNonPHI && "block is empty?");
202202
Value *CorrespondingVal = findCorrespondingValueIn(Other, FirstNonPHI);
203203
if (!CorrespondingVal)

llvm/lib/Transforms/IPO/SCCP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ static bool runIPSCCP(
235235
// nodes in executable blocks we found values for. The function's entry
236236
// block is not part of BlocksToErase, so we have to handle it separately.
237237
for (BasicBlock *BB : BlocksToErase) {
238-
NumInstRemoved += changeToUnreachable(BB->getFirstNonPHIOrDbg(),
238+
NumInstRemoved += changeToUnreachable(&*BB->getFirstNonPHIOrDbg(),
239239
/*PreserveLCSSA=*/false, &DTU);
240240
}
241241
if (!Solver.isBlockExecutable(&F.front()))
242-
NumInstRemoved += changeToUnreachable(F.front().getFirstNonPHIOrDbg(),
242+
NumInstRemoved += changeToUnreachable(&*F.front().getFirstNonPHIOrDbg(),
243243
/*PreserveLCSSA=*/false, &DTU);
244244

245245
BasicBlock *NewUnreachableBB = nullptr;

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
17471747
if (Weight != 0) {
17481748
if (Weight > MaxWeight) {
17491749
MaxWeight = Weight;
1750-
MaxDestInst = Succ->getFirstNonPHIOrDbgOrLifetime();
1750+
MaxDestInst = &*Succ->getFirstNonPHIOrDbgOrLifetime();
17511751
}
17521752
}
17531753
}

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ Instruction *InstCombinerImpl::visitAllocaInst(AllocaInst &AI) {
462462

463463
// Get the first instruction in the entry block.
464464
BasicBlock &EntryBlock = AI.getParent()->getParent()->getEntryBlock();
465-
Instruction *FirstInst = EntryBlock.getFirstNonPHIOrDbg();
466-
if (FirstInst != &AI) {
465+
BasicBlock::iterator FirstInst = EntryBlock.getFirstNonPHIOrDbg();
466+
if (&*FirstInst != &AI) {
467467
// If the entry block doesn't start with a zero-size alloca then move
468468
// this one to the start of the entry block. There is no problem with
469469
// dominance as the array size was forced to a constant earlier already.

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static void splitCallSite(CallBase &CB,
415415
// constant incoming values.
416416
static bool isPredicatedOnPHI(CallBase &CB) {
417417
BasicBlock *Parent = CB.getParent();
418-
if (&CB != Parent->getFirstNonPHIOrDbg())
418+
if (&CB != &*Parent->getFirstNonPHIOrDbg())
419419
return false;
420420

421421
for (auto &PN : Parent->phis()) {

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
770770
// instruction in the block.
771771
auto *TI = BBToCheck.getTerminator();
772772
bool isUnreachable = isa<UnreachableInst>(TI);
773-
return !isUnreachable || BBToCheck.getFirstNonPHIOrDbg() != TI;
773+
return !isUnreachable || &*BBToCheck.getFirstNonPHIOrDbg() != TI;
774774
};
775775

776776
SmallVector<int, 4> ExitCaseIndices;

llvm/lib/Transforms/Utils/CodeMoverUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ void llvm::moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB,
427427
DependenceInfo &DI) {
428428
for (Instruction &I :
429429
llvm::make_early_inc_range(llvm::drop_begin(llvm::reverse(FromBB)))) {
430-
Instruction *MovePos = ToBB.getFirstNonPHIOrDbg();
430+
BasicBlock::iterator MovePos = ToBB.getFirstNonPHIOrDbg();
431431

432432
if (isSafeToMoveBefore(I, *MovePos, DT, &PDT, &DI))
433433
I.moveBeforePreserving(MovePos);

llvm/lib/Transforms/Utils/IRNormalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void IRNormalizer::reorderInstructions(Function &F) const {
475475
Call->getIntrinsicID() == Intrinsic::experimental_convergence_loop)
476476
FirstNonPHIOrDbgOrAlloca++;
477477
}
478-
Instruction->moveBefore(&*FirstNonPHIOrDbgOrAlloca);
478+
Instruction->moveBefore(FirstNonPHIOrDbgOrAlloca);
479479
TopologicalSort.pop();
480480
}
481481
}

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6004,7 +6004,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
60046004
/// the phi node, and set PhiIndex to BB's index in the phi node.
60056005
static PHINode *findPHIForConditionForwarding(ConstantInt *CaseValue,
60066006
BasicBlock *BB, int *PhiIndex) {
6007-
if (BB->getFirstNonPHIOrDbg() != BB->getTerminator())
6007+
if (&*BB->getFirstNonPHIIt() != BB->getTerminator())
60086008
return nullptr; // BB must be empty to be a candidate for simplification.
60096009
if (!BB->getSinglePredecessor())
60106010
return nullptr; // BB must be dominated by the switch.
@@ -7885,7 +7885,7 @@ bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
78857885
Options.NeedCanonicalLoop &&
78867886
(!LoopHeaders.empty() && BB->hasNPredecessorsOrMore(2) &&
78877887
(is_contained(LoopHeaders, BB) || is_contained(LoopHeaders, Succ)));
7888-
BasicBlock::iterator I = BB->getFirstNonPHIOrDbg(true)->getIterator();
7888+
BasicBlock::iterator I = BB->getFirstNonPHIOrDbg();
78897889
if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() &&
78907890
!NeedCanonicalLoop && TryToSimplifyUncondBranchFromEmptyBlock(BB, DTU))
78917891
return true;

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,9 +4643,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithThreadLimit) {
46434643
dyn_cast<BranchInst>(PushNumTeamsCallInst->getNextNonDebugInstruction());
46444644
ASSERT_NE(BrInst, nullptr);
46454645
ASSERT_EQ(BrInst->getNumSuccessors(), 1U);
4646-
Instruction *NextInstruction =
4646+
BasicBlock::iterator NextInstruction =
46474647
BrInst->getSuccessor(0)->getFirstNonPHIOrDbgOrLifetime();
4648-
CallInst *ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
4648+
CallInst *ForkTeamsCI = nullptr;
4649+
if (NextInstruction != BrInst->getSuccessor(0)->end())
4650+
ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
46494651
ASSERT_NE(ForkTeamsCI, nullptr);
46504652
EXPECT_EQ(ForkTeamsCI->getCalledFunction(),
46514653
OMPBuilder.getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_fork_teams));
@@ -4698,9 +4700,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsUpper) {
46984700
dyn_cast<BranchInst>(PushNumTeamsCallInst->getNextNonDebugInstruction());
46994701
ASSERT_NE(BrInst, nullptr);
47004702
ASSERT_EQ(BrInst->getNumSuccessors(), 1U);
4701-
Instruction *NextInstruction =
4703+
BasicBlock::iterator NextInstruction =
47024704
BrInst->getSuccessor(0)->getFirstNonPHIOrDbgOrLifetime();
4703-
CallInst *ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
4705+
CallInst *ForkTeamsCI = nullptr;
4706+
if (NextInstruction != BrInst->getSuccessor(0)->end())
4707+
ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
47044708
ASSERT_NE(ForkTeamsCI, nullptr);
47054709
EXPECT_EQ(ForkTeamsCI->getCalledFunction(),
47064710
OMPBuilder.getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_fork_teams));
@@ -4756,9 +4760,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsBoth) {
47564760
dyn_cast<BranchInst>(PushNumTeamsCallInst->getNextNonDebugInstruction());
47574761
ASSERT_NE(BrInst, nullptr);
47584762
ASSERT_EQ(BrInst->getNumSuccessors(), 1U);
4759-
Instruction *NextInstruction =
4763+
BasicBlock::iterator NextInstruction =
47604764
BrInst->getSuccessor(0)->getFirstNonPHIOrDbgOrLifetime();
4761-
CallInst *ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
4765+
CallInst *ForkTeamsCI = nullptr;
4766+
if (NextInstruction != BrInst->getSuccessor(0)->end())
4767+
ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
47624768
ASSERT_NE(ForkTeamsCI, nullptr);
47634769
EXPECT_EQ(ForkTeamsCI->getCalledFunction(),
47644770
OMPBuilder.getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_fork_teams));
@@ -4820,9 +4826,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsAndThreadLimit) {
48204826
dyn_cast<BranchInst>(PushNumTeamsCallInst->getNextNonDebugInstruction());
48214827
ASSERT_NE(BrInst, nullptr);
48224828
ASSERT_EQ(BrInst->getNumSuccessors(), 1U);
4823-
Instruction *NextInstruction =
4829+
BasicBlock::iterator NextInstruction =
48244830
BrInst->getSuccessor(0)->getFirstNonPHIOrDbgOrLifetime();
4825-
CallInst *ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
4831+
CallInst *ForkTeamsCI = nullptr;
4832+
if (NextInstruction != BrInst->getSuccessor(0)->end())
4833+
ForkTeamsCI = dyn_cast_if_present<CallInst>(NextInstruction);
48264834
ASSERT_NE(ForkTeamsCI, nullptr);
48274835
EXPECT_EQ(ForkTeamsCI->getCalledFunction(),
48284836
OMPBuilder.getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_fork_teams));

0 commit comments

Comments
 (0)