From b6ba59830796b4efad69a3d3c1fae56c20029f30 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Tue, 22 Dec 2020 10:01:51 +0100 Subject: [PATCH] [clang][cli] Port getAllArgumentValues to the marshalling infrastructure Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D93679 --- clang/include/clang/Driver/Options.td | 66 ++++++++++++++++++++----------- clang/lib/Frontend/CompilerInvocation.cpp | 47 ++++++---------------- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ffa7fbd84df..6585fd1ceb0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -679,7 +679,8 @@ def MP : Flag<["-"], "MP">, Group, Flags<[CC1Option]>, def MQ : JoinedOrSeparate<["-"], "MQ">, Group, Flags<[CC1Option]>, HelpText<"Specify name of main file output to quote in depfile">; def MT : JoinedOrSeparate<["-"], "MT">, Group, Flags<[CC1Option]>, - HelpText<"Specify name of main file output in depfile">; + HelpText<"Specify name of main file output in depfile">, + MarshallingInfoStringVector<"DependencyOutputOpts.Targets">; def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>, HelpText<"Use NMake/Jom format for the depfile">, MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat", "DependencyOutputFormat::Make">, @@ -753,7 +754,8 @@ def Wp_COMMA : CommaJoined<["-"], "Wp,">, MetaVarName<"">, Group; def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, Group, Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">, - HelpText<"Enable warnings for undefined macros with a prefix in the comma separated list ">; + HelpText<"Enable warnings for undefined macros with a prefix in the comma separated list ">, + MarshallingInfoStringVector<"DiagnosticOpts->UndefPrefixes">; def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, Flags<[CC1Option, HelpHidden]>; def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, Flags<[CC1Option, HelpHidden]>; def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, CoreOption]>, @@ -1387,7 +1389,8 @@ def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, Group, Flags<[CoreOption, NoXarchOption]>; def fsanitize_blacklist : Joined<["-"], "fsanitize-blacklist=">, Group, - HelpText<"Path to blacklist file for sanitizers">; + HelpText<"Path to blacklist file for sanitizers">, + MarshallingInfoStringVector<"LangOpts->SanitizerBlacklistFiles">; def fsanitize_system_blacklist : Joined<["-"], "fsanitize-system-blacklist=">, HelpText<"Path to system blacklist file for sanitizers">, Flags<[CC1Option]>; @@ -1405,13 +1408,15 @@ def fno_sanitize_coverage "Sanitizers">, Values<"func,bb,edge,indirect-calls,trace-bb,trace-cmp,trace-div,trace-gep,8bit-counters,trace-pc,trace-pc-guard,no-prune,inline-8bit-counters,inline-bool-flag">; def fsanitize_coverage_allowlist : Joined<["-"], "fsanitize-coverage-allowlist=">, Group, Flags<[CoreOption, NoXarchOption]>, - HelpText<"Restrict sanitizer coverage instrumentation exclusively to modules and functions that match the provided special case list, except the blocked ones">; + HelpText<"Restrict sanitizer coverage instrumentation exclusively to modules and functions that match the provided special case list, except the blocked ones">, + MarshallingInfoStringVector<"CodeGenOpts.SanitizeCoverageAllowlistFiles">; def : Joined<["-"], "fsanitize-coverage-whitelist=">, Group, Flags<[CoreOption, HelpHidden]>, Alias, HelpText<"Deprecated, use -fsanitize-coverage-allowlist= instead">; def fsanitize_coverage_blocklist : Joined<["-"], "fsanitize-coverage-blocklist=">, Group, Flags<[CoreOption, NoXarchOption]>, - HelpText<"Disable sanitizer coverage instrumentation for modules and functions that match the provided special case list, even the allowed ones">; + HelpText<"Disable sanitizer coverage instrumentation for modules and functions that match the provided special case list, even the allowed ones">, + MarshallingInfoStringVector<"CodeGenOpts.SanitizeCoverageBlocklistFiles">; def : Joined<["-"], "fsanitize-coverage-blacklist=">, Group, Flags<[CoreOption, HelpHidden]>, Alias, HelpText<"Deprecated, use -fsanitize-coverage-blocklist= instead">; @@ -1616,7 +1621,8 @@ defm delete_null_pointer_checks : BoolFOption<"delete-null-pointer-checks", def frewrite_map_file : Separate<["-"], "frewrite-map-file">, Group, - Flags<[ NoXarchOption, CC1Option ]>; + Flags<[ NoXarchOption, CC1Option ]>, + MarshallingInfoStringVector<"CodeGenOpts.RewriteMapFiles">; def frewrite_map_file_EQ : Joined<["-"], "frewrite-map-file=">, Group, Flags<[NoXarchOption]>; @@ -1694,15 +1700,18 @@ def fxray_instruction_threshold_ : def fxray_always_instrument : JoinedOrSeparate<["-"], "fxray-always-instrument=">, Group, Flags<[CC1Option]>, - HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'always instrument' XRay attribute.">; + HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'always instrument' XRay attribute.">, + MarshallingInfoStringVector<"LangOpts->XRayAlwaysInstrumentFiles">; def fxray_never_instrument : JoinedOrSeparate<["-"], "fxray-never-instrument=">, Group, Flags<[CC1Option]>, - HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'never instrument' XRay attribute.">; + HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'never instrument' XRay attribute.">, + MarshallingInfoStringVector<"LangOpts->XRayNeverInstrumentFiles">; def fxray_attr_list : JoinedOrSeparate<["-"], "fxray-attr-list=">, Group, Flags<[CC1Option]>, - HelpText<"Filename defining the list of functions/types for imbuing XRay attributes.">; + HelpText<"Filename defining the list of functions/types for imbuing XRay attributes.">, + MarshallingInfoStringVector<"LangOpts->XRayAttrListFiles">; def fxray_modes : JoinedOrSeparate<["-"], "fxray-modes=">, Group, Flags<[CC1Option]>, @@ -2191,7 +2200,8 @@ def fplugin_EQ : Joined<["-"], "fplugin=">, Group, Flags<[NoXarchOption HelpText<"Load the named plugin (dynamic shared object)">; def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, Group, Flags<[CC1Option]>, MetaVarName<"">, - HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">; + HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, + MarshallingInfoStringVector<"CodeGenOpts.PassPlugins">; defm preserve_as_comments : BoolFOption<"preserve-as-comments", "CodeGenOpts.PreserveAsmComments", DefaultsToTrue, ChangedBy, @@ -2639,7 +2649,8 @@ def iframeworkwithsysroot : JoinedOrSeparate<["-"], "iframeworkwithsysroot">, "absolute paths are relative to -isysroot">, MetaVarName<"">, Flags<[CC1Option]>; def imacros : JoinedOrSeparate<["-", "--"], "imacros">, Group, Flags<[CC1Option]>, - HelpText<"Include macros from file before parsing">, MetaVarName<"">; + HelpText<"Include macros from file before parsing">, MetaVarName<"">, + MarshallingInfoStringVector<"PreprocessorOpts->MacroIncludes">; def image__base : Separate<["-"], "image_base">; def include_ : JoinedOrSeparate<["-", "--"], "include">, Group, EnumName<"include">, MetaVarName<"">, HelpText<"Include file before parsing">, Flags<[CC1Option]>; @@ -2786,7 +2797,8 @@ def mkernel : Flag<["-"], "mkernel">, Group; def mlinker_version_EQ : Joined<["-"], "mlinker-version=">, Flags<[NoXarchOption]>; def mllvm : Separate<["-"], "mllvm">, Flags<[CC1Option,CC1AsOption,CoreOption]>, - HelpText<"Additional arguments to forward to LLVM's option processing">; + HelpText<"Additional arguments to forward to LLVM's option processing">, + MarshallingInfoStringVector<"FrontendOpts.LLVMArgs">; def mmacosx_version_min_EQ : Joined<["-"], "mmacosx-version-min=">, Group, HelpText<"Set Mac OS X deployment target">; def mmacos_version_min_EQ : Joined<["-"], "mmacos-version-min=">, @@ -3124,7 +3136,8 @@ def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group, HelpText<"Don't generate implicit floating point instructions">; def mimplicit_float : Flag<["-"], "mimplicit-float">, Group; def mrecip : Flag<["-"], "mrecip">, Group; -def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>; +def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>, + MarshallingInfoStringVector<"CodeGenOpts.Reciprocals">; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, Flags<[CC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString<"CodeGenOpts.PreferVectorWidth">; @@ -4120,7 +4133,8 @@ def tune_cpu : Separate<["-"], "tune-cpu">, HelpText<"Tune for a specific cpu type">, MarshallingInfoString<"TargetOpts->TuneCPU">; def target_feature : Separate<["-"], "target-feature">, - HelpText<"Target specific attributes">; + HelpText<"Target specific attributes">, + MarshallingInfoStringVector<"TargetOpts->FeaturesAsWritten">; def triple : Separate<["-"], "triple">, HelpText<"Specify target triple (e.g. i686-apple-darwin9)">, MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">, @@ -4323,7 +4337,8 @@ def debug_info_macro : Flag<["-"], "debug-info-macro">, HelpText<"Emit macro debug information">, MarshallingInfoFlag<"CodeGenOpts.MacroDebugInfo">; def default_function_attr : Separate<["-"], "default-function-attr">, - HelpText<"Apply given attribute to all functions">; + HelpText<"Apply given attribute to all functions">, + MarshallingInfoStringVector<"CodeGenOpts.DefaultFunctionAttrs">; def dwarf_version_EQ : Joined<["-"], "dwarf-version=">, MarshallingInfoStringInt<"CodeGenOpts.DwarfVersion">; def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">, @@ -4496,9 +4511,11 @@ def vectorize_slp : Flag<["-"], "vectorize-slp">, HelpText<"Run the SLP vectorization passes">, MarshallingInfoFlag<"CodeGenOpts.VectorizeSLP">; def dependent_lib : Joined<["--"], "dependent-lib=">, - HelpText<"Add dependent library">; + HelpText<"Add dependent library">, + MarshallingInfoStringVector<"CodeGenOpts.DependentLibraries">; def linker_option : Joined<["--"], "linker-option=">, - HelpText<"Add linker option">; + HelpText<"Add linker option">, + MarshallingInfoStringVector<"CodeGenOpts.LinkerOptions">; def fsanitize_coverage_type : Joined<["-"], "fsanitize-coverage-type=">, HelpText<"Sanitizer coverage type">, MarshallingInfoStringInt<"CodeGenOpts.SanitizeCoverageType">; @@ -4658,7 +4675,8 @@ def fcaret_diagnostics_max_lines : def verify_EQ : CommaJoined<["-"], "verify=">, MetaVarName<"">, HelpText<"Verify diagnostic output using comment directives that start with" - " prefixes in the comma-separated sequence ">; + " prefixes in the comma-separated sequence ">, + MarshallingInfoStringVector<"DiagnosticOpts->VerifyPrefixes">; def verify : Flag<["-"], "verify">, HelpText<"Equivalent to -verify=expected">; def verify_ignore_unexpected : Flag<["-"], "verify-ignore-unexpected">, @@ -4679,7 +4697,8 @@ def cc1as : Flag<["-"], "cc1as">; def ast_merge : Separate<["-"], "ast-merge">, MetaVarName<"">, - HelpText<"Merge the given AST file into the translation unit being compiled.">; + HelpText<"Merge the given AST file into the translation unit being compiled.">, + MarshallingInfoStringVector<"FrontendOpts.ASTMergeFiles">; def aux_target_cpu : Separate<["-"], "aux-target-cpu">, HelpText<"Target a specific auxiliary cpu type">; def aux_target_feature : Separate<["-"], "aux-target-feature">, @@ -4746,11 +4765,13 @@ def fmodule_map_file_home_is_cwd : Flag<["-"], "fmodule-map-file-home-is-cwd">, MarshallingInfoFlag<"HeaderSearchOpts->ModuleMapFileHomeIsCwd">; def fmodule_feature : Separate<["-"], "fmodule-feature">, MetaVarName<"">, - HelpText<"Enable in module map requires declarations">; + HelpText<"Enable in module map requires declarations">, + MarshallingInfoStringVector<"LangOpts->ModuleFeatures">; def fmodules_embed_file_EQ : Joined<["-"], "fmodules-embed-file=">, MetaVarName<"">, HelpText<"Embed the contents of the specified file into the module file " - "being compiled.">; + "being compiled.">, + MarshallingInfoStringVector<"FrontendOpts.ModulesEmbedFiles">; def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">, HelpText<"Embed the contents of all files read by this compilation into " "the produced module file.">, @@ -5190,7 +5211,8 @@ def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">, //===----------------------------------------------------------------------===// def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, - HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">; + HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">, + MarshallingInfoStringVector<"TargetOpts->OpenCLExtensionsAsWritten">; //===----------------------------------------------------------------------===// // CUDA Options diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index da4213e8952..49447f16637 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -328,7 +328,8 @@ static void denormalizeStringVector(SmallVectorImpl &Args, Option::OptionClass OptClass, unsigned TableIndex, const std::vector &Values) { - if (OptClass == Option::OptionClass::CommaJoinedClass) { + switch (OptClass) { + case Option::CommaJoinedClass: { std::string CommaJoinedValue; if (!Values.empty()) { CommaJoinedValue.append(Values.front()); @@ -339,9 +340,17 @@ static void denormalizeStringVector(SmallVectorImpl &Args, } denormalizeString(Args, Spelling, SA, Option::OptionClass::JoinedClass, TableIndex, CommaJoinedValue); - } else if (OptClass == Option::OptionClass::JoinedClass) { + break; + } + case Option::JoinedClass: + case Option::SeparateClass: + case Option::JoinedOrSeparateClass: for (const std::string &Value : Values) denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value); + break; + default: + llvm_unreachable("Cannot denormalize an option with option class " + "incompatible with string vector denormalization."); } } @@ -996,8 +1005,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, } } - Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ); - // Basic Block Sections implies Function Sections. Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections) || @@ -1127,10 +1134,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, } Opts.LinkBitcodeFiles.push_back(F); } - Opts.SanitizeCoverageAllowlistFiles = - Args.getAllArgValues(OPT_fsanitize_coverage_allowlist); - Opts.SanitizeCoverageBlocklistFiles = - Args.getAllArgValues(OPT_fsanitize_coverage_blocklist); Opts.SSPBufferSize = getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags); @@ -1212,8 +1215,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, } } - Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib); - Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option); bool NeedLocTracking = false; if (!Opts.OptRecordFile.empty()) @@ -1287,8 +1288,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, if (NeedLocTracking && Opts.getDebugInfo() == codegenoptions::NoDebugInfo) Opts.setDebugInfo(codegenoptions::LocTrackingOnly); - Opts.RewriteMapFiles = Args.getAllArgValues(OPT_frewrite_map_file); - // Parse -fsanitize-recover= arguments. // FIXME: Report unrecoverable sanitizers incorrectly specified here. parseSanitizerKinds("-fsanitize-recover=", @@ -1300,16 +1299,11 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.EmitVersionIdentMetadata = Args.hasFlag(OPT_Qy, OPT_Qn, true); - Opts.DefaultFunctionAttrs = Args.getAllArgValues(OPT_default_function_attr); - - Opts.PassPlugins = Args.getAllArgValues(OPT_fpass_plugin_EQ); - return Success; } static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, ArgList &Args) { - Opts.Targets = Args.getAllArgValues(OPT_MT); if (Args.hasArg(OPT_show_includes)) { // Writing both /showIncludes and preprocessor output to stdout // would produce interleaved output, so use stderr for /showIncludes. @@ -1487,7 +1481,6 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location); Opts.VerifyDiagnostics = Args.hasArg(OPT_verify) || Args.hasArg(OPT_verify_EQ); - Opts.VerifyPrefixes = Args.getAllArgValues(OPT_verify_EQ); if (Args.hasArg(OPT_verify)) Opts.VerifyPrefixes.push_back("expected"); // Keep VerifyPrefixes in its original order for the sake of diagnostics, and @@ -1534,8 +1527,6 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length_EQ, 0, Diags); - Opts.UndefPrefixes = Args.getAllArgValues(OPT_Wundef_prefix_EQ); - addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings); addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks); @@ -1732,8 +1723,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, } Opts.Plugins = Args.getAllArgValues(OPT_load); - Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); - Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump, OPT_ast_dump_EQ); Opts.ASTDumpAll = Args.hasArg(OPT_ast_dump_all, OPT_ast_dump_all_EQ); // Only the -fmodule-file= form. @@ -1742,7 +1731,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, if (Val.find('=') == StringRef::npos) Opts.ModuleFiles.push_back(std::string(Val)); } - Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ); Opts.AllowPCMWithCompilerErrors = Args.hasArg(OPT_fallow_pcm_with_errors); if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule) @@ -2542,7 +2530,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.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); llvm::sort(Opts.ModuleFeatures); Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type); Opts.NativeHalfArgsAndReturns |= Args.hasArg(OPT_fnative_half_arguments_and_returns); @@ -2750,20 +2737,12 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, // Parse -fsanitize= arguments. parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ), Diags, Opts.Sanitize); - Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist); std::vector systemBlacklists = Args.getAllArgValues(OPT_fsanitize_system_blacklist); Opts.SanitizerBlacklistFiles.insert(Opts.SanitizerBlacklistFiles.end(), systemBlacklists.begin(), systemBlacklists.end()); - // -fxray-{always,never}-instrument= filenames. - Opts.XRayAlwaysInstrumentFiles = - Args.getAllArgValues(OPT_fxray_always_instrument); - Opts.XRayNeverInstrumentFiles = - Args.getAllArgValues(OPT_fxray_never_instrument); - Opts.XRayAttrListFiles = Args.getAllArgValues(OPT_fxray_attr_list); - if (Arg *A = Args.getLastArg(OPT_fclang_abi_compat_EQ)) { Opts.setClangABICompat(LangOptions::ClangABI::Latest); @@ -2938,8 +2917,6 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, Opts.addMacroUndef(A->getValue()); } - Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); - // Add the ordered list of -includes. for (const auto *A : Args.filtered(OPT_include)) Opts.Includes.emplace_back(A->getValue()); @@ -2978,8 +2955,6 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags) { - Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); - Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ); Opts.AllowAMDGPUUnsafeFPAtomics = Args.hasFlag(options::OPT_munsafe_fp_atomics, options::OPT_mno_unsafe_fp_atomics, false); -- 2.11.0