diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-08 16:31:42 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-08 16:31:42 +0000 |
commit | eb90adffe11072f0378cb3251747086a27ddf4d2 (patch) | |
tree | b91b8a899aba23c3ffa74b66088308de546d5218 | |
parent | 7c18922f85582816537a6c722e11589cd9692381 (diff) | |
download | external_llvm-eb90adffe11072f0378cb3251747086a27ddf4d2.zip external_llvm-eb90adffe11072f0378cb3251747086a27ddf4d2.tar.gz external_llvm-eb90adffe11072f0378cb3251747086a27ddf4d2.tar.bz2 |
BoundsChecking: add support for ConstantPointerNull. fixes a bunch of instrumentation failures in loops with reallocs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158210 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/BoundsChecking.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/BoundsChecking.cpp b/lib/Transforms/Scalar/BoundsChecking.cpp index a81ddfa..d10d97c 100644 --- a/lib/Transforms/Scalar/BoundsChecking.cpp +++ b/lib/Transforms/Scalar/BoundsChecking.cpp @@ -377,11 +377,13 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset, } RETURN(true); - // TODO: handle more standard functions: + // TODO: handle more standard functions (+ wchar cousins): // - strdup / strndup // - strcpy / strncpy + // - strcat / strncat // - memcpy / memmove // - strcat / strncat + // - memset } else if (PHINode *PHI = dyn_cast<PHINode>(Ptr)) { // create 2 PHIs: one for offset and another for size @@ -389,8 +391,7 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset, PHINode *SizePHI = Builder->CreatePHI(IntTy, PHI->getNumIncomingValues()); // insert right away in the cache to handle recursive PHIs - CacheData CacheEntry(APInt(), OffsetPHI, APInt(), SizePHI, true); - CacheMap[Ptr] = CacheEntry; + CacheMap[Ptr] = CacheData(APInt(), OffsetPHI, APInt(), SizePHI, true); // compute offset/size for each PHI incoming pointer for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) { @@ -419,7 +420,7 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset, SizeValue = SizePHI; RETURN(true); - } else if (isa<UndefValue>(Ptr)) { + } else if (isa<UndefValue>(Ptr) || isa<ConstantPointerNull>(Ptr)) { Size = 0; RETURN(true); @@ -428,12 +429,12 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset, RETURN(false); } + DEBUG(dbgs() << "computeAllocSize unhandled value:\n" << *Ptr << "\n"); RETURN(false); cache_and_return: // cache the result and return - CacheData CacheEntry(Offset, OffsetValue, Size, SizeValue, ReturnVal); - CacheMap[Ptr] = CacheEntry; + CacheMap[Ptr] = CacheData(Offset, OffsetValue, Size, SizeValue, ReturnVal); // non-computable results can be safely cached if (!ReturnVal) |