[clang] d1ad006 - [Driver] Prevent Mips specific code from claiming -mabi argument on other targets.
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 27 10:07:39 PDT 2022
Author: Craig Topper
Date: 2022-09-27T10:07:20-07:00
New Revision: d1ad006a8f64bdc17f618deffa9e7c91d82c444d
URL: https://github.com/llvm/llvm-project/commit/d1ad006a8f64bdc17f618deffa9e7c91d82c444d
DIFF: https://github.com/llvm/llvm-project/commit/d1ad006a8f64bdc17f618deffa9e7c91d82c444d.diff
LOG: [Driver] Prevent Mips specific code from claiming -mabi argument on other targets.
Fixes PR57976.
Reviewed By: erichkeane, arichardson, MaskRay
Differential Revision: https://reviews.llvm.org/D134671
Added:
clang/test/Driver/mabi.c
Modified:
clang/lib/Driver/Driver.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c16797f318f6d..73ee0b9585cf6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -634,36 +634,38 @@ static llvm::Triple computeTargetTriple(const Driver &D,
// If target is MIPS adjust the target triple
// accordingly to provided ABI name.
- A = Args.getLastArg(options::OPT_mabi_EQ);
- if (A && Target.isMIPS()) {
- StringRef ABIName = A->getValue();
- if (ABIName == "32") {
- Target = Target.get32BitArchVariant();
- if (Target.getEnvironment() == llvm::Triple::GNUABI64 ||
- Target.getEnvironment() == llvm::Triple::GNUABIN32)
- Target.setEnvironment(llvm::Triple::GNU);
- } else if (ABIName == "n32") {
- Target = Target.get64BitArchVariant();
- if (Target.getEnvironment() == llvm::Triple::GNU ||
- Target.getEnvironment() == llvm::Triple::GNUABI64)
- Target.setEnvironment(llvm::Triple::GNUABIN32);
- } else if (ABIName == "64") {
- Target = Target.get64BitArchVariant();
- if (Target.getEnvironment() == llvm::Triple::GNU ||
- Target.getEnvironment() == llvm::Triple::GNUABIN32)
- Target.setEnvironment(llvm::Triple::GNUABI64);
+ if (Target.isMIPS()) {
+ if (A = Args.getLastArg(options::OPT_mabi_EQ)) {
+ StringRef ABIName = A->getValue();
+ if (ABIName == "32") {
+ Target = Target.get32BitArchVariant();
+ if (Target.getEnvironment() == llvm::Triple::GNUABI64 ||
+ Target.getEnvironment() == llvm::Triple::GNUABIN32)
+ Target.setEnvironment(llvm::Triple::GNU);
+ } else if (ABIName == "n32") {
+ Target = Target.get64BitArchVariant();
+ if (Target.getEnvironment() == llvm::Triple::GNU ||
+ Target.getEnvironment() == llvm::Triple::GNUABI64)
+ Target.setEnvironment(llvm::Triple::GNUABIN32);
+ } else if (ABIName == "64") {
+ Target = Target.get64BitArchVariant();
+ if (Target.getEnvironment() == llvm::Triple::GNU ||
+ Target.getEnvironment() == llvm::Triple::GNUABIN32)
+ Target.setEnvironment(llvm::Triple::GNUABI64);
+ }
}
}
// If target is RISC-V adjust the target triple according to
// provided architecture name
- A = Args.getLastArg(options::OPT_march_EQ);
- if (A && Target.isRISCV()) {
- StringRef ArchName = A->getValue();
- if (ArchName.startswith_insensitive("rv32"))
- Target.setArch(llvm::Triple::riscv32);
- else if (ArchName.startswith_insensitive("rv64"))
- Target.setArch(llvm::Triple::riscv64);
+ if (Target.isRISCV()) {
+ if (A = Args.getLastArg(options::OPT_march_EQ)) {
+ StringRef ArchName = A->getValue();
+ if (ArchName.startswith_insensitive("rv32"))
+ Target.setArch(llvm::Triple::riscv32);
+ else if (ArchName.startswith_insensitive("rv64"))
+ Target.setArch(llvm::Triple::riscv64);
+ }
}
return Target;
diff --git a/clang/test/Driver/mabi.c b/clang/test/Driver/mabi.c
new file mode 100644
index 0000000000000..01e494d91b7a2
--- /dev/null
+++ b/clang/test/Driver/mabi.c
@@ -0,0 +1,6 @@
+// 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;
+}
More information about the cfe-commits
mailing list