Author: Fangrui Song Date: 2023-05-26T09:52:57-07:00 New Revision: 4a16f65fc83df494318ced1d894f6b1e562d330c
URL: https://github.com/llvm/llvm-project/commit/4a16f65fc83df494318ced1d894f6b1e562d330c DIFF: https://github.com/llvm/llvm-project/commit/4a16f65fc83df494318ced1d894f6b1e562d330c.diff LOG: [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 Added: clang/test/Driver/x86-mabi.c Modified: clang/lib/Driver/ToolChains/Arch/X86.cpp Removed: clang/test/Driver/mabi.c ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index f1ad370fe1acf..286bac2e7a2b6 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<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") { diff --git a/clang/test/Driver/mabi.c b/clang/test/Driver/mabi.c deleted file mode 100644 index 01e494d91b7a2..0000000000000 --- 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 0000000000000..790d3c8daf528 --- /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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits