[CGCall] Fix potential invalid iterator decrement in findDominatingStoreToReturnValue.
authorAlexey Samsonov <vonosmas@gmail.com>
Fri, 12 Jun 2015 21:05:32 +0000 (21:05 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Fri, 12 Jun 2015 21:05:32 +0000 (21:05 +0000)
If llvm.lifetime.end turns out to be the first instruction in the last
basic block, we can decrement the iterator twice, going past rend.
At the moment, this can never happen because llvm.lifetime.end always
goes immediately after bitcast, but relying on this is very brittle.

llvm-svn: 239638

clang/lib/CodeGen/CGCall.cpp

index 5d34e28..6903073 100644 (file)
@@ -2271,11 +2271,10 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
         if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
           const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
           ++II;
-          if (isa<llvm::BitCastInst>(&*II)) {
-            if (CastAddr == &*II) {
-              continue;
-            }
-          }
+          if (II == IE)
+            break;
+          if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
+            continue;
         }
       }
       I = &*II;