Refactor 'PostStmt' and 'PreStmt' to subclass a common parent 'StmtPoint'.
Educate GRExprEngine::VisitGraph() about 'PreStmt'.
Mark the constructor of 'PostStmt' to be explicit, preventing implicit
conversions and the selection of the wrong 'generateNode' method in
GRStmtNodeBuilder.
Constify a bunch of arguments, which falls out of the changes to ProgramPoint.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76809 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp
index 8bbf94c..7620377 100644
--- a/lib/Analysis/BasicObjCFoundationChecks.cpp
+++ b/lib/Analysis/BasicObjCFoundationChecks.cpp
@@ -63,10 +63,10 @@
ASTContext &Ctx;
bool isNSString(const ObjCInterfaceType *T, const char* suffix);
- bool AuditNSString(NodeTy* N, ObjCMessageExpr* ME);
+ bool AuditNSString(NodeTy* N, const ObjCMessageExpr* ME);
- void Warn(NodeTy* N, Expr* E, const std::string& s);
- void WarnNilArg(NodeTy* N, Expr* E);
+ void Warn(NodeTy* N, const Expr* E, const std::string& s);
+ void WarnNilArg(NodeTy* N, const Expr* E);
bool CheckNilArg(NodeTy* N, unsigned Arg);
@@ -77,7 +77,7 @@
bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
private:
- void WarnNilArg(NodeTy* N, ObjCMessageExpr* ME, unsigned Arg) {
+ void WarnNilArg(NodeTy* N, const ObjCMessageExpr* ME, unsigned Arg) {
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
os << "Argument to '" << GetReceiverNameType(ME) << "' method '"
@@ -106,7 +106,7 @@
bool BasicObjCFoundationChecks::Audit(ExplodedNode<GRState>* N,
GRStateManager&) {
- ObjCMessageExpr* ME =
+ const ObjCMessageExpr* ME =
cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
const ObjCInterfaceType *ReceiverType = GetReceiverType(ME);
@@ -140,10 +140,10 @@
//===----------------------------------------------------------------------===//
bool BasicObjCFoundationChecks::CheckNilArg(NodeTy* N, unsigned Arg) {
- ObjCMessageExpr* ME =
+ const ObjCMessageExpr* ME =
cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
- Expr * E = ME->getArg(Arg);
+ const Expr * E = ME->getArg(Arg);
if (isNil(N->getState()->getSVal(E))) {
WarnNilArg(N, ME, Arg);
@@ -163,7 +163,7 @@
}
bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N,
- ObjCMessageExpr* ME) {
+ const ObjCMessageExpr* ME) {
Selector S = ME->getSelector();
@@ -257,7 +257,7 @@
bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
private:
- void AddError(const TypedRegion* R, Expr* Ex, ExplodedNode<GRState> *N,
+ void AddError(const TypedRegion* R, const Expr* Ex, ExplodedNode<GRState> *N,
uint64_t SourceSize, uint64_t TargetSize, uint64_t NumberKind);
};
} // end anonymous namespace
@@ -356,8 +356,9 @@
#endif
bool AuditCFNumberCreate::Audit(ExplodedNode<GRState>* N,GRStateManager&){
- CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
- Expr* Callee = CE->getCallee();
+ const CallExpr* CE =
+ cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
+ const Expr* Callee = CE->getCallee();
SVal CallV = N->getState()->getSVal(Callee);
const FunctionDecl* FD = CallV.getAsFunctionDecl();
@@ -423,7 +424,7 @@
return SourceSize < TargetSize;
}
-void AuditCFNumberCreate::AddError(const TypedRegion* R, Expr* Ex,
+void AuditCFNumberCreate::AddError(const TypedRegion* R, const Expr* Ex,
ExplodedNode<GRState> *N,
uint64_t SourceSize, uint64_t TargetSize,
uint64_t NumberKind) {
@@ -486,7 +487,7 @@
bool AuditCFRetainRelease::Audit(ExplodedNode<GRState>* N, GRStateManager&) {
- CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
+ const CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
// If the CallExpr doesn't have exactly 1 argument just give up checking.
if (CE->getNumArgs() != 1)
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index a691bb6..43e1e6c 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -40,7 +40,7 @@
// Helper routines for walking the ExplodedGraph and fetching statements.
//===----------------------------------------------------------------------===//
-static inline Stmt* GetStmt(ProgramPoint P) {
+static inline const Stmt* GetStmt(ProgramPoint P) {
if (const PostStmt* PS = dyn_cast<PostStmt>(&P))
return PS->getStmt();
else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P))
@@ -59,17 +59,17 @@
return N->succ_empty() ? NULL : *(N->succ_begin());
}
-static Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
for (N = GetPredecessorNode(N); N; N = GetPredecessorNode(N))
- if (Stmt *S = GetStmt(N->getLocation()))
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return 0;
}
-static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
for (N = GetSuccessorNode(N); N; N = GetSuccessorNode(N))
- if (Stmt *S = GetStmt(N->getLocation())) {
+ if (const Stmt *S = GetStmt(N->getLocation())) {
// Check if the statement is '?' or '&&'/'||'. These are "merges",
// not actual statement points.
switch (S->getStmtClass()) {
@@ -90,15 +90,17 @@
return 0;
}
-static inline Stmt* GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return GetPreviousStmt(N);
}
-static inline Stmt* GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return GetNextStmt(N);
@@ -179,7 +181,7 @@
PathDiagnosticLocation
PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetNextStmt(N))
+ if (const Stmt *S = GetNextStmt(N))
return PathDiagnosticLocation(S, getSourceManager());
return FullSourceLoc(getCodeDecl().getBodyRBrace(), getSourceManager());
@@ -330,7 +332,7 @@
if (!isa<PostStmt>(P))
continue;
- DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
+ const DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
if (!DR)
continue;
@@ -340,7 +342,7 @@
if (X != Y)
continue;
- VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+ const VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
if (!VD)
continue;
@@ -457,13 +459,13 @@
llvm::SmallSet<SymbolRef, 10> AlreadyProcessed;
const ExplodedNode<GRState>* N;
- Stmt* S;
+ const Stmt* S;
GRBugReporter& BR;
PathDiagnostic& PD;
public:
- ScanNotableSymbols(const ExplodedNode<GRState>* n, Stmt* s, GRBugReporter& br,
- PathDiagnostic& pd)
+ ScanNotableSymbols(const ExplodedNode<GRState>* n, const Stmt* s,
+ GRBugReporter& br, PathDiagnostic& pd)
: N(n), S(s), BR(br), PD(pd) {}
bool HandleBinding(StoreManager& SMgr, Store store,
@@ -523,7 +525,7 @@
case Stmt::GotoStmtClass:
case Stmt::IndirectGotoStmtClass: {
- Stmt* S = GetNextStmt(N);
+ const Stmt* S = GetNextStmt(N);
if (!S)
continue;
@@ -1199,14 +1201,15 @@
BugReport::~BugReport() {}
RangedBugReport::~RangedBugReport() {}
-Stmt* BugReport::getStmt(BugReporter& BR) const {
+const Stmt* BugReport::getStmt(BugReporter& BR) const {
ProgramPoint ProgP = EndNode->getLocation();
- Stmt *S = NULL;
+ const Stmt *S = NULL;
if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) {
if (BE->getBlock() == &BR.getCFG()->getExit()) S = GetPreviousStmt(EndNode);
}
- if (!S) S = GetStmt(ProgP);
+ if (!S)
+ S = GetStmt(ProgP);
return S;
}
@@ -1215,7 +1218,7 @@
BugReport::getEndPath(BugReporterContext& BRC,
const ExplodedNode<GRState>* EndPathNode) {
- Stmt* S = getStmt(BRC.getBugReporter());
+ const Stmt* S = getStmt(BRC.getBugReporter());
if (!S)
return NULL;
@@ -1238,7 +1241,7 @@
void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
const SourceRange*& end) {
- if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+ if (const Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
R = E->getSourceRange();
assert(R.isValid());
beg = &R;
@@ -1250,9 +1253,9 @@
SourceLocation BugReport::getLocation() const {
if (EndNode)
- if (Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
+ if (const Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
// For member expressions, return the location of the '.' or '->'.
- if (MemberExpr* ME = dyn_cast<MemberExpr>(S))
+ if (const MemberExpr* ME = dyn_cast<MemberExpr>(S))
return ME->getMemberLoc();
return S->getLocStart();
diff --git a/lib/Analysis/BugReporterVisitors.cpp b/lib/Analysis/BugReporterVisitors.cpp
index 7096f66..2efa4c6 100644
--- a/lib/Analysis/BugReporterVisitors.cpp
+++ b/lib/Analysis/BugReporterVisitors.cpp
@@ -200,7 +200,7 @@
}
// FIXME: Refactor this into BugReporterContext.
- Stmt *S = 0;
+ const Stmt *S = 0;
ProgramPoint P = N->getLocation();
if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
@@ -266,7 +266,7 @@
return NULL;
// FIXME: Refactor this into BugReporterContext.
- Stmt *S = 0;
+ const Stmt *S = 0;
ProgramPoint P = N->getLocation();
if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index 908211a..04f9cb8 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -2298,9 +2298,9 @@
// This is the allocation site since the previous node had no bindings
// for this symbol.
if (!PrevT) {
- Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
- if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
+ if (const CallExpr *CE = dyn_cast<CallExpr>(S)) {
// Get the name of the callee (if it is available).
SVal X = CurrSt->getSValAsScalarOrLoc(CE->getCallee());
if (const FunctionDecl* FD = X.getAsFunctionDecl())
@@ -2347,14 +2347,14 @@
TF.getSummaryOfNode(BRC.getNodeResolver().getOriginalNode(N))) {
// We only have summaries attached to nodes after evaluating CallExpr and
// ObjCMessageExprs.
- Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
- if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
+ if (const CallExpr *CE = dyn_cast<CallExpr>(S)) {
// Iterate through the parameter expressions and see if the symbol
// was ever passed as an argument.
unsigned i = 0;
- for (CallExpr::arg_iterator AI=CE->arg_begin(), AE=CE->arg_end();
+ for (CallExpr::const_arg_iterator AI=CE->arg_begin(), AE=CE->arg_end();
AI!=AE; ++AI, ++i) {
// Retrieve the value of the argument. Is it the symbol
@@ -2366,8 +2366,8 @@
AEffects.push_back(Summ->getArg(i));
}
}
- else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S)) {
- if (Expr *receiver = ME->getReceiver())
+ else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S)) {
+ if (const Expr *receiver = ME->getReceiver())
if (CurrSt->getSValAsScalarOrLoc(receiver).getAsLocSymbol() == Sym) {
// The symbol we are tracking is the receiver.
AEffects.push_back(Summ->getReceiverEffect());
@@ -2395,7 +2395,7 @@
// Specially handle CFMakeCollectable and friends.
if (contains(AEffects, MakeCollectable)) {
// Get the name of the function.
- Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
SVal X = CurrSt->getSValAsScalarOrLoc(cast<CallExpr>(S)->getCallee());
const FunctionDecl* FD = X.getAsFunctionDecl();
const std::string& FName = FD->getNameAsString();
@@ -2499,14 +2499,15 @@
if (os.str().empty())
return 0; // We have nothing to say!
- Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
PathDiagnosticLocation Pos(S, BRC.getSourceManager());
PathDiagnosticPiece* P = new PathDiagnosticEventPiece(Pos, os.str());
// Add the range by scanning the children of the statement for any bindings
// to Sym.
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Expr* Exp = dyn_cast_or_null<Expr>(*I))
+ for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
+ I!=E; ++I)
+ if (const Expr* Exp = dyn_cast_or_null<Expr>(*I))
if (CurrSt->getSValAsScalarOrLoc(Exp).getAsLocSymbol() == Sym) {
P->addRange(Exp->getSourceRange());
break;
@@ -2602,7 +2603,7 @@
// Get the allocate site.
assert(AllocNode);
- Stmt* FirstStmt = cast<PostStmt>(AllocNode->getLocation()).getStmt();
+ const Stmt* FirstStmt = cast<PostStmt>(AllocNode->getLocation()).getStmt();
SourceManager& SMgr = BRC.getSourceManager();
unsigned AllocLine =SMgr.getInstantiationLineNumber(FirstStmt->getLocStart());
diff --git a/lib/Analysis/GRCoreEngine.cpp b/lib/Analysis/GRCoreEngine.cpp
index 5a45ad2..5a92143 100644
--- a/lib/Analysis/GRCoreEngine.cpp
+++ b/lib/Analysis/GRCoreEngine.cpp
@@ -390,7 +390,7 @@
Eng.WList->Enqueue(Succ, B, Idx+1);
}
-static inline PostStmt GetPostLoc(Stmt* S, ProgramPoint::Kind K,
+static inline PostStmt GetPostLoc(const Stmt* S, ProgramPoint::Kind K,
const void *tag) {
switch (K) {
default:
@@ -426,7 +426,7 @@
}
ExplodedNodeImpl*
-GRStmtNodeBuilderImpl::generateNodeImpl(Stmt* S, const void* State,
+GRStmtNodeBuilderImpl::generateNodeImpl(const Stmt* S, const void* State,
ExplodedNodeImpl* Pred,
ProgramPoint::Kind K,
const void *tag) {
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 24e4cfa..eb31f84 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -89,7 +89,7 @@
isSink |= (*I)->Audit(N, VMgr);
// Next handle the auditors that accept only specific statements.
- Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
void* key = reinterpret_cast<void*>((uintptr_t) S->getStmtClass());
MapTy::iterator MI = M.find(key);
if (MI != M.end()) {
@@ -3096,9 +3096,8 @@
break;
default: {
- if (isa<PostStmt>(Loc)) {
- const PostStmt& L = cast<PostStmt>(Loc);
- Stmt* S = L.getStmt();
+ if (StmtPoint *L = dyn_cast<StmtPoint>(&Loc)) {
+ const Stmt* S = L->getStmt();
SourceLocation SLoc = S->getLocStart();
Out << S->getStmtClassName() << ' ' << (void*) S << ' ';
@@ -3113,7 +3112,9 @@
<< "\\l";
}
- if (isa<PostLoad>(Loc))
+ if (isa<PreStmt>(Loc))
+ Out << "\\lPreStmt\\l;";
+ else if (isa<PostLoad>(Loc))
Out << "\\lPostLoad\\l;";
else if (isa<PostStore>(Loc))
Out << "\\lPostStore\\l";
diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp
index c84b6c0..91fb6a8 100644
--- a/lib/Analysis/GRExprEngineInternalChecks.cpp
+++ b/lib/Analysis/GRExprEngineInternalChecks.cpp
@@ -120,7 +120,7 @@
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
PostStmt P = cast<PostStmt>((*I)->getLocation());
- ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
+ const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
os << "The receiver in the message expression is 'nil' and results in the"
" returned value (of type '"
<< ME->getType().getAsString()
@@ -153,7 +153,7 @@
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
PostStmt P = cast<PostStmt>((*I)->getLocation());
- ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
+ const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
os << "The receiver in the message expression is 'nil' and results in the"
" returned value (of type '"
<< ME->getType().getAsString()
@@ -305,8 +305,8 @@
// Generate a report for this bug.
BuiltinBugReport *report = new BuiltinBugReport(*this, desc.c_str(), *I);
ExplodedNode<GRState>* N = *I;
- Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
- Expr* E = cast<ObjCMessageExpr>(S)->getReceiver();
+ const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Expr* E = cast<ObjCMessageExpr>(S)->getReceiver();
assert (E && "Receiver cannot be NULL");
report->addRange(E->getSourceRange());
BR.EmitReport(report);
@@ -330,9 +330,9 @@
End = Eng.ret_stackaddr_end(); I!=End; ++I) {
ExplodedNode<GRState>* N = *I;
- Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
- Expr* E = cast<ReturnStmt>(S)->getRetValue();
- assert (E && "Return expression cannot be NULL");
+ const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
+ const Expr* E = cast<ReturnStmt>(S)->getRetValue();
+ assert(E && "Return expression cannot be NULL");
// Get the value associated with E.
loc::MemRegionVal V = cast<loc::MemRegionVal>(N->getState()->getSVal(E));
@@ -493,7 +493,7 @@
// undefined size.
GRExprEngine::NodeTy* N = *I;
PostStmt PS = cast<PostStmt>(N->getLocation());
- DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
+ const DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
VarDecl* VD = cast<VarDecl>(*DS->decl_begin());
QualType T = Eng.getContext().getCanonicalType(VD->getType());
VariableArrayType* VT = cast<VariableArrayType>(T);
diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp
index b849bea..5728aae 100644
--- a/lib/Analysis/GRState.cpp
+++ b/lib/Analysis/GRState.cpp
@@ -324,7 +324,7 @@
// Queries.
//===----------------------------------------------------------------------===//
-bool GRStateManager::isEqual(const GRState* state, Expr* Ex,
+bool GRStateManager::isEqual(const GRState* state, const Expr* Ex,
const llvm::APSInt& Y) {
SVal V = state->getSVal(Ex);
@@ -341,7 +341,7 @@
return false;
}
-bool GRStateManager::isEqual(const GRState* state, Expr* Ex, uint64_t x) {
+bool GRStateManager::isEqual(const GRState* state, const Expr* Ex, uint64_t x) {
return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType()));
}