r278898 - CodeGen: Avoid dereferencing end() in ScalarExprEmitter::EmitOverflowCheckedBinOp

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 16 20:15:29 PDT 2016


Author: dexonsmith
Date: Tue Aug 16 22:15:29 2016
New Revision: 278898

URL: http://llvm.org/viewvc/llvm-project?rev=278898&view=rev
Log:
CodeGen: Avoid dereferencing end() in ScalarExprEmitter::EmitOverflowCheckedBinOp

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.

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=278898&r1=278897&r2=278898&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Aug 16 22:15:29 2016
@@ -2371,9 +2371,8 @@ Value *ScalarExprEmitter::EmitOverflowCh
 
   // 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);




More information about the cfe-commits mailing list