Added driver option "-checker-opt-analyze-headers" to force the static
analyzer to analyze functions declared in header files.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49675 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index 727c57a..77cc996 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -643,12 +643,13 @@
   bool Visualize;
   bool TrimGraph;
   llvm::OwningPtr<PathDiagnosticClient> 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 @@
   
   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 @@
 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 @@
 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 @@
 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 @@
 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/Driver/ASTConsumers.h b/Driver/ASTConsumers.h
index 0c0cf58..98164d4 100644
--- a/Driver/ASTConsumers.h
+++ b/Driver/ASTConsumers.h
@@ -44,13 +44,13 @@
   
 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/Driver/clang.cpp b/Driver/clang.cpp
index 098450d..287ea9d 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -146,21 +146,34 @@
 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<bool>
 VerifyDiagnostics("verify",
                   llvm::cl::desc("Verify emitted diagnostics and warnings."));
 
-static llvm::cl::opt<bool>
-VisualizeEG("visualize-egraph",
-            llvm::cl::desc("Display static analysis Exploded Graph."));
-
 static llvm::cl::opt<std::string>
 HTMLDiag("html-diags",
          llvm::cl::desc("Generate HTML to report diagnostics"),
          llvm::cl::value_desc("HTML directory"));
 
 //===----------------------------------------------------------------------===//
+// Analyzer Options
+//===----------------------------------------------------------------------===//
+
+static llvm::cl::opt<bool>
+VisualizeEG("visualize-egraph",
+            llvm::cl::desc("Display static analysis Exploded Graph."));
+
+static llvm::cl::opt<bool>
+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 @@
       
     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);