CheckerRegistration.cpp revision deb6447d0029bdb122397fafb5fa2a4e76f2e555
143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//                     The LLVM Compiler Infrastructure
443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source
643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// License. See LICENSE.TXT for details.
743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===----------------------------------------------------------------------===//
943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
1043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// Defines the registration function for the analyzer checkers.
1143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
1243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===----------------------------------------------------------------------===//
1343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
1427af04bcca46f8a3374586be1301477f9123f5e1Argyrios Kyrtzidis#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
15116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
1643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "../Checkers/ClangSACheckerProvider.h"
1743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/StaticAnalyzer/Core/CheckerManager.h"
1843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/StaticAnalyzer/Core/CheckerProvider.h"
1943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Frontend/AnalyzerOptions.h"
2043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Frontend/FrontendDiagnostic.h"
2143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Basic/Diagnostic.h"
22116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis#include "llvm/Support/raw_ostream.h"
2343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "llvm/ADT/OwningPtr.h"
2443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "llvm/ADT/SmallVector.h"
2543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
2643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidisusing namespace clang;
2743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidisusing namespace ento;
2843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
2943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios KyrtzidisCheckerManager *ento::registerCheckers(const AnalyzerOptions &opts,
302e471a3e476396be1ddca4ab8b9df721bcfc9437Argyrios Kyrtzidis                                       const LangOptions &langOpts,
3143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis                                       Diagnostic &diags) {
322e471a3e476396be1ddca4ab8b9df721bcfc9437Argyrios Kyrtzidis  llvm::OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts));
3343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
3443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  llvm::SmallVector<CheckerOptInfo, 8> checkerOpts;
3543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
3643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
3743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
3843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  }
3943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
4043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  llvm::OwningPtr<CheckerProvider> provider(createClangSACheckerProvider());
4143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  provider->registerCheckers(*checkerMgr,
4243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis                             checkerOpts.data(), checkerOpts.size());
4343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
4443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  // FIXME: Load CheckerProviders from plugins.
4543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
46deb6447d0029bdb122397fafb5fa2a4e76f2e555Argyrios Kyrtzidis  checkerMgr->finishedCheckerRegistration();
47deb6447d0029bdb122397fafb5fa2a4e76f2e555Argyrios Kyrtzidis
4843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
4943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    if (checkerOpts[i].isUnclaimed())
5043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis      diags.Report(diag::warn_unkwown_analyzer_checker)
5143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis          << checkerOpts[i].getName();
5243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  }
5343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
5443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  return checkerMgr.take();
5543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis}
56116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis
57116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidisvoid ento::printCheckerHelp(llvm::raw_ostream &OS) {
58116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  OS << "OVERVIEW: Clang Static Analyzer Checkers List\n";
59116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  OS << '\n';
60116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  OS << "USAGE: -analyzer-checker <check1,check2,...>\n";
61116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  OS << '\n';
62116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  OS << "CHECKERS:\n";
63116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis
64116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  llvm::OwningPtr<CheckerProvider> provider(createClangSACheckerProvider());
65116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  provider->printHelp(OS);
66116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis
67116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis  // FIXME: Load CheckerProviders from plugins.
68116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis}
69