aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/EscapeAnalysis.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-10-12 08:10:46 +0000
committerOwen Anderson <resistor@mac.com>2008-10-12 08:10:46 +0000
commit9d9d6baf02a91b842a3a7204bc5303423a005b28 (patch)
treed580d6785a13154ab39360d29f4ea3b08cce2800 /lib/Analysis/EscapeAnalysis.cpp
parent3f2f6faff5d7cdd7d037f15e4020e5e3ef3d8984 (diff)
downloadexternal_llvm-9d9d6baf02a91b842a3a7204bc5303423a005b28.zip
external_llvm-9d9d6baf02a91b842a3a7204bc5303423a005b28.tar.gz
external_llvm-9d9d6baf02a91b842a3a7204bc5303423a005b28.tar.bz2
Add special-case code to allow null-guards on calls to malloc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57413 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/EscapeAnalysis.cpp')
-rw-r--r--lib/Analysis/EscapeAnalysis.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Analysis/EscapeAnalysis.cpp b/lib/Analysis/EscapeAnalysis.cpp
index 43bad29..94e953d 100644
--- a/lib/Analysis/EscapeAnalysis.cpp
+++ b/lib/Analysis/EscapeAnalysis.cpp
@@ -13,6 +13,7 @@
#define DEBUG_TYPE "escape-analysis"
#include "llvm/Analysis/EscapeAnalysis.h"
+#include "llvm/Constants.h"
#include "llvm/Module.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -112,8 +113,21 @@ bool EscapeAnalysis::escapes(Value* A) {
worklist.pop_back();
if (Instruction* I = dyn_cast<Instruction>(curr))
- if (EscapePoints.count(I))
- return true;
+ if (EscapePoints.count(I)) {
+ BranchInst* B = dyn_cast<BranchInst>(I);
+ if (!B) return true;
+ Value* condition = B->getCondition();
+ ICmpInst* C = dyn_cast<ICmpInst>(condition);
+ if (!C) return true;
+ Value* O1 = C->getOperand(0);
+ Value* O2 = C->getOperand(1);
+ if (isa<MallocInst>(O1->stripPointerCasts())) {
+ if (!isa<ConstantPointerNull>(O2)) return true;
+ } else if(isa<MallocInst>(O2->stripPointerCasts())) {
+ if (!isa<ConstantPointerNull>(O1)) return true;
+ } else
+ return true;
+ }
if (StoreInst* S = dyn_cast<StoreInst>(curr)) {
// We know this must be an instruction, because constant gep's would