]> granicus.if.org Git - clang/commitdiff
Migrated driver logic for running the CF retain/release checker over to the new Analy...
authorTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 00:44:58 +0000 (00:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 00:44:58 +0000 (00:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53002 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/ASTConsumers.h
Driver/AnalysisConsumer.cpp
Driver/AnalysisConsumer.h
Driver/clang.cpp

index dbdce45d1cf7b0ba4ed179df68206248fe4e5f25..9ff0387702eda43e4071d0ce69688df7f6d7e683 100644 (file)
@@ -765,58 +765,6 @@ ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
                                  Visualize, TrimGraph, AnalyzeAll);
 }
 
-
-//===----------------------------------------------------------------------===//
-// Core Foundation Reference Counting Checker
-
-namespace {
-class CFRefCountCheckerVisitor : public CheckerConsumer {
-  const LangOptions& LangOpts;
-public:
-  CFRefCountCheckerVisitor(Diagnostic &diags, Preprocessor* pp,
-                           PreprocessorFactory* ppf,
-                           const LangOptions& lopts,
-                           const std::string& fname,
-                           const std::string& htmldir,
-                           bool visualize, bool trim, bool analyzeAll)
-  : CheckerConsumer(diags, pp, ppf, fname, htmldir, visualize,
-                    trim, analyzeAll), LangOpts(lopts) {}
-  
-  virtual const char* getCheckerName() { return "CFRefCountChecker"; }
-  
-  virtual void getTransferFunctions(std::vector<GRTransferFuncs*>& TFs) {
-    switch (LangOpts.getGCMode()) {
-      case LangOptions::NonGC:
-        TFs.push_back(MakeCFRefCountTF(*Ctx, false, true, LangOpts));
-        break;
-        
-      case LangOptions::GCOnly:
-        TFs.push_back(MakeCFRefCountTF(*Ctx, true, true, LangOpts));
-        break;
-        
-      case LangOptions::HybridGC:
-        TFs.push_back(MakeCFRefCountTF(*Ctx, false, true, LangOpts));
-        TFs.push_back(MakeCFRefCountTF(*Ctx, true, false, LangOpts));
-        break;
-    }
-  }
-};
-} // end anonymous namespace
-
-ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags,
-                                       Preprocessor* PP,
-                                       PreprocessorFactory* PPF,
-                                       const LangOptions& LangOpts,
-                                       const std::string& FunctionName,
-                                       const std::string& HTMLDir,
-                                       bool Visualize, bool TrimGraph,
-                                       bool AnalyzeAll) {
-  
-  return new CFRefCountCheckerVisitor(Diags, PP, PPF, LangOpts, FunctionName,
-                                      HTMLDir, Visualize, TrimGraph,
-                                      AnalyzeAll);
-}
-
 //===----------------------------------------------------------------------===//
 // AST Serializer
 
index 5853664832b45245a340e32454021d55f9ab43d5..c19a1afa5cf5c44dd01d20c585dc163567da42c4 100644 (file)
@@ -45,13 +45,6 @@ ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
                                 const std::string& Function,
                                 const std::string& HTMLDir, bool Visualize,
                                 bool TrimGraph, bool AnalyzeAll);
-  
-ASTConsumer *CreateCFRefChecker(Diagnostic &Diags,
-                                Preprocessor* PP, PreprocessorFactory* PPF,
-                                const LangOptions& LangOpts,
-                                const std::string& Function,
-                                const std::string& HTMLDir, bool Visualize,
-                                bool TrimGraph, bool AnalyzeAll);
 
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     const std::string& OutFile,
index 11fb4a95c1f149252bef2576dbe02ad8f66b4f03..57be0ff55d6a50e74bf4af8cc4c30957cf3e0cb4 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "ASTConsumers.h"
+#include "HTMLDiagnostics.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
@@ -104,6 +105,7 @@ namespace {
     llvm::OwningPtr<CFG> cfg;
     llvm::OwningPtr<LiveVariables> liveness;
     llvm::OwningPtr<ParentMap> PM;
+    llvm::OwningPtr<PathDiagnosticClient> PD;
 
   public:
     AnalysisManager(AnalysisConsumer& c, Decl* d, Stmt* b) 
@@ -130,6 +132,17 @@ namespace {
     Diagnostic& getDiagnostic() {
       return C.Diags;
     }
+    
+    const LangOptions& getLangOptions() const {
+      return C.LOpts;
+    }
+    
+    PathDiagnosticClient* getPathDiagnosticClient() {
+      if (PD.get() == 0 && !C.HTMLDir.empty())
+        PD.reset(CreateHTMLDiagnosticClient(C.HTMLDir, C.PP, C.PPF));
+      
+      return PD.get();      
+    }
       
     LiveVariables* getLiveVariables() {
       if (!liveness) liveness.reset(new LiveVariables(*getCFG()));
@@ -213,6 +226,47 @@ static void ActionUninitVals(AnalysisManager& mgr) {
                            mgr.getDiagnostic());
 }
 
+
+static void ActionRefLeakCheckerAux(AnalysisManager& mgr, bool GCEnabled,
+                                    bool StandardWarnings) {
+    
+  // Construct the analysis engine.
+  GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext());
+  
+  // Construct the transfer function object.
+  llvm::OwningPtr<GRTransferFuncs>
+  TF(MakeCFRefCountTF(mgr.getContext(), GCEnabled, StandardWarnings,
+                      mgr.getLangOptions()));
+     
+  Eng.setTransferFunctions(TF.get());
+
+  // Execute the worklist algorithm.
+  Eng.ExecuteWorkList();
+   
+  // Display warnings.
+  Eng.EmitWarnings(mgr.getDiagnostic(), mgr.getPathDiagnosticClient());     
+}
+
+static void ActionRefLeakChecker(AnalysisManager& mgr) {
+     
+ switch (mgr.getLangOptions().getGCMode()) {
+   default:
+     assert (false && "Invalid GC mode.");
+   case LangOptions::NonGC:
+     ActionRefLeakCheckerAux(mgr, false, true);
+     break;
+    
+   case LangOptions::GCOnly:
+     ActionRefLeakCheckerAux(mgr, true, true);
+     break;
+     
+   case LangOptions::HybridGC:
+     ActionRefLeakCheckerAux(mgr, false, true);
+     ActionRefLeakCheckerAux(mgr, true, false);
+     break;
+ }
+}
+
 //===----------------------------------------------------------------------===//
 // AnalysisConsumer creation.
 //===----------------------------------------------------------------------===//
@@ -240,6 +294,10 @@ ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
         C->addCodeAction(&ActionUninitVals);
         break;
         
+      case CheckerCFRef:
+        C->addCodeAction(&ActionRefLeakChecker);
+        break;
+        
       default: break;
     }
   
index 3a2f3b94371443859e2afa2ad4766ddc0153fbbd..8514a9b531abf6980588387100b9187b77c9f6ac 100644 (file)
@@ -18,7 +18,8 @@ namespace clang {
 
 enum Analyses {
   WarnDeadStores,
-  WarnUninitVals
+  WarnUninitVals,
+  CheckerCFRef
 };
   
 ASTConsumer* CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
index eddaca3a88dd8f0951e0997c2be6be517979ca4f..344fe08bffd6a0f882beecf62d4f4b7c8215c81c 100644 (file)
@@ -77,7 +77,6 @@ enum ProgActions {
   AnalysisLiveVariables,        // Print results of live-variable analysis.
   AnalysisGRSimpleVals,         // Perform graph-reachability constant prop.
   AnalysisGRSimpleValsView,     // Visualize results of path-sens. analysis.
-  CheckerCFRef,                 // Run the Core Foundation Ref. Count Checker.
   TestSerialization,            // Run experimental serialization code.
   ParsePrintCallbacks,          // Parse and print each callback.
   ParseSyntaxOnly,              // Parse and perform semantic analysis.
@@ -120,8 +119,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
                         "Print results of live variable analysis"),
              clEnumValN(AnalysisGRSimpleVals, "checker-simple",
                         "Perform path-sensitive constant propagation"),
-             clEnumValN(CheckerCFRef, "checker-cfref",
-                        "Run the Core Foundation reference count checker"),
              clEnumValN(TestSerialization, "test-pickling",
                         "Run prototype serialization code"),
              clEnumValN(EmitLLVM, "emit-llvm",
@@ -182,6 +179,8 @@ clEnumValN(WarnDeadStores, "warn-dead-stores",
            "Flag warnings of stores to dead variables"),
 clEnumValN(WarnUninitVals, "warn-uninit-values",
            "Flag warnings of uses of unitialized variables"),
+clEnumValN(CheckerCFRef, "checker-cfref",
+           "Run the [Core] Foundation reference count checker"),      
 clEnumValEnd));          
 
 //===----------------------------------------------------------------------===//
@@ -1206,11 +1205,6 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
       return CreateGRSimpleVals(Diag, PP, PPF, AnalyzeSpecificFunction,
                                 OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
       
-    case CheckerCFRef:
-      return CreateCFRefChecker(Diag, PP, PPF, LangOpts,
-                                AnalyzeSpecificFunction,
-                                OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
-      
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr);