Fix the clang-wpa example.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 Feb 2011 16:54:12 +0000 (16:54 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 Feb 2011 16:54:12 +0000 (16:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125565 91177308-0d34-0410-b5e6-96231b3b80d8

examples/wpa/clang-wpa.cpp
include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h [new file with mode: 0644]
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.h
lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp

index a234931c8ef5b256bfebfa4aa090409eb4963fd9..bbb9e147ebade6a96e8a654b40abcbeac5d961d4 100644 (file)
 
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/TransferFuncs.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Checkers/LocalCheckers.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -26,6 +28,7 @@
 #include "clang/Index/DeclReferenceMap.h"
 #include "clang/Index/SelectorMap.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/raw_ostream.h"
@@ -131,20 +134,41 @@ int main(int argc, char **argv) {
   // Create an analysis engine.
   Preprocessor &PP = TU->getPreprocessor();
 
-  // Hard code options for now.
+  AnalyzerOptions Opts;
+
+  // Hard code options and checkers for now.
+
+  Opts.MaxNodes = 300000;
+  Opts.MaxLoop = 3;
+  Opts.InlineCall = true;
+  Opts.CFGAddImplicitDtors = true;
+  Opts.EagerlyTrimEGraph = true;
+
+  Opts.CheckersControlList.push_back(std::make_pair("core", true));
+  if (PP.getTargetInfo().getTriple().getOS() != llvm::Triple::Win32)
+    Opts.CheckersControlList.push_back(std::make_pair("unix", true));
+  if (PP.getTargetInfo().getTriple().getVendor() == llvm::Triple::Apple)
+    Opts.CheckersControlList.push_back(std::make_pair("macosx", true));
+
+  // Checks to perform for Objective-C/Objective-C++.
+  if (PP.getLangOptions().ObjC1)
+    Opts.CheckersControlList.push_back(std::make_pair("cocoa", true));
+
+  llvm::OwningPtr<ento::CheckerManager> checkerMgr;
+  checkerMgr.reset(ento::registerCheckers(Opts, PP.getDiagnostics()));
+
   using namespace clang::ento;
   AnalysisManager AMgr(TU->getASTContext(), PP.getDiagnostics(),
                        PP.getLangOptions(), /* PathDiagnostic */ 0,
                        CreateRegionStoreManager,
-                       CreateRangeConstraintManager, &Idxer,
-                       /* MaxNodes */ 300000, /* MaxVisit */ 3,
-                       /* VisualizeEG */ false, /* VisualizeEGUbi */ false,
-                       /* PurgeDead */ true, /* EagerlyAssume */ false,
-                       /* TrimGraph */ false, /* InlineCall */ true, 
-                       /* UseUnoptimizedCFG */ false,
-                       /* addImplicitDtors */ true,
-                       /* addInitializers */ false,
-                       /* reclaimeNodes */ true);
+                       CreateRangeConstraintManager, checkerMgr.get(), &Idxer,
+                       Opts.MaxNodes, Opts.MaxLoop,
+                       Opts.VisualizeEGDot, Opts.VisualizeEGUbi,
+                       Opts.PurgeDead, Opts.EagerlyAssume,
+                       Opts.TrimGraph, Opts.InlineCall,
+                       Opts.UnoptimizedCFG, Opts.CFGAddImplicitDtors,
+                       Opts.CFGAddInitializers,
+                       Opts.EagerlyTrimEGraph);
 
   TransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false,
                                          AMgr.getLangOptions());
diff --git a/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h b/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
new file mode 100644 (file)
index 0000000..4c3e379
--- /dev/null
@@ -0,0 +1,26 @@
+//===-- CheckerRegistration.h - Checker Registration Function-------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SA_FRONTEND_CHECKERREGISTRATION_H
+#define LLVM_CLANG_SA_FRONTEND_CHECKERREGISTRATION_H
+
+namespace clang {
+  class AnalyzerOptions;
+  class Diagnostic;
+
+namespace ento {
+  class CheckerManager;
+
+CheckerManager *registerCheckers(const AnalyzerOptions &opts,Diagnostic &diags);
+
+} // end ento namespace
+
+} // end namespace clang
+
+#endif
index 6c8f55f308e78596a71089a71e42fc12d623a7fa..56475c55919d1953ea951858268e348b1595ef70 100644 (file)
@@ -20,6 +20,7 @@
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Analysis/Analyses/UninitializedValues.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Checkers/LocalCheckers.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
index d382bdf0f531e0b6f2276912ca44363875ae8ab5..646fe97564b818b8eb019a3e53854106bf43ed21 100644 (file)
@@ -34,8 +34,6 @@ ASTConsumer* CreateAnalysisConsumer(const Preprocessor &pp,
                                     const std::string &output,
                                     const AnalyzerOptions& Opts);
 
-CheckerManager *registerCheckers(const AnalyzerOptions &opts,Diagnostic &diags);
-
 } // end GR namespace
 
 } // end clang namespace
index ca25f71823101675f73185ca13cb91308a5eaa75..6625729eafe4e9702c5d01e22a4aadccbeac46a9 100644 (file)
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
 #include "../Checkers/ClangSACheckerProvider.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/CheckerProvider.h"