//===- CheckerRegistry.h - Maintains all available checkers -----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Contains the logic for parsing the TableGen file Checkers.td, and parsing the // specific invocation of the analyzer (which checker/package is enabled, values // of their options, etc). This is in the frontend library because checker // registry functions are called from here but are defined in the dependent // library libStaticAnalyzerCheckers, but the actual data structure that holds // the parsed information is in the Core library. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRY_H #define LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRY_H #include "clang/Basic/LLVM.h" #include "clang/StaticAnalyzer/Core/CheckerRegistryData.h" #include "llvm/ADT/StringRef.h" // FIXME: move this information to an HTML file in docs/. // At the very least, a checker plugin is a dynamic library that exports // clang_analyzerAPIVersionString. This should be defined as follows: // // extern "C" // const char clang_analyzerAPIVersionString[] = // CLANG_ANALYZER_API_VERSION_STRING; // // This is used to check whether the current version of the analyzer is known to // be incompatible with a plugin. Plugins with incompatible version strings, // or without a version string at all, will not be loaded. // // To add a custom checker to the analyzer, the plugin must also define the // function clang_registerCheckers. For example: // // extern "C" // void clang_registerCheckers (CheckerRegistry ®istry) { // registry.addChecker<MainCallChecker>("example.MainCallChecker", // "Disallows calls to functions called main"); // } // // The first method argument is the full name of the checker, including its // enclosing package. By convention, the registered name of a checker is the // name of the associated class (the template argument). // The second method argument is a short human-readable description of the // checker. // // The clang_registerCheckers function may add any number of checkers to the // registry. If any checkers require additional initialization, use the three- // argument form of CheckerRegistry::addChecker. // // To load a checker plugin, specify the full path to the dynamic library as // the argument to the -load option in the cc1 frontend. You can then enable // your custom checker using the -analyzer-checker: // // clang -cc1 -load </path/to/plugin.dylib> -analyze // -analyzer-checker=<example.MainCallChecker> // // For a complete working example, see examples/analyzer-plugin. #ifndef CLANG_ANALYZER_API_VERSION_STRING // FIXME: The Clang version string is not particularly granular; // the analyzer infrastructure can change a lot between releases. // Unfortunately, this string has to be statically embedded in each plugin, // so we can't just use the functions defined in Version.h. #include "clang/Basic/Version.h" #define CLANG_ANALYZER_API_VERSION_STRING … #endif namespace clang { class AnalyzerOptions; class DiagnosticsEngine; namespace ento { class CheckerManager; /// Manages a set of available checkers for running a static analysis. /// The checkers are organized into packages by full name, where including /// a package will recursively include all subpackages and checkers within it. /// For example, the checker "core.builtin.NoReturnFunctionChecker" will be /// included if initializeManager() is called with an option of "core", /// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker". class CheckerRegistry { … }; } // namespace ento } // namespace clang #endif // LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRY_H