Fix lint's memcpy and memmove checks, and its basic block traversal.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104970 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-05-28 17:44:00 +00:00
parent 5caeff5c01
commit 13ec30b6a1
2 changed files with 12 additions and 5 deletions

View File

@ -248,9 +248,9 @@ void Lint::visitCallSite(CallSite CS) {
case Intrinsic::memcpy: {
MemCpyInst *MCI = cast<MemCpyInst>(&I);
visitMemoryReference(I, MCI->getSource(), MCI->getAlignment(), 0,
MemRef::Write);
visitMemoryReference(I, MCI->getDest(), MCI->getAlignment(), 0,
MemRef::Write);
visitMemoryReference(I, MCI->getSource(), MCI->getAlignment(), 0,
MemRef::Read);
// Check that the memcpy arguments don't overlap. The AliasAnalysis API
@ -269,9 +269,9 @@ void Lint::visitCallSite(CallSite CS) {
}
case Intrinsic::memmove: {
MemMoveInst *MMI = cast<MemMoveInst>(&I);
visitMemoryReference(I, MMI->getSource(), MMI->getAlignment(), 0,
MemRef::Write);
visitMemoryReference(I, MMI->getDest(), MMI->getAlignment(), 0,
MemRef::Write);
visitMemoryReference(I, MMI->getSource(), MMI->getAlignment(), 0,
MemRef::Read);
break;
}
@ -519,11 +519,14 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
if (LoadInst *L = dyn_cast<LoadInst>(V)) {
BasicBlock::iterator BBI = L;
BasicBlock *BB = L->getParent();
SmallPtrSet<BasicBlock *, 4> VisitedBlocks;
for (;;) {
if (!VisitedBlocks.insert(BB)) break;
if (Value *U = FindAvailableLoadedValue(L->getPointerOperand(),
BB, BBI, 6, AA))
return findValueImpl(U, OffsetOk, Visited);
BB = L->getParent()->getUniquePredecessor();
if (BBI != BB->begin()) break;
BB = BB->getUniquePredecessor();
if (!BB) break;
BBI = BB->end();
}

View File

@ -3,6 +3,7 @@ target datalayout = "e-p:64:64:64"
declare fastcc void @bar()
declare void @llvm.stackrestore(i8*)
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
@CG = constant i32 7
@ -54,6 +55,9 @@ define i32 @foo() noreturn {
; CHECK: Undefined behavior: Null pointer dereference
call void @llvm.stackrestore(i8* null)
; CHECK: Write to read-only memory
call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i32 1, i1 0)
br label %next
next: