diff --git a/gen/ms-cxx-helper.cpp b/gen/ms-cxx-helper.cpp index 54dbbb92e6..2060a01755 100644 --- a/gen/ms-cxx-helper.cpp +++ b/gen/ms-cxx-helper.cpp @@ -36,10 +36,18 @@ void findSuccessors(std::vector &blocks, llvm::BasicBlock *bb, llvm::BasicBlock *ebb) { blocks.push_back(bb); if (bb != ebb) { +#if LLVM_VERSION_MAJOR >= 23 + assert(bb->getTerminatorOrNull()); +#else assert(bb->getTerminator()); +#endif for (size_t pos = 0; pos < blocks.size(); ++pos) { bb = blocks[pos]; +#if LLVM_VERSION_MAJOR >= 23 + if (auto term = bb->getTerminatorOrNull()) { +#else if (auto term = bb->getTerminator()) { +#endif llvm::BasicBlock *unwindDest = getUnwindDest(term); unsigned cnt = term->getNumSuccessors(); for (unsigned s = 0; s < cnt; s++) { @@ -84,10 +92,16 @@ void cloneBlocks(const std::vector &srcblocks, llvm::Value *funclet) { llvm::ValueToValueMapTy VMap; // map the terminal branch to the new target - if (continueWith) - if (auto term = srcblocks.back()->getTerminator()) - if (auto succ = term->getSuccessor(0)) - VMap[succ] = continueWith; + if (continueWith) { +#if LLVM_VERSION_MAJOR >= 23 + auto term = srcblocks.back()->getTerminatorOrNull(); +#else + auto term = srcblocks.back()->getTerminator(); +#endif + if (term) + if (auto succ = term->getSuccessor(0)) + VMap[succ] = continueWith; + } for (auto bb : srcblocks) { llvm::Function *F = bb->getParent(); diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 871ae3c962..33611579e6 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -611,7 +611,11 @@ static bool mayBeUsedAfterRealloc(Instruction *Def, BasicBlock::iterator Alloc, // All instructions after the starting point in this block have been // accounted for. Look for successors to add to the work list. +#if LLVM_VERSION_MAJOR >= 23 + auto *Term = B->getTerminatorOrNull(); +#else auto *Term = B->getTerminator(); +#endif unsigned SuccCount = Term->getNumSuccessors(); for (unsigned i = 0; i < SuccCount; i++) { BasicBlock *Succ = Term->getSuccessor(i); diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp index c498449cfb..c3e3664860 100644 --- a/gen/trycatchfinally.cpp +++ b/gen/trycatchfinally.cpp @@ -374,7 +374,11 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock, // And convert the BranchInst to the existing branch target to a // SelectInst so we can append the other cases to it. +#if LLVM_VERSION_MAJOR >= 23 + endBlock()->getTerminatorOrNull()->eraseFromParent(); +#else endBlock()->getTerminator()->eraseFromParent(); +#endif llvm::Value *sel = new llvm::LoadInst(branchSelectorType, branchSelector, "", endBlock()); llvm::SwitchInst::Create( @@ -405,7 +409,11 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock, // We don't know this branch target yet, so add it to the SwitchInst... llvm::ConstantInt *const selectorVal = DtoConstUint(exitTargets.size()); +#if LLVM_VERSION_MAJOR >= 23 + llvm::cast(endBlock()->getTerminatorOrNull()) +#else llvm::cast(endBlock()->getTerminator()) +#endif ->addCase(selectorVal, continueWith); // ... insert the store into the source block... @@ -428,7 +436,11 @@ llvm::BasicBlock *CleanupScope::runCopying(IRState &irs, if (isCatchSwitchBlock(beginBlock())) return continueWith; if (exitTargets.empty()) { +#if LLVM_VERSION_MAJOR >= 23 + if (!endBlock()->getTerminatorOrNull()) +#else if (!endBlock()->getTerminator()) +#endif // Set up the unconditional branch at the end of the cleanup createBranch(continueWith, endBlock()); @@ -459,7 +471,11 @@ llvm::BasicBlock *CleanupScope::runCopying(IRState &irs, // change the continuation target if the initial branch was created // by another instance with unwinding if (continueWith) +#if LLVM_VERSION_MAJOR >= 23 + if (auto term = endBlock()->getTerminatorOrNull()) +#else if (auto term = endBlock()->getTerminator()) +#endif if (auto succ = term->getSuccessor(0)) if (succ != continueWith) remapBlocksValue(blocks, succ, continueWith);