1 //===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Defines the registration function for the analyzer checkers.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
15 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
16 #include "../Checkers/ClangSACheckerProvider.h"
17 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
18 #include "clang/StaticAnalyzer/Core/CheckerProvider.h"
19 #include "clang/Frontend/AnalyzerOptions.h"
20 #include "clang/Frontend/FrontendDiagnostic.h"
21 #include "clang/Basic/Diagnostic.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/ADT/OwningPtr.h"
24 #include "llvm/ADT/SmallVector.h"
25
26 using namespace clang;
27 using namespace ento;
28
registerCheckers(const AnalyzerOptions & opts,const LangOptions & langOpts,Diagnostic & diags)29 CheckerManager *ento::registerCheckers(const AnalyzerOptions &opts,
30 const LangOptions &langOpts,
31 Diagnostic &diags) {
32 llvm::OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts));
33
34 llvm::SmallVector<CheckerOptInfo, 8> checkerOpts;
35 for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
36 const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
37 checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
38 }
39
40 llvm::OwningPtr<CheckerProvider> provider(createClangSACheckerProvider());
41 provider->registerCheckers(*checkerMgr,
42 checkerOpts.data(), checkerOpts.size());
43
44 // FIXME: Load CheckerProviders from plugins.
45
46 checkerMgr->finishedCheckerRegistration();
47
48 for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
49 if (checkerOpts[i].isUnclaimed())
50 diags.Report(diag::warn_unkwown_analyzer_checker)
51 << checkerOpts[i].getName();
52 }
53
54 return checkerMgr.take();
55 }
56
printCheckerHelp(llvm::raw_ostream & OS)57 void ento::printCheckerHelp(llvm::raw_ostream &OS) {
58 OS << "OVERVIEW: Clang Static Analyzer Checkers List\n";
59 OS << '\n';
60
61 llvm::OwningPtr<CheckerProvider> provider(createClangSACheckerProvider());
62 provider->printHelp(OS);
63
64 // FIXME: Load CheckerProviders from plugins.
65 }
66