[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
This commit is contained in:
Jan Svoboda 2020-12-16 14:26:45 +01:00
parent ff4b76d74f
commit aec2991d08
3 changed files with 100 additions and 204 deletions

View File

@ -108,8 +108,6 @@ def err_fe_action_not_available : Error<
"action %0 not compiled in">;
def err_fe_invalid_alignment : Error<
"invalid value '%1' in '%0'; alignment must be a power of 2">;
def err_fe_invalid_wchar_type
: Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 'int'">;
def err_fe_invalid_exception_model
: Error<"invalid exception model '%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
def warn_fe_concepts_ts_flag : Warning<

View File

@ -994,7 +994,8 @@ def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=
def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">;
HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
MarshallingInfoStringInt<"LangOpts->MaxTokens">;
def fPIC : Flag<["-"], "fPIC">, Group<f_Group>;
def fno_PIC : Flag<["-"], "fno-PIC">, Group<f_Group>;
def fPIE : Flag<["-"], "fPIE">, Group<f_Group>;
@ -1212,7 +1213,10 @@ defm complete_member_pointers : BoolOption<"complete-member-pointers",
" would be significant under the Microsoft ABI">, "f">,
Group<f_clang_Group>;
def fcf_runtime_abi_EQ : Joined<["-"], "fcf-runtime-abi=">, Group<f_Group>,
Flags<[CC1Option]>;
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<"LangOpts->CFRuntime", "ObjectiveC">, AutoNormalizeEnum;
defm constant_cfstrings : BoolFOption<"constant-cfstrings",
"LangOpts->NoConstantCFStrings", DefaultsToFalse,
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
Group<f_clang_Group>;
def fsanitize_address_field_padding : Joined<["-"], "fsanitize-address-field-padding=">,
Group<f_clang_Group>,
HelpText<"Level of field padding for AddressSanitizer">;
HelpText<"Level of field padding for AddressSanitizer">,
MarshallingInfoStringInt<"LangOpts->SanitizeAddressFieldPadding">;
defm sanitize_address_use_after_scope : BoolOption<"sanitize-address-use-after-scope",
"CodeGenOpts.SanitizeAddressUseAfterScope", DefaultsToFalse,
ChangedBy<PosFlag, [], "Enable">, ResetBy<NegFlag, [CoreOption, NoXarchOption], "Disable">,
@ -1739,7 +1744,10 @@ defm experimental_relative_cxx_abi_vtables : BoolFOption<"experimental-relative-
def flat__namespace : Flag<["-"], "flat_namespace">;
def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, Group<f_Group>,
HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, Flags<[CC1Option]>;
HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, Flags<[CC1Option]>,
NormalizedValuesScope<"LangOptions::LaxVectorConversionKind">,
NormalizedValues<["None", "Integer", "All"]>,
MarshallingInfoString<"LangOpts->LaxVectorConversions", "All">, AutoNormalizeEnum;
def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>,
Alias<flax_vector_conversions_EQ>, AliasArgs<["integer"]>;
def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group<f_Group>;
@ -1791,7 +1799,12 @@ defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
ChangedBy<PosFlag, [], "Parse templated function definitions at the end of the translation unit">,
ResetBy<NegFlag, [NoXarchOption], "Disable delayed template parsing">,
BothFlags<[CoreOption]>>;
def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, Group<f_Group>, Flags<[CC1Option]>;
def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, Group<f_Group>, Flags<[CC1Option]>,
Values<"single,multiple,virtual">, NormalizedValuesScope<"LangOptions">,
NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", "PPTMK_FullGeneralityMultipleInheritance",
"PPTMK_FullGeneralityVirtualInheritance"]>,
MarshallingInfoString<"LangOpts->MSPointerToMemberRepresentationMethod", "PPTMK_BestCase">,
AutoNormalizeEnum;
def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, Group<i_Group>,
Flags<[NoXarchOption, CC1Option]>, MetaVarName<"<directory>">,
HelpText<"Specify the module cache path">;
@ -1880,7 +1893,8 @@ def fmodules_ts : Flag <["-"], "fmodules-ts">, Group<f_Group>,
def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias<fimplicit_module_maps>;
def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group<f_Group>,
Flags<[NoXarchOption,CC1Option]>, MetaVarName<"<name>">,
HelpText<"Specify the name of the module to build">;
HelpText<"Specify the name of the module to build">,
MarshallingInfoString<"LangOpts->ModuleName">;
def fmodule_name : Separate<["-"], "fmodule-name">, Alias<fmodule_name_EQ>;
def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
Flags<[CC1Option]>, Alias<fmodule_name_EQ>;
@ -2035,7 +2049,8 @@ def fno_aligned_allocation: Flag<["-"], "fno-aligned-allocation">,
Group<f_Group>, Flags<[CC1Option]>;
def fnew_alignment_EQ : Joined<["-"], "fnew-alignment=">,
HelpText<"Specifies the largest alignment guaranteed by '::operator new(size_t)'">,
MetaVarName<"<align>">, Group<f_Group>, Flags<[CC1Option]>;
MetaVarName<"<align>">, Group<f_Group>, Flags<[CC1Option]>,
MarshallingInfoStringInt<"LangOpts->NewAlignOverride">;
def : Separate<["-"], "fnew-alignment">, Alias<fnew_alignment_EQ>;
def : Flag<["-"], "faligned-new">, Alias<faligned_allocation>;
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>;
def fpack_struct : Flag<["-"], "fpack-struct">, Group<f_Group>;
def fno_pack_struct : Flag<["-"], "fno-pack-struct">, Group<f_Group>;
def fpack_struct_EQ : Joined<["-"], "fpack-struct=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Specify the default maximum struct packing alignment">;
HelpText<"Specify the default maximum struct packing alignment">,
MarshallingInfoStringInt<"LangOpts->PackStruct">;
def fmax_type_align_EQ : Joined<["-"], "fmax-type-align=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Specify the maximum alignment to enforce on pointers lacking an explicit alignment">;
HelpText<"Specify the maximum alignment to enforce on pointers lacking an explicit alignment">,
MarshallingInfoStringInt<"LangOpts->MaxTypeAlign">;
def fno_max_type_align : Flag<["-"], "fno-max-type-align">, Group<f_Group>;
defm pascal_strings : BoolFOption<"pascal-strings",
"LangOpts->PascalStrings", DefaultsToFalse,
@ -2217,12 +2234,16 @@ def fstack_protector : Flag<["-"], "fstack-protector">, Group<f_Group>,
"address. The reference stack guard value is stored in a global variable.">;
def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, Group<f_Group>,
Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
" | pattern">, Values<"uninitialized,pattern">;
" | pattern">, Values<"uninitialized,zero,pattern">,
NormalizedValuesScope<"LangOptions::TrivialAutoVarInitKind">,
NormalizedValues<["Uninitialized", "Zero", "Pattern"]>,
MarshallingInfoString<"LangOpts->TrivialAutoVarInit", "Uninitialized">, AutoNormalizeEnum;
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">;
def ftrivial_auto_var_init_stop_after : Joined<["-"], "ftrivial-auto-var-init-stop-after=">, Group<f_Group>,
Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial automatic stack variables after the specified number of instances">;
Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial automatic stack variables after the specified number of instances">,
MarshallingInfoStringInt<"LangOpts->TrivialAutoVarInitStopAfter">;
def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group<f_Group>, Flags<[CoreOption]>,
HelpText<"Emit full debug info for all types used by the program">;
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>;
def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">,
HelpText<"Warn if a function definition returns or accepts an object larger "
"in bytes than a given value">, Flags<[HelpHidden]>;
def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1Option]>;
def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1Option]>,
MarshallingInfoStringInt<"LangOpts->NumLargeByValueCopy">;
// These "special" warning flags are effectively processed as f_Group flags by the driver:
// 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
def mlong_calls : Flag<["-"], "mlong-calls">, Group<m_Group>,
HelpText<"Generate branches with extended addressability, usually via indirect jumps.">;
def mdouble_EQ : Joined<["-"], "mdouble=">, Group<m_Group>, Values<"32,64">, Flags<[CC1Option]>,
HelpText<"Force double to be 32 bits or 64 bits">;
HelpText<"Force double to be 32 bits or 64 bits">,
MarshallingInfoStringInt<"LangOpts->DoubleSize", "0">;
def LongDouble_Group : OptionGroup<"<LongDouble group>">, Group<m_Group>,
DocName<"Long double flags">,
DocBrief<[{Selects the long double implementation}]>;
@ -4878,7 +4901,8 @@ def fno_wchar : Flag<["-"], "fno-wchar">,
HelpText<"Disable C++ builtin type wchar_t">;
def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
MetaVarName<"<class name>">,
HelpText<"Specify the class to use for constant Objective-C string objects.">;
HelpText<"Specify the class to use for constant Objective-C string objects.">,
MarshallingInfoString<"LangOpts->ObjCConstantStringClass">;
def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
HelpText<"Objective-C++ Automatic Reference Counting standard library kind">, Values<"libc++,libstdc++,none">;
def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">,
@ -4892,7 +4916,8 @@ def fencode_extended_block_signature : Flag<["-"], "fencode-extended-block-signa
HelpText<"enable extended encoding of block type signature">,
MarshallingInfoFlag<"LangOpts->EncodeExtendedBlockSig">;
def function_alignment : Separate<["-"], "function-alignment">,
HelpText<"default alignment for functions">;
HelpText<"default alignment for functions">,
MarshallingInfoStringInt<"LangOpts->FunctionAlignment">;
def pic_level : Separate<["-"], "pic-level">,
HelpText<"Value for __PIC__">;
def pic_is_pie : Flag<["-"], "pic-is-pie">,
@ -4916,26 +4941,38 @@ def static_define : Flag<["-"], "static-define">,
HelpText<"Should __STATIC__ be defined">,
MarshallingInfoFlag<"LangOpts->Static">;
def stack_protector : Separate<["-"], "stack-protector">,
HelpText<"Enable stack protectors">;
HelpText<"Enable stack protectors">, Values<"0,1,2,3">,
NormalizedValuesScope<"LangOptions">,
NormalizedValues<["SSPOff", "SSPOn", "SSPStrong", "SSPReq"]>,
MarshallingInfoString<"LangOpts->StackProtector", "SSPOff">, AutoNormalizeEnum;
def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">,
HelpText<"Lower bound for a buffer to be considered for stack protection">;
// FIXME: diagnose if target does not support protected visibility
// Good place for this is CompilerInvocation::fixupInvocation. Do the same for parseVisibility.
def fvisibility : Separate<["-"], "fvisibility">,
HelpText<"Default type and symbol visibility">;
HelpText<"Default type and symbol visibility">, Values<"default,hidden,internal,protected">,
NormalizedValues<["DefaultVisibility", "HiddenVisibility", "HiddenVisibility", "ProtectedVisibility"]>,
MarshallingInfoString<"LangOpts->ValueVisibilityMode", "DefaultVisibility">, AutoNormalizeEnum;
def ftype_visibility : Separate<["-"], "ftype-visibility">,
HelpText<"Default type visibility">;
def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-to-externs">,
HelpText<"Apply global symbol visibility to external declarations without an explicit visibility">,
MarshallingInfoFlag<"LangOpts->SetVisibilityForExternDecls">;
def ftemplate_depth : Separate<["-"], "ftemplate-depth">,
HelpText<"Maximum depth of recursive template instantiation">;
HelpText<"Maximum depth of recursive template instantiation">,
MarshallingInfoStringInt<"LangOpts->InstantiationDepth", "1024">;
def foperator_arrow_depth : Separate<["-"], "foperator-arrow-depth">,
HelpText<"Maximum number of 'operator->'s to call for a member access">;
HelpText<"Maximum number of 'operator->'s to call for a member access">,
MarshallingInfoStringInt<"LangOpts->ArrowDepth", "256">;
def fconstexpr_depth : Separate<["-"], "fconstexpr-depth">,
HelpText<"Maximum depth of recursive constexpr function calls">;
HelpText<"Maximum depth of recursive constexpr function calls">,
MarshallingInfoStringInt<"LangOpts->ConstexprCallDepth", "512">;
def fconstexpr_steps : Separate<["-"], "fconstexpr-steps">,
HelpText<"Maximum number of steps in constexpr function evaluation">;
HelpText<"Maximum number of steps in constexpr function evaluation">,
MarshallingInfoStringInt<"LangOpts->ConstexprStepLimit", "1048576">;
def fbracket_depth : Separate<["-"], "fbracket-depth">,
HelpText<"Maximum nesting level for parentheses, brackets, and braces">;
HelpText<"Maximum nesting level for parentheses, brackets, and braces">,
MarshallingInfoStringInt<"LangOpts->BracketDepth", "256">;
defm const_strings : BoolFOption<"const-strings",
"LangOpts->ConstStrings", DefaultsToFalse,
ChangedBy<PosFlag, [], "Use">, ResetBy<NegFlag, [], "Don't use">,
@ -4947,7 +4984,10 @@ def ffake_address_space_map : Flag<["-"], "ffake-address-space-map">,
HelpText<"Use a fake address space map; OpenCL testing purposes only">,
MarshallingInfoFlag<"LangOpts->FakeAddressSpaceMap">;
def faddress_space_map_mangling_EQ : Joined<["-"], "faddress-space-map-mangling=">, MetaVarName<"<yes|no|target>">,
HelpText<"Set the mode for address space map based mangling; OpenCL testing purposes only">;
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<"LangOpts->AddressSpaceMapMangling", "ASMM_Target">, AutoNormalizeEnum;
def funknown_anytype : Flag<["-"], "funknown-anytype">,
HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">,
MarshallingInfoFlag<"LangOpts->ParseUnknownAnytype">;
@ -4966,8 +5006,10 @@ def fno_deprecated_macro : Flag<["-"], "fno-deprecated-macro">,
HelpText<"Undefines the __DEPRECATED macro">;
def fobjc_subscripting_legacy_runtime : Flag<["-"], "fobjc-subscripting-legacy-runtime">,
HelpText<"Allow Objective-C array and dictionary subscripting in legacy runtime">;
// TODO: Enforce values valid for MSVtorDispMode.
def vtordisp_mode_EQ : Joined<["-"], "vtordisp-mode=">,
HelpText<"Control vtordisp placement on win32 targets">;
HelpText<"Control vtordisp placement on win32 targets">,
MarshallingInfoStringInt<"LangOpts->VtorDispMode", "1">;
def fnative_half_type: Flag<["-"], "fnative-half-type">,
HelpText<"Use the native half type for __fp16 instead of promoting to float">;
def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and-returns">,
@ -4975,7 +5017,10 @@ def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and
def fallow_half_arguments_and_returns : Flag<["-"], "fallow-half-arguments-and-returns">,
HelpText<"Allow function arguments and returns of type half">;
def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">,
HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">;
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<"LangOpts->DefaultCallingConv", "DCC_None">, AutoNormalizeEnum;
def finclude_default_header : Flag<["-"], "finclude-default-header">,
HelpText<"Include default header file for OpenCL">,
MarshallingInfoFlag<"LangOpts->IncludeDefaultHeader">;
@ -4986,7 +5031,9 @@ def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">,
HelpText<"Preserve 3-component vector type">,
MarshallingInfoFlag<"CodeGenOpts.PreserveVec3Type">;
def fwchar_type_EQ : Joined<["-"], "fwchar-type=">,
HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">;
HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">,
NormalizedValues<["1", "2", "4"]>,
MarshallingInfoString<"LangOpts->WCharSize", "0">, AutoNormalizeEnum;
defm signed_wchar : BoolFOption<"signed-wchar",
"LangOpts->WCharIsSigned", DefaultsToTrue,
ChangedBy<NegFlag, [], "Use an unsigned">, ResetBy<PosFlag, [], "Use a signed">,

View File

@ -352,7 +352,8 @@ static T extractMaskValue(T KeyPath) {
}
static void FixupInvocation(CompilerInvocation &Invocation,
DiagnosticsEngine &Diags) {
DiagnosticsEngine &Diags,
InputArgList &Args) {
LangOptions &LangOpts = *Invocation.getLangOpts();
DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
@ -366,10 +367,12 @@ static void FixupInvocation(CompilerInvocation &Invocation,
LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
LangOpts.CurrentModule = LangOpts.ModuleName;
llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
llvm::Triple T(TargetOpts.Triple);
llvm::Triple::ArchType Arch = T.getArch();
if (LangOpts.getExceptionHandling() != llvm::ExceptionHandling::None &&
T.isWindowsMSVCEnvironment())
@ -378,6 +381,28 @@ static void FixupInvocation(CompilerInvocation &Invocation,
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
Diags.Report(diag::warn_c_kext);
if (LangOpts.NewAlignOverride &&
!llvm::isPowerOf2_32(LangOpts.NewAlignOverride)) {
Arg *A = Args.getLastArg(OPT_fnew_alignment_EQ);
Diags.Report(diag::err_fe_invalid_alignment)
<< A->getAsString(Args) << A->getValue();
LangOpts.NewAlignOverride = 0;
}
if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
auto DefaultCC = LangOpts.getDefaultCallingConv();
bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
DefaultCC == LangOptions::DCC_StdCall) &&
Arch != llvm::Triple::x86;
emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
DefaultCC == LangOptions::DCC_RegCall) &&
!T.isX86();
if (emitError)
Diags.Report(diag::err_drv_argument_not_allowed_with)
<< A->getSpelling() << T.getTriple();
}
}
//===----------------------------------------------------------------------===//
@ -2605,24 +2630,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.GNUInline = 1;
}
if (const auto *A = Args.getLastArg(OPT_fcf_runtime_abi_EQ))
Opts.CFRuntime =
llvm::StringSwitch<LangOptions::CoreFoundationABI>(A->getValue())
.Cases("unspecified", "standalone", "objc",
LangOptions::CoreFoundationABI::ObjectiveC)
.Cases("swift", "swift-5.0",
LangOptions::CoreFoundationABI::Swift5_0)
.Case("swift-4.2", LangOptions::CoreFoundationABI::Swift4_2)
.Case("swift-4.1", LangOptions::CoreFoundationABI::Swift4_1)
.Default(LangOptions::CoreFoundationABI::ObjectiveC);
// The value-visibility mode defaults to "default".
if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) {
Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags));
} else {
Opts.setValueVisibilityMode(DefaultVisibility);
}
// The type-visibility mode defaults to the value-visibility mode.
if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
@ -2696,20 +2703,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
OPT_fno_dollars_in_identifiers,
Opts.DollarIdents);
Opts.setVtorDispMode(
MSVtorDispMode(getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags)));
if (Arg *A = Args.getLastArg(OPT_flax_vector_conversions_EQ)) {
using LaxKind = LangOptions::LaxVectorConversionKind;
if (auto Kind = llvm::StringSwitch<Optional<LaxKind>>(A->getValue())
.Case("none", LaxKind::None)
.Case("integer", LaxKind::Integer)
.Case("all", LaxKind::All)
.Default(llvm::None))
Opts.setLaxVectorConversions(*Kind);
else
Diags.Report(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
}
// -ffixed-point
Opts.FixedPoint =
@ -2752,15 +2745,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
Opts.Char8 = Args.hasFlag(OPT_fchar8__t, OPT_fno_char8__t, Opts.CPlusPlus20);
if (const Arg *A = Args.getLastArg(OPT_fwchar_type_EQ)) {
Opts.WCharSize = llvm::StringSwitch<unsigned>(A->getValue())
.Case("char", 1)
.Case("short", 2)
.Case("int", 4)
.Default(0);
if (Opts.WCharSize == 0)
Diags.Report(diag::err_fe_invalid_wchar_type) << A->getValue();
}
Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
if (!Opts.NoBuiltin)
getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs);
@ -2769,33 +2753,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.AlignedAllocation);
Opts.AlignedAllocationUnavailable =
Opts.AlignedAllocation && Args.hasArg(OPT_aligned_alloc_unavailable);
Opts.NewAlignOverride =
getLastArgIntValue(Args, OPT_fnew_alignment_EQ, 0, Diags);
if (Opts.NewAlignOverride && !llvm::isPowerOf2_32(Opts.NewAlignOverride)) {
Arg *A = Args.getLastArg(OPT_fnew_alignment_EQ);
Diags.Report(diag::err_fe_invalid_alignment) << A->getAsString(Args)
<< A->getValue();
Opts.NewAlignOverride = 0;
}
if (Args.hasArg(OPT_fconcepts_ts))
Diags.Report(diag::warn_fe_concepts_ts_flag);
Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno);
Opts.InstantiationDepth =
getLastArgIntValue(Args, OPT_ftemplate_depth, 1024, Diags);
Opts.ArrowDepth =
getLastArgIntValue(Args, OPT_foperator_arrow_depth, 256, Diags);
Opts.ConstexprCallDepth =
getLastArgIntValue(Args, OPT_fconstexpr_depth, 512, Diags);
Opts.ConstexprStepLimit =
getLastArgIntValue(Args, OPT_fconstexpr_steps, 1048576, Diags);
Opts.BracketDepth = getLastArgIntValue(Args, OPT_fbracket_depth, 256, Diags);
Opts.NumLargeByValueCopy =
getLastArgIntValue(Args, OPT_Wlarge_by_value_copy_EQ, 0, Diags);
Opts.ObjCConstantStringClass =
std::string(Args.getLastArgValue(OPT_fconstant_string_class));
Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags);
Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags);
Opts.DoubleSize = getLastArgIntValue(Args, OPT_mdouble_EQ, 0, Diags);
Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128)
? 128
: Args.hasArg(OPT_mlong_double_64) ? 64 : 0;
@ -2805,8 +2765,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
|| Args.hasArg(OPT_fdump_record_layouts);
if (Opts.FastRelaxedMath)
Opts.setDefaultFPContractMode(LangOptions::FPM_Fast);
Opts.ModuleName = std::string(Args.getLastArgValue(OPT_fmodule_name_EQ));
Opts.CurrentModule = Opts.ModuleName;
Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature);
llvm::sort(Opts.ModuleFeatures);
Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type);
@ -2831,75 +2789,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Args.hasFlag(OPT_fdeclspec, OPT_fno_declspec,
(Opts.MicrosoftExt || Opts.Borland || Opts.CUDA));
if (Arg *A = Args.getLastArg(OPT_faddress_space_map_mangling_EQ)) {
switch (llvm::StringSwitch<unsigned>(A->getValue())
.Case("target", LangOptions::ASMM_Target)
.Case("no", LangOptions::ASMM_Off)
.Case("yes", LangOptions::ASMM_On)
.Default(255)) {
default:
Diags.Report(diag::err_drv_invalid_value)
<< "-faddress-space-map-mangling=" << A->getValue();
break;
case LangOptions::ASMM_Target:
Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Target);
break;
case LangOptions::ASMM_On:
Opts.setAddressSpaceMapMangling(LangOptions::ASMM_On);
break;
case LangOptions::ASMM_Off:
Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Off);
break;
}
}
if (Arg *A = Args.getLastArg(OPT_fms_memptr_rep_EQ)) {
LangOptions::PragmaMSPointersToMembersKind InheritanceModel =
llvm::StringSwitch<LangOptions::PragmaMSPointersToMembersKind>(
A->getValue())
.Case("single",
LangOptions::PPTMK_FullGeneralitySingleInheritance)
.Case("multiple",
LangOptions::PPTMK_FullGeneralityMultipleInheritance)
.Case("virtual",
LangOptions::PPTMK_FullGeneralityVirtualInheritance)
.Default(LangOptions::PPTMK_BestCase);
if (InheritanceModel == LangOptions::PPTMK_BestCase)
Diags.Report(diag::err_drv_invalid_value)
<< "-fms-memptr-rep=" << A->getValue();
Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
}
// Check for MS default calling conventions being specified.
if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
LangOptions::DefaultCallingConvention DefaultCC =
llvm::StringSwitch<LangOptions::DefaultCallingConvention>(A->getValue())
.Case("cdecl", LangOptions::DCC_CDecl)
.Case("fastcall", LangOptions::DCC_FastCall)
.Case("stdcall", LangOptions::DCC_StdCall)
.Case("vectorcall", LangOptions::DCC_VectorCall)
.Case("regcall", LangOptions::DCC_RegCall)
.Default(LangOptions::DCC_None);
if (DefaultCC == LangOptions::DCC_None)
Diags.Report(diag::err_drv_invalid_value)
<< "-fdefault-calling-conv=" << A->getValue();
llvm::Triple T(TargetOpts.Triple);
llvm::Triple::ArchType Arch = T.getArch();
bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
DefaultCC == LangOptions::DCC_StdCall) &&
Arch != llvm::Triple::x86;
emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
DefaultCC == LangOptions::DCC_RegCall) &&
!T.isX86();
if (emitError)
Diags.Report(diag::err_drv_argument_not_allowed_with)
<< A->getSpelling() << T.getTriple();
else
Opts.setDefaultCallingConv(DefaultCC);
}
// -mrtd option
if (Arg *A = Args.getLastArg(OPT_mrtd)) {
if (Opts.getDefaultCallingConv() != LangOptions::DCC_None)
@ -3084,42 +2973,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
}
Opts.setFPExceptionMode(FPEB);
unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags);
switch (SSP) {
default:
Diags.Report(diag::err_drv_invalid_value)
<< Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
break;
case 0: Opts.setStackProtector(LangOptions::SSPOff); break;
case 1: Opts.setStackProtector(LangOptions::SSPOn); break;
case 2: Opts.setStackProtector(LangOptions::SSPStrong); break;
case 3: Opts.setStackProtector(LangOptions::SSPReq); break;
}
if (Arg *A = Args.getLastArg(OPT_ftrivial_auto_var_init)) {
StringRef Val = A->getValue();
if (Val == "uninitialized")
Opts.setTrivialAutoVarInit(
LangOptions::TrivialAutoVarInitKind::Uninitialized);
else if (Val == "zero")
Opts.setTrivialAutoVarInit(LangOptions::TrivialAutoVarInitKind::Zero);
else if (Val == "pattern")
Opts.setTrivialAutoVarInit(LangOptions::TrivialAutoVarInitKind::Pattern);
else
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
}
if (Arg *A = Args.getLastArg(OPT_ftrivial_auto_var_init_stop_after)) {
int Val = std::stoi(A->getValue());
Opts.TrivialAutoVarInitStopAfter = Val;
}
// Parse -fsanitize= arguments.
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
Diags, Opts.Sanitize);
// -fsanitize-address-field-padding=N has to be a LangOpt, parse it here.
Opts.SanitizeAddressFieldPadding =
getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags);
Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
std::vector<std::string> systemBlacklists =
Args.getAllArgValues(OPT_fsanitize_system_blacklist);
@ -3169,8 +3025,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
}
}
Opts.MaxTokens = getLastArgIntValue(Args, OPT_fmax_tokens_EQ, 0, Diags);
if (Arg *A = Args.getLastArg(OPT_msign_return_address_EQ)) {
StringRef SignScope = A->getValue();
@ -3483,9 +3337,6 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
}
}
LangOpts.FunctionAlignment =
getLastArgIntValue(Args, OPT_function_alignment, 0, Diags);
if (LangOpts.CUDA) {
// During CUDA device-side compilation, the aux triple is the
// triple used for host compilation.
@ -3526,7 +3377,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Res.getCodeGenOpts().Argv0 = Argv0;
Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
FixupInvocation(Res, Diags);
FixupInvocation(Res, Diags, Args);
return Success;
}