CodeGen: Avoid dereferencing end() in ScalarExprEmitter::EmitOverflowCheckedBinOp
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 17 Aug 2016 03:15:29 +0000 (03:15 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 17 Aug 2016 03:15:29 +0000 (03:15 +0000)
Use BB.getNextNode(), which returns nullptr on end(), instead of
&*BB.getIterator(), which is UB on end().
CodeGenFunction::createBasicBlock expects nullptr in this case already.

llvm-svn: 278898

clang/lib/CodeGen/CGExprScalar.cpp

index 700b537..ba7f49b 100644 (file)
@@ -2371,9 +2371,8 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
 
   // Branch in case of overflow.
   llvm::BasicBlock *initialBB = Builder.GetInsertBlock();
-  llvm::Function::iterator insertPt = initialBB->getIterator();
-  llvm::BasicBlock *continueBB = CGF.createBasicBlock("nooverflow", CGF.CurFn,
-                                                      &*std::next(insertPt));
+  llvm::BasicBlock *continueBB =
+      CGF.createBasicBlock("nooverflow", CGF.CurFn, initialBB->getNextNode());
   llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow", CGF.CurFn);
 
   Builder.CreateCondBr(overflow, overflowBB, continueBB);