From: Argyrios Kyrtzidis Date: Tue, 15 Feb 2011 16:54:12 +0000 (+0000) Subject: Fix the clang-wpa example. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27af04bcca46f8a3374586be1301477f9123f5e1;p=clang Fix the clang-wpa example. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125565 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp index a234931c8e..bbb9e147eb 100644 --- a/examples/wpa/clang-wpa.cpp +++ b/examples/wpa/clang-wpa.cpp @@ -14,9 +14,11 @@ #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 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 index 0000000000..4c3e379f33 --- /dev/null +++ b/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h @@ -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 diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 6c8f55f308..56475c5591 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -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" diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.h b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.h index d382bdf0f5..646fe97564 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.h +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.h @@ -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 diff --git a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp index ca25f71823..6625729eaf 100644 --- a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -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"