diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-07-02 21:24:01 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-07-02 21:24:01 +0000 |
commit | c095997b853270d8adb6fe55209a4dbc42803d16 (patch) | |
tree | 998b434ab07cafbb018bf3c248bcf2476e5738a8 /lib/Analysis | |
parent | 8b23361a6a50be6dbd1056add570eb90598474b0 (diff) |
Refactored some of the BugReporter interface so that data such as the ASTContext&, PathDiagnosticClient*, can be provided by an external source.
Split BugReporter into BugReporter and GRBugReporter so checkers not based on GRExprEngine can still use the BugReporter mechanism.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53048 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/BugReporter.cpp | 23 | ||||
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 4 | ||||
-rw-r--r-- | lib/Analysis/DeadStores.cpp | 4 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 8 | ||||
-rw-r--r-- | lib/Analysis/GRSimpleVals.cpp | 20 |
5 files changed, 30 insertions, 29 deletions
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index 26dba4e7e8..1741e7dc9b 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -27,22 +27,20 @@ using namespace clang; BugReporter::~BugReporter() {} +GRBugReporter::~GRBugReporter() {} +BugReporterData::~BugReporterData() {} BugType::~BugType() {} BugReport::~BugReport() {} RangedBugReport::~RangedBugReport() {} -ExplodedGraph<ValueState>& BugReporter::getGraph() { +ExplodedGraph<ValueState>& GRBugReporter::getGraph() { return Eng.getGraph(); } -ValueStateManager& BugReporter::getStateManager() { +ValueStateManager& GRBugReporter::getStateManager() { return Eng.getStateManager(); } -ParentMap& BugReporter::getParentMap() { - return Eng.getParentMap(); -} - static inline Stmt* GetStmt(const ProgramPoint& P) { if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) { return PS->getStmt(); @@ -338,7 +336,7 @@ static void HandleNotableSymbol(ExplodedNode<ValueState>* N, Stmt* S, // specified symbol. Are any of them not in the previous state. ValueState* St = N->getState(); - ValueStateManager& VMgr = BR.getStateManager(); + ValueStateManager& VMgr = cast<GRBugReporter>(BR).getStateManager(); // FIXME: Later generalize for a broader memory model. @@ -411,8 +409,8 @@ static void HandleNotableSymbol(ExplodedNode<ValueState>* N, Stmt* S, } } -void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, - BugReport& R) { +void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, + BugReport& R) { ExplodedNode<ValueState>* N = R.getEndNode(); @@ -438,6 +436,7 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ExplodedNode<ValueState>* NextNode = N->pred_empty() ? NULL : *(N->pred_begin()); + ASTContext& Ctx = getContext(); SourceManager& SMgr = Ctx.getSourceManager(); while (NextNode) { @@ -715,6 +714,8 @@ void BugReporter::EmitWarning(BugReport& R) { // Emit a full diagnostic for the path if we have a PathDiagnosticClient. + PathDiagnosticClient* PD = getPathDiagnosticClient(); + if (PD && !D->empty()) { PD->HandlePathDiagnostic(D.take()); return; @@ -723,7 +724,7 @@ void BugReporter::EmitWarning(BugReport& R) { // We don't have a PathDiagnosticClient, but we can still emit a single // line diagnostic. Determine the location. - FullSourceLoc L = D->empty() ? R.getLocation(Ctx.getSourceManager()) + FullSourceLoc L = D->empty() ? R.getLocation(getSourceManager()) : D->back()->getLocation(); @@ -749,7 +750,6 @@ void BugReporter::EmitWarning(BugReport& R) { } else { std::ostringstream os; - os << "[CHECKER] "; if (D->empty()) os << R.getDescription(); @@ -757,6 +757,7 @@ void BugReporter::EmitWarning(BugReport& R) { os << D->back()->getString(); + Diagnostic& Diag = getDiagnostic(); unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning, os.str().c_str()); diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index b190ac20df..323181a302 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2202,7 +2202,7 @@ PathDiagnosticPiece* CFRefReport::VisitNode(ExplodedNode<ValueState>* N, // Add the range by scanning the children of the statement for any bindings // to Sym. - ValueStateManager& VSM = BR.getEngine().getStateManager(); + ValueStateManager& VSM = cast<GRBugReporter>(BR).getStateManager(); for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) if (Expr* Exp = dyn_cast_or_null<Expr>(*I)) { @@ -2266,7 +2266,7 @@ PathDiagnosticPiece* CFRefReport::getEndPath(BugReporter& BR, // Tell the BugReporter to report cases when the tracked symbol is // assigned to different variables, etc. - BR.addNotableSymbol(Sym); + cast<GRBugReporter>(BR).addNotableSymbol(Sym); if (!getBugType().isLeak()) return RangedBugReport::getEndPath(BR, EndN); diff --git a/lib/Analysis/DeadStores.cpp b/lib/Analysis/DeadStores.cpp index 265679ff7e..3097dc355d 100644 --- a/lib/Analysis/DeadStores.cpp +++ b/lib/Analysis/DeadStores.cpp @@ -242,8 +242,8 @@ public: DiagCollector C(*this); DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap()); - GRExprEngine& Eng = BR.getEngine(); - Eng.getLiveness().runOnAllBlocks(BR.getCFG(), &A); + + BR.getLiveVariables().runOnAllBlocks(BR.getCFG(), &A); // Emit the bug reports. diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index c9ab8097ba..0c9a1b6df5 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -108,21 +108,21 @@ struct VISIBILITY_HIDDEN SaveOr { }; -void GRExprEngine::EmitWarnings(Diagnostic& Diag, PathDiagnosticClient* PD) { +void GRExprEngine::EmitWarnings(BugReporterData& BRData) { for (bug_type_iterator I = bug_types_begin(), E = bug_types_end(); I!=E; ++I){ - BugReporter BR(Diag, PD, getContext(), *this); + GRBugReporter BR(BRData, *this); (*I)->EmitWarnings(BR); } for (SimpleChecksTy::iterator I = CallChecks.begin(), E = CallChecks.end(); I != E; ++I) { - BugReporter BR(Diag, PD, getContext(), *this); + GRBugReporter BR(BRData, *this); (*I)->EmitWarnings(BR); } for (SimpleChecksTy::iterator I=MsgExprChecks.begin(), E=MsgExprChecks.end(); I != E; ++I) { - BugReporter BR(Diag, PD, getContext(), *this); + GRBugReporter BR(BRData, *this); (*I)->EmitWarnings(BR); } } diff --git a/lib/Analysis/GRSimpleVals.cpp b/lib/Analysis/GRSimpleVals.cpp index c208f0c7b5..33657dadb1 100644 --- a/lib/Analysis/GRSimpleVals.cpp +++ b/lib/Analysis/GRSimpleVals.cpp @@ -66,7 +66,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.null_derefs_begin(), Eng.null_derefs_end()); } @@ -83,7 +83,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.undef_derefs_begin(), Eng.undef_derefs_end()); } @@ -113,7 +113,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.explicit_bad_divides_begin(), Eng.explicit_bad_divides_end()); } @@ -130,7 +130,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.undef_results_begin(), Eng.undef_results_end()); } @@ -147,7 +147,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.bad_calls_begin(), Eng.bad_calls_end()); } @@ -168,7 +168,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); for (GRExprEngine::UndefArgsTy::iterator I = Eng.undef_arg_begin(), E = Eng.undef_arg_end(); I!=E; ++I) { @@ -195,7 +195,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); for (GRExprEngine::UndefArgsTy::iterator I=Eng.msg_expr_undef_arg_begin(), E = Eng.msg_expr_undef_arg_end(); I!=E; ++I) { @@ -221,7 +221,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); for (GRExprEngine::UndefReceiversTy::iterator I=Eng.undef_receivers_begin(), End = Eng.undef_receivers_end(); I!=End; ++I) { @@ -252,7 +252,7 @@ public: } virtual void EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); GenericEmitWarnings(BR, *this, Eng.ret_stackaddr_begin(), Eng.ret_stackaddr_end()); } @@ -291,7 +291,7 @@ struct VISIBILITY_HIDDEN FindUndefExpr { void UndefBranch::EmitWarnings(BugReporter& BR) { - GRExprEngine& Eng = BR.getEngine(); + GRExprEngine& Eng = cast<GRBugReporter>(BR).getEngine(); for (GRExprEngine::undef_branch_iterator I=Eng.undef_branches_begin(), E=Eng.undef_branches_end(); I!=E; ++I) { |