diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -634,36 +634,38 @@ // 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 --- /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; +}