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

llvm-svn: 104970
This commit is contained in:
Dan Gohman 2010-05-28 17:44:00 +00:00
parent 37eb2c24b9
commit c575ec61ea
2 changed files with 12 additions and 5 deletions

View File

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

View File

@ -3,6 +3,7 @@ target datalayout = "e-p:64:64:64"
declare fastcc void @bar() declare fastcc void @bar()
declare void @llvm.stackrestore(i8*) declare void @llvm.stackrestore(i8*)
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
@CG = constant i32 7 @CG = constant i32 7
@ -54,6 +55,9 @@ define i32 @foo() noreturn {
; CHECK: Undefined behavior: Null pointer dereference ; CHECK: Undefined behavior: Null pointer dereference
call void @llvm.stackrestore(i8* null) 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 br label %next
next: next: