Hi clang,
I fixed upper issues, and here is the new patch.
2011/5/4 Ted Kremenek <[email protected]>
> One other thing I noticed in the patch:
>
> (const Decl* D, AnalysisManager &mgr, ...)
>
> why use a generic Decl*? Since it is always going to be a
> TranslationUnitDecl*, we should pass the most specific type.
>
> On May 3, 2011, at 10:50 AM, Argyrios Kyrtzidis wrote:
>
> > A more appropriate name is checkEndOfTranslationUnit (a checker can
> already check the TranslationUnitDecl with checkASTDecl which is called at
> the beginning).
> >
> > So please change runCheckersOnTranslationUnit ->
> runCheckersOnEndOfTranslationUnit and likewise for the rest of the patch
> ("class TranslationUnit" -> "class EndOfTranslationUnit", etc.).
> >
> > Otherwise looks good!
> >
> > On May 2, 2011, at 8:33 PM, 章磊 wrote:
> >
> >> Hi Clang,
> >>
> >> This patch add a new check position checkTranslationUnit for a check
> after all the decls in the translation unit analyzed, then we can do some
> statistical analysis in this check position.
> >>
> >> This patch is preparation for statistical UncheckedRenturn checker.
> >> I'll appreciate it if there are any advice about this patch.
> >>
> >> --
> >> Best regards!
> >>
> >> Lei Zhang
> >>
> <checkTranslationUnit.patch>_______________________________________________
> >> cfe-commits mailing list
> >> [email protected]
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > [email protected]
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
--
Best regards!
Lei Zhang
Index: include/clang/StaticAnalyzer/Core/CheckerManager.h
===================================================================
--- include/clang/StaticAnalyzer/Core/CheckerManager.h (revision 130748)
+++ include/clang/StaticAnalyzer/Core/CheckerManager.h (working copy)
@@ -252,6 +252,11 @@
const ExplodedNodeSet &Src,
const CallExpr *CE, ExprEngine &Eng,
GraphExpander *defaultEval = 0);
+
+ /// \brief Run checkers for the entire Translation Unit.
+ void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl* TU,
+ AnalysisManager &mgr,
+ BugReporter &BR);
//===----------------------------------------------------------------------===//
// Internal registration functions for AST traversing.
@@ -312,6 +317,10 @@
typedef CheckerFn<bool (const CallExpr *, CheckerContext &)>
EvalCallFunc;
+ typedef CheckerFn<void (const TranslationUnitDecl *,
+ AnalysisManager&, BugReporter &)>
+ CheckEndOfTranslationUnit;
+
typedef bool (*HandlesStmtFunc)(const Stmt *D);
void _registerForPreStmt(CheckStmtFunc checkfn,
HandlesStmtFunc isForStmtFn);
@@ -342,6 +351,8 @@
void _registerForEvalCall(EvalCallFunc checkfn);
+ void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn);
+
//===----------------------------------------------------------------------===//
// Internal registration functions for events.
//===----------------------------------------------------------------------===//
@@ -462,6 +473,8 @@
std::vector<EvalCallFunc> EvalCallCheckers;
+ std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
+
struct EventInfo {
llvm::SmallVector<CheckEventFunc, 4> Checkers;
bool HasDispatcher;
Index: include/clang/StaticAnalyzer/Core/Checker.h
===================================================================
--- include/clang/StaticAnalyzer/Core/Checker.h (revision 130748)
+++ include/clang/StaticAnalyzer/Core/Checker.h (working copy)
@@ -63,6 +63,24 @@
}
};
+class EndOfTranslationUnit {
+ template <typename CHECKER>
+ static void _checkEndOfTranslationUnit(void *checker,
+ const TranslationUnitDecl *TU,
+ AnalysisManager& mgr,
+ BugReporter &BR) {
+ ((const CHECKER *)checker)->checkEndOfTranslationUnit(TU, mgr, BR);
+ }
+
+public:
+ template <typename CHECKER>
+ static void _register(CHECKER *checker, CheckerManager &mgr){
+ mgr._registerForEndOfTranslationUnit(
+ CheckerManager::CheckEndOfTranslationUnit(checker,
+ _checkEndOfTranslationUnit<CHECKER>));
+ }
+};
+
template <typename STMT>
class PreStmt {
template <typename CHECKER>
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (revision 130748)
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (working copy)
@@ -232,6 +232,9 @@
checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
HandleDeclContext(C, TU);
+ // After all decls handled, run checkers on the entire TranslationUnit.
+ checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
+
// Explicitly destroy the PathDiagnosticClient. This will flush its output.
// FIXME: This should be replaced with something that doesn't rely on
// side-effects in PathDiagnosticClient's destructor. This is required when
Index: lib/StaticAnalyzer/Core/CheckerManager.cpp
===================================================================
--- lib/StaticAnalyzer/Core/CheckerManager.cpp (revision 130748)
+++ lib/StaticAnalyzer/Core/CheckerManager.cpp (working copy)
@@ -416,6 +416,15 @@
}
}
+/// \brief Run checkers for the entire Translation Unit.
+void CheckerManager::runCheckersOnEndOfTranslationUnit(
+ const TranslationUnitDecl *TU,
+ AnalysisManager &mgr,
+ BugReporter &BR) {
+ for (unsigned i = 0, e = EndOfTranslationUnitCheckers.size(); i != e; ++i)
+ EndOfTranslationUnitCheckers[i](TU, mgr, BR);
+}
+
//===----------------------------------------------------------------------===//
// Internal registration functions for AST traversing.
//===----------------------------------------------------------------------===//
@@ -495,6 +504,11 @@
EvalCallCheckers.push_back(checkfn);
}
+void CheckerManager::_registerForEndOfTranslationUnit(
+ CheckEndOfTranslationUnit checkfn) {
+ EndOfTranslationUnitCheckers.push_back(checkfn);
+}
+
//===----------------------------------------------------------------------===//
// Implementation details.
//===----------------------------------------------------------------------===//
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits