aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Analysis/Lint.cpp13
-rw-r--r--test/Other/lint.ll4
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/Analysis/Lint.cpp b/lib/Analysis/Lint.cpp
index 751c41c..91929be 100644
--- a/lib/Analysis/Lint.cpp
+++ b/lib/Analysis/Lint.cpp
@@ -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();
}
diff --git a/test/Other/lint.ll b/test/Other/lint.ll
index ea02d43..bed3dba3 100644
--- a/test/Other/lint.ll
+++ b/test/Other/lint.ll
@@ -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: