diff --git a/clang/include/clang/Driver/Options.h b/clang/include/clang/Driver/Options.h --- a/clang/include/clang/Driver/Options.h +++ b/clang/include/clang/Driver/Options.h @@ -38,6 +38,7 @@ DXCOption = (1 << 17), CLDXCOption = (1 << 18), Ignored = (1 << 19), + TargetSpecific = (1 << 20), }; enum ID { 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 @@ -75,6 +75,10 @@ // FC1Option - This option should be accepted by flang -fc1. def FC1Option : OptionFlag; +// This is a target-specific option for compilation. Using it on an unsupported +// target will lead to an err_drv_unsupported_opt_for_target error. +def TargetSpecific : OptionFlag; + // A short name to show in documentation. The name will be interpreted as rST. class DocName { string DocName = name; } @@ -89,6 +93,8 @@ // GCC compatibility. class IgnoredGCCCompat : Flags<[HelpHidden]> {} +class TargetSpecific : Flags<[TargetSpecific]> {} + ///////// // Groups @@ -3114,7 +3120,7 @@ NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">, NormalizedValues<["None", "Explicit", "All"]>, HelpText<"Mapping between default visibility and export">, - Group, Flags<[CC1Option]>, + Group, Flags<[CC1Option,TargetSpecific]>, MarshallingInfoEnum,"None">; defm new_infallible : BoolFOption<"new-infallible", LangOpts<"NewInfallible">, DefaultFalse, @@ -3498,7 +3504,7 @@ def mwatchos_version_min_EQ : Joined<["-"], "mwatchos-version-min=">, Group; def mwatchos_simulator_version_min_EQ : Joined<["-"], "mwatchos-simulator-version-min=">; def mwatchsimulator_version_min_EQ : Joined<["-"], "mwatchsimulator-version-min=">, Alias; -def march_EQ : Joined<["-"], "march=">, Group, Flags<[CoreOption]>, +def march_EQ : Joined<["-"], "march=">, Group, Flags<[CoreOption,TargetSpecific]>, HelpText<"For a list of available architectures for the target use '-mcpu=help'">; def masm_EQ : Joined<["-"], "masm=">, Group, Flags<[NoXarchOption]>; def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group, Flags<[CC1Option]>, @@ -3523,7 +3529,7 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group, Flags<[NoXarchOption]>, HelpText<"Enable or disable Control Flow Guard checks and guard tables emission">, Values<"none,cf,cf-nochecks">; -def mcpu_EQ : Joined<["-"], "mcpu=">, Group, +def mcpu_EQ : Joined<["-"], "mcpu=">, Group, TargetSpecific, HelpText<"For a list of available CPUs for the target use '-mcpu=help'">; def mmcu_EQ : Joined<["-"], "mmcu=">, Group; def msim : Flag<["-"], "msim">, Group; @@ -3934,7 +3940,7 @@ HelpText<"On AIX, request creation of a build-id string, \"0xHEXSTRING\", in the string table of the loader section inside the linked binary">; def mignore_xcoff_visibility : Flag<["-"], "mignore-xcoff-visibility">, Group, HelpText<"Not emit the visibility attribute for asm in AIX OS or give all symbols 'unspecified' visibility in XCOFF object file">, - Flags<[CC1Option]>; + Flags<[CC1Option,TargetSpecific]>; defm backchain : BoolOption<"m", "backchain", CodeGenOpts<"Backchain">, DefaultFalse, PosFlag, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4885,9 +4885,15 @@ // In clang-cl, don't mention unknown arguments here since they have // already been warned about. - if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) - Diag(clang::diag::warn_drv_unused_argument) - << A->getAsString(C.getArgs()); + if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) { + if (A->getOption().hasFlag(options::TargetSpecific)) { + Diag(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << getTargetTriple(); + } else { + Diag(clang::diag::warn_drv_unused_argument) + << A->getAsString(C.getArgs()); + } + } } } } diff --git a/clang/lib/Driver/ToolChains/AIX.h b/clang/lib/Driver/ToolChains/AIX.h --- a/clang/lib/Driver/ToolChains/AIX.h +++ b/clang/lib/Driver/ToolChains/AIX.h @@ -80,6 +80,10 @@ void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; + void addClangTargetOptions( + const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args, + Action::OffloadKind DeviceOffloadingKind) const override; + void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -430,3 +430,14 @@ auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); } auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); } + +void AIX::addClangTargetOptions( + const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args, + Action::OffloadKind DeviceOffloadingKind) const { + Args.AddLastArg(CC1Args, options::OPT_mignore_xcoff_visibility); + Args.AddLastArg(CC1Args, options::OPT_mdefault_visibility_export_mapping_EQ); + + if (Args.hasFlag(options::OPT_fxl_pragma_pack, + options::OPT_fno_xl_pragma_pack, true)) + CC1Args.push_back("-fxl-pragma-pack"); +} diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp --- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -87,10 +87,6 @@ /// Get the (LLVM) name of the PowerPC cpu we are targeting. std::string ppc::getPPCTargetCPU(const Driver &D, const ArgList &Args, const llvm::Triple &T) { - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getSpelling() << T.getTriple(); - } if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) return normalizeCPUName(A->getValue(), T); return getPPCGenericTargetCPU(T); diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp --- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp +++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp @@ -118,12 +118,6 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args, const llvm::Triple &Triple) { - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getSpelling() << Triple.getTriple(); - return ""; - } - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); if (CPUName == "native") { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6142,23 +6142,6 @@ } } - if (const Arg *A = Args.getLastArg(options::OPT_mignore_xcoff_visibility)) { - if (Triple.isOSAIX()) - CmdArgs.push_back("-mignore-xcoff-visibility"); - else - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getAsString(Args) << TripleStr; - } - - if (const Arg *A = - Args.getLastArg(options::OPT_mdefault_visibility_export_mapping_EQ)) { - if (Triple.isOSAIX()) - A->render(Args, CmdArgs); - else - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getAsString(Args) << TripleStr; - } - if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden, options::OPT_fno_visibility_inlines_hidden, false)) CmdArgs.push_back("-fvisibility-inlines-hidden"); @@ -6967,10 +6950,6 @@ Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack, options::OPT_fno_apple_pragma_pack); - if (Args.hasFlag(options::OPT_fxl_pragma_pack, - options::OPT_fno_xl_pragma_pack, RawTriple.isOSAIX())) - CmdArgs.push_back("-fxl-pragma-pack"); - // Remarks can be enabled with any of the `-f.*optimization-record.*` flags. if (willEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple)) renderRemarksOptions(Args, CmdArgs, Triple, Input, Output, JA);