diff --git a/clang/Driver/ASTConsumers.cpp b/clang/Driver/ASTConsumers.cpp index 727c57ab41b9..77cc99640a80 100644 --- a/clang/Driver/ASTConsumers.cpp +++ b/clang/Driver/ASTConsumers.cpp @@ -643,12 +643,13 @@ protected: bool Visualize; bool TrimGraph; llvm::OwningPtr PD; + bool AnalyzeAll; public: CheckerConsumer(Diagnostic &diags, const std::string& fname, const std::string& htmldir, - bool visualize, bool trim) + bool visualize, bool trim, bool analyzeAll) : CFGVisitor(fname), Diags(diags), HTMLDir(htmldir), - Visualize(visualize), TrimGraph(trim) {} + Visualize(visualize), TrimGraph(trim), AnalyzeAll(analyzeAll) {} virtual void Initialize(ASTContext &Context) { Ctx = &Context; } virtual void VisitCFG(CFG& C, Decl&); @@ -666,8 +667,10 @@ void CheckerConsumer::VisitCFG(CFG& C, Decl& CD) { SourceLocation Loc = CD.getLocation(); - if (!Loc.isFileID() || - Loc.getFileID() != Ctx->getSourceManager().getMainFileID()) + if (!Loc.isFileID()) + return; + + if (!AnalyzeAll && Loc.getFileID() != Ctx->getSourceManager().getMainFileID()) return; // Lazily create the diagnostic client. @@ -721,8 +724,8 @@ class GRSimpleValsVisitor : public CheckerConsumer { public: GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname, const std::string& htmldir, - bool visualize, bool trim) - : CheckerConsumer(diags, fname, htmldir, visualize, trim) {} + bool visualize, bool trim, bool analyzeAll) + : CheckerConsumer(diags, fname, htmldir, visualize, trim, analyzeAll) {} virtual const char* getCheckerName() { return "GRSimpleVals"; } @@ -735,10 +738,11 @@ public: ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags, const std::string& FunctionName, const std::string& HTMLDir, - bool Visualize, bool TrimGraph) { + bool Visualize, bool TrimGraph, + bool AnalyzeAll) { return new GRSimpleValsVisitor(Diags, FunctionName, HTMLDir, - Visualize, TrimGraph); + Visualize, TrimGraph, AnalyzeAll); } @@ -750,8 +754,8 @@ class CFRefCountCheckerVisitor : public CheckerConsumer { public: CFRefCountCheckerVisitor(Diagnostic &diags, const std::string& fname, const std::string& htmldir, - bool visualize, bool trim) - : CheckerConsumer(diags, fname, htmldir, visualize, trim) {} + bool visualize, bool trim, bool analyzeAll) + : CheckerConsumer(diags, fname, htmldir, visualize, trim, analyzeAll) {} virtual const char* getCheckerName() { return "CFRefCountChecker"; } @@ -764,10 +768,11 @@ public: ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags, const std::string& FunctionName, const std::string& HTMLDir, - bool Visualize, bool TrimGraph) { + bool Visualize, bool TrimGraph, + bool AnalyzeAll) { return new CFRefCountCheckerVisitor(Diags, FunctionName, HTMLDir, - Visualize, TrimGraph); + Visualize, TrimGraph, AnalyzeAll); } //===----------------------------------------------------------------------===// diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 0c0cf5807664..98164d40e6cd 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -44,13 +44,13 @@ ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags); ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags, const std::string& Function, - const std::string& HTMLDir, - bool Visualize = false, bool TrimGraph = false); + const std::string& HTMLDir, bool Visualize, + bool TrimGraph, bool AnalyzeAll); ASTConsumer *CreateCFRefChecker(Diagnostic &Diags, const std::string& Function, - const std::string& HTMLDir, - bool Visualize = false, bool TrimGraph = false); + const std::string& HTMLDir, bool Visualize, + bool TrimGraph, bool AnalyzeAll); ASTConsumer *CreateCodeRewriterTest(const std::string& InFile, const std::string& OutFile, diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 098450d72d11..287ea9da9bb8 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -146,20 +146,33 @@ static llvm::cl::opt OutputFile("o", llvm::cl::value_desc("path"), llvm::cl::desc("Specify output file (for --serialize, this is a directory)")); - + +//===----------------------------------------------------------------------===// +// Diagnostic Options +//===----------------------------------------------------------------------===// + static llvm::cl::opt VerifyDiagnostics("verify", llvm::cl::desc("Verify emitted diagnostics and warnings.")); -static llvm::cl::opt -VisualizeEG("visualize-egraph", - llvm::cl::desc("Display static analysis Exploded Graph.")); - static llvm::cl::opt HTMLDiag("html-diags", llvm::cl::desc("Generate HTML to report diagnostics"), llvm::cl::value_desc("HTML directory")); +//===----------------------------------------------------------------------===// +// Analyzer Options +//===----------------------------------------------------------------------===// + +static llvm::cl::opt +VisualizeEG("visualize-egraph", + llvm::cl::desc("Display static analysis Exploded Graph.")); + +static llvm::cl::opt +AnalyzeAll("checker-opt-analyze-headers", + llvm::cl::desc("Force the static analyzer to analyze " + "functions defined in header files.")); + //===----------------------------------------------------------------------===// // Language Options //===----------------------------------------------------------------------===// @@ -1057,11 +1070,11 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, case AnalysisGRSimpleVals: return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, OutputFile, - VisualizeEG, TrimGraph); + VisualizeEG, TrimGraph, AnalyzeAll); case CheckerCFRef: return CreateCFRefChecker(Diag, AnalyzeSpecificFunction, OutputFile, - VisualizeEG, TrimGraph); + VisualizeEG, TrimGraph, AnalyzeAll); case TestSerialization: return CreateSerializationTest(Diag, FileMgr, LangOpts);