From 4a16f65fc83df494318ced1d894f6b1e562d330c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 26 May 2023 09:52:57 -0700 Subject: [PATCH] [Driver][X86] Reject unsupported value for -mabi= -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 --- clang/lib/Driver/ToolChains/Arch/X86.cpp | 9 +++++++++ clang/test/Driver/mabi.c | 6 ------ clang/test/Driver/x86-mabi.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) delete mode 100644 clang/test/Driver/mabi.c create mode 100644 clang/test/Driver/x86-mabi.c diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index f1ad370..286bac2 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -119,6 +119,15 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args, void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector &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") { diff --git a/clang/test/Driver/mabi.c b/clang/test/Driver/mabi.c deleted file mode 100644 index 01e494d..0000000 --- a/clang/test/Driver/mabi.c +++ /dev/null @@ -1,6 +0,0 @@ -// 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; -} diff --git a/clang/test/Driver/x86-mabi.c b/clang/test/Driver/x86-mabi.c new file mode 100644 index 0000000..790d3c8 --- /dev/null +++ b/clang/test/Driver/x86-mabi.c @@ -0,0 +1,13 @@ +// 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; +} -- 2.7.4