-mabi= was incorrectly claimed before D134671. -mabi=sysv appears to be
somewhat common in open-source packages, even if it was not intended to
be supported by Clang.
(For common options supported by multiple architectures, it's easy to
forget to report an error on unsupported targets. Unfortunately
the driver infrastructure doesn't make this less error-prone.)
On x86, support -mabi=sysv for non-Windows targets and -mabi=ms for Windows,
and remove the spurious -Wunused-command-line-argument warning.
With this change, all popular architectures claim -mabi=, so we don't
have to worry much about -Wunused-command-line-argument for other
architectures.
Differential Revision: https://reviews.llvm.org/D151509
void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector<StringRef> &Features) {
+ // Claim and report unsupported -mabi=. Note: we don't support "sysv_abi" or
+ // "ms_abi" as default function attributes.
+ if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mabi_EQ)) {
+ StringRef DefaultAbi = Triple.isOSWindows() ? "ms" : "sysv";
+ if (A->getValue() != DefaultAbi)
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << A->getSpelling() << Triple.getTriple();
+ }
+
// If -march=native, autodetect the feature list.
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
if (StringRef(A->getValue()) == "native") {
+++ /dev/null
-// RUN: %clang --target=i386-unknown-linux -mabi=ms -S %s -### 2>&1 | FileCheck --check-prefix=CHECK %s
-
-int f() {
- // CHECK: warning: argument unused during compilation: '-mabi=ms'
- return 0;
-}
--- /dev/null
+// RUN: %clang -### --target=x86_64-windows-msvc -mabi=ms -S %s 2>&1 | FileCheck %s
+// RUN: %clang -### --target=i386-unknown-linux -mabi=ms -S %s 2>&1 | FileCheck --check-prefix=ERR %s
+// RUN: %clang -### --target=x86_64-windows-msvc -mabi=sysv -S %s 2>&1 | FileCheck --check-prefix=ERR %s
+// RUN: %clang -### --target=i386-unknown-linux -mabi=sysv -S %s 2>&1 | FileCheck %s
+
+// RUN: %clang -### --target=x86_64-windows-gnu -mabi=ms -S %s 2>&1 | FileCheck %s
+
+// CHECK-NOT: {{error|warning}}:
+// ERR: error: unsupported option '-mabi=' for target '{{.*}}'
+
+int f() {
+ return 0;
+}