Index: clang/include/clang/CMakeLists.txt =================================================================== --- clang/include/clang/CMakeLists.txt +++ clang/include/clang/CMakeLists.txt @@ -4,5 +4,5 @@ add_subdirectory(Parse) add_subdirectory(Sema) add_subdirectory(Serialization) -add_subdirectory(StaticAnalyzer/Checkers) +add_subdirectory(StaticAnalyzer) add_subdirectory(Tooling/Syntax) Index: clang/include/clang/StaticAnalyzer/AnalyzerFlagsBase.td =================================================================== --- /dev/null +++ clang/include/clang/StaticAnalyzer/AnalyzerFlagsBase.td @@ -0,0 +1,23 @@ +//===-- AnalyzerFlagBase.td - Static Analyzer Flags TableGen base classes -===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +/// Describes ain option type. This is important for validating user supplied +/// inputs. +/// New option types can be added by modifying this enum. Note that this +/// requires changes in the TableGen emitter files found in +/// clang/utils/TableGen. +class CmdLineOptionTypeEnum val> { + bits<2> Type = val; +} +def Integer : CmdLineOptionTypeEnum<0>; +def String : CmdLineOptionTypeEnum<1>; +def Boolean : CmdLineOptionTypeEnum<2>; + +/// A description. May be displayed to the user when clang is invoked with +/// a '-help'-like command line option. +class HelpText { string HelpText = text; } Index: clang/include/clang/StaticAnalyzer/CMakeLists.txt =================================================================== --- /dev/null +++ clang/include/clang/StaticAnalyzer/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Checkers) +add_subdirectory(Core) Index: clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td =================================================================== --- clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td +++ clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td @@ -10,16 +10,7 @@ // //===----------------------------------------------------------------------===// -/// Describes a checker or package option type. This is important for validating -/// user supplied inputs. -/// New option types can be added by modifying this enum. Note that this -/// requires changes in the TableGen emitter file ClangSACheckersEmitter.cpp. -class CmdLineOptionTypeEnum val> { - bits<2> Type = val; -} -def Integer : CmdLineOptionTypeEnum<0>; -def String : CmdLineOptionTypeEnum<1>; -def Boolean : CmdLineOptionTypeEnum<2>; +include "../AnalyzerFlagsBase.td" /// Describes the state of the entry. We wouldn't like to display, for example, /// developer only entries for a list meant for end users. @@ -81,10 +72,6 @@ /// def CoreBuiltin : Package<"builtin">, ParentPackage; class ParentPackage { Package ParentPackage = P; } -/// A description. May be displayed to the user when clang is invoked with -/// a '-help'-like command line option. -class HelpText { string HelpText = text; } - /// Describes what kind of documentation exists for the checker. class DocumentationEnum val> { bits<2> Documentation = val; Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.td =================================================================== --- /dev/null +++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.td @@ -0,0 +1,94 @@ +//===--- AnalyzerOptions.td - Analyzer configs ----------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file defines the analyzer options avaible with -analyzer-config. +// TODO: Copy documentation from AnalyzerOptions.def before deleting it. +// +//===----------------------------------------------------------------------===// + +include "../AnalyzerFlagsBase.td" + + +class Config { + string Name = name; + bits<2> Type = type.Type; + string HelpText; + string DefaultVal; +} + +class DefaultVal { string DefaultVal = val; } +//===----------------------------------------------------------------------===// + +class BooleanConfig : Config; +//===----------------------------------------------------------------------===// + +class IntegerConfig : Config { + list Values = ?; +} + +class IntValues Vals> { + list Values = Vals; +} +//===----------------------------------------------------------------------===// + +class StringConfig : Config { + bit NeedsNoValidation = 0; +} +//===----------------------------------------------------------------------===// + +class FileNameConfig : Config; +//===----------------------------------------------------------------------===// + +class EnumVal { + string CmdFlag = cmdFlag; + string EnumName = enumName; +} + +class EnumConfig : Config { + list Values; + string EnumPrefix; +} + +class EnumValues Vals> { + list Values = Vals; +} + +class EnumPrefix { + string EnumPrefix = enumPrefix; +} +//===----------------------------------------------------------------------===// + + +def ShouldIncludeImplicitDtorsInCFG : BooleanConfig<"cfg-implicit-dtors">, + HelpText<"Whether or not implicit destructors for C++ objects should be " + "included in the CFG.">, + DefaultVal<"true">; + +def AlwaysInlineSize : IntegerConfig<"ipa-always-inline-size">, + HelpText<"The size of the functions (in basic blocks), which should be " + "considered to be small enough to always inline.">, + DefaultVal<"3">; + +def RawSilencedCheckersAndPackages : StringConfig<"silence-checkers">, + HelpText<"A semicolon separated list of checker and package names to " + "silence. Silenced checkers will not emit reports, but the modeling " + "remain enabled.">, + DefaultVal<"">; + +def CXXMemberInliningMode : EnumConfig<"c++-inlining">, + HelpText<"Controls which C++ member functions will be considered for " + "inlining.">, + EnumPrefix<"CIMK">, + EnumValues<[ + EnumVal<"none", "None">, + EnumVal<"constructors", "Constructors">, + EnumVal<"destructors", "Destructors">, + EnumVal<"methods", "Memberfunctions"> + ]>, + DefaultVal<"destructors">; + Index: clang/include/clang/StaticAnalyzer/Core/CMakeLists.txt =================================================================== --- /dev/null +++ clang/include/clang/StaticAnalyzer/Core/CMakeLists.txt @@ -0,0 +1,3 @@ +clang_tablegen(Configs.inc -gen-clang-sa-configs + SOURCE AnalyzerOptions.td + TARGET ClangSAConfigs) Index: clang/utils/TableGen/CMakeLists.txt =================================================================== --- clang/utils/TableGen/CMakeLists.txt +++ clang/utils/TableGen/CMakeLists.txt @@ -14,6 +14,7 @@ ClangOpenCLBuiltinEmitter.cpp ClangOptionDocEmitter.cpp ClangSACheckersEmitter.cpp + ClangSAConfigsEmitter.cpp ClangSyntaxEmitter.cpp ClangTypeNodesEmitter.cpp MveEmitter.cpp Index: clang/utils/TableGen/ClangSAConfigsEmitter.cpp =================================================================== --- /dev/null +++ clang/utils/TableGen/ClangSAConfigsEmitter.cpp @@ -0,0 +1,173 @@ +//==- ClangSAConfigsEmitter.cpp - Generate Clang SA config tables -*- 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 +// +//===----------------------------------------------------------------------===// +// +// This tablegen backend emits Clang Static Analyzer -analyzer-config tables. +// +//===----------------------------------------------------------------------===// + +#include "TableGenBackends.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TableGen/Error.h" +#include "llvm/TableGen/Record.h" +#include "llvm/TableGen/TableGenBackend.h" +#include +#include + +using namespace llvm; + +using SortedRecords = llvm::StringMap; + +static void printOptionFields(const Record *R, raw_ostream &OS, + bool IsDefaultValString) { + OS << R->getName() << "," + << "\""; + OS.write_escaped(R->getValueAsString("Name")) << "\",\""; + OS.write_escaped(R->getValueAsString("HelpText")) << "\","; + StringRef DefaultVal = R->getValueAsString("DefaultVal"); + + if (IsDefaultValString) { + if (DefaultVal == "") + OS << "\"\""; + else + OS << "\"" << DefaultVal << "\""; + } else + OS << DefaultVal; +} + +static SortedRecords getSortedDerivedDefinitions(RecordKeeper &Records, + StringRef ClassName) { + SortedRecords Ret; + for (const Record *R : Records.getAllDerivedDefinitions(ClassName)) + Ret[R->getValueAsString("Name")] = R; + return Ret; +} + +static std::string getEnumName(const Record *R) { + return R->getNameInitAsString() + "Kind"; +} + +void clang::EmitClangSAConfigs(RecordKeeper &Records, raw_ostream &OS) { + + OS << "// This file is automatically generated. Do not edit this file by " + "hand.\n"; + + // Emit boolean options. + // + // BOOLEAN_OPTION(TYPE, FIELD_NAME, CMDFLAG, HELPTEXT, DEFAULTVAL) + // - TYPE: Type of the option in class AnalyzerOptions. + // - FIELD_NAME: Name of the field in class AnalyzerOptions. + // - CMDFLAG: Name of the flag to be specified on the command line. For + // specifics, check clang -cc1 -analyzer-config-help. + // - HELPTEXT: Text displayed under -analyzer-config-help. + // - DEFAULTVAL: Default value of the option if its not specified in the + // command line. + OS << "\n" + "#ifdef BOOLEAN_OPTIONS\n"; + for (const auto &Pair : + getSortedDerivedDefinitions(Records, "BooleanConfig")) { + const Record *R = Pair.second; + OS << "BOOLEAN_OPTION(bool,"; + printOptionFields(R, OS, /*IsDefaultValString*/false); + OS << ")\n"; + } + OS << "#endif // BOOLEAN_OPTIONS\n" + "\n"; + + // Emit integer options. + // + // INTEGER_OPTIONS(TYPE, FIELD_NAME, CMDFLAG, HELPTEXT, DEFAULTVAL) + // Check the comments around BOOLEAN_OPTION for description of the parameters. + OS << "\n" + "#ifdef INTEGER_OPTIONS\n"; + for (const auto &Pair : + getSortedDerivedDefinitions(Records, "IntegerConfig")) { + const Record *R = Pair.second; + OS << "INTEGER_OPTION(int,"; + printOptionFields(R, OS, /*IsDefaultValString*/false); + OS << ")\n"; + } + OS << "#endif // INTEGER_OPTIONS\n" + "\n"; + + // Emit string options. + // + // STRING_OPTIONS(TYPE, FIELD_NAME, CMDFLAG, HELPTEXT, DEFAULTVAL) + // Check the comments around BOOLEAN_OPTION for description of the parameters. + OS << "\n" + "#ifdef STRING_OPTIONS\n"; + for (const auto &Pair : + getSortedDerivedDefinitions(Records, "StringConfig")) { + const Record *R = Pair.second; + OS << "STRING_OPTION(StringRef,"; + printOptionFields(R, OS, /*IsDefaultValString*/true); + OS << ")\n"; + } + OS << "#endif // STRING_OPTIONS\n" + "\n"; + + // Emit enum options. These are string options can only take a select fe + // values, and are parsed into enums. + // + // ENUM_OPTIONS( + // TYPE, FIELD_NAME, CMDFLAG, HELPTEXT, DEFAULTVAL, VALUES) + // + // Check the comments around BOOLEAN_OPTION for description of the first few + // parameters. + // - VALUES: A string that lists all options that can be specified on the + // command line. Each value is separated with a comma (its still one + // big string!). They correspond with enum values with the same + // index (see ENUMS below). + OS << "\n" + "#ifdef ENUM_OPTIONS\n"; + for (const auto &Pair : getSortedDerivedDefinitions(Records, "EnumConfig")) { + const Record *R = Pair.second; + OS << "ENUM_OPTION(" << getEnumName(R) << ","; + printOptionFields(R, OS, /*IsDefaultValString*/true); + OS << ','; + if (!R->isValueUnset("Values")) { + for (const Record *EnumVal : R->getValueAsListOfDefs("Values")) { + OS << "\""; + OS.write_escaped(EnumVal->getValueAsString("CmdFlag")); + OS << ",\""; + } + } + OS << ")\n"; + } + OS << "#endif // ENUM_OPTIONS\n" + "\n"; + + // Emit enum classes corresponding with the enum options. + // + // enum class