mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 06:06:34 +08:00
[Driver] Allow warning for unclaimed TargetSpecific options
For unclaimed target-agnostic options, we can apply clang_ignored_gcc_optimization_f_Group to accept but warn about them. ``` % clang -c -fexpensive-optimizations a.c clang: warning: optimization flag '-fexpensive-optimizations' is not supported [-Wignored-optimization-argument] ``` For an unclaimed target-specific option, one target may want to accept but warn about it. Add `llvm::opt::Arg::IgnoredTargetSpecific` to support this warning need. Close https://github.com/llvm/llvm-project/issues/63282 Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D152856
This commit is contained in:
@@ -3555,7 +3555,6 @@ def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group<m_Group>, Flags<[NoXarch
|
||||
def m64 : Flag<["-"], "m64">, Group<m_Group>, Flags<[NoXarchOption, CoreOption]>;
|
||||
def maix64 : Flag<["-"], "maix64">, Group<m_Group>, Flags<[NoXarchOption]>;
|
||||
def mx32 : Flag<["-"], "mx32">, Group<m_Group>, Flags<[NoXarchOption, CoreOption]>;
|
||||
def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>;
|
||||
def miamcu : Flag<["-"], "miamcu">, Group<m_Group>, Flags<[NoXarchOption, CoreOption]>,
|
||||
HelpText<"Use Intel MCU ABI">;
|
||||
def mno_iamcu : Flag<["-"], "mno-iamcu">, Group<m_Group>, Flags<[NoXarchOption, CoreOption]>;
|
||||
@@ -3564,6 +3563,7 @@ def malign_loops_EQ : Joined<["-"], "malign-loops=">, Group<clang_ignored_m_Grou
|
||||
def malign_jumps_EQ : Joined<["-"], "malign-jumps=">, Group<clang_ignored_m_Group>;
|
||||
|
||||
let Flags = [TargetSpecific] in {
|
||||
def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>;
|
||||
def malign_branch_EQ : CommaJoined<["-"], "malign-branch=">, Group<m_Group>,
|
||||
HelpText<"Specify types of branches to align">;
|
||||
def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, Group<m_Group>,
|
||||
@@ -3651,9 +3651,7 @@ def malign_double : Flag<["-"], "malign-double">, Group<m_Group>, Flags<[CC1Opti
|
||||
let Flags = [TargetSpecific] in {
|
||||
def mfloat_abi_EQ : Joined<["-"], "mfloat-abi=">, Group<m_Group>, Values<"soft,softfp,hard">;
|
||||
def mfpmath_EQ : Joined<["-"], "mfpmath=">, Group<m_Group>;
|
||||
} // let Flags = [TargetSpecific]
|
||||
def mfpu_EQ : Joined<["-"], "mfpu=">, Group<m_Group>;
|
||||
let Flags = [TargetSpecific] in {
|
||||
def mhwdiv_EQ : Joined<["-"], "mhwdiv=">, Group<m_Group>;
|
||||
def mhwmult_EQ : Joined<["-"], "mhwmult=">, Group<m_Group>;
|
||||
} // let Flags = [TargetSpecific]
|
||||
|
||||
@@ -4892,7 +4892,8 @@ void Driver::BuildJobs(Compilation &C) const {
|
||||
// In clang-cl, don't mention unknown arguments here since they have
|
||||
// already been warned about.
|
||||
if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) {
|
||||
if (A->getOption().hasFlag(options::TargetSpecific)) {
|
||||
if (A->getOption().hasFlag(options::TargetSpecific) &&
|
||||
!A->isIgnoredTargetSpecific()) {
|
||||
Diag(diag::err_drv_unsupported_opt_for_target)
|
||||
<< A->getSpelling() << getTargetTriple();
|
||||
} else {
|
||||
|
||||
@@ -139,4 +139,10 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
|
||||
// or the alias -m[no-]strict-align.
|
||||
AddTargetFeature(Args, Features, options::OPT_munaligned_access,
|
||||
options::OPT_mno_unaligned_access, "ual");
|
||||
|
||||
// Accept but warn about these TargetSpecific options.
|
||||
if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
|
||||
A->ignoreTargetSpecific();
|
||||
if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
|
||||
A->ignoreTargetSpecific();
|
||||
}
|
||||
|
||||
@@ -701,6 +701,9 @@ void toolchains::MinGW::addClangTargetOptions(
|
||||
<< A->getSpelling() << GuardArgs;
|
||||
}
|
||||
}
|
||||
|
||||
if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
|
||||
A->ignoreTargetSpecific();
|
||||
}
|
||||
|
||||
void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
|
||||
|
||||
@@ -47,11 +47,17 @@ private:
|
||||
/// ArgList.
|
||||
unsigned Index;
|
||||
|
||||
/// Was this argument used to effect compilation?
|
||||
/// Was this argument used to affect compilation?
|
||||
///
|
||||
/// This is used for generating "argument unused" diagnostics.
|
||||
/// This is used to generate an "argument unused" warning (without
|
||||
/// clang::driver::options::TargetSpecific) or "unsupported option" error
|
||||
/// (with TargetSpecific).
|
||||
mutable unsigned Claimed : 1;
|
||||
|
||||
/// Used by an unclaimed option with the TargetSpecific flag. If set, report
|
||||
/// an "argument unused" warning instead of an "unsupported option" error.
|
||||
unsigned IgnoredTargetSpecific : 1;
|
||||
|
||||
/// Does this argument own its values?
|
||||
mutable unsigned OwnsValues : 1;
|
||||
|
||||
@@ -93,6 +99,7 @@ public:
|
||||
const Arg &getBaseArg() const {
|
||||
return BaseArg ? *BaseArg : *this;
|
||||
}
|
||||
Arg &getBaseArg() { return BaseArg ? const_cast<Arg &>(*BaseArg) : *this; }
|
||||
void setBaseArg(const Arg *BaseArg) { this->BaseArg = BaseArg; }
|
||||
|
||||
/// Args are converted to their unaliased form. For args that originally
|
||||
@@ -104,10 +111,15 @@ public:
|
||||
void setOwnsValues(bool Value) const { OwnsValues = Value; }
|
||||
|
||||
bool isClaimed() const { return getBaseArg().Claimed; }
|
||||
|
||||
/// Set the Arg claimed bit.
|
||||
void claim() const { getBaseArg().Claimed = true; }
|
||||
|
||||
bool isIgnoredTargetSpecific() const {
|
||||
return getBaseArg().IgnoredTargetSpecific;
|
||||
}
|
||||
void ignoreTargetSpecific() {
|
||||
getBaseArg().IgnoredTargetSpecific = true;
|
||||
}
|
||||
|
||||
unsigned getNumValues() const { return Values.size(); }
|
||||
|
||||
const char *getValue(unsigned N = 0) const {
|
||||
|
||||
@@ -20,19 +20,19 @@ using namespace llvm::opt;
|
||||
|
||||
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
|
||||
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
|
||||
OwnsValues(false) {}
|
||||
IgnoredTargetSpecific(false), OwnsValues(false) {}
|
||||
|
||||
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
|
||||
const Arg *BaseArg)
|
||||
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
|
||||
OwnsValues(false) {
|
||||
IgnoredTargetSpecific(false), OwnsValues(false) {
|
||||
Values.push_back(Value0);
|
||||
}
|
||||
|
||||
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
|
||||
const char *Value1, const Arg *BaseArg)
|
||||
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
|
||||
OwnsValues(false) {
|
||||
IgnoredTargetSpecific(false), OwnsValues(false) {
|
||||
Values.push_back(Value0);
|
||||
Values.push_back(Value1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user