Skip to content

Commit 79976be

Browse files
authored
use getTerminatorOrNull for Windows EH with LLVM23 (#5121)
1 parent 44f8481 commit 79976be

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

gen/ms-cxx-helper.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ void findSuccessors(std::vector<llvm::BasicBlock *> &blocks,
3636
llvm::BasicBlock *bb, llvm::BasicBlock *ebb) {
3737
blocks.push_back(bb);
3838
if (bb != ebb) {
39+
#if LLVM_VERSION_MAJOR >= 23
40+
assert(bb->getTerminatorOrNull());
41+
#else
3942
assert(bb->getTerminator());
43+
#endif
4044
for (size_t pos = 0; pos < blocks.size(); ++pos) {
4145
bb = blocks[pos];
46+
#if LLVM_VERSION_MAJOR >= 23
47+
if (auto term = bb->getTerminatorOrNull()) {
48+
#else
4249
if (auto term = bb->getTerminator()) {
50+
#endif
4351
llvm::BasicBlock *unwindDest = getUnwindDest(term);
4452
unsigned cnt = term->getNumSuccessors();
4553
for (unsigned s = 0; s < cnt; s++) {
@@ -84,10 +92,16 @@ void cloneBlocks(const std::vector<llvm::BasicBlock *> &srcblocks,
8492
llvm::Value *funclet) {
8593
llvm::ValueToValueMapTy VMap;
8694
// map the terminal branch to the new target
87-
if (continueWith)
88-
if (auto term = srcblocks.back()->getTerminator())
89-
if (auto succ = term->getSuccessor(0))
90-
VMap[succ] = continueWith;
95+
if (continueWith) {
96+
#if LLVM_VERSION_MAJOR >= 23
97+
auto term = srcblocks.back()->getTerminatorOrNull();
98+
#else
99+
auto term = srcblocks.back()->getTerminator();
100+
#endif
101+
if (term)
102+
if (auto succ = term->getSuccessor(0))
103+
VMap[succ] = continueWith;
104+
}
91105

92106
for (auto bb : srcblocks) {
93107
llvm::Function *F = bb->getParent();

gen/passes/GarbageCollect2Stack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ static bool mayBeUsedAfterRealloc(Instruction *Def, BasicBlock::iterator Alloc,
611611

612612
// All instructions after the starting point in this block have been
613613
// accounted for. Look for successors to add to the work list.
614+
#if LLVM_VERSION_MAJOR >= 23
615+
auto *Term = B->getTerminatorOrNull();
616+
#else
614617
auto *Term = B->getTerminator();
618+
#endif
615619
unsigned SuccCount = Term->getNumSuccessors();
616620
for (unsigned i = 0; i < SuccCount; i++) {
617621
BasicBlock *Succ = Term->getSuccessor(i);

gen/trycatchfinally.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
374374

375375
// And convert the BranchInst to the existing branch target to a
376376
// SelectInst so we can append the other cases to it.
377+
#if LLVM_VERSION_MAJOR >= 23
378+
endBlock()->getTerminatorOrNull()->eraseFromParent();
379+
#else
377380
endBlock()->getTerminator()->eraseFromParent();
381+
#endif
378382
llvm::Value *sel =
379383
new llvm::LoadInst(branchSelectorType, branchSelector, "", endBlock());
380384
llvm::SwitchInst::Create(
@@ -405,7 +409,11 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
405409

406410
// We don't know this branch target yet, so add it to the SwitchInst...
407411
llvm::ConstantInt *const selectorVal = DtoConstUint(exitTargets.size());
412+
#if LLVM_VERSION_MAJOR >= 23
413+
llvm::cast<llvm::SwitchInst>(endBlock()->getTerminatorOrNull())
414+
#else
408415
llvm::cast<llvm::SwitchInst>(endBlock()->getTerminator())
416+
#endif
409417
->addCase(selectorVal, continueWith);
410418

411419
// ... insert the store into the source block...
@@ -428,7 +436,11 @@ llvm::BasicBlock *CleanupScope::runCopying(IRState &irs,
428436
if (isCatchSwitchBlock(beginBlock()))
429437
return continueWith;
430438
if (exitTargets.empty()) {
439+
#if LLVM_VERSION_MAJOR >= 23
440+
if (!endBlock()->getTerminatorOrNull())
441+
#else
431442
if (!endBlock()->getTerminator())
443+
#endif
432444
// Set up the unconditional branch at the end of the cleanup
433445
createBranch(continueWith, endBlock());
434446

@@ -459,7 +471,11 @@ llvm::BasicBlock *CleanupScope::runCopying(IRState &irs,
459471
// change the continuation target if the initial branch was created
460472
// by another instance with unwinding
461473
if (continueWith)
474+
#if LLVM_VERSION_MAJOR >= 23
475+
if (auto term = endBlock()->getTerminatorOrNull())
476+
#else
462477
if (auto term = endBlock()->getTerminator())
478+
#endif
463479
if (auto succ = term->getSuccessor(0))
464480
if (succ != continueWith)
465481
remapBlocksValue(blocks, succ, continueWith);

0 commit comments

Comments
 (0)