mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 23:31:37 +00:00
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
This commit is contained in:
parent
7c18922f85
commit
eb90adffe1
@ -377,11 +377,13 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset,
|
|||||||
}
|
}
|
||||||
RETURN(true);
|
RETURN(true);
|
||||||
|
|
||||||
// TODO: handle more standard functions:
|
// TODO: handle more standard functions (+ wchar cousins):
|
||||||
// - strdup / strndup
|
// - strdup / strndup
|
||||||
// - strcpy / strncpy
|
// - strcpy / strncpy
|
||||||
|
// - strcat / strncat
|
||||||
// - memcpy / memmove
|
// - memcpy / memmove
|
||||||
// - strcat / strncat
|
// - strcat / strncat
|
||||||
|
// - memset
|
||||||
|
|
||||||
} else if (PHINode *PHI = dyn_cast<PHINode>(Ptr)) {
|
} else if (PHINode *PHI = dyn_cast<PHINode>(Ptr)) {
|
||||||
// create 2 PHIs: one for offset and another for size
|
// 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());
|
PHINode *SizePHI = Builder->CreatePHI(IntTy, PHI->getNumIncomingValues());
|
||||||
|
|
||||||
// insert right away in the cache to handle recursive PHIs
|
// insert right away in the cache to handle recursive PHIs
|
||||||
CacheData CacheEntry(APInt(), OffsetPHI, APInt(), SizePHI, true);
|
CacheMap[Ptr] = CacheData(APInt(), OffsetPHI, APInt(), SizePHI, true);
|
||||||
CacheMap[Ptr] = CacheEntry;
|
|
||||||
|
|
||||||
// compute offset/size for each PHI incoming pointer
|
// compute offset/size for each PHI incoming pointer
|
||||||
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
||||||
@ -419,7 +420,7 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset,
|
|||||||
SizeValue = SizePHI;
|
SizeValue = SizePHI;
|
||||||
RETURN(true);
|
RETURN(true);
|
||||||
|
|
||||||
} else if (isa<UndefValue>(Ptr)) {
|
} else if (isa<UndefValue>(Ptr) || isa<ConstantPointerNull>(Ptr)) {
|
||||||
Size = 0;
|
Size = 0;
|
||||||
RETURN(true);
|
RETURN(true);
|
||||||
|
|
||||||
@ -428,12 +429,12 @@ bool BoundsChecking::computeAllocSize(Value *Ptr, APInt &Offset,
|
|||||||
RETURN(false);
|
RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEBUG(dbgs() << "computeAllocSize unhandled value:\n" << *Ptr << "\n");
|
||||||
RETURN(false);
|
RETURN(false);
|
||||||
|
|
||||||
cache_and_return:
|
cache_and_return:
|
||||||
// cache the result and return
|
// cache the result and return
|
||||||
CacheData CacheEntry(Offset, OffsetValue, Size, SizeValue, ReturnVal);
|
CacheMap[Ptr] = CacheData(Offset, OffsetValue, Size, SizeValue, ReturnVal);
|
||||||
CacheMap[Ptr] = CacheEntry;
|
|
||||||
|
|
||||||
// non-computable results can be safely cached
|
// non-computable results can be safely cached
|
||||||
if (!ReturnVal)
|
if (!ReturnVal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user