MaskRay created this revision. MaskRay added reviewers: aaron.ballman, arichardson, craig.topper, erichkeane, pengfei. Herald added a project: All. MaskRay requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
-mabi= was incorrectly claimed before D134671 <https://reviews.llvm.org/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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D151509 Files: clang/lib/Driver/ToolChains/Arch/X86.cpp clang/test/Driver/mabi.c clang/test/Driver/x86-mabi.c Index: clang/test/Driver/x86-mabi.c =================================================================== --- /dev/null +++ clang/test/Driver/x86-mabi.c @@ -0,0 +1,11 @@ +// 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 + +// CHECK-NOT: {{error|warning}}: +// ERR: error: unsupported option '-mabi=' for target '{{.*}}' + +int f() { + return 0; +} Index: clang/test/Driver/mabi.c =================================================================== --- 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; -} Index: clang/lib/Driver/ToolChains/Arch/X86.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/X86.cpp +++ clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -119,6 +119,15 @@ 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") {
Index: clang/test/Driver/x86-mabi.c =================================================================== --- /dev/null +++ clang/test/Driver/x86-mabi.c @@ -0,0 +1,11 @@ +// 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 + +// CHECK-NOT: {{error|warning}}: +// ERR: error: unsupported option '-mabi=' for target '{{.*}}' + +int f() { + return 0; +} Index: clang/test/Driver/mabi.c =================================================================== --- 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; -} Index: clang/lib/Driver/ToolChains/Arch/X86.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/X86.cpp +++ clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -119,6 +119,15 @@ 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") {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits