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
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]>;
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>,
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]
// 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 {
// 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();
}
<< A->getSpelling() << GuardArgs;
}
}
+
+ if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
+ A->ignoreTargetSpecific();
}
void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
/// 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;
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
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 {
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);
}