@@ -213,7 +213,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
213213 // redirect scope to avoid the generation of debug info before the
214214 // catchpad
215215 const auto savedInsertPoint = irs.saveInsertPoint ();
216- irs.ir ->SetInsertPoint (gIR -> topallocapoint ());
216+ irs.ir ->SetInsertPoint (irs. nextAllocaPos ());
217217 DtoVarDeclaration (var);
218218
219219 // catch handler will be outlined, so always treat as a nested reference
@@ -332,6 +332,20 @@ CleanupScope::CleanupScope(llvm::BasicBlock *beginBlock,
332332 blocks.push_back (endBlock);
333333}
334334
335+ namespace {
336+ #if LDC_LLVM_VER >= 1900
337+ llvm::BasicBlock::iterator getTerminatorPos (llvm::BasicBlock *bb) {
338+ auto it = bb->rbegin ().getReverse ();
339+ assert (it->isTerminator ());
340+ return it;
341+ }
342+ #else
343+ llvm::Instruction *getTerminatorPos (llvm::BasicBlock *bb) {
344+ return bb->getTerminator ();
345+ }
346+ #endif
347+ } // anonymous namespace
348+
335349llvm::BasicBlock *CleanupScope::run (IRState &irs, llvm::BasicBlock *sourceBlock,
336350 llvm::BasicBlock *continueWith) {
337351 if (useMSVCEH ())
@@ -359,12 +373,13 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
359373 branchSelector = new llvm::AllocaInst (
360374 branchSelectorType, irs.module .getDataLayout ().getAllocaAddrSpace (),
361375 llvm::Twine (" branchsel." ) + beginBlock ()->getName (),
362- irs.topallocapoint ());
376+ irs.nextAllocaPos ());
363377
364378 // Now we also need to store 0 to it to keep the paths that go to the
365379 // only existing branch target the same.
366380 for (auto bb : exitTargets.front ().sourceBlocks ) {
367- new llvm::StoreInst (DtoConstUint (0 ), branchSelector, bb->getTerminator ());
381+ new llvm::StoreInst (DtoConstUint (0 ), branchSelector,
382+ getTerminatorPos (bb));
368383 }
369384
370385 // And convert the BranchInst to the existing branch target to a
@@ -385,7 +400,7 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
385400 CleanupExitTarget &t = exitTargets[i];
386401 if (t.branchTarget == continueWith) {
387402 new llvm::StoreInst (DtoConstUint (i), branchSelector,
388- sourceBlock-> getTerminator ( ));
403+ getTerminatorPos (sourceBlock ));
389404
390405 // Note: Strictly speaking, keeping this up to date would not be
391406 // needed right now, because we never to any optimizations that
@@ -405,7 +420,7 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
405420
406421 // ... insert the store into the source block...
407422 new llvm::StoreInst (selectorVal, branchSelector,
408- sourceBlock-> getTerminator ( ));
423+ getTerminatorPos (sourceBlock ));
409424
410425 // ... and keep track of it (again, this is unnecessary right now as
411426 // discussed in the above note).
0 commit comments