@@ -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