Skip to content

Commit aec2991

Browse files
committed
[clang][cli] Port LangOpts simple string based options to new option parsing system
Depends on D84670 Reviewed By: Bigcheese Original patch by Daniel Grumberg. Differential Revision: https://reviews.llvm.org/D84671
1 parent ff4b76d commit aec2991

File tree

3 files changed

+100
-204
lines changed

3 files changed

+100
-204
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ def err_fe_action_not_available : Error<
108108
"action %0 not compiled in">;
109109
def err_fe_invalid_alignment : Error<
110110
"invalid value '%1' in '%0'; alignment must be a power of 2">;
111-
def err_fe_invalid_wchar_type
112-
: Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 'int'">;
113111
def err_fe_invalid_exception_model
114112
: Error<"invalid exception model '%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
115113
def warn_fe_concepts_ts_flag : Warning<

clang/include/clang/Driver/Options.td

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=
994994
def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
995995
def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
996996
def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group<f_Group>, Flags<[CC1Option]>,
997-
HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">;
997+
HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
998+
MarshallingInfoStringInt<"LangOpts->MaxTokens">;
998999
def fPIC : Flag<["-"], "fPIC">, Group<f_Group>;
9991000
def fno_PIC : Flag<["-"], "fno-PIC">, Group<f_Group>;
10001001
def fPIE : Flag<["-"], "fPIE">, Group<f_Group>;
@@ -1212,7 +1213,10 @@ defm complete_member_pointers : BoolOption<"complete-member-pointers",
12121213
" would be significant under the Microsoft ABI">, "f">,
12131214
Group<f_clang_Group>;
12141215
def fcf_runtime_abi_EQ : Joined<["-"], "fcf-runtime-abi=">, Group<f_Group>,
1215-
Flags<[CC1Option]>;
1216+
Flags<[CC1Option]>, Values<"unspecified,standalone,objc,swift,swift-5.0,swift-4.2,swift-4.1">,
1217+
NormalizedValuesScope<"LangOptions::CoreFoundationABI">,
1218+
NormalizedValues<["ObjectiveC", "ObjectiveC", "ObjectiveC", "Swift5_0", "Swift5_0", "Swift4_2", "Swift4_1"]>,
1219+
MarshallingInfoString<"LangOpts->CFRuntime", "ObjectiveC">, AutoNormalizeEnum;
12161220
defm constant_cfstrings : BoolFOption<"constant-cfstrings",
12171221
"LangOpts->NoConstantCFStrings", DefaultsToFalse,
12181222
ChangedBy<NegFlag, [], "Disable creation of CodeFoundation-type constant strings">,
@@ -1420,7 +1424,8 @@ defm sanitize_memory_use_after_dtor : BoolOption<"sanitize-memory-use-after-dtor
14201424
Group<f_clang_Group>;
14211425
def fsanitize_address_field_padding : Joined<["-"], "fsanitize-address-field-padding=">,
14221426
Group<f_clang_Group>,
1423-
HelpText<"Level of field padding for AddressSanitizer">;
1427+
HelpText<"Level of field padding for AddressSanitizer">,
1428+
MarshallingInfoStringInt<"LangOpts->SanitizeAddressFieldPadding">;
14241429
defm sanitize_address_use_after_scope : BoolOption<"sanitize-address-use-after-scope",
14251430
"CodeGenOpts.SanitizeAddressUseAfterScope", DefaultsToFalse,
14261431
ChangedBy<PosFlag, [], "Enable">, ResetBy<NegFlag, [CoreOption, NoXarchOption], "Disable">,
@@ -1739,7 +1744,10 @@ defm experimental_relative_cxx_abi_vtables : BoolFOption<"experimental-relative-
17391744

17401745
def flat__namespace : Flag<["-"], "flat_namespace">;
17411746
def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, Group<f_Group>,
1742-
HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, Flags<[CC1Option]>;
1747+
HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, Flags<[CC1Option]>,
1748+
NormalizedValuesScope<"LangOptions::LaxVectorConversionKind">,
1749+
NormalizedValues<["None", "Integer", "All"]>,
1750+
MarshallingInfoString<"LangOpts->LaxVectorConversions", "All">, AutoNormalizeEnum;
17431751
def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>,
17441752
Alias<flax_vector_conversions_EQ>, AliasArgs<["integer"]>;
17451753
def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group<f_Group>;
@@ -1791,7 +1799,12 @@ defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
17911799
ChangedBy<PosFlag, [], "Parse templated function definitions at the end of the translation unit">,
17921800
ResetBy<NegFlag, [NoXarchOption], "Disable delayed template parsing">,
17931801
BothFlags<[CoreOption]>>;
1794-
def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, Group<f_Group>, Flags<[CC1Option]>;
1802+
def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, Group<f_Group>, Flags<[CC1Option]>,
1803+
Values<"single,multiple,virtual">, NormalizedValuesScope<"LangOptions">,
1804+
NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", "PPTMK_FullGeneralityMultipleInheritance",
1805+
"PPTMK_FullGeneralityVirtualInheritance"]>,
1806+
MarshallingInfoString<"LangOpts->MSPointerToMemberRepresentationMethod", "PPTMK_BestCase">,
1807+
AutoNormalizeEnum;
17951808
def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, Group<i_Group>,
17961809
Flags<[NoXarchOption, CC1Option]>, MetaVarName<"<directory>">,
17971810
HelpText<"Specify the module cache path">;
@@ -1880,7 +1893,8 @@ def fmodules_ts : Flag <["-"], "fmodules-ts">, Group<f_Group>,
18801893
def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias<fimplicit_module_maps>;
18811894
def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group<f_Group>,
18821895
Flags<[NoXarchOption,CC1Option]>, MetaVarName<"<name>">,
1883-
HelpText<"Specify the name of the module to build">;
1896+
HelpText<"Specify the name of the module to build">,
1897+
MarshallingInfoString<"LangOpts->ModuleName">;
18841898
def fmodule_name : Separate<["-"], "fmodule-name">, Alias<fmodule_name_EQ>;
18851899
def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
18861900
Flags<[CC1Option]>, Alias<fmodule_name_EQ>;
@@ -2035,7 +2049,8 @@ def fno_aligned_allocation: Flag<["-"], "fno-aligned-allocation">,
20352049
Group<f_Group>, Flags<[CC1Option]>;
20362050
def fnew_alignment_EQ : Joined<["-"], "fnew-alignment=">,
20372051
HelpText<"Specifies the largest alignment guaranteed by '::operator new(size_t)'">,
2038-
MetaVarName<"<align>">, Group<f_Group>, Flags<[CC1Option]>;
2052+
MetaVarName<"<align>">, Group<f_Group>, Flags<[CC1Option]>,
2053+
MarshallingInfoStringInt<"LangOpts->NewAlignOverride">;
20392054
def : Separate<["-"], "fnew-alignment">, Alias<fnew_alignment_EQ>;
20402055
def : Flag<["-"], "faligned-new">, Alias<faligned_allocation>;
20412056
def : Flag<["-"], "fno-aligned-new">, Alias<fno_aligned_allocation>;
@@ -2120,9 +2135,11 @@ def foutput_class_dir_EQ : Joined<["-"], "foutput-class-dir=">, Group<f_Group>;
21202135
def fpack_struct : Flag<["-"], "fpack-struct">, Group<f_Group>;
21212136
def fno_pack_struct : Flag<["-"], "fno-pack-struct">, Group<f_Group>;
21222137
def fpack_struct_EQ : Joined<["-"], "fpack-struct=">, Group<f_Group>, Flags<[CC1Option]>,
2123-
HelpText<"Specify the default maximum struct packing alignment">;
2138+
HelpText<"Specify the default maximum struct packing alignment">,
2139+
MarshallingInfoStringInt<"LangOpts->PackStruct">;
21242140
def fmax_type_align_EQ : Joined<["-"], "fmax-type-align=">, Group<f_Group>, Flags<[CC1Option]>,
2125-
HelpText<"Specify the maximum alignment to enforce on pointers lacking an explicit alignment">;
2141+
HelpText<"Specify the maximum alignment to enforce on pointers lacking an explicit alignment">,
2142+
MarshallingInfoStringInt<"LangOpts->MaxTypeAlign">;
21262143
def fno_max_type_align : Flag<["-"], "fno-max-type-align">, Group<f_Group>;
21272144
defm pascal_strings : BoolFOption<"pascal-strings",
21282145
"LangOpts->PascalStrings", DefaultsToFalse,
@@ -2217,12 +2234,16 @@ def fstack_protector : Flag<["-"], "fstack-protector">, Group<f_Group>,
22172234
"address. The reference stack guard value is stored in a global variable.">;
22182235
def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, Group<f_Group>,
22192236
Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
2220-
" | pattern">, Values<"uninitialized,pattern">;
2237+
" | pattern">, Values<"uninitialized,zero,pattern">,
2238+
NormalizedValuesScope<"LangOptions::TrivialAutoVarInitKind">,
2239+
NormalizedValues<["Uninitialized", "Zero", "Pattern"]>,
2240+
MarshallingInfoString<"LangOpts->TrivialAutoVarInit", "Uninitialized">, AutoNormalizeEnum;
22212241
def enable_trivial_var_init_zero : Flag<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
22222242
Flags<[CC1Option, CoreOption]>,
22232243
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">;
22242244
def ftrivial_auto_var_init_stop_after : Joined<["-"], "ftrivial-auto-var-init-stop-after=">, Group<f_Group>,
2225-
Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial automatic stack variables after the specified number of instances">;
2245+
Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial automatic stack variables after the specified number of instances">,
2246+
MarshallingInfoStringInt<"LangOpts->TrivialAutoVarInitStopAfter">;
22262247
def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group<f_Group>, Flags<[CoreOption]>,
22272248
HelpText<"Emit full debug info for all types used by the program">;
22282249
def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, Group<f_Group>, Flags<[CoreOption]>,
@@ -2287,7 +2308,8 @@ def : Flag<["-"], "fno-tree-slp-vectorize">, Alias<fno_slp_vectorize>;
22872308
def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">,
22882309
HelpText<"Warn if a function definition returns or accepts an object larger "
22892310
"in bytes than a given value">, Flags<[HelpHidden]>;
2290-
def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1Option]>;
2311+
def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1Option]>,
2312+
MarshallingInfoStringInt<"LangOpts->NumLargeByValueCopy">;
22912313

22922314
// These "special" warning flags are effectively processed as f_Group flags by the driver:
22932315
// Just silence warnings about -Wlarger-than for now.
@@ -2661,7 +2683,8 @@ def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, Group<clang_ignored_m_Grou
26612683
def mlong_calls : Flag<["-"], "mlong-calls">, Group<m_Group>,
26622684
HelpText<"Generate branches with extended addressability, usually via indirect jumps.">;
26632685
def mdouble_EQ : Joined<["-"], "mdouble=">, Group<m_Group>, Values<"32,64">, Flags<[CC1Option]>,
2664-
HelpText<"Force double to be 32 bits or 64 bits">;
2686+
HelpText<"Force double to be 32 bits or 64 bits">,
2687+
MarshallingInfoStringInt<"LangOpts->DoubleSize", "0">;
26652688
def LongDouble_Group : OptionGroup<"<LongDouble group>">, Group<m_Group>,
26662689
DocName<"Long double flags">,
26672690
DocBrief<[{Selects the long double implementation}]>;
@@ -4878,7 +4901,8 @@ def fno_wchar : Flag<["-"], "fno-wchar">,
48784901
HelpText<"Disable C++ builtin type wchar_t">;
48794902
def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
48804903
MetaVarName<"<class name>">,
4881-
HelpText<"Specify the class to use for constant Objective-C string objects.">;
4904+
HelpText<"Specify the class to use for constant Objective-C string objects.">,
4905+
MarshallingInfoString<"LangOpts->ObjCConstantStringClass">;
48824906
def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
48834907
HelpText<"Objective-C++ Automatic Reference Counting standard library kind">, Values<"libc++,libstdc++,none">;
48844908
def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">,
@@ -4892,7 +4916,8 @@ def fencode_extended_block_signature : Flag<["-"], "fencode-extended-block-signa
48924916
HelpText<"enable extended encoding of block type signature">,
48934917
MarshallingInfoFlag<"LangOpts->EncodeExtendedBlockSig">;
48944918
def function_alignment : Separate<["-"], "function-alignment">,
4895-
HelpText<"default alignment for functions">;
4919+
HelpText<"default alignment for functions">,
4920+
MarshallingInfoStringInt<"LangOpts->FunctionAlignment">;
48964921
def pic_level : Separate<["-"], "pic-level">,
48974922
HelpText<"Value for __PIC__">;
48984923
def pic_is_pie : Flag<["-"], "pic-is-pie">,
@@ -4916,26 +4941,38 @@ def static_define : Flag<["-"], "static-define">,
49164941
HelpText<"Should __STATIC__ be defined">,
49174942
MarshallingInfoFlag<"LangOpts->Static">;
49184943
def stack_protector : Separate<["-"], "stack-protector">,
4919-
HelpText<"Enable stack protectors">;
4944+
HelpText<"Enable stack protectors">, Values<"0,1,2,3">,
4945+
NormalizedValuesScope<"LangOptions">,
4946+
NormalizedValues<["SSPOff", "SSPOn", "SSPStrong", "SSPReq"]>,
4947+
MarshallingInfoString<"LangOpts->StackProtector", "SSPOff">, AutoNormalizeEnum;
49204948
def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">,
49214949
HelpText<"Lower bound for a buffer to be considered for stack protection">;
4950+
// FIXME: diagnose if target does not support protected visibility
4951+
// Good place for this is CompilerInvocation::fixupInvocation. Do the same for parseVisibility.
49224952
def fvisibility : Separate<["-"], "fvisibility">,
4923-
HelpText<"Default type and symbol visibility">;
4953+
HelpText<"Default type and symbol visibility">, Values<"default,hidden,internal,protected">,
4954+
NormalizedValues<["DefaultVisibility", "HiddenVisibility", "HiddenVisibility", "ProtectedVisibility"]>,
4955+
MarshallingInfoString<"LangOpts->ValueVisibilityMode", "DefaultVisibility">, AutoNormalizeEnum;
49244956
def ftype_visibility : Separate<["-"], "ftype-visibility">,
49254957
HelpText<"Default type visibility">;
49264958
def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-to-externs">,
49274959
HelpText<"Apply global symbol visibility to external declarations without an explicit visibility">,
49284960
MarshallingInfoFlag<"LangOpts->SetVisibilityForExternDecls">;
49294961
def ftemplate_depth : Separate<["-"], "ftemplate-depth">,
4930-
HelpText<"Maximum depth of recursive template instantiation">;
4962+
HelpText<"Maximum depth of recursive template instantiation">,
4963+
MarshallingInfoStringInt<"LangOpts->InstantiationDepth", "1024">;
49314964
def foperator_arrow_depth : Separate<["-"], "foperator-arrow-depth">,
4932-
HelpText<"Maximum number of 'operator->'s to call for a member access">;
4965+
HelpText<"Maximum number of 'operator->'s to call for a member access">,
4966+
MarshallingInfoStringInt<"LangOpts->ArrowDepth", "256">;
49334967
def fconstexpr_depth : Separate<["-"], "fconstexpr-depth">,
4934-
HelpText<"Maximum depth of recursive constexpr function calls">;
4968+
HelpText<"Maximum depth of recursive constexpr function calls">,
4969+
MarshallingInfoStringInt<"LangOpts->ConstexprCallDepth", "512">;
49354970
def fconstexpr_steps : Separate<["-"], "fconstexpr-steps">,
4936-
HelpText<"Maximum number of steps in constexpr function evaluation">;
4971+
HelpText<"Maximum number of steps in constexpr function evaluation">,
4972+
MarshallingInfoStringInt<"LangOpts->ConstexprStepLimit", "1048576">;
49374973
def fbracket_depth : Separate<["-"], "fbracket-depth">,
4938-
HelpText<"Maximum nesting level for parentheses, brackets, and braces">;
4974+
HelpText<"Maximum nesting level for parentheses, brackets, and braces">,
4975+
MarshallingInfoStringInt<"LangOpts->BracketDepth", "256">;
49394976
defm const_strings : BoolFOption<"const-strings",
49404977
"LangOpts->ConstStrings", DefaultsToFalse,
49414978
ChangedBy<PosFlag, [], "Use">, ResetBy<NegFlag, [], "Don't use">,
@@ -4947,7 +4984,10 @@ def ffake_address_space_map : Flag<["-"], "ffake-address-space-map">,
49474984
HelpText<"Use a fake address space map; OpenCL testing purposes only">,
49484985
MarshallingInfoFlag<"LangOpts->FakeAddressSpaceMap">;
49494986
def faddress_space_map_mangling_EQ : Joined<["-"], "faddress-space-map-mangling=">, MetaVarName<"<yes|no|target>">,
4950-
HelpText<"Set the mode for address space map based mangling; OpenCL testing purposes only">;
4987+
HelpText<"Set the mode for address space map based mangling; OpenCL testing purposes only">,
4988+
Values<"target,no,yes">, NormalizedValuesScope<"LangOptions">,
4989+
NormalizedValues<["ASMM_Target", "ASMM_Off", "ASMM_On"]>,
4990+
MarshallingInfoString<"LangOpts->AddressSpaceMapMangling", "ASMM_Target">, AutoNormalizeEnum;
49514991
def funknown_anytype : Flag<["-"], "funknown-anytype">,
49524992
HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">,
49534993
MarshallingInfoFlag<"LangOpts->ParseUnknownAnytype">;
@@ -4966,16 +5006,21 @@ def fno_deprecated_macro : Flag<["-"], "fno-deprecated-macro">,
49665006
HelpText<"Undefines the __DEPRECATED macro">;
49675007
def fobjc_subscripting_legacy_runtime : Flag<["-"], "fobjc-subscripting-legacy-runtime">,
49685008
HelpText<"Allow Objective-C array and dictionary subscripting in legacy runtime">;
5009+
// TODO: Enforce values valid for MSVtorDispMode.
49695010
def vtordisp_mode_EQ : Joined<["-"], "vtordisp-mode=">,
4970-
HelpText<"Control vtordisp placement on win32 targets">;
5011+
HelpText<"Control vtordisp placement on win32 targets">,
5012+
MarshallingInfoStringInt<"LangOpts->VtorDispMode", "1">;
49715013
def fnative_half_type: Flag<["-"], "fnative-half-type">,
49725014
HelpText<"Use the native half type for __fp16 instead of promoting to float">;
49735015
def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and-returns">,
49745016
HelpText<"Use the native __fp16 type for arguments and returns (and skip ABI-specific lowering)">;
49755017
def fallow_half_arguments_and_returns : Flag<["-"], "fallow-half-arguments-and-returns">,
49765018
HelpText<"Allow function arguments and returns of type half">;
49775019
def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">,
4978-
HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">;
5020+
HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">,
5021+
NormalizedValuesScope<"LangOptions">,
5022+
NormalizedValues<["DCC_CDecl", "DCC_FastCall", "DCC_StdCall", "DCC_VectorCall", "DCC_RegCall"]>,
5023+
MarshallingInfoString<"LangOpts->DefaultCallingConv", "DCC_None">, AutoNormalizeEnum;
49795024
def finclude_default_header : Flag<["-"], "finclude-default-header">,
49805025
HelpText<"Include default header file for OpenCL">,
49815026
MarshallingInfoFlag<"LangOpts->IncludeDefaultHeader">;
@@ -4986,7 +5031,9 @@ def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">,
49865031
HelpText<"Preserve 3-component vector type">,
49875032
MarshallingInfoFlag<"CodeGenOpts.PreserveVec3Type">;
49885033
def fwchar_type_EQ : Joined<["-"], "fwchar-type=">,
4989-
HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">;
5034+
HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">,
5035+
NormalizedValues<["1", "2", "4"]>,
5036+
MarshallingInfoString<"LangOpts->WCharSize", "0">, AutoNormalizeEnum;
49905037
defm signed_wchar : BoolFOption<"signed-wchar",
49915038
"LangOpts->WCharIsSigned", DefaultsToTrue,
49925039
ChangedBy<NegFlag, [], "Use an unsigned">, ResetBy<PosFlag, [], "Use a signed">,

0 commit comments

Comments
 (0)