From 23ccad006d494cc5b254576929d288f6cc1e0190 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 12 Jun 2015 21:05:32 +0000 Subject: [PATCH] [CGCall] Fix potential invalid iterator decrement in findDominatingStoreToReturnValue. 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239638 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 5d34e28892..6903073266 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -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(&*II)) { - if (CastAddr == &*II) { - continue; - } - } + if (II == IE) + break; + if (isa(&*II) && (CastAddr == &*II)) + continue; } } I = &*II; -- 2.50.1