forked from OSchip/llvm-project
Fix lint's memcpy and memmove checks, and its basic block traversal.
llvm-svn: 104970
This commit is contained in:
parent
37eb2c24b9
commit
c575ec61ea
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue