diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -110,75 +110,15 @@ Embed_Marker // Embed a marker as a placeholder for bitcode. }; - // This field stores one of the allowed values for the option - // -fbasic-block-sections=. The allowed values with this option are: - // {"labels", "all", "list=", "none"}. - // - // "labels": Only generate basic block symbols (labels) for all basic - // blocks, do not generate unique sections for basic blocks. - // Use the machine basic block id in the symbol name to - // associate profile info from virtual address to machine - // basic block. - // "all" : Generate basic block sections for all basic blocks. - // "list=": Generate basic block sections for a subset of basic blocks. - // The functions and the machine basic block ids are specified - // in the file. - // "none": Disable sections/labels for basic blocks. - std::string BBSections; - enum class FramePointerKind { None, // Omit all frame pointers. NonLeaf, // Keep non-leaf frame pointers. All, // Keep all frame pointers. }; - /// The code model to use (-mcmodel). - std::string CodeModel; - - /// The filename with path we use for coverage data files. The runtime - /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP - /// environment variables. - std::string CoverageDataFile; - - /// The filename with path we use for coverage notes files. - std::string CoverageNotesFile; - - /// Regexes separated by a semi-colon to filter the files to instrument. - std::string ProfileFilterFiles; - - /// Regexes separated by a semi-colon to filter the files to not instrument. - std::string ProfileExcludeFiles; - - /// The version string to put into coverage files. - char CoverageVersion[4]; - - /// Enable additional debugging information. - std::string DebugPass; - - /// The string to embed in debug information as the current working directory. - std::string DebugCompilationDir; - - /// The string to embed in the debug information for the compile unit, if - /// non-empty. - std::string DwarfDebugFlags; - - /// The string containing the commandline for the llvm.commandline metadata, - /// if non-empty. - std::string RecordCommandLine; - - std::map DebugPrefixMap; - - /// The ABI to use for passing floating point arguments. - std::string FloatABI; - - /// The floating-point denormal mode to use. - llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE(); + using DebugPrefixMapTy = std::map; - /// The floating-point denormal mode to use, for float. - llvm::DenormalMode FP32DenormalMode = llvm::DenormalMode::getIEEE(); - - /// The float precision limit to use, if non-empty. - std::string LimitFloatPrecision; + using CoverageVersionTy = char[4]; struct BitcodeFileToLink { /// The filename of the bitcode file to link in. @@ -193,156 +133,14 @@ unsigned LinkFlags = 0; }; - /// The files specified here are linked in to the module before optimizations. - std::vector LinkBitcodeFiles; - - /// The user provided name for the "main file", if non-empty. This is useful - /// in situations where the input file name does not match the original input - /// file, for example with -save-temps. - std::string MainFileName; - - /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name - /// attribute in the skeleton CU. - std::string SplitDwarfFile; - - /// Output filename for the split debug info, not used in the skeleton CU. - std::string SplitDwarfOutput; - - /// The name of the relocation model to use. - llvm::Reloc::Model RelocationModel; - - /// The thread model to use - std::string ThreadModel; - - /// If not an empty string, trap intrinsics are lowered to calls to this - /// function instead of to trap instructions. - std::string TrapFuncName; - - /// A list of dependent libraries. - std::vector DependentLibraries; - - /// A list of linker options to embed in the object file. - std::vector LinkerOptions; - - /// Name of the profile file to use as output for -fprofile-instr-generate, - /// -fprofile-generate, and -fcs-profile-generate. - std::string InstrProfileOutput; - - /// Name of the profile file to use with -fprofile-sample-use. - std::string SampleProfileFile; - - /// Name of the profile file to use as input for -fprofile-instr-use - std::string ProfileInstrumentUsePath; - - /// Name of the profile remapping file to apply to the profile data supplied - /// by -fprofile-sample-use or -fprofile-instr-use. - std::string ProfileRemappingFile; - - /// Name of the function summary index file to use for ThinLTO function - /// importing. - std::string ThinLTOIndexFile; - - /// Name of a file that can optionally be written with minimized bitcode - /// to be used as input for the ThinLTO thin link step, which only needs - /// the summary and module symbol table (and not, e.g. any debug metadata). - std::string ThinLinkBitcodeFile; - - /// Prefix to use for -save-temps output. - std::string SaveTempsFilePrefix; - - /// Name of file passed with -fcuda-include-gpubinary option to forward to - /// CUDA runtime back-end for incorporating them into host-side object file. - std::string CudaGpuBinaryFileName; - - /// The name of the file to which the backend should save YAML optimization - /// records. - std::string OptRecordFile; - - /// The regex that filters the passes that should be saved to the optimization - /// records. - std::string OptRecordPasses; - - /// The format used for serializing remarks (default: YAML) - std::string OptRecordFormat; - - /// The name of the partition that symbols are assigned to, specified with - /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html). - std::string SymbolPartition; - - /// Regular expression to select optimizations for which we should enable - /// optimization remarks. Transformation passes whose name matches this - /// expression (and support this feature), will emit a diagnostic - /// whenever they perform a transformation. This is enabled by the - /// -Rpass=regexp flag. - std::shared_ptr OptimizationRemarkPattern; - - /// Regular expression to select optimizations for which we should enable - /// missed optimization remarks. Transformation passes whose name matches this - /// expression (and support this feature), will emit a diagnostic - /// whenever they tried but failed to perform a transformation. This is - /// enabled by the -Rpass-missed=regexp flag. - std::shared_ptr OptimizationRemarkMissedPattern; - - /// Regular expression to select optimizations for which we should enable - /// optimization analyses. Transformation passes whose name matches this - /// expression (and support this feature), will emit a diagnostic - /// whenever they want to explain why they decided to apply or not apply - /// a given transformation. This is enabled by the -Rpass-analysis=regexp - /// flag. - std::shared_ptr OptimizationRemarkAnalysisPattern; - - /// Set of files defining the rules for the symbol rewriting. - std::vector RewriteMapFiles; - - /// Set of sanitizer checks that are non-fatal (i.e. execution should be - /// continued when possible). - SanitizerSet SanitizeRecover; - - /// Set of sanitizer checks that trap rather than diagnose. - SanitizerSet SanitizeTrap; - - /// List of backend command-line options for -fembed-bitcode. - std::vector CmdArgs; - - /// A list of all -fno-builtin-* function names (e.g., memset). - std::vector NoBuiltinFuncs; - - std::vector Reciprocals; - - /// The preferred width for auto-vectorization transforms. This is intended to - /// override default transforms based on the width of the architected vector - /// registers. - std::string PreferVectorWidth; - - /// Set of XRay instrumentation kinds to emit. - XRayInstrSet XRayInstrumentationBundle; - - std::vector DefaultFunctionAttrs; - - /// List of dynamic shared object files to be loaded as pass plugins. - std::vector PassPlugins; - - /// Path to allowlist file specifying which objects - /// (files, functions) should exclusively be instrumented - /// by sanitizer coverage pass. - std::vector SanitizeCoverageAllowlistFiles; - - /// Path to blocklist file specifying which objects - /// (files, functions) listed for instrumentation by sanitizer - /// coverage pass should actually not be instrumented. - std::vector SanitizeCoverageBlocklistFiles; - - /// Executable and command-line used to create a given CompilerInvocation. - /// Most of the time this will be the full -cc1 command. - const char *Argv0 = nullptr; - ArrayRef CommandLineArgs; public: // Define accessors/mutators for code generation options of enumeration type. #define CODEGENOPT(Name, Bits, Default) -#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ - Type get##Name() const { return static_cast(Name); } \ +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ + Type get##Name() const { return static_cast(Name); } \ void set##Name(Type Value) { Name = static_cast(Value); } +#define TYPED_CODEGENOPT(Type, Name, Description) Type Name; #include "clang/Basic/CodeGenOptions.def" CodeGenOptions(); diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -14,17 +14,20 @@ // //===----------------------------------------------------------------------===// #ifndef CODEGENOPT -# error Define the CODEGENOPT macro to handle language options +#error Define the CODEGENOPT macro to handle language options #endif #ifndef VALUE_CODEGENOPT -# define VALUE_CODEGENOPT(Name, Bits, Default) \ -CODEGENOPT(Name, Bits, Default) +#define VALUE_CODEGENOPT(Name, Bits, Default) CODEGENOPT(Name, Bits, Default) #endif #ifndef ENUM_CODEGENOPT -# define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ -CODEGENOPT(Name, Bits, Default) +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ + CODEGENOPT(Name, Bits, Default) +#endif + +#ifndef TYPED_CODEGENOPT +#define TYPED_CODEGENOPT(Type, Name, Description) #endif CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as @@ -395,6 +398,226 @@ /// Whether to not follow the AAPCS that enforce at least one read before storing to a volatile bitfield CODEGENOPT(ForceAAPCSBitfieldLoad, 1, 0) +TYPED_CODEGENOPT( + std::string, BBSections, + "This field stores one of the allowed values for the option " + "-fbasic-block-sections=. The allowed values with this option are: " + "{\"labels\", \"all\", \"list=\", \"none\"}. \"labels\": Only " + "generate basic block symbols (labels) for all basic blocks, do not " + "generate unique sections for basic blocks. Use the machine basic block id " + "in the symbol name to associate profile info from virtual address to " + "machine basic block. \"all\" : Generate basic block sections for " + "all basic blocks. \"list=\": Generate basic block sections for a " + "subset of basic blocks. The functions and the machine basic block ids are " + "specified in the file. \"none\": Disable sections/labels for basic " + "blocks.") + +TYPED_CODEGENOPT(std::string, CodeModel, "The code model to use (-mcmodel).") + +TYPED_CODEGENOPT(std::string, CoverageDataFile, + "The filename with path we use for coverage data files. The " + "runtime allows further manipulation with the GCOV_PREFIX and " + "GCOV_PREFIX_STRIP environment variables. The filename with " + "path we use for coverage notes files.") +TYPED_CODEGENOPT(std::string, CoverageNotesFile, "") + +TYPED_CODEGENOPT( + std::string, ProfileFilterFiles, + "Regexes separated by a semi-colon to filter the files to instrument.") + +TYPED_CODEGENOPT( + std::string, ProfileExcludeFiles, + "Regexes separated by a semi-colon to filter the files to not instrument.") + +TYPED_CODEGENOPT(CoverageVersionTy, CoverageVersion, + "The version string to put into coverage files.") + +TYPED_CODEGENOPT(std::string, DebugPass, + "Enable additional debugging information.") + +TYPED_CODEGENOPT(std::string, DebugCompilationDir, + "The string to embed in debug information as the current " + "working directory.") + +TYPED_CODEGENOPT(std::string, DwarfDebugFlags, + "The string to embed in the debug information for the compile " + "unit, if non-empty.") + +TYPED_CODEGENOPT(std::string, RecordCommandLine, + "The string containing the commandline for the " + "llvm.commandline metadata, if non-empty.") + +TYPED_CODEGENOPT(DebugPrefixMapTy, DebugPrefixMap, "") + +TYPED_CODEGENOPT(std::string, FloatABI, + "The ABI to use for passing floating point arguments.") + +TYPED_CODEGENOPT(llvm::DenormalMode, FPDenormalMode, + "The floating-point denormal mode to use.") + +TYPED_CODEGENOPT(llvm::DenormalMode, FP32DenormalMode, + "The floating-point denormal mode to use, for float.") + +TYPED_CODEGENOPT(std::string, LimitFloatPrecision, + "The float precision limit to use, if non-empty.") + +TYPED_CODEGENOPT(std::vector, LinkBitcodeFiles, + "The files specified here are linked in to the module before " + "optimizations.") + +TYPED_CODEGENOPT( + std::string, MainFileName, + "The user provided name for the \"main file\", if non-empty. This is " + "useful in situations where the input file name does not match the " + "original input file, for example with -save-temps.") + +TYPED_CODEGENOPT(std::string, SplitDwarfFile, + "The name for the split debug info file used for the " + "DW_AT_[GNU_]dwo_name attribute in the skeleton CU.") + +TYPED_CODEGENOPT( + std::string, SplitDwarfOutput, + "Output filename for the split debug info, not used in the skeleton CU.") + +TYPED_CODEGENOPT(llvm::Reloc::Model, RelocationModel, + "The name of the relocation model to use.") + +TYPED_CODEGENOPT(std::string, ThreadModel, "The thread model to use") + +TYPED_CODEGENOPT(std::string, TrapFuncName, + "If not an empty string, trap intrinsics are lowered to calls " + "to this function instead of to trap instructions.") + +TYPED_CODEGENOPT(std::vector, DependentLibraries, + "A list of dependent libraries.") + +TYPED_CODEGENOPT(std::vector, LinkerOptions, + "A list of linker options to embed in the object file.") + +TYPED_CODEGENOPT( + std::string, InstrProfileOutput, + "Name of the profile file to use as output for -fprofile-instr-generate, " + "-fprofile-generate, and -fcs-profile-generate.") + +TYPED_CODEGENOPT(std::string, SampleProfileFile, + "Name of the profile file to use with -fprofile-sample-use.") + +TYPED_CODEGENOPT( + std::string, ProfileInstrumentUsePath, + "Name of the profile file to use as input for -fprofile-instr-use") + +TYPED_CODEGENOPT( + std::string, ProfileRemappingFile, + "Name of the profile remapping file to apply to the profile data supplied " + "by -fprofile-sample-use or -fprofile-instr-use.") + +TYPED_CODEGENOPT(std::string, ThinLTOIndexFile, + "Name of the function summary index file to use for ThinLTO " + "function importing.") + +TYPED_CODEGENOPT( + std::string, ThinLinkBitcodeFile, + "Name of a file that can optionally be written with minimized bitcode to " + "be used as input for the ThinLTO thin link step, which only needs the " + "summary and module symbol table (and not, e.g. any debug metadata).") + +TYPED_CODEGENOPT(std::string, SaveTempsFilePrefix, + "Prefix to use for -save-temps output.") + +TYPED_CODEGENOPT( + std::string, CudaGpuBinaryFileName, + "Name of file passed with -fcuda-include-gpubinary option to forward to " + "CUDA runtime back-end for incorporating them into host-side object file.") + +TYPED_CODEGENOPT(std::string, OptRecordFile, + "The name of the file to which the backend should save YAML " + "optimization records.") + +TYPED_CODEGENOPT(std::string, OptRecordPasses, + "The regex that filters the passes that should be saved to " + "the optimization records.") + +TYPED_CODEGENOPT(std::string, OptRecordFormat, + "The format used for serializing remarks (default: YAML)") + +TYPED_CODEGENOPT( + std::string, SymbolPartition, + "The name of the partition that symbols are assigned to, specified with " + "-fsymbol-partition (see https://lld.llvm.org/Partitions.html).") + +TYPED_CODEGENOPT( + std::shared_ptr, OptimizationRemarkPattern, + "Regular expression to select optimizations for which we should enable " + "optimization remarks. Transformation passes whose name matches this " + "expression (and support this feature), will emit a diagnostic whenever " + "they perform a transformation. This is enabled by the -Rpass=regexp flag.") + +TYPED_CODEGENOPT( + std::shared_ptr, OptimizationRemarkMissedPattern, + "Regular expression to select optimizations for which we should enable " + "missed optimization remarks. Transformation passes whose name matches " + "this expression (and support this feature), will emit a diagnostic " + "whenever they tried but failed to perform a transformation. This is " + "enabled by the -Rpass-missed=regexp flag.") + +TYPED_CODEGENOPT( + std::shared_ptr, OptimizationRemarkAnalysisPattern, + "Regular expression to select optimizations for which we should enable " + "optimization analyses. Transformation passes whose name matches this " + "expression (and support this feature), will emit a diagnostic whenever " + "they want to explain why they decided to apply or not apply a given " + "transformation. This is enabled by the -Rpass-analysis=regexp flag.") + +TYPED_CODEGENOPT(std::vector, RewriteMapFiles, + "Set of files defining the rules for the symbol rewriting.") + +TYPED_CODEGENOPT(SanitizerSet, SanitizeRecover, + "Set of sanitizer checks that are non-fatal (i.e. execution " + "should be continued when possible).") + +TYPED_CODEGENOPT(SanitizerSet, SanitizeTrap, + "Set of sanitizer checks that trap rather than diagnose.") + +TYPED_CODEGENOPT(std::vector, CmdArgs, + "List of backend command-line options for -fembed-bitcode.") + +TYPED_CODEGENOPT(std::vector, NoBuiltinFuncs, + "A list of all -fno-builtin-* function names (e.g., memset).") + +TYPED_CODEGENOPT(std::vector, Reciprocals, "") + +TYPED_CODEGENOPT(std::string, PreferVectorWidth, + "The preferred width for auto-vectorization transforms. This " + "is intended to override default transforms based on the " + "width of the architected vector registers.") + +TYPED_CODEGENOPT(XRayInstrSet, XRayInstrumentationBundle, + "Set of XRay instrumentation kinds to emit.") + +TYPED_CODEGENOPT(std::vector, DefaultFunctionAttrs, "") + +TYPED_CODEGENOPT( + std::vector, PassPlugins, + "List of dynamic shared object files to be loaded as pass plugins.") + +TYPED_CODEGENOPT( + std::vector, SanitizeCoverageAllowlistFiles, + "Path to allowlist file specifying which objects (files, functions) should " + "exclusively be instrumented by sanitizer coverage pass.") + +TYPED_CODEGENOPT(std::vector, SanitizeCoverageBlocklistFiles, + "Path to blocklist file specifying which objects (files, " + "functions) listed for instrumentation by sanitizer coverage " + "pass should actually not be instrumented.") + +TYPED_CODEGENOPT( + const char *, Argv0, + "Executable and command-line used to create a given CompilerInvocation. " + "Most of the time this will be the full -cc1 command.") + +TYPED_CODEGENOPT(ArrayRef, CommandLineArgs, "") + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT +#undef TYPED_CODEGENOPT diff --git a/clang/include/clang/Basic/CommentOptions.h b/clang/include/clang/Basic/CommentOptions.h --- a/clang/include/clang/Basic/CommentOptions.h +++ b/clang/include/clang/Basic/CommentOptions.h @@ -23,14 +23,10 @@ struct CommentOptions { using BlockCommandNamesTy = std::vector; - /// Command names to treat as block commands in comments. - /// Should not include the leading backslash. - BlockCommandNamesTy BlockCommandNames; +#define TYPED_COMMENTOPT(Type, Name, Description) Type Name; +#include "clang/Basic/CommentOptions.def" - /// Treat ordinary comments as documentation comments. - bool ParseAllComments = false; - - CommentOptions() = default; + CommentOptions() : ParseAllComments(false) {} }; } // namespace clang diff --git a/clang/include/clang/Basic/CommentOptions.def b/clang/include/clang/Basic/CommentOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Basic/CommentOptions.def @@ -0,0 +1,26 @@ +//===--- CommentOptions.def - Comment option database -------------*- 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 file defines the comment options. Users of this file must +// define the TYPED_COMMENTOPT macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_COMMENTOPT +#define TYPED_COMMENTOPT(Type, Name, Description) +#endif + +TYPED_COMMENTOPT(BlockCommandNamesTy, BlockCommandNames, + "Command names to treat as vlock commands in comments. Should " + "not include the leading backslash.") + +TYPED_COMMENTOPT(bool, ParseAllComments, + "Treat ordinary comments as documentation comments") + +#undef TYPED_COMMENTOPT diff --git a/clang/include/clang/Basic/DiagnosticOptions.h b/clang/include/clang/Basic/DiagnosticOptions.h --- a/clang/include/clang/Basic/DiagnosticOptions.h +++ b/clang/include/clang/Basic/DiagnosticOptions.h @@ -88,31 +88,9 @@ #include "clang/Basic/DiagnosticOptions.def" public: - /// The file to log diagnostic output to. - std::string DiagnosticLogFile; - - /// The file to serialize diagnostics to (non-appending). - std::string DiagnosticSerializationFile; - - /// The list of -W... options used to alter the diagnostic mappings, with the - /// prefixes removed. - std::vector Warnings; - - /// The list of prefixes from -Wundef-prefix=... used to generate warnings - /// for undefined macros. - std::vector UndefPrefixes; - - /// The list of -R... options used to alter the diagnostic mappings, with the - /// prefixes removed. - std::vector Remarks; - - /// The prefixes for comment directives sought by -verify ("expected" by - /// default). - std::vector VerifyPrefixes; - -public: - // Define accessors/mutators for diagnostic options of enumeration type. +#define TYPED_DIAGOPT(Type, Name, Description) Type Name; #define DIAGOPT(Name, Bits, Default) +// Define accessors/mutators for diagnostic options of enumeration type. #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ Type get##Name() const { return static_cast(Name); } \ void set##Name(Type Value) { Name = static_cast(Value); } diff --git a/clang/include/clang/Basic/DiagnosticOptions.def b/clang/include/clang/Basic/DiagnosticOptions.def --- a/clang/include/clang/Basic/DiagnosticOptions.def +++ b/clang/include/clang/Basic/DiagnosticOptions.def @@ -43,6 +43,10 @@ ENUM_DIAGOPT(Name, Type, Bits, Default) #endif +#ifndef TYPED_DIAGOPT +#define TYPED_DIAGOPT(Type, Name, Description) +#endif + SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0) /// -w DIAGOPT(NoRewriteMacros, 1, 0) /// -Wno-rewrite-macros DIAGOPT(Pedantic, 1, 0) /// -pedantic @@ -95,9 +99,32 @@ /// Column limit for formatting message diagnostics, or 0 if unused. VALUE_DIAGOPT(MessageLength, 32, 0) +TYPED_DIAGOPT(std::string, DiagnosticLogFile, + "The file to log diagnostic output to.") + +TYPED_DIAGOPT(std::string, DiagnosticSerializationFile, + "The file to serialize diagnostics to (non-appending).") + +TYPED_DIAGOPT(std::vector, Warnings, + "The list of -W... options used to alter the diagnostic " + "mappings, with the prefixes removed.") + +TYPED_DIAGOPT(std::vector, UndefPrefixes, + "The list of prefixes from -Wundef-prefix=... used to generate " + "warnings for undefined macros.") + +TYPED_DIAGOPT(std::vector, Remarks, + "The list of -R... options used to alter the diagnostic " + "mappings, with the prefixes removed.") + +TYPED_DIAGOPT(std::vector, VerifyPrefixes, + "The prefixes for comment directives sought by -verify " + "(\"expected\" by /// default).") + #undef DIAGOPT #undef ENUM_DIAGOPT #undef VALUE_DIAGOPT #undef SEMANTIC_DIAGOPT #undef SEMANTIC_ENUM_DIAGOPT #undef SEMANTIC_VALUE_DIAGOPT +#undef TYPED_DIAGOPT diff --git a/clang/include/clang/Basic/FileSystemOptions.h b/clang/include/clang/Basic/FileSystemOptions.h --- a/clang/include/clang/Basic/FileSystemOptions.h +++ b/clang/include/clang/Basic/FileSystemOptions.h @@ -21,9 +21,8 @@ /// Keeps track of options that affect how file operations are performed. class FileSystemOptions { public: - /// If set, paths are resolved as if the working directory was - /// set to the value of WorkingDir. - std::string WorkingDir; +#define TYPED_FILESYSTEMOPT(Type, Name, Description) Type Name; +#include "clang/Basic/FileSystemOptions.def" }; } // end namespace clang diff --git a/clang/include/clang/Basic/FileSystemOptions.def b/clang/include/clang/Basic/FileSystemOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Basic/FileSystemOptions.def @@ -0,0 +1,21 @@ +//===--- FileSystemOptions.def - FileSystem option database -----*- 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 file defines the FileSystem options. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_FILESYSTEMOPT +#error define TYPED_FILESYSTEMOPT macro to hand filesystem options +#endif + +TYPED_FILESYSTEMOPT(std::string, WorkingDir, + "If set, paths are resolved as if the working directory was set " + "to the value of WorkingDir.") + +#undef TYPED_FILESYSTEMOPT diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -227,75 +227,12 @@ }; public: - /// Set of enabled sanitizers. - SanitizerSet Sanitize; - - /// Paths to blacklist files specifying which objects - /// (files, functions, variables) should not be instrumented. - std::vector SanitizerBlacklistFiles; - - /// Paths to the XRay "always instrument" files specifying which - /// objects (files, functions, variables) should be imbued with the XRay - /// "always instrument" attribute. - /// WARNING: This is a deprecated field and will go away in the future. - std::vector XRayAlwaysInstrumentFiles; - - /// Paths to the XRay "never instrument" files specifying which - /// objects (files, functions, variables) should be imbued with the XRay - /// "never instrument" attribute. - /// WARNING: This is a deprecated field and will go away in the future. - std::vector XRayNeverInstrumentFiles; - - /// Paths to the XRay attribute list files, specifying which objects - /// (files, functions, variables) should be imbued with the appropriate XRay - /// attribute(s). - std::vector XRayAttrListFiles; - - clang::ObjCRuntime ObjCRuntime; - - CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified; - - std::string ObjCConstantStringClass; - - /// The name of the handler function to be called when -ftrapv is - /// specified. - /// - /// If none is specified, abort (GCC-compatible behaviour). - std::string OverflowHandler; - - /// The module currently being compiled as specified by -fmodule-name. - std::string ModuleName; - - /// The name of the current module, of which the main source file - /// is a part. If CompilingModule is set, we are compiling the interface - /// of this module, otherwise we are compiling an implementation file of - /// it. This starts as ModuleName in case -fmodule-name is provided and - /// changes during compilation to reflect the current module. - std::string CurrentModule; - - /// The names of any features to enable in module 'requires' decls - /// in addition to the hard-coded list in Module.cpp and the target features. - /// - /// This list is sorted. - std::vector ModuleFeatures; - /// Options for parsing comments. CommentOptions CommentOpts; - /// A list of all -fno-builtin-* function names (e.g., memset). - std::vector NoBuiltinFuncs; - - /// Triples of the OpenMP targets that the host code codegen should - /// take into account in order to generate accurate offloading descriptors. - std::vector OMPTargetTriples; - - /// Name of the IR file that contains the result of the OpenMP target - /// host code generation. - std::string OMPHostIRFile; - - /// Indicates whether the front-end is explicitly told that the - /// input is a header file (i.e. -x c-header). - bool IsHeaderFile = false; +#define LANGOPT(Name, Bits, Default, Description) +#define TYPED_LANGOPT(Type, Name, Description) Type Name; +#include "clang/Basic/LangOptions.def" LangOptions(); diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -78,6 +78,10 @@ COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) #endif +#ifndef TYPED_LANGOPT +#define TYPED_LANGOPT(Type, Name, Descritpion) +#endif + // FIXME: A lot of the BENIGN_ options should be COMPATIBLE_ instead. LANGOPT(C99 , 1, 0, "C99") LANGOPT(C11 , 1, 0, "C11") @@ -384,6 +388,73 @@ LANGOPT(ArmSveVectorBits, 32, 0, "SVE vector size in bits") +TYPED_LANGOPT(SanitizerSet, Sanitize, "Set of enabled sanitizers.") + +TYPED_LANGOPT(std::vector, SanitizerBlacklistFiles, + "Paths to blacklist files specifying which objects (files, " + "functions, variables) should not be instrumented.") + +TYPED_LANGOPT(std::vector, XRayAlwaysInstrumentFiles, + "Paths to the XRay \"always instrument\" files specifying which " + "objects (files, functions, variables) should be imbued with the " + "XRay \"always instrument\" attribute. WARNING: This is a " + "deprecated field and will go away in the future.") + +TYPED_LANGOPT(std::vector, XRayNeverInstrumentFiles, + "Paths to the XRay \"never instrument\" files specifying which " + "objects (files, functions, variables) should be imbued with the " + "XRay \"never instrument\" attribute. WARNING: This is a " + "deprecated field and will go away in the future.") + +TYPED_LANGOPT(std::vector, XRayAttrListFiles, + "Paths to the XRay attribute list files, specifying which " + "objects (files, functions, variables) should be imbued with the " + "appropriate XRay attribute(s).") + +TYPED_LANGOPT(clang::ObjCRuntime, ObjCRuntime, "") + +TYPED_LANGOPT(CoreFoundationABI, CFRuntime, "") + +TYPED_LANGOPT(std::string, ObjCConstantStringClass, "") + +TYPED_LANGOPT( + std::string, OverflowHandler, + "The name of the handler function to be called when -ftrapv is specified. " + "If none is specified, abort (GCC-compatible behaviour).") + +TYPED_LANGOPT( + std::string, ModuleName, + "The module currently being compiled as specified by -fmodule-name.") + +TYPED_LANGOPT( + std::string, CurrentModule, + "The name of the current module, of which the main source file is a part. " + "If CompilingModule is set, we are compiling the interface of this module, " + "otherwise we are compiling an implementation file of it. This starts as " + "ModuleName in case -fmodule-name is provided and changes during " + "compilation to reflect the current module.") + +TYPED_LANGOPT(std::vector, ModuleFeatures, + "The names of any features to enable in module 'requires' decls " + "in addition to the hard-coded list in Module.cpp and the target " + "features. This list is sorted.") + +TYPED_LANGOPT(std::vector, NoBuiltinFuncs, + "A list of all -fno-builtin-* function names (e.g., memset).") + +TYPED_LANGOPT( + std::vector, OMPTargetTriples, + "Triples of the OpenMP targets that the host code codegen should take into " + "account in order to generate accurate offloading descriptors.") + +TYPED_LANGOPT(std::string, OMPHostIRFile, + "Name of the IR file that contains the result of the OpenMP " + "target host code generation.") + +TYPED_LANGOPT(bool, IsHeaderFile, + "Indicates whether the front-end is explicitly told that the " + "input is a header file (i.e. -x c-header).") + #undef LANGOPT #undef COMPATIBLE_LANGOPT #undef BENIGN_LANGOPT @@ -393,3 +464,4 @@ #undef VALUE_LANGOPT #undef COMPATIBLE_VALUE_LANGOPT #undef BENIGN_VALUE_LANGOPT +#undef TYPED_LANGOPT diff --git a/clang/include/clang/Basic/TargetOptions.h b/clang/include/clang/Basic/TargetOptions.h --- a/clang/include/clang/Basic/TargetOptions.h +++ b/clang/include/clang/Basic/TargetOptions.h @@ -25,69 +25,9 @@ /// Options for controlling the target. class TargetOptions { public: - /// The name of the target triple to compile for. - std::string Triple; - - /// When compiling for the device side, contains the triple used to compile - /// for the host. - std::string HostTriple; - - /// If given, the name of the target CPU to generate code for. - std::string CPU; - - /// If given, the name of the target CPU to tune code for. - std::string TuneCPU; - - /// If given, the unit to use for floating point math. - std::string FPMath; - - /// If given, the name of the target ABI to use. - std::string ABI; - - /// The EABI version to use - llvm::EABI EABIVersion; - - /// If given, the version string of the linker in use. - std::string LinkerVersion; - - /// The list of target specific features to enable or disable, as written on the command line. - std::vector FeaturesAsWritten; - - /// The list of target specific features to enable or disable -- this should - /// be a list of strings starting with by '+' or '-'. - std::vector Features; - - /// The map of which features have been enabled disabled based on the command - /// line. - llvm::StringMap FeatureMap; - - /// Supported OpenCL extensions and optional core features. - OpenCLOptions SupportedOpenCLOptions; - - /// The list of OpenCL extensions to enable or disable, as written on - /// the command line. - std::vector OpenCLExtensionsAsWritten; - - /// If given, enables support for __int128_t and __uint128_t types. - bool ForceEnableInt128 = false; - - /// \brief If enabled, use 32-bit pointers for accessing const/local/shared - /// address space. - bool NVPTXUseShortPointers = false; - - // The code model to be used as specified by the user. Corresponds to - // CodeModel::Model enum defined in include/llvm/Support/CodeGen.h, plus - // "default" for the case when the user has not explicitly specified a - // code model. - std::string CodeModel; - - /// The version of the SDK which was used during the compilation. - /// The option is used for two different purposes: - /// * on darwin the version is propagated to LLVM where it's used - /// to support SDK Version metadata (See D55673). - /// * CUDA compilation uses it to control parts of CUDA compilation - /// in clang that depend on specific version of the CUDA SDK. - llvm::VersionTuple SDKVersion; +#define TYPED_TARGETOPT(Type, Name, Description) Type Name; +#include "clang/Basic/TargetOptions.def" + TargetOptions() : ForceEnableInt128(false), NVPTXUseShortPointers(false) {} }; } // end namespace clang diff --git a/clang/include/clang/Basic/TargetOptions.def b/clang/include/clang/Basic/TargetOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Basic/TargetOptions.def @@ -0,0 +1,88 @@ +//===--- TargetOptions.def - Target option database -------------*- 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 file defines the target options. Users of this file must +// define the TYPED_TARGETOPT macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_TARGETOPT +#error Define the TYPED_TARGETOPT macro to handle target options +#endif + +TYPED_TARGETOPT(std::string, Triple, + "The name of the target triple to compile for.") + +TYPED_TARGETOPT( + std::string, HostTriple, + "When compiling for the device side, contains the triple used to " + "compile for the host.") + +TYPED_TARGETOPT(std::string, CPU, + "If given, the name of the target CPU to generate code for.") + +TYPED_TARGETOPT(std::string, TuneCPU, + "If given, the name of the target CPU to tune code for.") + +TYPED_TARGETOPT(std::string, FPMath, + "If given, the unit to use for floating point math.") + +TYPED_TARGETOPT(std::string, ABI, + "If given, the name of the target ABI to use.") + +TYPED_TARGETOPT(llvm::EABI, EABIVersion, "The EABI version to use.") + +TYPED_TARGETOPT(std::string, LinkerVersion, + "If given, the version string of the linker in use.") + +TYPED_TARGETOPT(std::vector, FeaturesAsWritten, + "The list of target specific features to enable or disable, as " + "written on the command line.") + +TYPED_TARGETOPT( + std::vector, Features, + "The list of target specific features to enable or disable -- this " + "should be a list of strings starting with by '+' or '-'.") + +TYPED_TARGETOPT(llvm::StringMap, FeatureMap, + "The map of which features have been enabled disabled based on " + "the command line.") + +TYPED_TARGETOPT(OpenCLOptions, SupportedOpenCLOptions, + "Supported OpenCL extensions and optional core features.") + +TYPED_TARGETOPT( + std::vector, OpenCLExtensionsAsWritten, + "The list of OpenCL extensions to enable or disable, as written on " + "the command line.") + +TYPED_TARGETOPT( + bool, ForceEnableInt128, + "If given, enables support for __int128_t and __uint128_t types.") + +TYPED_TARGETOPT( + bool, NVPTXUseShortPointers, + "If enabled, use 32-bit pointers for accessing const/local/shared " + "address space.") + +TYPED_TARGETOPT( + std::string, CodeModel, + "The code model to be used as specified by the user. Corresponds to " + "CodeModel::Model enum defined in include/llvm/Support/CodeGen.h, " + "plus \"default\" for the case when the user has not explicitly " + "specified a code model.") + +TYPED_TARGETOPT( + llvm::VersionTuple, SDKVersion, + "The version of the SDK which was used during the compilation. The option " + "is used for two different purposes. On Darwin the version is propagated " + "to LLVM where it's used to support SDK Version metadata (See D55673). " + "CUDA compilation uses it to control parts of CUDA compilation in clang " + "that depend on specific version of the CUDA SDK.") + +#undef TYPED_TARGETOPT diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -19,9 +19,10 @@ #include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/MigratorOptions.h" #include "clang/Frontend/PreprocessorOutputOptions.h" +#include "clang/Sema/CodeCompleteOptions.h" #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" #include #include @@ -86,6 +87,9 @@ LangOptions *getLangOpts() { return LangOpts.get(); } const LangOptions *getLangOpts() const { return LangOpts.get(); } + CommentOptions &getCommentOpts() { return LangOpts->CommentOpts; } + const CommentOptions &getCommentOpts() const { return LangOpts->CommentOpts; } + TargetOptions &getTargetOpts() { return *TargetOpts.get(); } const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); } @@ -227,6 +231,14 @@ FrontendOptions &getFrontendOpts() { return FrontendOpts; } const FrontendOptions &getFrontendOpts() const { return FrontendOpts; } + CodeCompleteOptions &getCodeCompleteOpts() { + return FrontendOpts.CodeCompleteOpts; + } + + const CodeCompleteOptions &getCodeCompleteOpts() const { + return FrontendOpts.CodeCompleteOpts; + } + PreprocessorOutputOptions &getPreprocessorOutputOpts() { return PreprocessorOutputOpts; } diff --git a/clang/include/clang/Frontend/DependencyOutputOptions.h b/clang/include/clang/Frontend/DependencyOutputOptions.h --- a/clang/include/clang/Frontend/DependencyOutputOptions.h +++ b/clang/include/clang/Frontend/DependencyOutputOptions.h @@ -24,49 +24,15 @@ /// file generation. class DependencyOutputOptions { public: - unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies. - unsigned ShowHeaderIncludes : 1; ///< Show header inclusions (-H). - unsigned UsePhonyTargets : 1; ///< Include phony targets for each - /// dependency, which can avoid some 'make' - /// problems. - unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list - unsigned IncludeModuleFiles : 1; ///< Include module file dependencies. - - /// Destination of cl.exe style /showIncludes info. - ShowIncludesDestination ShowIncludesDest = ShowIncludesDestination::None; - - /// The format for the dependency file. - DependencyOutputFormat OutputFormat = DependencyOutputFormat::Make; - - /// The file to write dependency output to. - std::string OutputFile; - - /// The file to write header include output to. This is orthogonal to - /// ShowHeaderIncludes (-H) and will include headers mentioned in the - /// predefines buffer. If the output file is "-", output will be sent to - /// stderr. - std::string HeaderIncludeOutputFile; - - /// A list of names to use as the targets in the dependency file; this list - /// must contain at least one entry. - std::vector Targets; - - /// A list of filenames to be used as extra dependencies for every target. - std::vector ExtraDeps; - - /// In /showIncludes mode, pretend the main TU is a header with this name. - std::string ShowIncludesPretendHeader; - - /// The file to write GraphViz-formatted header dependencies to. - std::string DOTOutputFile; - - /// The directory to copy module dependencies to when collecting them. - std::string ModuleDependencyOutputDir; - +#define TYPED_DEPENDENCY_OUTPUTOPT(Type, Name, Description) Type Name; +#define DEPENDENCY_OUTPUTOPT(Name, Bits, Description) unsigned Name : Bits; +#include "clang/Frontend/DependencyOutputOptions.def" public: DependencyOutputOptions() : IncludeSystemHeaders(0), ShowHeaderIncludes(0), UsePhonyTargets(0), - AddMissingHeaderDeps(0), IncludeModuleFiles(0) {} + AddMissingHeaderDeps(0), IncludeModuleFiles(0), + ShowIncludesDest(ShowIncludesDestination::None), + OutputFormat(DependencyOutputFormat::Make) {} }; } // end namespace clang diff --git a/clang/include/clang/Frontend/DependencyOutputOptions.def b/clang/include/clang/Frontend/DependencyOutputOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Frontend/DependencyOutputOptions.def @@ -0,0 +1,50 @@ +//===--- DependencyOutputOptions.def -------------------------------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 file contains the DependencyOutput options, to use this file one needs +// to define the TYPED_DEPENDENCY_OUTPUTOPT and/or the DEPENDECY_OUTPUTOPT macro +// to get more information about bitfields. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_DEPENDENCY_OUTPUTOPT +#define TYPED_DEPENDENCY_OUTPUTOPT(Type, Name, Description) +#endif + +#ifndef DEPENDENCY_OUTPUTOPT +#define DEPENDENCY_OUTPUTOPT(Name, Bits, Description) \ + TYPED_DEPENDENCY_OUTPUTOPT(unsigned, Name, Description) +#endif + +DEPENDENCY_OUTPUTOPT(IncludeSystemHeaders, 1, "Include system header dependencies.") +DEPENDENCY_OUTPUTOPT(ShowHeaderIncludes, 1, "Show header inclusions (-H).") +DEPENDENCY_OUTPUTOPT(UsePhonyTargets, 1, "Include phony targets for each dependency, which can " + "avoid some 'make' problems.") +DEPENDENCY_OUTPUTOPT(AddMissingHeaderDeps, 1, "Add missing headers to dependency list.") +DEPENDENCY_OUTPUTOPT(IncludeModuleFiles, 1, "Include module file dependencies.") + +TYPED_DEPENDENCY_OUTPUTOPT(ShowIncludesDestination, ShowIncludesDest, "Destination of cl.exe style /showIncludes info.") + +TYPED_DEPENDENCY_OUTPUTOPT(DependencyOutputFormat, OutputFormat, "The format for the dependency file") + +TYPED_DEPENDENCY_OUTPUTOPT(std::string, OutputFile, "The file to write dependency output to.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::string, HeaderIncludeOutputFile, "The file to write header include output to. This is orthogonal to ShowHeaderIncludes (-H) and will include headers mentioned in the predefines buffer. If the output file is \"-\", output will be sent to stderr.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::vector, Targets, "A list of names to use as the targets in the dependency file; this list must contain at least one entry.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::vector, ExtraDeps, "A list of filenames to be used as extra dependencies for every target.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::string, ShowIncludesPretendHeader, "In /showIncludes mode, pretend the main TU is a header with this name.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::string, DOTOutputFile, "The file to write GraphViz-formatted header dependencies to.") + +TYPED_DEPENDENCY_OUTPUTOPT(std::string, ModuleDependencyOutputDir, "The directory to copy module dependencies to when collecting them.") + +#undef TYPED_DEPENDENCY_OUTPUTOPT +#undef DEPENDENCY_OUTPUTOPT \ No newline at end of file diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -226,94 +226,14 @@ /// FrontendOptions - Options for controlling the behavior of the frontend. class FrontendOptions { public: - /// Disable memory freeing on exit. - unsigned DisableFree : 1; + using PluginArgsTy = + std::unordered_map>; - /// When generating PCH files, instruct the AST writer to create relocatable - /// PCH files. - unsigned RelocatablePCH : 1; - - /// Show the -help text. - unsigned ShowHelp : 1; - - /// Show frontend performance metrics and statistics. - unsigned ShowStats : 1; - - /// Show timers for individual actions. - unsigned ShowTimers : 1; - - /// print the supported cpus for the current target - unsigned PrintSupportedCPUs : 1; - - /// Output time trace profile. - unsigned TimeTrace : 1; - - /// Show the -version text. - unsigned ShowVersion : 1; - - /// Apply fixes even if there are unfixable errors. - unsigned FixWhatYouCan : 1; - - /// Apply fixes only for warnings. - unsigned FixOnlyWarnings : 1; - - /// Apply fixes and recompile. - unsigned FixAndRecompile : 1; - - /// Apply fixes to temporary files. - unsigned FixToTemporaries : 1; - - /// Emit ARC errors even if the migrator can fix them. - unsigned ARCMTMigrateEmitARCErrors : 1; - - /// Skip over function bodies to speed up parsing in cases you do not need - /// them (e.g. with code completion). - unsigned SkipFunctionBodies : 1; - - /// Whether we can use the global module index if available. - unsigned UseGlobalModuleIndex : 1; - - /// Whether we can generate the global module index if needed. - unsigned GenerateGlobalModuleIndex : 1; - - /// Whether we include declaration dumps in AST dumps. - unsigned ASTDumpDecls : 1; - - /// Whether we deserialize all decls when forming AST dumps. - unsigned ASTDumpAll : 1; - - /// Whether we include lookup table dumps in AST dumps. - unsigned ASTDumpLookups : 1; - - /// Whether we include declaration type dumps in AST dumps. - unsigned ASTDumpDeclTypes : 1; - - /// Whether we are performing an implicit module build. - unsigned BuildingImplicitModule : 1; - - /// Whether we should embed all used files into the PCM file. - unsigned ModulesEmbedAllFiles : 1; - - /// Whether timestamps should be written to the produced PCH file. - unsigned IncludeTimestamps : 1; - - /// Should a temporary file be used during compilation. - unsigned UseTemporary : 1; - - /// When using -emit-module, treat the modulemap as a system module. - unsigned IsSystemModule : 1; + using InputsTy = llvm::SmallVector; CodeCompleteOptions CodeCompleteOpts; - /// Specifies the output format of the AST. - ASTDumpOutputFormat ASTDumpFormat = ADOF_Default; - - enum { - ARCMT_None, - ARCMT_Check, - ARCMT_Modify, - ARCMT_Migrate - } ARCMTAction = ARCMT_None; + enum { ARCMT_None, ARCMT_Check, ARCMT_Modify, ARCMT_Migrate }; enum { ObjCMT_None = 0, @@ -360,92 +280,18 @@ /// Enable converting setter/getter expressions to property-dot syntx. ObjCMT_PropertyDotSyntax = 0x1000, - ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | - ObjCMT_Annotation | ObjCMT_Instancetype | - ObjCMT_NsMacros | ObjCMT_ProtocolConformance | - ObjCMT_NsAtomicIOSOnlyProperty | - ObjCMT_DesignatedInitializer), + ObjCMT_MigrateDecls = + (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | + ObjCMT_Annotation | ObjCMT_Instancetype | ObjCMT_NsMacros | + ObjCMT_ProtocolConformance | ObjCMT_NsAtomicIOSOnlyProperty | + ObjCMT_DesignatedInitializer), ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax) }; - unsigned ObjCMTAction = ObjCMT_None; - std::string ObjCMTWhiteListPath; - - std::string MTMigrateDir; - std::string ARCMTMigrateReportOut; - - /// The input files and their types. - SmallVector Inputs; - - /// When the input is a module map, the original module map file from which - /// that map was inferred, if any (for umbrella modules). - std::string OriginalModuleMap; - - /// The output file, if any. - std::string OutputFile; - - /// If given, the new suffix for fix-it rewritten files. - std::string FixItSuffix; - - /// If given, filter dumped AST Decl nodes by this substring. - std::string ASTDumpFilter; - - /// If given, enable code completion at the provided location. - ParsedSourceLocation CodeCompletionAt; - - /// The frontend action to perform. - frontend::ActionKind ProgramAction = frontend::ParseSyntaxOnly; - - /// The name of the action to run when using a plugin action. - std::string ActionName; - - /// Args to pass to the plugins - std::unordered_map> PluginArgs; - - /// The list of plugin actions to run in addition to the normal action. - std::vector AddPluginActions; - - /// The list of plugins to load. - std::vector Plugins; - - /// The list of module file extensions. - std::vector> ModuleFileExtensions; - - /// The list of module map files to load before processing the input. - std::vector ModuleMapFiles; - - /// The list of additional prebuilt module files to load before - /// processing the input. - std::vector ModuleFiles; - - /// The list of files to embed into the compiled module file. - std::vector ModulesEmbedFiles; - - /// The list of AST files to merge. - std::vector ASTMergeFiles; - - /// A list of arguments to forward to LLVM's option processing; this - /// should only be used for debugging and experimental features. - std::vector LLVMArgs; - - /// File name of the file that will provide record layouts - /// (in the format produced by -fdump-record-layouts). - std::string OverrideRecordLayoutsFile; - - /// Auxiliary triple for CUDA/HIP compilation. - std::string AuxTriple; - - /// Auxiliary target CPU for CUDA/HIP compilation. - Optional AuxTargetCPU; - - /// Auxiliary target features for CUDA/HIP compilation. - Optional> AuxTargetFeatures; - - /// Filename to write statistics to. - std::string StatsFile; - /// Minimum time granularity (in microseconds) traced by time profiler. - unsigned TimeTraceGranularity; +#define FRONTENDOPT(Name, Bits, Description) unsigned Name : Bits; +#define TYPED_FRONTENDOPT(Type, Name, Description) Type Name; +#include "clang/Frontend/FrontendOptions.def" public: FrontendOptions() @@ -453,11 +299,14 @@ ShowStats(false), ShowTimers(false), TimeTrace(false), ShowVersion(false), FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), FixToTemporaries(false), - ARCMTMigrateEmitARCErrors(false), SkipFunctionBodies(false), - UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true), - ASTDumpDecls(false), ASTDumpLookups(false), - BuildingImplicitModule(false), ModulesEmbedAllFiles(false), - IncludeTimestamps(true), UseTemporary(true), TimeTraceGranularity(500) {} + ARCMTAction(ARCMT_None), ARCMTMigrateEmitARCErrors(false), + SkipFunctionBodies(false), UseGlobalModuleIndex(true), + GenerateGlobalModuleIndex(true), ASTDumpDecls(false), + ASTDumpLookups(false), BuildingImplicitModule(false), + ModulesEmbedAllFiles(false), IncludeTimestamps(true), + UseTemporary(true), ASTDumpFormat(ADOF_Default), + ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly), + TimeTraceGranularity(500), DashX() {} /// getInputKindForExtension - Return the appropriate input kind for a file /// extension. For example, "c" would return Language::C. diff --git a/clang/include/clang/Frontend/FrontendOptions.def b/clang/include/clang/Frontend/FrontendOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Frontend/FrontendOptions.def @@ -0,0 +1,179 @@ +//===--- FrontendOptions.def - FileSystem option database -----*- 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 file defines the Frontend options. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_FRONTENDOPT +#define TYPED_FRONTENDOPT(Type, Name, Description) +#endif + +#ifndef FRONTENDOPT +#define FRONTENDOPT(Name, Bits, Description) \ + TYPED_FRONTENDOPT(unsigned, Name, Description) +#endif + +FRONTENDOPT(DisableFree, 1, "Disable memory freeing on exit.") + +FRONTENDOPT(RelocatablePCH, 1, + "When generating PCH files, instruct the AST writer to create " + "relocatable PCH files.") + +FRONTENDOPT(ShowHelp, 1, "Show the -help text.") + +FRONTENDOPT(ShowStats, 1, "Show frontend performance metrics and statistics.") + +FRONTENDOPT(ShowTimers, 1, "Show timers for individual actions.") + +FRONTENDOPT(PrintSupportedCPUs, 1, + "print the supported cpus for the current target") + +FRONTENDOPT(TimeTrace, 1, "Output time trace profile.") + +FRONTENDOPT(ShowVersion, 1, "Show the -version text.") + +FRONTENDOPT(FixWhatYouCan, 1, "Apply fixes even if there are unfixable errors.") + +FRONTENDOPT(FixOnlyWarnings, 1, "Apply fixes only for warnings.") + +FRONTENDOPT(FixAndRecompile, 1, "Apply fixes and recompile.") + +FRONTENDOPT(FixToTemporaries, 1, "Apply fixes to temporary files.") + +FRONTENDOPT(ARCMTAction, 3, "") + +FRONTENDOPT(ARCMTMigrateEmitARCErrors, 1, + "Emit ARC errors even if the migrator can fix them.") + +FRONTENDOPT(SkipFunctionBodies, 1, + "Skip over function bodies to speed up parsing in cases you do not " + "need them (e.g. with code completion).") + +FRONTENDOPT(UseGlobalModuleIndex, 1, + "Whether we can use the global module index if available.") + +FRONTENDOPT(GenerateGlobalModuleIndex, 1, + "Whether we can generate the global module index if needed.") + +FRONTENDOPT(ASTDumpDecls, 1, + "Whether we include declaration dumps in AST dumps.") + +FRONTENDOPT(ASTDumpAll, 1, + "Whether we deserialize all decls when forming AST dumps.") + +FRONTENDOPT(ASTDumpLookups, 1, + "Whether we include lookup table dumps in AST dumps.") + +FRONTENDOPT(ASTDumpDeclTypes, 1, + "Whether we include declaration type dumps in AST dumps.") + +FRONTENDOPT(BuildingImplicitModule, 1, + "Whether we are performing an implicit module build.") + +FRONTENDOPT(ModulesEmbedAllFiles, 1, + "Whether we should embed all used files into the PCM file.") + +FRONTENDOPT(IncludeTimestamps, 1, + "Whether timestamps should be written to the produced PCH file.") + +FRONTENDOPT(UseTemporary, 1, + "Should a temporary file be used during compilation.") + +FRONTENDOPT(IsSystemModule, 1, + "When using -emit-module, treat the modulemap as a system module.") + +TYPED_FRONTENDOPT(ASTDumpOutputFormat, ASTDumpFormat, + "Specifies the output format of the AST.") + +TYPED_FRONTENDOPT(unsigned, ObjCMTAction, "") + +TYPED_FRONTENDOPT(std::string, ObjCMTWhiteListPath, "") + +TYPED_FRONTENDOPT(std::string, MTMigrateDir, "") + +TYPED_FRONTENDOPT(std::string, ARCMTMigrateReportOut, "") + +TYPED_FRONTENDOPT(InputsTy, Inputs, "The input files and their types.") + +TYPED_FRONTENDOPT( + std::string, OriginalModuleMap, + "When the input is a module map, the original module map file from which " + "that map was inferred, if any (for umbrella modules).") + +TYPED_FRONTENDOPT(std::string, OutputFile, "The output file, if any.") + +TYPED_FRONTENDOPT(std::string, FixItSuffix, + "If given, the new suffix for fix-it rewritten files.") + +TYPED_FRONTENDOPT(std::string, ASTDumpFilter, + "If given, filter dumped AST Decl nodes by this substring.") + +TYPED_FRONTENDOPT(ParsedSourceLocation, CodeCompletionAt, + "If given, enable code completion at the provided location.") + +TYPED_FRONTENDOPT(frontend::ActionKind, ProgramAction, + "The frontend action to perform.") + +TYPED_FRONTENDOPT(std::string, ActionName, + "The name of the action to run when using a plugin action.") + +TYPED_FRONTENDOPT(PluginArgsTy, PluginArgs, "Args to pass to the plugins") + +TYPED_FRONTENDOPT( + std::vector, AddPluginActions, + "The list of plugin actions to run in addition to the normal action.") + +TYPED_FRONTENDOPT(std::vector, Plugins, + "The list of plugins to load.") + +TYPED_FRONTENDOPT(std::vector>, + ModuleFileExtensions, "The list of module file extensions.") + +TYPED_FRONTENDOPT( + std::vector, ModuleMapFiles, + "The list of module map files to load before processing the input.") + +TYPED_FRONTENDOPT(std::vector, ModuleFiles, + "The list of additional prebuilt module files to load before " + "processing the input.") + +TYPED_FRONTENDOPT(std::vector, ModulesEmbedFiles, + "The list of files to embed into the compiled module file.") + +TYPED_FRONTENDOPT(std::vector, ASTMergeFiles, + "The list of AST files to merge.") + +TYPED_FRONTENDOPT( + std::vector, LLVMArgs, + "A list of arguments to forward to LLVM's option processing; this should " + "only be used for debugging and experimental features.") + +TYPED_FRONTENDOPT(std::string, OverrideRecordLayoutsFile, + "File name of the file that will provide record layouts (in " + "the format produced by -fdump-record-layouts).") + +TYPED_FRONTENDOPT(std::string, AuxTriple, + "Auxiliary triple for CUDA/HIP compilation.") + +TYPED_FRONTENDOPT(Optional, AuxTargetCPU, + "Auxiliary target CPU for CUDA/HIP compilation.") + +TYPED_FRONTENDOPT(Optional>, AuxTargetFeatures, + "Auxiliary target features for CUDA/HIP compilation.") + +TYPED_FRONTENDOPT(std::string, StatsFile, "Filename to write statistics to.") + +TYPED_FRONTENDOPT( + unsigned, TimeTraceGranularity, + "Minimum time granularity (in microseconds) traced by time profiler.") + +TYPED_FRONTENDOPT(InputKind, DashX, "Input Kind") + +#undef TYPED_FRONTENDOPT +#undef FRONTENDOPT \ No newline at end of file diff --git a/clang/include/clang/Frontend/MigratorOptions.h b/clang/include/clang/Frontend/MigratorOptions.h --- a/clang/include/clang/Frontend/MigratorOptions.h +++ b/clang/include/clang/Frontend/MigratorOptions.h @@ -18,13 +18,10 @@ class MigratorOptions { public: - unsigned NoNSAllocReallocError : 1; - unsigned NoFinalizeRemoval : 1; - MigratorOptions() { - NoNSAllocReallocError = 0; - NoFinalizeRemoval = 0; - } -}; +#define MIGRATOROPT(Name, Bits, Description) unsigned Name : Bits; +#include "clang/Frontend/MigratorOptions.def" + MigratorOptions() : NoNSAllocReallocError(0), NoFinalizeRemoval(0) {} +}; } #endif diff --git a/clang/include/clang/Frontend/MigratorOptions.def b/clang/include/clang/Frontend/MigratorOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Frontend/MigratorOptions.def @@ -0,0 +1,27 @@ +//===--- MigratorOptions.def - Migrator option database ---------*- 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 file defines the migrator options. Users of this file must +// define the TYPED_MIGRATOROPT macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_MIGRATOROPT +#define TYPED_MIGRATOROPT(Type, Name, Description) +#endif + +#ifndef MIGRATOROPT +#define MIGRATOROPT(Name, Bits, Description) \ + TYPED_MIGRATOROPT(unsigned, Name, Description) +#endif + +MIGRATOROPT(NoNSAllocReallocError, 1, "") +MIGRATOROPT(NoFinalizeRemoval, 1, "") + +#undef TYPED_MIGRATOROPT +#undef MIGRATOROPT diff --git a/clang/include/clang/Frontend/PreprocessorOutputOptions.h b/clang/include/clang/Frontend/PreprocessorOutputOptions.h --- a/clang/include/clang/Frontend/PreprocessorOutputOptions.h +++ b/clang/include/clang/Frontend/PreprocessorOutputOptions.h @@ -15,15 +15,9 @@ /// output (e.g., -E). class PreprocessorOutputOptions { public: - unsigned ShowCPP : 1; ///< Print normal preprocessed output. - unsigned ShowComments : 1; ///< Show comments. - unsigned ShowLineMarkers : 1; ///< Show \#line markers. - unsigned UseLineDirectives : 1; ///< Use \#line instead of GCC-style \# N. - unsigned ShowMacroComments : 1; ///< Show comments, even in macros. - unsigned ShowMacros : 1; ///< Print macro definitions. - unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output. - unsigned RewriteIncludes : 1; ///< Preprocess include directives only. - unsigned RewriteImports : 1; ///< Include contents of transitively-imported modules. +#define PREPROCESSOR_OUTPUTOPT(Name, Bits, Description) unsigned Name : Bits; +#define TYPED_PREPROCESSOR_OUTPUTOPT(Type, Name, Description) Type Name; +#include "clang/Frontend/PreprocessorOutputOptions.def" public: PreprocessorOutputOptions() { diff --git a/clang/include/clang/Frontend/PreprocessorOutputOptions.def b/clang/include/clang/Frontend/PreprocessorOutputOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Frontend/PreprocessorOutputOptions.def @@ -0,0 +1,46 @@ +//=== PreprocessorOutputOptions.def - FileSystem option database -*- 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 file defines the PreprocessorOutput options. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_PREPROCESSOR_OUTPUTOPT +#define TYPED_PREPROCESSOR_OUTPUTOPT(Type, Name, Description) +#endif + +#ifndef PREPROCESSOR_OUTPUTOPT +#define PREPROCESSOR_OUTPUTOPT(Name, Bits, Description) \ + TYPED_PREPROCESSOR_OUTPUTOPT(unsigned, Name, Description) +#endif + +PREPROCESSOR_OUTPUTOPT(ShowCPP, 1, "Print normal preprocessed output.") + +PREPROCESSOR_OUTPUTOPT(ShowComments, 1, "Show comments.") + +PREPROCESSOR_OUTPUTOPT(ShowLineMarkers, 1, "Show \#line markers.") + +PREPROCESSOR_OUTPUTOPT(UseLineDirectives, 1, + "Use \#line instead of GCC-style \# N.") + +PREPROCESSOR_OUTPUTOPT(ShowMacroComments, 1, "Show comments, even in macros.") + +PREPROCESSOR_OUTPUTOPT(ShowMacros, 1, "Print macro definitions.") + +PREPROCESSOR_OUTPUTOPT( + ShowIncludeDirectives, 1, + "Print includes, imports etc. within preprocessed output.") + +PREPROCESSOR_OUTPUTOPT(RewriteIncludes, 1, + "Preprocess include directives only.") + +PREPROCESSOR_OUTPUTOPT(RewriteImports, 1, + "Include contents of transitively-imported modules.") + +#undef TYPED_PREPROCESSOR_OUTPUTOPT +#undef PREPROCESSOR_OUTPUTOPT \ No newline at end of file diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h --- a/clang/include/clang/Lex/HeaderSearchOptions.h +++ b/clang/include/clang/Lex/HeaderSearchOptions.h @@ -94,125 +94,14 @@ : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} }; - /// If non-empty, the directory to use as a "virtual system root" for include - /// paths. - std::string Sysroot; - - /// User specified include entries. - std::vector UserEntries; - - /// User-specified system header prefixes. - std::vector SystemHeaderPrefixes; - - /// The directory which holds the compiler resource files (builtin includes, - /// etc.). - std::string ResourceDir; + using PrebuiltModuleFilesTy = std::map>; - /// The directory used for the module cache. - std::string ModuleCachePath; - - /// The directory used for a user build. - std::string ModuleUserBuildPath; - - /// The mapping of module names to prebuilt module files. - std::map> PrebuiltModuleFiles; - - /// The directories used to load prebuilt module files. - std::vector PrebuiltModulePaths; - - /// The module/pch container format. - std::string ModuleFormat; - - /// Whether we should disable the use of the hash string within the - /// module cache. - /// - /// Note: Only used for testing! - unsigned DisableModuleHash : 1; - - /// Implicit module maps. This option is enabld by default when - /// modules is enabled. - unsigned ImplicitModuleMaps : 1; - - /// Set the 'home directory' of a module map file to the current - /// working directory (or the home directory of the module map file that - /// contained the 'extern module' directive importing this module map file - /// if any) rather than the directory containing the module map file. - // - /// The home directory is where we look for files named in the module map - /// file. - unsigned ModuleMapFileHomeIsCwd : 1; - - /// The interval (in seconds) between pruning operations. - /// - /// This operation is expensive, because it requires Clang to walk through - /// the directory structure of the module cache, stat()'ing and removing - /// files. - /// - /// The default value is large, e.g., the operation runs once a week. - unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60; - - /// The time (in seconds) after which an unused module file will be - /// considered unused and will, therefore, be pruned. - /// - /// When the module cache is pruned, any module file that has not been - /// accessed in this many seconds will be removed. The default value is - /// large, e.g., a month, to avoid forcing infrequently-used modules to be - /// regenerated often. - unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60; - - /// The time in seconds when the build session started. - /// - /// This time is used by other optimizations in header search and module - /// loading. - uint64_t BuildSessionTimestamp = 0; - - /// The set of macro names that should be ignored for the purposes - /// of computing the module hash. - llvm::SmallSetVector ModulesIgnoreMacros; - - /// The set of user-provided virtual filesystem overlay files. - std::vector VFSOverlayFiles; - - /// Include the compiler builtin includes. - unsigned UseBuiltinIncludes : 1; - - /// Include the system standard include search directories. - unsigned UseStandardSystemIncludes : 1; - - /// Include the system standard C++ library include search directories. - unsigned UseStandardCXXIncludes : 1; - - /// Use libc++ instead of the default libstdc++. - unsigned UseLibcxx : 1; - - /// Whether header search information should be output as for -v. - unsigned Verbose : 1; - - /// If true, skip verifying input files used by modules if the - /// module was already verified during this build session (see - /// \c BuildSessionTimestamp). - unsigned ModulesValidateOncePerBuildSession : 1; - - /// Whether to validate system input files when a module is loaded. - unsigned ModulesValidateSystemHeaders : 1; + using ModulesIgnoreMacrosTy = + llvm::SmallSetVector; - // Whether the content of input files should be hashed and used to - // validate consistency. - unsigned ValidateASTInputFilesContent : 1; - - /// Whether the module includes debug information (-gmodules). - unsigned UseDebugInfo : 1; - - unsigned ModulesValidateDiagnosticOptions : 1; - - unsigned ModulesHashContent : 1; - - /// Whether we should include all things that could impact the module in the - /// hash. - /// - /// This includes things like the full header search path, and enabled - /// diagnostics. - unsigned ModulesStrictContextHash : 1; +#define HEADERSEARCHOPT(Name, Bits, Description) unsigned Name : Bits; +#define TYPED_HEADERSEARCHOPT(Type, Name, Description) Type Name; +#include "clang/Lex/HeaderSearchOptions.def" HeaderSearchOptions(StringRef _Sysroot = "/") : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false), @@ -223,7 +112,9 @@ ModulesValidateSystemHeaders(false), ValidateASTInputFilesContent(false), UseDebugInfo(false), ModulesValidateDiagnosticOptions(true), ModulesHashContent(false), - ModulesStrictContextHash(false) {} + ModulesStrictContextHash(false), + ModuleCachePruneInterval(7 * 24 * 60 * 60), + ModuleCachePruneAfter(31 * 24 * 60 * 60), BuildSessionTimestamp(0) {} /// AddPath - Add the \p Path path to the specified \p Group list. void AddPath(StringRef Path, frontend::IncludeDirGroup Group, diff --git a/clang/include/clang/Lex/HeaderSearchOptions.def b/clang/include/clang/Lex/HeaderSearchOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Lex/HeaderSearchOptions.def @@ -0,0 +1,136 @@ +//===--- HeaderSearchOptions.def - HeaderSearch option database -*- 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 file defines the header search options. Users of this file must +// define the HEADERSEARCHOPT macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef HEADERSEARCHOPT +#define HEADERSEARCHOPT(Name, Bits, Description) \ + TYPED_HEADERSEARCHOPT(unsigned, Name, Description) +#endif + +#ifndef TYPED_HEADERSEARCHOPT +#define TYPED_HEADERSEARCHOPT(Type, Name, Description) +#endif + +TYPED_HEADERSEARCHOPT(std::string, Sysroot, + "If non-empty, the directory to use as a \"virtual " + "system root\" for include paths.") + +TYPED_HEADERSEARCHOPT(std::string, ModuleFormat, + "The module/pch container format.") + +HEADERSEARCHOPT(DisableModuleHash, 1, + "Whether we should disable the use of the hash string within " + "the module cache. Note: Only used for testing!") + +HEADERSEARCHOPT(ImplicitModuleMaps, 1, + "Implicit module maps. This option is enabld by default when " + "modules is enabled.") + +HEADERSEARCHOPT( + ModuleMapFileHomeIsCwd, 1, + "Set the 'home directory' of a module map file to the current working " + "directory (or the home directory of the module map file that contained " + "the 'extern module' directive importing this module map file if any) " + "rather than the directory containing the module map file. The home " + "directory is where we look for files named in the module map file.") + +HEADERSEARCHOPT(UseBuiltinIncludes, 1, "Include the compiler builtin includes.") + +HEADERSEARCHOPT(UseStandardSystemIncludes, 1, + "Include the system standard include search directories.") + +HEADERSEARCHOPT( + UseStandardCXXIncludes, 1, + "Include the system standard C++ library include search directories.") + +HEADERSEARCHOPT(UseLibcxx, 1, "Use libc++ instead of the default libstdc++.") + +HEADERSEARCHOPT(Verbose, 1, + "Whether header search information should be output as for -v.") + +HEADERSEARCHOPT( + ModulesValidateOncePerBuildSession, 1, + "If true, skip verifying input files used by modules if the module was " + "already verified during this build session (see BuildSessionTimestamp).") + +HEADERSEARCHOPT( + ModulesValidateSystemHeaders, 1, + "Whether to validate system input files when a module is loaded.") + +HEADERSEARCHOPT(ValidateASTInputFilesContent, 1, + "Whether the content of input files should be hashed and used " + "to validate consistency.") + +HEADERSEARCHOPT(UseDebugInfo, 1, + "Whether the module includes debug information (-gmodules).") + +HEADERSEARCHOPT(ModulesValidateDiagnosticOptions, 1, "") + +HEADERSEARCHOPT(ModulesHashContent, 1, "") + +HEADERSEARCHOPT(ModulesStrictContextHash, 1, + "Whether we should include all things that could impact the " + "module in the hash. This includes things like the full header " + "search path, and enabled diagnostics.") + +TYPED_HEADERSEARCHOPT(std::vector, UserEntries, + "User specified include entries.") + +TYPED_HEADERSEARCHOPT(std::vector, SystemHeaderPrefixes, + "User-specified system header prefixes.") + +TYPED_HEADERSEARCHOPT(std::string, ResourceDir, + "The directory which holds the compiler resource files " + "(builtin includes, etc.).") + +TYPED_HEADERSEARCHOPT(std::string, ModuleCachePath, + "The directory used for the module cache.") + +TYPED_HEADERSEARCHOPT(std::string, ModuleUserBuildPath, + "The directory used for a user build.") + +TYPED_HEADERSEARCHOPT(PrebuiltModuleFilesTy, PrebuiltModuleFiles, + "The mapping of module names to prebuilt module files.") + +TYPED_HEADERSEARCHOPT(std::vector, PrebuiltModulePaths, + "The directories used to load prebuilt module files.") + +TYPED_HEADERSEARCHOPT( + unsigned, ModuleCachePruneInterval, + "The interval (in seconds) between pruning operations. This operation is " + "expensive, because it requires Clang to walk through the directory " + "structure of the module cache, stat()'ing and removing files. The " + "default value is large, e.g., the operation runs once a week.") + +TYPED_HEADERSEARCHOPT( + unsigned, ModuleCachePruneAfter, + "The time (in seconds) after which an unused module file will be " + "considered unused and will, therefore, be pruned. When the module cache " + "is pruned, any module file that has not been accessed in this many " + "seconds will be removed. The default value is large, e.g., a month, to " + "avoid forcing infrequently-used modules to be regenerated often.") + +TYPED_HEADERSEARCHOPT( + uint64_t, BuildSessionTimestamp, + "The time in seconds when the build session started. This time is used " + "by other optimizations in header search and module loading.") + +TYPED_HEADERSEARCHOPT(ModulesIgnoreMacrosTy, ModulesIgnoreMacros, + "The set of macro names that should be ignored for the " + "purposes of computing the module hash.") + +TYPED_HEADERSEARCHOPT( + std::vector, VFSOverlayFiles, + "The set of user-provided virtual filesystem overlay files.") + +#undef HEADERSEARCHOPT +#undef TYPED_HEADERSEARCHOPT diff --git a/clang/include/clang/Lex/PreprocessorOptions.h b/clang/include/clang/Lex/PreprocessorOptions.h --- a/clang/include/clang/Lex/PreprocessorOptions.h +++ b/clang/include/clang/Lex/PreprocessorOptions.h @@ -44,114 +44,13 @@ /// used in preprocessor initialization to InitializePreprocessor(). class PreprocessorOptions { public: - std::vector> Macros; - std::vector Includes; - std::vector MacroIncludes; - - /// Initialize the preprocessor with the compiler and target specific - /// predefines. - bool UsePredefines = true; - - /// Whether we should maintain a detailed record of all macro - /// definitions and expansions. - bool DetailedRecord = false; - - /// When true, we are creating or using a PCH where a #pragma hdrstop is - /// expected to indicate the beginning or end of the PCH. - bool PCHWithHdrStop = false; - - /// When true, we are creating a PCH or creating the PCH object while - /// expecting a #pragma hdrstop to separate the two. Allow for a - /// missing #pragma hdrstop, which generates a PCH for the whole file, - /// and creates an empty PCH object. - bool PCHWithHdrStopCreate = false; - - /// If non-empty, the filename used in an #include directive in the primary - /// source file (or command-line preinclude) that is used to implement - /// MSVC-style precompiled headers. When creating a PCH, after the #include - /// of this header, the PCH generation stops. When using a PCH, tokens are - /// skipped until after an #include of this header is seen. - std::string PCHThroughHeader; - - /// The implicit PCH included at the start of the translation unit, or empty. - std::string ImplicitPCHInclude; - - /// Headers that will be converted to chained PCHs in memory. - std::vector ChainedIncludes; - - /// When true, disables most of the normal validation performed on - /// precompiled headers. - bool DisablePCHValidation = false; - - /// When true, a PCH with compiler errors will not be rejected. - bool AllowPCHWithCompilerErrors = false; - - /// Dump declarations that are deserialized from PCH, for testing. - bool DumpDeserializedPCHDecls = false; - - /// This is a set of names for decls that we do not want to be - /// deserialized, and we emit an error if they are; for testing purposes. - std::set DeserializedPCHDeclsToErrorOn; - - /// If non-zero, the implicit PCH include is actually a precompiled - /// preamble that covers this number of bytes in the main source file. - /// - /// The boolean indicates whether the preamble ends at the start of a new - /// line. - std::pair PrecompiledPreambleBytes; - - /// True indicates that a preamble is being generated. - /// - /// When the lexer is done, one of the things that need to be preserved is the - /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when - /// processing the rest of the file. - bool GeneratePreamble = false; - - /// Whether to write comment locations into the PCH when building it. - /// Reading the comments from the PCH can be a performance hit even if the - /// clients don't use them. - bool WriteCommentListToPCH = true; - - /// When enabled, preprocessor is in a mode for parsing a single file only. - /// - /// Disables #includes of other files and if there are unresolved identifiers - /// in preprocessor directive conditions it causes all blocks to be parsed so - /// that the client can get the maximum amount of information from the parser. - bool SingleFileParseMode = false; - - /// When enabled, the preprocessor will construct editor placeholder tokens. - bool LexEditorPlaceholders = true; - - /// True if the SourceManager should report the original file name for - /// contents of files that were remapped to other files. Defaults to true. - bool RemappedFilesKeepOriginalName = true; - - /// The set of file remappings, which take existing files on - /// the system (the first part of each pair) and gives them the - /// contents of other files on the system (the second part of each - /// pair). - std::vector> RemappedFiles; - - /// The set of file-to-buffer remappings, which take existing files - /// on the system (the first part of each pair) and gives them the contents - /// of the specified memory buffer (the second part of each pair). - std::vector> RemappedFileBuffers; - - /// Whether the compiler instance should retain (i.e., not free) - /// the buffers associated with remapped files. - /// - /// This flag defaults to false; it can be set true only through direct - /// manipulation of the compiler invocation object, in cases where the - /// compiler invocation and its buffers will be reused. - bool RetainRemappedFileBuffers = false; - - /// When enabled, excluded conditional blocks retain in the main file. - bool RetainExcludedConditionalBlocks = false; - - /// The Objective-C++ ARC standard library that we should support, - /// by providing appropriate definitions to retrofit the standard library - /// with support for lifetime-qualified pointers. - ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary = ARCXX_nolib; + using MacrosTy = std::vector>; + using PrecompiledPreambleBytesTy = std::pair; + using RemappedFilesTy = std::vector>; + using RemappedFileBuffersTy = + std::vector>; + using MacroPrefixMapTy = + std::map>; /// Records the set of modules class FailedModulesSet { @@ -167,33 +66,21 @@ } }; - /// The set of modules that failed to build. - /// - /// This pointer will be shared among all of the compiler instances created - /// to (re)build modules, so that once a module fails to build anywhere, - /// other instances will see that the module has failed and won't try to - /// build it again. - std::shared_ptr FailedModules; - - /// A prefix map for __FILE__ and __BASE_FILE__. - std::map> MacroPrefixMap; - - /// Contains the currently active skipped range mappings for skipping excluded - /// conditional directives. - /// - /// The pointer is passed to the Preprocessor when it's constructed. The - /// pointer is unowned, the client is responsible for its lifetime. - ExcludedPreprocessorDirectiveSkipMapping - *ExcludedConditionalDirectiveSkipMappings = nullptr; - - /// Set up preprocessor for RunAnalysis action. - bool SetUpStaticAnalyzer = false; - - /// Prevents intended crashes when using #pragma clang __debug. For testing. - bool DisablePragmaDebugCrash = false; - -public: - PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {} +#define TYPED_PREPROCESSOROPT(Type, Name, Description) Type Name; +#include "clang/Lex/PreprocessorOptions.def" + + PreprocessorOptions() + : UsePredefines(true), DetailedRecord(false), PCHWithHdrStop(false), + PCHWithHdrStopCreate(false), DisablePCHValidation(false), + AllowPCHWithCompilerErrors(false), DumpDeserializedPCHDecls(false), + PrecompiledPreambleBytes(0, false), GeneratePreamble(false), + WriteCommentListToPCH(true), SingleFileParseMode(false), + LexEditorPlaceholders(true), RemappedFilesKeepOriginalName(true), + RetainRemappedFileBuffers(false), + RetainExcludedConditionalBlocks(false), + ObjCXXARCStandardLibrary(ARCXX_nolib), + ExcludedConditionalDirectiveSkipMappings(nullptr), + SetUpStaticAnalyzer(false), DisablePragmaDebugCrash(false) {} void addMacroDef(StringRef Name) { Macros.emplace_back(std::string(Name), false); diff --git a/clang/include/clang/Lex/PreprocessorOptions.def b/clang/include/clang/Lex/PreprocessorOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Lex/PreprocessorOptions.def @@ -0,0 +1,166 @@ +//===--- PreprocessorOptions.def - Preprocessor option database -*- 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 file defines the preprocessor options. Users of this file must +// define the TYPED_PREPROCESSOROPT macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_PREPROCESSOROPT +#error Define the TYPED_PREPROCESSOROPT macro to handle target options +#endif + +TYPED_PREPROCESSOROPT(MacrosTy, Macros, "") + +TYPED_PREPROCESSOROPT(std::vector, Includes, "") + +TYPED_PREPROCESSOROPT(std::vector, MacroIncludes, "") + +TYPED_PREPROCESSOROPT( + bool, UsePredefines, + "Initialize the preprocessor with the compiler and target " + "specific predefines.") + +TYPED_PREPROCESSOROPT( + bool, DetailedRecord, + "Whether we should maintain a detailed record of all macro " + "definitions and expansions.") + +TYPED_PREPROCESSOROPT( + bool, PCHWithHdrStop, + "When true, we are creating or using a PCH where a #pragma hdrstop is " + "expected to indicate the beginning or end of the PCH.") + +TYPED_PREPROCESSOROPT( + bool, PCHWithHdrStopCreate, + "When true, we are creating a PCH or creating the PCH object " + "while expecting a #pragma hdrstop to separate the two. Allow " + "for a missing #pragma hdrstop, which generates a PCH for the " + "whole file, and creates an empty PCH object.") + +TYPED_PREPROCESSOROPT( + std::string, PCHThroughHeader, + "If non-empty, the filename used in an #include directive in the primary " + "source file (or command-line preinclude) that is used to implement " + "MSVC-style precompiled headers. When creating a PCH, after the #include " + "of this header, the PCH generation stops. When using a PCH, tokens are " + "skipped until after an #include of this header is seen.") + +TYPED_PREPROCESSOROPT( + std::string, ImplicitPCHInclude, + "The implicit PCH included at the start of the translation unit, or empty.") + +TYPED_PREPROCESSOROPT( + std::vector, ChainedIncludes, + "Headers that will be converted to chained PCHs in memory.") + +TYPED_PREPROCESSOROPT( + bool, DisablePCHValidation, + "When true, disables most of the normal validation performed " + "on precompiled headers.") + +TYPED_PREPROCESSOROPT( + bool, AllowPCHWithCompilerErrors, + "When true, a PCH with compiler errors will not be rejected.") + +TYPED_PREPROCESSOROPT( + bool, DumpDeserializedPCHDecls, + "Dump declarations that are deserialized from PCH, for testing.") + +TYPED_PREPROCESSOROPT( + std::set, DeserializedPCHDeclsToErrorOn, + "This is a set of names for decls that we do not want to be deserialized, " + "and we emit an error if they are; for testing purposes.") + +TYPED_PREPROCESSOROPT( + PrecompiledPreambleBytesTy, PrecompiledPreambleBytes, + "If non-zero, the implicit PCH include is actually a precompiled preamble " + "that covers this number of bytes in the main source file. The boolean " + "indicates whether the preamble ends at the start of a new line.") + +TYPED_PREPROCESSOROPT( + bool, GeneratePreamble, + "True indicates that a preamble is being generated. When the " + "lexer is done, one of the things that need to be preserved is " + "the conditional #if stack, so the ASTWriter/ASTReader can " + "save/restore it when processing the rest of the file.") + +TYPED_PREPROCESSOROPT( + bool, WriteCommentListToPCH, + "Whether to write comment locations into the PCH when building " + "it. Reading the comments from the PCH can be a performance " + "hit even if the clients don't use them.") + +TYPED_PREPROCESSOROPT( + bool, SingleFileParseMode, + "When enabled, preprocessor is in a mode for parsing a single " + "file only. Disables #includes of other files and if there are " + "unresolved identifiers in preprocessor directive conditions " + "it causes all blocks to be parsed so that the client can get " + "the maximum amount of information from the parser.") + +TYPED_PREPROCESSOROPT( + bool, LexEditorPlaceholders, + "When enabled, the preprocessor will construct editor placeholder tokens.") + +TYPED_PREPROCESSOROPT( + bool, RemappedFilesKeepOriginalName, + "True if the SourceManager should report the original file name for " + "contents of files that were remapped to other files. Defaults to true.") + +TYPED_PREPROCESSOROPT( + RemappedFilesTy, RemappedFiles, + "The set of file remappings, which take existing files on the system (the " + "first part of each pair) and gives them the contents of other files on " + "the system (the second part of each pair).") + +TYPED_PREPROCESSOROPT( + RemappedFileBuffersTy, RemappedFileBuffers, + "The set of file-to-buffer remappings, which take existing files on the " + "system (the first part of each pair) and gives them the contents of the " + "specified memory buffer (the second part of each pair).") + +TYPED_PREPROCESSOROPT( + bool, RetainRemappedFileBuffers, + "Whether the compiler instance should retain (i.e., not free) " + "the buffers associated with remapped files. This flag " + "defaults to false; it can be set true only through direct " + "manipulation of the compiler invocation object, in cases " + "where the compiler invocation and its buffers will be reused.") + +TYPED_PREPROCESSOROPT( + bool, RetainExcludedConditionalBlocks, + "When enabled, excluded conditional blocks retain in the main file.") + +TYPED_PREPROCESSOROPT( + ObjCXXARCStandardLibraryKind, ObjCXXARCStandardLibrary, + "The Objective-C++ ARC standard library that we should support, by " + "providing appropriate definitions to retrofit the standard library with " + "support for lifetime-qualified pointers.") + +TYPED_PREPROCESSOROPT(std::shared_ptr, FailedModules, "") + +TYPED_PREPROCESSOROPT(MacroPrefixMapTy, MacroPrefixMap, + "A prefix map for __FILE__ and __BASE_FILE__.") + +TYPED_PREPROCESSOROPT( + ExcludedPreprocessorDirectiveSkipMapping *, + ExcludedConditionalDirectiveSkipMappings, + "Contains the currently active skipped range mappings for " + "skipping excluded conditional directives. The pointer is " + "passed to the Preprocessor when it's constructed. The pointer " + "is unowned, the client is responsible for its lifetime.") + +TYPED_PREPROCESSOROPT(bool, SetUpStaticAnalyzer, + "Set up preprocessor for RunAnalysis action.") + +TYPED_PREPROCESSOROPT( + bool, DisablePragmaDebugCrash, + "Prevents intended crashes when using #pragma clang __debug. For testing.") + +#undef TYPED_PREPROCESSOROPT diff --git a/clang/include/clang/Sema/CodeCompleteOptions.h b/clang/include/clang/Sema/CodeCompleteOptions.h --- a/clang/include/clang/Sema/CodeCompleteOptions.h +++ b/clang/include/clang/Sema/CodeCompleteOptions.h @@ -14,39 +14,14 @@ /// Options controlling the behavior of code completion. class CodeCompleteOptions { public: - /// Show macros in code completion results. - unsigned IncludeMacros : 1; - - /// Show code patterns in code completion results. - unsigned IncludeCodePatterns : 1; - - /// Show top-level decls in code completion results. - unsigned IncludeGlobals : 1; - - /// Show decls in namespace (including the global namespace) in code - /// completion results. If this is 0, `IncludeGlobals` will be ignored. - /// - /// Currently, this only works when completing qualified IDs (i.e. - /// `Sema::CodeCompleteQualifiedId`). - /// FIXME: consider supporting more completion cases with this option. - unsigned IncludeNamespaceLevelDecls : 1; - - /// Show brief documentation comments in code completion results. - unsigned IncludeBriefComments : 1; - - /// Hint whether to load data from the external AST to provide full results. - /// If false, namespace-level declarations and macros from the preamble may be - /// omitted. - unsigned LoadExternal : 1; - - /// Include results after corrections (small fix-its), e.g. change '.' to '->' - /// on member access, etc. - unsigned IncludeFixIts : 1; +#define CODE_COMPLETEOPT(Name, Bits, Description) unsigned Name : Bits; +#define TYPED_CODE_COMPLETEOPT(Type, Name, Description) Type Name; +#include "clang/Sema/CodeCompleteOptions.def" CodeCompleteOptions() : IncludeMacros(0), IncludeCodePatterns(0), IncludeGlobals(1), - IncludeNamespaceLevelDecls(1), IncludeBriefComments(0), - LoadExternal(1), IncludeFixIts(0) {} + IncludeNamespaceLevelDecls(1), IncludeBriefComments(0), LoadExternal(1), + IncludeFixIts(0) {} }; } // namespace clang diff --git a/clang/include/clang/Sema/CodeCompleteOptions.def b/clang/include/clang/Sema/CodeCompleteOptions.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Sema/CodeCompleteOptions.def @@ -0,0 +1,51 @@ +//===--- CodeCompleteOptions.def - FileSystem option database ----*- 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 file defines the CodeComplete options. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPED_CODE_COMPLETEOPT +#define TYPED_CODE_COMPLETEOPT(Type, Name, Description) +#endif + +#ifndef CODE_COMPLETEOPT +#define CODE_COMPLETEOPT(Name, Bits, Description) \ + TYPED_CODE_COMPLETEOPT(unsigned, Name, Description); +#endif + +CODE_COMPLETEOPT(IncludeMacros, 1, "Show macros in code completion results.") + +CODE_COMPLETEOPT(IncludeCodePatterns, 1, + "Show code patterns in code completion results.") + +CODE_COMPLETEOPT(IncludeGlobals, 1, + "Show top-level decls in code completion results.") + +CODE_COMPLETEOPT(IncludeNamespaceLevelDecls, 1, + "Show decls in namespace (including the global namespace) in " + "code completion results. If this is 0, `IncludeGlobals` will " + "be ignored. Currently, this only works when completing " + "qualified IDs (i.e. `Sema::CodeCompleteQualifiedId`). FIXME: " + "consider supporting more completion cases with this option.") + +CODE_COMPLETEOPT( + IncludeBriefComments, 1, + "Show brief documentation comments in code completion results.") + +CODE_COMPLETEOPT(LoadExternal, 1, + "Hint whether to load data from the external AST to provide " + "full results. If false, namespace-level declarations and " + "macros from the preamble may be omitted.") + +CODE_COMPLETEOPT(IncludeFixIts, 1, + "Include results after corrections (small fix-its), e.g. " + "change '.' to '->' on member access, etc.") + +#undef TYPED_CODE_COMPLETEOPT +#undef CODE_COMPLETEOPT \ No newline at end of file diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -162,6 +162,7 @@ class AnalyzerOptions : public RefCountedBase { public: using ConfigTable = llvm::StringMap; + using CheckersAndPackagesTy = std::vector>; /// Retrieves the list of checkers generated from Checkers.td. This doesn't /// contain statically linked but non-generated checkers and plugin checkers! @@ -195,86 +196,9 @@ size_t InitialPad, size_t EntryWidth, size_t MinLineWidth = 0); - /// Pairs of checker/package name and enable/disable. - std::vector> CheckersAndPackages; - - /// Vector of checker/package names which will not emit warnings. - std::vector SilencedCheckersAndPackages; - - /// A key-value table of use-specified configuration values. - // TODO: This shouldn't be public. - ConfigTable Config; - AnalysisStores AnalysisStoreOpt = RegionStoreModel; - AnalysisConstraints AnalysisConstraintsOpt = RangeConstraintsModel; - AnalysisDiagClients AnalysisDiagOpt = PD_HTML; - AnalysisPurgeMode AnalysisPurgeOpt = PurgeStmt; - - std::string AnalyzeSpecificFunction; - - /// File path to which the exploded graph should be dumped. - std::string DumpExplodedGraphTo; - - /// Store full compiler invocation for reproducible instructions in the - /// generated report. - std::string FullCompilerInvocation; - - /// The maximum number of times the analyzer visits a block. - unsigned maxBlockVisitOnPath; - - /// Disable all analyzer checkers. - /// - /// This flag allows one to disable analyzer checkers on the code processed by - /// the given analysis consumer. Note, the code will get parsed and the - /// command-line options will get checked. - unsigned DisableAllCheckers : 1; - - unsigned ShowCheckerHelp : 1; - unsigned ShowCheckerHelpAlpha : 1; - unsigned ShowCheckerHelpDeveloper : 1; - - unsigned ShowCheckerOptionList : 1; - unsigned ShowCheckerOptionAlphaList : 1; - unsigned ShowCheckerOptionDeveloperList : 1; - - unsigned ShowEnabledCheckerList : 1; - unsigned ShowConfigOptionsList : 1; - unsigned ShouldEmitErrorsOnInvalidConfigValue : 1; - unsigned AnalyzeAll : 1; - unsigned AnalyzerDisplayProgress : 1; - unsigned AnalyzeNestedBlocks : 1; - - unsigned eagerlyAssumeBinOpBifurcation : 1; - - unsigned TrimGraph : 1; - unsigned visualizeExplodedGraphWithGraphViz : 1; - unsigned UnoptimizedCFG : 1; - unsigned PrintStats : 1; - - /// Do not re-analyze paths leading to exhausted nodes with a different - /// strategy. We get better code coverage when retry is enabled. - unsigned NoRetryExhausted : 1; - - /// Emit analyzer warnings as errors. - unsigned AnalyzerWerror : 1; - - /// The inlining stack depth limit. - // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). - unsigned InlineMaxStackDepth = 5; - - /// The mode of function selection used during inlining. - AnalysisInliningMode InliningMode = NoRedundancy; - - // Create a field for each -analyzer-config option. -#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \ - SHALLOW_VAL, DEEP_VAL) \ - ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL) - -#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \ - TYPE NAME; - +#define ANALYZEROPT(NAME, BITS, DESCRIPTION) unsigned NAME : BITS; +#define TYPED_ANALYZEROPT(TYPE, NAME, DESCRIPTION) TYPE NAME; #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def" -#undef ANALYZER_OPTION -#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE // Create an array of all -analyzer-config command line options. Sort it in // the constructor. @@ -299,15 +223,19 @@ } AnalyzerOptions() - : DisableAllCheckers(false), ShowCheckerHelp(false), - ShowCheckerHelpAlpha(false), ShowCheckerHelpDeveloper(false), - ShowCheckerOptionList(false), ShowCheckerOptionAlphaList(false), + : AnalysisStoreOpt(RegionStoreModel), + AnalysisConstraintsOpt(RangeConstraintsModel), AnalysisDiagOpt(PD_HTML), + AnalysisPurgeOpt(PurgeStmt), DisableAllCheckers(false), + ShowCheckerHelp(false), ShowCheckerHelpAlpha(false), + ShowCheckerHelpDeveloper(false), ShowCheckerOptionList(false), + ShowCheckerOptionAlphaList(false), ShowCheckerOptionDeveloperList(false), ShowEnabledCheckerList(false), ShowConfigOptionsList(false), AnalyzeAll(false), AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false), eagerlyAssumeBinOpBifurcation(false), TrimGraph(false), visualizeExplodedGraphWithGraphViz(false), UnoptimizedCFG(false), - PrintStats(false), NoRetryExhausted(false), AnalyzerWerror(false) { + PrintStats(false), NoRetryExhausted(false), AnalyzerWerror(false), + InlineMaxStackDepth(5), InliningMode(NoRedundancy) { llvm::sort(AnalyzerConfigCmdFlags); } diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -6,7 +6,10 @@ // //===----------------------------------------------------------------------===// // -// This file defines the analyzer options avaible with -analyzer-config. +// This file defines the analyzer options avaible with -analyzer-config, using +// the ANLAYZER_OPTION and ANALYZER_OPTION_DEPENDS_ON_USER_MODE macros. +// Other analyzer options use the simpler ANALYZEROPT and TYPED_ANALYZEROPT +// macro. // //===----------------------------------------------------------------------===// @@ -29,6 +32,15 @@ #endif #endif +#ifndef TYPED_ANALYZEROPT +#define TYPED_ANALYZEROPT(TYPE, NAME, DESCRIPTION) +#endif + +#ifndef ANALYZEROPT +#define ANALYZEROPT(NAME, BITS, DESCRIPTION) \ + TYPED_ANALYZEROPT(unsigned, NAME, DESCRITPTION) +#endif + #ifndef ANALYZER_OPTION /// Create a new analyzer option, but dont generate a method for it in /// AnalyzerOptions. @@ -42,7 +54,8 @@ /// (-analyzer-config CMDFLAG=VALUE) /// DESC - Description of the flag. /// DEFAULT_VAL - The default value for CMDFLAG. -#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) +#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \ + TYPED_ANALYZEROPT(TYPE, NAME, DESC) #endif #ifndef ANALYZER_OPTION_DEPENDS_ON_USER_MODE @@ -62,7 +75,8 @@ /// DEEP_VAL - The default value for CMDFLAG, when "user-mode" was set to /// "deep". #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \ - SHALLOW_VAL, DEEP_VAL) + SHALLOW_VAL, DEEP_VAL) \ + TYPED_ANALYZEROPT(TYPE, NAME, DESC) #endif //===----------------------------------------------------------------------===// @@ -435,5 +449,79 @@ "\"basic-inlining\", \"inlining\", \"dynamic\", \"dynamic-bifurcate\".", /* SHALLOW_VAL */ "inlining", /* DEEP_VAL */ "dynamic-bifurcate") +//===----------------------------------------------------------------------===// +// Other analyzer options. +//===----------------------------------------------------------------------===// + +TYPED_ANALYZEROPT(CheckersAndPackagesTy, CheckersAndPackages, + "Pairs of checker/package name and enable/disable.") + +TYPED_ANALYZEROPT( + std::vector, SilencedCheckersAndPackages, + "Vector of checker/package names which will not emit warnings.") + +TYPED_ANALYZEROPT(ConfigTable, Config, + "A key-value table of use-specified configuration values.") +TYPED_ANALYZEROPT(AnalysisStores, AnalysisStoreOpt, "") +TYPED_ANALYZEROPT(AnalysisConstraints, AnalysisConstraintsOpt, "") +TYPED_ANALYZEROPT(AnalysisDiagClients, AnalysisDiagOpt, "") +TYPED_ANALYZEROPT(AnalysisPurgeMode, AnalysisPurgeOpt, "") + +TYPED_ANALYZEROPT(std::string, AnalyzeSpecificFunction, "") + +TYPED_ANALYZEROPT(std::string, DumpExplodedGraphTo, + "File path to which the exploded graph should be dumped.") + +TYPED_ANALYZEROPT(std::string, FullCompilerInvocation, + "Store full compiler invocation for reproducible " + "instructions in the generated report.") + +TYPED_ANALYZEROPT(unsigned, maxBlockVisitOnPath, + "The maximum number of times the analyzer visits a block.") + +ANALYZEROPT( + DisableAllCheckers, 1, + "Disable all analyzer checkers. This flag allows one to disable analyzer " + "checkers on the code processed by the given analysis consumer. Note, the " + "code will get parsed and the command-line options will get checked.") + +ANALYZEROPT(ShowCheckerHelp, 1, "") +ANALYZEROPT(ShowCheckerHelpAlpha, 1, "") +ANALYZEROPT(ShowCheckerHelpDeveloper, 1, "") + +ANALYZEROPT(ShowCheckerOptionList, 1, "") +ANALYZEROPT(ShowCheckerOptionAlphaList, 1, "") +ANALYZEROPT(ShowCheckerOptionDeveloperList, 1, "") + +ANALYZEROPT(ShowEnabledCheckerList, 1, "") +ANALYZEROPT(ShowConfigOptionsList, 1, "") +ANALYZEROPT(ShouldEmitErrorsOnInvalidConfigValue, 1, "") +ANALYZEROPT(AnalyzeAll, 1, "") +ANALYZEROPT(AnalyzerDisplayProgress, 1, "") +ANALYZEROPT(AnalyzeNestedBlocks, 1, "") + +ANALYZEROPT(eagerlyAssumeBinOpBifurcation, 1, "") + +ANALYZEROPT(TrimGraph, 1, "") +ANALYZEROPT(visualizeExplodedGraphWithGraphViz, 1, "") +ANALYZEROPT(UnoptimizedCFG, 1, "") +ANALYZEROPT(PrintStats, 1, "") + +ANALYZEROPT( + NoRetryExhausted, 1, + "Do not re-analyze paths leading to exhausted nodes with a different " + "strategy. We get better code coverage when retry is enabled.") + +ANALYZEROPT(AnalyzerWerror, 1, "Emit analyzer warnings as errors.") + +TYPED_ANALYZEROPT(unsigned, InlineMaxStackDepth, + "The inlining stack depth limit. Cap the stack depth at 4 " + "calls (5 stack frames, base + 4 calls).") + +TYPED_ANALYZEROPT(AnalysisInliningMode, InliningMode, + "The mode of function selection used during inlining.") + #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE #undef ANALYZER_OPTION +#undef TYPED_ANALYZEROPT +#undef ANALYZEROPT diff --git a/clang/lib/Basic/CodeGenOptions.cpp b/clang/lib/Basic/CodeGenOptions.cpp --- a/clang/lib/Basic/CodeGenOptions.cpp +++ b/clang/lib/Basic/CodeGenOptions.cpp @@ -10,8 +10,9 @@ #include namespace clang { - -CodeGenOptions::CodeGenOptions() { +CodeGenOptions::CodeGenOptions() + : FPDenormalMode(llvm::DenormalMode::getIEEE()), + FP32DenormalMode(llvm::DenormalMode::getIEEE()), Argv0(nullptr) { #define CODEGENOPT(Name, Bits, Default) Name = Default; #define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default); #include "clang/Basic/CodeGenOptions.def" diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -14,7 +14,8 @@ using namespace clang; -LangOptions::LangOptions() { +LangOptions::LangOptions() + : CFRuntime(CoreFoundationABI::Unspecified), IsHeaderFile(false) { #define LANGOPT(Name, Bits, Default, Description) Name = Default; #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default); #include "clang/Basic/LangOptions.def"