Skip to content

Commit

Permalink
[analyzer] Remove the dependency on CheckerContext::getStmt() as well…
Browse files Browse the repository at this point in the history
… as the method itself.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141262 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
AnnaZaks committed Oct 6, 2011
1 parent d1ab1a2 commit 390909c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 29 deletions.
10 changes: 6 additions & 4 deletions include/clang/StaticAnalyzer/Core/Checker.h
Expand Up @@ -152,9 +152,10 @@ class PostObjCMessage {

class Location {
template <typename CHECKER>
static void _checkLocation(void *checker, const SVal &location, bool isLoad,
static void _checkLocation(void *checker,
const SVal &location, bool isLoad, const Stmt *S,
CheckerContext &C) {
((const CHECKER *)checker)->checkLocation(location, isLoad, C);
((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
}

public:
Expand All @@ -167,9 +168,10 @@ class Location {

class Bind {
template <typename CHECKER>
static void _checkBind(void *checker, const SVal &location, const SVal &val,
static void _checkBind(void *checker,
const SVal &location, const SVal &val, const Stmt *S,
CheckerContext &C) {
((const CHECKER *)checker)->checkBind(location, val, C);
((const CHECKER *)checker)->checkBind(location, val, S, C);
}

public:
Expand Down
8 changes: 5 additions & 3 deletions include/clang/StaticAnalyzer/Core/CheckerManager.h
Expand Up @@ -320,11 +320,13 @@ class CheckerManager {
typedef CheckerFn<void (const ObjCMessage &, CheckerContext &)>
CheckObjCMessageFunc;

typedef CheckerFn<void (const SVal &location, bool isLoad, CheckerContext &)>
typedef CheckerFn<void (const SVal &location, bool isLoad, const Stmt *S,
CheckerContext &)>
CheckLocationFunc;

typedef CheckerFn<void (const SVal &location, const SVal &val,
CheckerContext &)> CheckBindFunc;
typedef CheckerFn<void (const SVal &location, const SVal &val,
const Stmt *S, CheckerContext &)>
CheckBindFunc;

typedef CheckerFn<void (ExplodedGraph &, BugReporter &, ExprEngine &)>
CheckEndAnalysisFunc;
Expand Down
Expand Up @@ -80,7 +80,6 @@ class CheckerContext {
ExplodedNodeSet &getNodeSet() { return Dst; }
ExplodedNode *&getPredecessor() { return Pred; }
const ProgramState *getState() { return ST ? ST : Pred->getState(); }
const Stmt *getStmt() const { return statement; }

/// \brief Returns the number of times the current block has been visited
/// along the analyzed path.
Expand Down
7 changes: 4 additions & 3 deletions lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
Expand Up @@ -27,11 +27,12 @@ class ArrayBoundChecker :
public Checker<check::Location> {
mutable llvm::OwningPtr<BuiltinBug> BT;
public:
void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
void checkLocation(SVal l, bool isLoad, const Stmt* S,
CheckerContext &C) const;
};
}

void ArrayBoundChecker::checkLocation(SVal l, bool isLoad,
void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS,
CheckerContext &C) const {
// Check for out of bound array element access.
const MemRegion *R = l.getAsRegion();
Expand Down Expand Up @@ -76,7 +77,7 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad,
BugReport *report =
new BugReport(*BT, BT->getDescription(), N);

report->addRange(C.getStmt()->getSourceRange());
report->addRange(LoadS->getSourceRange());
C.EmitReport(report);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
Expand Up @@ -34,7 +34,8 @@ class ArrayBoundCheckerV2 :
OOB_Kind kind) const;

public:
void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
void checkLocation(SVal l, bool isLoad, const Stmt*S,
CheckerContext &C) const;
};

// FIXME: Eventually replace RegionRawOffset with this class.
Expand Down Expand Up @@ -79,6 +80,7 @@ static SVal computeExtentBegin(SValBuilder &svalBuilder,
}

void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
const Stmt* LoadS,
CheckerContext &checkerContext) const {

// NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
Expand Down
8 changes: 4 additions & 4 deletions lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
Expand Up @@ -29,7 +29,8 @@ class DereferenceChecker
mutable llvm::OwningPtr<BuiltinBug> BT_undef;

public:
void checkLocation(SVal location, bool isLoad, CheckerContext &C) const;
void checkLocation(SVal location, bool isLoad, const Stmt* S,
CheckerContext &C) const;

static void AddDerefSource(raw_ostream &os,
SmallVectorImpl<SourceRange> &Ranges,
Expand All @@ -38,7 +39,7 @@ class DereferenceChecker
} // end anonymous namespace

void DereferenceChecker::AddDerefSource(raw_ostream &os,
SmallVectorImpl<SourceRange> &Ranges,
SmallVectorImpl<SourceRange> &Ranges,
const Expr *Ex,
bool loadedFrom) {
Ex = Ex->IgnoreParenLValueCasts();
Expand All @@ -65,7 +66,7 @@ void DereferenceChecker::AddDerefSource(raw_ostream &os,
}
}

void DereferenceChecker::checkLocation(SVal l, bool isLoad,
void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S,
CheckerContext &C) const {
// Check for dereference of an undefined value.
if (l.isUndef()) {
Expand All @@ -88,7 +89,6 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad,
if (!isa<Loc>(location))
return;

const Stmt *S = C.getStmt();
const ProgramState *state = C.getState();
const ProgramState *notNullState, *nullState;
llvm::tie(notNullState, nullState) = state->assume(location);
Expand Down
14 changes: 9 additions & 5 deletions lib/StaticAnalyzer/Checkers/MallocChecker.cpp
Expand Up @@ -82,8 +82,10 @@ class MallocChecker : public Checker<eval::Call, check::DeadSymbols, check::EndP
void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
const ProgramState *evalAssume(const ProgramState *state, SVal Cond,
bool Assumption) const;
void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
void checkBind(SVal location, SVal val, CheckerContext &C) const;
void checkLocation(SVal l, bool isLoad, const Stmt *S,
CheckerContext &C) const;
void checkBind(SVal location, SVal val, const Stmt*S,
CheckerContext &C) const;

private:
static void MallocMem(CheckerContext &C, const CallExpr *CE);
Expand Down Expand Up @@ -661,7 +663,8 @@ const ProgramState *MallocChecker::evalAssume(const ProgramState *state, SVal Co
}

// Check if the location is a freed symbolic region.
void MallocChecker::checkLocation(SVal l, bool isLoad,CheckerContext &C) const {
void MallocChecker::checkLocation(SVal l, bool isLoad, const Stmt *S,
CheckerContext &C) const {
SymbolRef Sym = l.getLocSymbolInBase();
if (Sym) {
const RefState *RS = C.getState()->get<RegionState>(Sym);
Expand All @@ -679,7 +682,8 @@ void MallocChecker::checkLocation(SVal l, bool isLoad,CheckerContext &C) const {
}
}

void MallocChecker::checkBind(SVal location, SVal val,CheckerContext &C) const {
void MallocChecker::checkBind(SVal location, SVal val,
const Stmt *BindS, CheckerContext &C) const {
// The PreVisitBind implements the same algorithm as already used by the
// Objective C ownership checker: if the pointer escaped from this scope by
// assignment, let it go. However, assigning to fields of a stack-storage
Expand Down Expand Up @@ -728,7 +732,7 @@ void MallocChecker::checkBind(SVal location, SVal val,CheckerContext &C) const {
// We no longer own this pointer.
notNullState =
notNullState->set<RegionState>(Sym,
RefState::getRelinquished(C.getStmt()));
RefState::getRelinquished(BindS));
}
while (false);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
Expand Up @@ -157,7 +157,8 @@ class NSOrCFErrorDerefChecker
NSOrCFErrorDerefChecker() : NSErrorII(0), CFErrorII(0),
ShouldCheckNSError(0), ShouldCheckCFError(0) { }

void checkLocation(SVal loc, bool isLoad, CheckerContext &C) const;
void checkLocation(SVal loc, bool isLoad, const Stmt *S,
CheckerContext &C) const;
void checkEvent(ImplicitNullDerefEvent event) const;
};
}
Expand Down Expand Up @@ -211,6 +212,7 @@ static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
}

void NSOrCFErrorDerefChecker::checkLocation(SVal loc, bool isLoad,
const Stmt *S,
CheckerContext &C) const {
if (!isLoad)
return;
Expand Down
4 changes: 3 additions & 1 deletion lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
Expand Up @@ -77,7 +77,8 @@ class ObjCSelfInitChecker : public Checker<
void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
void checkLocation(SVal location, bool isLoad, CheckerContext &C) const;
void checkLocation(SVal location, bool isLoad, const Stmt *S,
CheckerContext &C) const;
};
} // end anonymous namespace

Expand Down Expand Up @@ -295,6 +296,7 @@ void ObjCSelfInitChecker::checkPostStmt(const CallExpr *CE,
}

void ObjCSelfInitChecker::checkLocation(SVal location, bool isLoad,
const Stmt *S,
CheckerContext &C) const {
// Tag the result of a load from 'self' so that we can easily know that the
// value is the object that 'self' points to.
Expand Down
4 changes: 2 additions & 2 deletions lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
Expand Up @@ -2409,7 +2409,7 @@ class RetainCountChecker
void printState(raw_ostream &Out, const ProgramState *State,
const char *NL, const char *Sep) const;

void checkBind(SVal loc, SVal val, CheckerContext &C) const;
void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const;
void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const;
void checkPostStmt(const CastExpr *CE, CheckerContext &C) const;

Expand Down Expand Up @@ -3225,7 +3225,7 @@ void RetainCountChecker::checkReturnWithRetEffect(const ReturnStmt *S,
// Check various ways a symbol can be invalidated.
//===----------------------------------------------------------------------===//

void RetainCountChecker::checkBind(SVal loc, SVal val,
void RetainCountChecker::checkBind(SVal loc, SVal val, const Stmt *S,
CheckerContext &C) const {
// Are we storing to something that causes the value to "escape"?
bool escapes = true;
Expand Down
5 changes: 3 additions & 2 deletions lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
Expand Up @@ -27,11 +27,13 @@ class UndefinedAssignmentChecker
mutable llvm::OwningPtr<BugType> BT;

public:
void checkBind(SVal location, SVal val, CheckerContext &C) const;
void checkBind(SVal location, SVal val, const Stmt *S,
CheckerContext &C) const;
};
}

void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
const Stmt *StoreE,
CheckerContext &C) const {
if (!val.isUndef())
return;
Expand All @@ -49,7 +51,6 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
// Generate a report for this bug.
const Expr *ex = 0;

const Stmt *StoreE = C.getStmt();
while (StoreE) {
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
if (B->isCompoundAssignmentOp()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/StaticAnalyzer/Core/CheckerManager.cpp
Expand Up @@ -219,7 +219,7 @@ namespace {
CheckerContext C(Dst, Eng.getBuilder(), Eng, Pred, checkFn.Checker,
IsLoad ? ProgramPoint::PreLoadKind :
ProgramPoint::PreStoreKind, 0, S);
checkFn(Loc, IsLoad, C);
checkFn(Loc, IsLoad, S, C);
}
};
}
Expand Down Expand Up @@ -253,7 +253,7 @@ namespace {
ExplodedNodeSet &Dst, ExplodedNode *Pred) {
CheckerContext C(Dst, Eng.getBuilder(), Eng, Pred, checkFn.Checker,
ProgramPoint::PreStmtKind, 0, S);
checkFn(Loc, Val, C);
checkFn(Loc, Val, S, C);
}
};
}
Expand Down

0 comments on commit 390909c

Please sign in to comment.