diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst --- a/clang/docs/InternalsManual.rst +++ b/clang/docs/InternalsManual.rst @@ -940,23 +940,22 @@ **Enumeration** -The key path defaults to the value specified in ``MarshallingInfoString`` -prefixed by the contents of ``NormalizedValuesScope`` and ``::``. This ensures -correct reference to an enum case is formed even if the enum resides in different +The key path defaults to the value specified in ``MarshallingInfoEnum`` prefixed +by the contents of ``NormalizedValuesScope`` and ``::``. This ensures correct +reference to an enum case is formed even if the enum resides in different namespace or is an enum class. If the value present on command line does not match any of the comma-separated values from ``Values``, an error diagnostics is issued. Otherwise, the corresponding element from ``NormalizedValues`` at the same index is assigned to the key path (also correctly scoped). The number of comma-separated string values and elements of the array within -``NormalizedValues`` must match. The ``AutoNormalizeEnum`` mix-in denotes the -key path option should be treated as an enum and not as a string. +``NormalizedValues`` must match. .. code-block:: def mthread_model : Separate<["-"], "mthread-model">, Flags<[CC1Option]>, Values<"posix,single">, NormalizedValues<["POSIX", "Single"]>, NormalizedValuesScope<"LangOptions::ThreadModelKind">, - MarshallingInfoString, "POSIX">, AutoNormalizeEnum; + MarshallingInfoEnum, "POSIX">; .. Intentionally omitting MarshallingInfoBitfieldFlag. It's adding some diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -427,11 +427,10 @@ // FIXME: Diagnose if target does not support protected visibility. class MarshallingInfoVisibility - : MarshallingInfoString, + : MarshallingInfoEnum, Values<"default,hidden,internal,protected">, NormalizedValues<["DefaultVisibility", "HiddenVisibility", - "HiddenVisibility", "ProtectedVisibility"]>, - AutoNormalizeEnum {} + "HiddenVisibility", "ProtectedVisibility"]> {} // Key paths that are constant during parsing of options with the same key path prefix. defvar cplusplus = LangOpts<"CPlusPlus">; @@ -1062,7 +1061,7 @@ HelpText<"Embed LLVM bitcode (option: off, all, bitcode, marker)">, Values<"off,all,bitcode,marker">, NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["Embed_Off", "Embed_All", "Embed_Bitcode", "Embed_Marker"]>, - MarshallingInfoString, "Embed_Off">, AutoNormalizeEnum; + MarshallingInfoEnum, "Embed_Off">; def fembed_bitcode : Flag<["-"], "fembed-bitcode">, Group, Alias, AliasArgs<["all"]>, HelpText<"Embed LLVM IR bitcode as data">; @@ -1248,7 +1247,7 @@ Flags<[CC1Option]>, Values<"unspecified,standalone,objc,swift,swift-5.0,swift-4.2,swift-4.1">, NormalizedValuesScope<"LangOptions::CoreFoundationABI">, NormalizedValues<["ObjectiveC", "ObjectiveC", "ObjectiveC", "Swift5_0", "Swift5_0", "Swift4_2", "Swift4_1"]>, - MarshallingInfoString, "ObjectiveC">, AutoNormalizeEnum; + MarshallingInfoEnum, "ObjectiveC">; defm constant_cfstrings : BoolFOption<"constant-cfstrings", LangOpts<"NoConstantCFStrings">, DefaultFalse, NegFlag, @@ -1356,8 +1355,7 @@ Values<"dwarf,sjlj,seh,wasm">, NormalizedValuesScope<"llvm::ExceptionHandling">, NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm"]>, - MarshallingInfoString, "None">, - AutoNormalizeEnum; + MarshallingInfoEnum, "None">; def exception_model_EQ : Joined<["-"], "exception-model=">, Flags<[CC1Option, NoDriverOption]>, Alias; def fignore_exceptions : Flag<["-"], "fignore-exceptions">, Group, Flags<[CC1Option]>, @@ -1380,7 +1378,7 @@ HelpText<"Specifies the exception behavior of floating-point operations.">, Values<"ignore,maytrap,strict">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["FPE_Ignore", "FPE_MayTrap", "FPE_Strict"]>, - MarshallingInfoString, "FPE_Ignore">, AutoNormalizeEnum; + MarshallingInfoEnum, "FPE_Ignore">; defm fast_math : OptInFFlag<"fast-math", "Allow aggressive, lossy floating-point optimizations", "", "", [], LangOpts<"FastMath">, [cl_fast_relaxed_math.KeyPath]>; def menable_unsafe_fp_math : Flag<["-"], "menable-unsafe-fp-math">, Flags<[CC1Option]>, @@ -1820,10 +1818,9 @@ NormalizedValues<["LangOptions::LaxVectorConversionKind::None", "LangOptions::LaxVectorConversionKind::Integer", "LangOptions::LaxVectorConversionKind::All"]>, - MarshallingInfoString, - !strconcat(open_cl.KeyPath, " ? LangOptions::LaxVectorConversionKind::None" - " : LangOptions::LaxVectorConversionKind::All")>, - AutoNormalizeEnum; + MarshallingInfoEnum, + !strconcat(open_cl.KeyPath, " ? LangOptions::LaxVectorConversionKind::None" + " : LangOptions::LaxVectorConversionKind::All")>; def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group, Alias, AliasArgs<["integer"]>; def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group; @@ -1885,8 +1882,7 @@ Values<"single,multiple,virtual">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", "PPTMK_FullGeneralityMultipleInheritance", "PPTMK_FullGeneralityVirtualInheritance"]>, - MarshallingInfoString, "PPTMK_BestCase">, - AutoNormalizeEnum; + MarshallingInfoEnum, "PPTMK_BestCase">; // __declspec is enabled by default for the PS4 by the driver, and also // enabled for Microsoft Extensions or Borland Extensions, here. // @@ -2057,7 +2053,7 @@ Values<"Accelerate,libmvec,MASSV,SVML,none">, NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "NoLibrary"]>, - MarshallingInfoString, "NoLibrary">, AutoNormalizeEnum; + MarshallingInfoEnum, "NoLibrary">; def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group, Alias, AliasArgs<["none"]>; def fno_implicit_module_maps : Flag <["-"], "fno-implicit-module-maps">, Group, @@ -2304,7 +2300,7 @@ HelpText<"Which overload candidates to show when overload resolution fails: " "best|all; defaults to all">, Values<"best,all">, NormalizedValues<["Ovl_Best", "Ovl_All"]>, - MarshallingInfoString, "Ovl_All">, AutoNormalizeEnum; + MarshallingInfoEnum, "Ovl_All">; defm show_column : BoolFOption<"show-column", DiagnosticOpts<"ShowColumn">, DefaultTrue, NegFlag, @@ -2350,7 +2346,7 @@ " | pattern">, Values<"uninitialized,zero,pattern">, NormalizedValuesScope<"LangOptions::TrivialAutoVarInitKind">, NormalizedValues<["Uninitialized", "Zero", "Pattern"]>, - MarshallingInfoString, "Uninitialized">, AutoNormalizeEnum; + MarshallingInfoEnum, "Uninitialized">; def enable_trivial_var_init_zero : Flag<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">, Flags<[CC1Option, CoreOption]>, HelpText<"Trivial automatic variable initialization to zero is only here for benchmarks, it'll eventually be removed, and I'm OK with that because I'm only using it to benchmark">; @@ -2459,7 +2455,7 @@ Values<"global-dynamic,local-dynamic,initial-exec,local-exec">, NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["GeneralDynamicTLSModel", "LocalDynamicTLSModel", "InitialExecTLSModel", "LocalExecTLSModel"]>, - MarshallingInfoString, "GeneralDynamicTLSModel">, AutoNormalizeEnum; + MarshallingInfoEnum, "GeneralDynamicTLSModel">; def ftrapv : Flag<["-"], "ftrapv">, Group, Flags<[CC1Option]>, HelpText<"Trap on integer overflow">; def ftrapv_handler_EQ : Joined<["-"], "ftrapv-handler=">, Group, @@ -2935,12 +2931,12 @@ def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>, HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">, NormalizedValues<["POSIX", "Single"]>, NormalizedValuesScope<"LangOptions::ThreadModelKind">, - MarshallingInfoString, "POSIX">, AutoNormalizeEnum; + MarshallingInfoEnum, "POSIX">; def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>, HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">, - MarshallingInfoString, "Default">, + MarshallingInfoEnum, "Default">, NormalizedValuesScope<"llvm::EABI">, - NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>, AutoNormalizeEnum; + NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>; def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, Group; def mno_global_merge : Flag<["-"], "mno-global-merge">, Group, Flags<[CC1Option]>, @@ -3058,7 +3054,7 @@ " vector length agnostic value of \"scalable\". (AArch64 only)">, Values<"128,256,512,1024,2048,scalable">, NormalizedValues<["128", "256", "512", "1024", "2048", "0"]>, - MarshallingInfoString, "0">, AutoNormalizeEnum; + MarshallingInfoEnum, "0">; def msign_return_address_EQ : Joined<["-"], "msign-return-address=">, Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">, @@ -4235,7 +4231,7 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, Flags<[CC1Option, NoArgumentUnused, CoreOption]>, HelpText<"SYCL language standard to compile for.">, Values<"2017,121,1.2.1,sycl-1.2.1">, NormalizedValues<["SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">, - MarshallingInfoString, "SYCL_None">, ShouldParseIf, AutoNormalizeEnum; + MarshallingInfoEnum, "SYCL_None">, ShouldParseIf; //===----------------------------------------------------------------------===// // FLangOption + CoreOption + NoXarchOption @@ -4496,8 +4492,7 @@ def analyzer_config_compatibility_mode : Separate<["-"], "analyzer-config-compatibility-mode">, HelpText<"Don't emit errors on invalid analyzer-config inputs">, Values<"true,false">, NormalizedValues<[[{false}], [{true}]]>, - MarshallingInfoString, [{true}]>, - AutoNormalizeEnum; + MarshallingInfoEnum, [{true}]>; def analyzer_config_compatibility_mode_EQ : Joined<["-"], "analyzer-config-compatibility-mode=">, Alias; @@ -4534,7 +4529,7 @@ def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">, Values<"gdb,lldb,sce">, NormalizedValuesScope<"llvm::DebuggerKind">, NormalizedValues<["GDB", "LLDB", "SCE"]>, - MarshallingInfoString, "Default">, AutoNormalizeEnum; + MarshallingInfoEnum, "Default">; def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">, HelpText<"The string to embed in the Dwarf debug flags record.">, MarshallingInfoString>; @@ -4544,7 +4539,7 @@ def compress_debug_sections_EQ : Joined<["-", "--"], "compress-debug-sections=">, HelpText<"DWARF debug sections compression type">, Values<"none,zlib,zlib-gnu">, NormalizedValuesScope<"llvm::DebugCompressionType">, NormalizedValues<["None", "Z", "GNU"]>, - MarshallingInfoString, "None">, AutoNormalizeEnum; + MarshallingInfoEnum, "None">; def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">, Alias, AliasArgs<["zlib"]>; def mno_exec_stack : Flag<["-"], "mnoexecstack">, @@ -4568,8 +4563,7 @@ HelpText<"The relocation model to use">, Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">, NormalizedValuesScope<"llvm::Reloc">, NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", "DynamicNoPIC"]>, - MarshallingInfoString, "PIC_">, - AutoNormalizeEnum; + MarshallingInfoEnum, "PIC_">; def fno_math_builtin : Flag<["-"], "fno-math-builtin">, HelpText<"Disable implicit builtin knowledge of math functions">, MarshallingInfoFlag>; @@ -4654,7 +4648,7 @@ def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">, HelpText<"Specify which frame pointers to retain (all, non-leaf, none).">, Values<"all,non-leaf,none">, NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, NormalizedValues<["All", "NonLeaf", "None"]>, - MarshallingInfoString, "None">, AutoNormalizeEnum; + MarshallingInfoEnum, "None">; def mdisable_tail_calls : Flag<["-"], "mdisable-tail-calls">, HelpText<"Disable tail call optimization, keeping the call stack accurate">, MarshallingInfoFlag>; @@ -4776,7 +4770,7 @@ "or none">, Values<"none,clang,llvm,csllvm">, NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["ProfileNone", "ProfileClangInstr", "ProfileIRInstr", "ProfileCSIRInstr"]>, - MarshallingInfoString, "ProfileNone">, AutoNormalizeEnum; + MarshallingInfoEnum, "ProfileNone">; def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">, HelpText<"Generate instrumented code to collect execution counts into " " (overridden by LLVM_PROFILE_FILE env var)">, @@ -4850,11 +4844,11 @@ def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">, HelpText<"Change diagnostic formatting to match IDE and command line tools">, Values<"clang,msvc,vi">, NormalizedValuesScope<"DiagnosticOptions">, NormalizedValues<["Clang", "MSVC", "Vi"]>, - MarshallingInfoString, "Clang">, AutoNormalizeEnum; + MarshallingInfoEnum, "Clang">; def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">, HelpText<"Print diagnostic category">, Values<"none,id,name">, NormalizedValues<["0", "1", "2"]>, - MarshallingInfoString, "0">, AutoNormalizeEnum; + MarshallingInfoEnum, "0">; def fno_diagnostics_use_presumed_location : Flag<["-"], "fno-diagnostics-use-presumed-location">, HelpText<"Ignore #line directives when displaying diagnostic locations">, MarshallingInfoNegativeFlag>; @@ -5113,8 +5107,7 @@ HelpText<"The ARC migration action to take">, Values<"check,modify,migrate">, NormalizedValuesScope<"FrontendOptions">, NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>, - MarshallingInfoString, "ARCMT_None">, - AutoNormalizeEnum; + MarshallingInfoEnum, "ARCMT_None">; def opt_record_file : Separate<["-"], "opt-record-file">, HelpText<"File name to use for YAML optimization record output">, @@ -5212,13 +5205,13 @@ def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">, HelpText<"Objective-C++ Automatic Reference Counting standard library kind">, Values<"libc++,libstdc++,none">, NormalizedValues<["ARCXX_libcxx", "ARCXX_libstdcxx", "ARCXX_nolib"]>, - MarshallingInfoString, "ARCXX_nolib">, AutoNormalizeEnum; + MarshallingInfoEnum, "ARCXX_nolib">; def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">, HelpText<"The target Objective-C runtime supports ARC weak operations">; def fobjc_dispatch_method_EQ : Joined<["-"], "fobjc-dispatch-method=">, HelpText<"Objective-C dispatch method to use">, Values<"legacy,non-legacy,mixed">, NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["Legacy", "NonLegacy", "Mixed"]>, - MarshallingInfoString, "Legacy">, AutoNormalizeEnum; + MarshallingInfoEnum, "Legacy">; def disable_objc_default_synthesize_properties : Flag<["-"], "disable-objc-default-synthesize-properties">, HelpText<"disable the default synthesis of Objective-C properties">, MarshallingInfoNegativeFlag>; @@ -5262,7 +5255,7 @@ HelpText<"Enable stack protectors">, Values<"0,1,2,3">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["SSPOff", "SSPOn", "SSPStrong", "SSPReq"]>, - MarshallingInfoString, "SSPOff">, AutoNormalizeEnum; + MarshallingInfoEnum, "SSPOff">; def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">, HelpText<"Lower bound for a buffer to be considered for stack protection">, MarshallingInfoStringInt, "8">; @@ -5304,7 +5297,7 @@ HelpText<"Set the mode for address space map based mangling; OpenCL testing purposes only">, Values<"target,no,yes">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["ASMM_Target", "ASMM_Off", "ASMM_On"]>, - MarshallingInfoString, "ASMM_Target">, AutoNormalizeEnum; + MarshallingInfoEnum, "ASMM_Target">; def funknown_anytype : Flag<["-"], "funknown-anytype">, HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">, MarshallingInfoFlag>; @@ -5343,7 +5336,7 @@ HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["DCC_CDecl", "DCC_FastCall", "DCC_StdCall", "DCC_VectorCall", "DCC_RegCall"]>, - MarshallingInfoString, "DCC_None">, AutoNormalizeEnum; + MarshallingInfoEnum, "DCC_None">; // These options cannot be marshalled, because they are used to set up the LangOptions defaults. def finclude_default_header : Flag<["-"], "finclude-default-header">, @@ -5357,7 +5350,7 @@ def fwchar_type_EQ : Joined<["-"], "fwchar-type=">, HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">, NormalizedValues<["1", "2", "4"]>, - MarshallingInfoString, "0">, AutoNormalizeEnum; + MarshallingInfoEnum, "0">; defm signed_wchar : BoolOption<"f", "signed-wchar", LangOpts<"WCharIsSigned">, DefaultTrue, NegFlag, PosFlag, diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td --- a/llvm/include/llvm/Option/OptParser.td +++ b/llvm/include/llvm/Option/OptParser.td @@ -211,6 +211,14 @@ code Denormalizer = "makeBooleanOptionDenormalizer("#value#")"; } +// Marshalling info for enums. Typically used with `Values`, `NormalizedValues` +// and `NormalizedValuesScope` mixins. +class MarshallingInfoEnum + : MarshallingInfo { + code Normalizer = "normalizeSimpleEnum"; + code Denormalizer = "denormalizeSimpleEnum"; +} + // Mixins for additional marshalling attributes. class ShouldParseIf { code ShouldParse = condition; } @@ -219,10 +227,6 @@ class Denormalizer { code Denormalizer = denormalizer; } class NormalizedValuesScope { code NormalizedValuesScope = scope; } class NormalizedValues definitions> { list NormalizedValues = definitions; } -class AutoNormalizeEnum { - code Normalizer = "normalizeSimpleEnum"; - code Denormalizer = "denormalizeSimpleEnum"; -} class ValueMerger { code ValueMerger = merger; } class ValueExtractor { code ValueExtractor = extractor; }