Skip to content

Commit

Permalink
[analyzer] Removing references to CheckerContext::getNodeBuilder(): c…
Browse files Browse the repository at this point in the history
…heckers can obtain block count directly from the Context.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141112 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
AnnaZaks committed Oct 4, 2011
1 parent 118c6c0 commit 5d0ea6d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
Expand Up @@ -26,6 +26,9 @@ class StackFrameContext;

namespace ento {

/// \class BlockCounter
/// \brief An abstract data type used to count the number of times a given
/// block has been visited along a path analyzed by CoreEngine.
class BlockCounter {
void *Data;

Expand Down
Expand Up @@ -83,6 +83,10 @@ class CheckerContext {
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.
unsigned getCurrentBlockCount() {return B.getCurrentBlockCount();}

ASTContext &getASTContext() {
return Eng.getContext();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
Expand Up @@ -57,7 +57,7 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
// FIXME: Refactor into StoreManager itself?
MemRegionManager& RM = C.getStoreManager().getRegionManager();
const AllocaRegion* R =
RM.getAllocaRegion(CE, C.getNodeBuilder().getCurrentBlockCount(),
RM.getAllocaRegion(CE, C.getCurrentBlockCount(),
C.getPredecessor()->getLocationContext());

// Set the extent of the region in bytes. This enables us to use the
Expand Down
16 changes: 8 additions & 8 deletions lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Expand Up @@ -638,7 +638,7 @@ SVal CStringChecker::getCStringLengthForRegion(CheckerContext &C,
}

// Otherwise, get a new symbol and update the state.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SValBuilder &svalBuilder = C.getSValBuilder();
QualType sizeTy = svalBuilder.getContext().getSizeType();
SVal strLength = svalBuilder.getMetadataSymbolVal(CStringChecker::getTag(),
Expand Down Expand Up @@ -785,7 +785,7 @@ const ProgramState *CStringChecker::InvalidateBuffer(CheckerContext &C,
}

// Invalidate this region.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
return state->invalidateRegions(R, E, Count);
}

Expand Down Expand Up @@ -913,7 +913,7 @@ void CStringChecker::evalCopyCommon(CheckerContext &C,
} else {
// If we don't know how much we copied, we can at least
// conjure a return value for later.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SVal result =
C.getSValBuilder().getConjuredSymbolVal(NULL, CE, Count);
state = state->BindExpr(CE, result);
Expand Down Expand Up @@ -1028,7 +1028,7 @@ void CStringChecker::evalMemcmp(CheckerContext &C, const CallExpr *CE) const {
state = CheckBufferAccess(C, state, Size, Left, Right);
if (state) {
// The return value is the comparison result, which we don't know.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SVal CmpV = svalBuilder.getConjuredSymbolVal(NULL, CE, Count);
state = state->BindExpr(CE, CmpV);
C.addTransition(state);
Expand Down Expand Up @@ -1134,7 +1134,7 @@ void CStringChecker::evalstrLengthCommon(CheckerContext &C, const CallExpr *CE,
// no guarantee the full string length will actually be returned.
// All we know is the return value is the min of the string length
// and the limit. This is better than nothing.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
result = C.getSValBuilder().getConjuredSymbolVal(NULL, CE, Count);
NonLoc *resultNL = cast<NonLoc>(&result);

Expand Down Expand Up @@ -1162,7 +1162,7 @@ void CStringChecker::evalstrLengthCommon(CheckerContext &C, const CallExpr *CE,
// If we don't know the length of the string, conjure a return
// value, so it can be used in constraints, at least.
if (result.isUnknown()) {
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
result = C.getSValBuilder().getConjuredSymbolVal(NULL, CE, Count);
}
}
Expand Down Expand Up @@ -1506,7 +1506,7 @@ void CStringChecker::evalStrcpyCommon(CheckerContext &C, const CallExpr *CE,
// If this is a stpcpy-style copy, but we were unable to check for a buffer
// overflow, we still need a result. Conjure a return value.
if (returnEnd && Result.isUnknown()) {
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
Result = svalBuilder.getConjuredSymbolVal(NULL, CE, Count);
}

Expand Down Expand Up @@ -1650,7 +1650,7 @@ void CStringChecker::evalStrcmpCommon(CheckerContext &C, const CallExpr *CE,

if (!canComputeResult) {
// Conjure a symbolic value. It's the best we can do.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SVal resultVal = svalBuilder.getConjuredSymbolVal(NULL, CE, Count);
state = state->BindExpr(CE, resultVal);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Checkers/MallocChecker.cpp
Expand Up @@ -219,7 +219,7 @@ const ProgramState *MallocChecker::MallocMemAux(CheckerContext &C,
const CallExpr *CE,
SVal Size, SVal Init,
const ProgramState *state) {
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SValBuilder &svalBuilder = C.getSValBuilder();

// Set the return value.
Expand Down
4 changes: 2 additions & 2 deletions lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
Expand Up @@ -3020,7 +3020,7 @@ bool RetainCountChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
if (RetVal.isUnknown()) {
// If the receiver is unknown, conjure a return value.
SValBuilder &SVB = C.getSValBuilder();
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SVal RetVal = SVB.getConjuredSymbolVal(0, CE, ResultTy, Count);
}
state = state->BindExpr(CE, RetVal, false);
Expand All @@ -3035,7 +3035,7 @@ bool RetainCountChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
Binding = state->get<RefBindings>(Sym);

// Invalidate the argument region.
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
state = state->invalidateRegions(ArgRegion, CE, Count);

// Restore the refcount status of the argument.
Expand Down
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Checkers/StreamChecker.cpp
Expand Up @@ -222,7 +222,7 @@ void StreamChecker::Tmpfile(CheckerContext &C, const CallExpr *CE) const {

void StreamChecker::OpenFileAux(CheckerContext &C, const CallExpr *CE) const {
const ProgramState *state = C.getState();
unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
unsigned Count = C.getCurrentBlockCount();
SValBuilder &svalBuilder = C.getSValBuilder();
DefinedSVal RetVal =
cast<DefinedSVal>(svalBuilder.getConjuredSymbolVal(0, CE, Count));
Expand Down

0 comments on commit 5d0ea6d

Please sign in to comment.