Path: blob/main/contrib/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalyzerHelpFlags.cpp
35266 views
//===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Defines the registration function for the analyzer checkers.9//10//===----------------------------------------------------------------------===//1112#include "clang/StaticAnalyzer/Frontend/AnalyzerHelpFlags.h"13#include "clang/Basic/Diagnostic.h"14#include "clang/Frontend/CompilerInstance.h"15#include "clang/Frontend/FrontendDiagnostic.h"16#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"17#include "clang/StaticAnalyzer/Core/CheckerManager.h"18#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"19#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"20#include "llvm/ADT/SmallVector.h"21#include "llvm/Support/raw_ostream.h"22#include <memory>2324using namespace clang;25using namespace ento;2627void ento::printCheckerHelp(raw_ostream &out, CompilerInstance &CI) {28out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";29out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";3031auto CheckerMgr = std::make_unique<CheckerManager>(32CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),33CI.getFrontendOpts().Plugins);3435CheckerMgr->getCheckerRegistryData().printCheckerWithDescList(36CI.getAnalyzerOpts(), out);37}3839void ento::printEnabledCheckerList(raw_ostream &out, CompilerInstance &CI) {40out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";4142auto CheckerMgr = std::make_unique<CheckerManager>(43CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),44CI.getFrontendOpts().Plugins);4546CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out);47}4849void ento::printCheckerConfigList(raw_ostream &out, CompilerInstance &CI) {5051auto CheckerMgr = std::make_unique<CheckerManager>(52CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),53CI.getFrontendOpts().Plugins);5455CheckerMgr->getCheckerRegistryData().printCheckerOptionList(56CI.getAnalyzerOpts(), out);57}5859void ento::printAnalyzerConfigList(raw_ostream &out) {60// FIXME: This message sounds scary, should be scary, but incorrectly states61// that all configs are super dangerous. In reality, many of them should be62// accessible to the user. We should create a user-facing subset of config63// options under a different frontend flag.64out << R"(65OVERVIEW: Clang Static Analyzer -analyzer-config Option List6667The following list of configurations are meant for development purposes only, as68some of the variables they define are set to result in the most optimal69analysis. Setting them to other values may drastically change how the analyzer70behaves, and may even result in instabilities, crashes!7172USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>73-analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...74OPTIONS:75)";7677using OptionAndDescriptionTy = std::pair<StringRef, std::string>;78OptionAndDescriptionTy PrintableOptions[] = {79#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \80{ \81CMDFLAG, \82llvm::Twine(llvm::Twine() + "(" + \83(StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \84") " DESC \85" (default: " #DEFAULT_VAL ")").str() \86},8788#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \89SHALLOW_VAL, DEEP_VAL) \90{ \91CMDFLAG, \92llvm::Twine(llvm::Twine() + "(" + \93(StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \94") " DESC \95" (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL \96" in deep mode)").str() \97},98#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"99#undef ANALYZER_OPTION100#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE101};102103llvm::sort(PrintableOptions, llvm::less_first());104105for (const auto &Pair : PrintableOptions) {106AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,107/*EntryWidth*/ 30,108/*MinLineWidth*/ 70);109out << "\n\n";110}111}112113114