[driver][mips] Adjust target triple's environment accordingly to provided ABI name

For MIPS we need to adjust not only architecture name accordingly to ABI
provided by the `-mabi` command line option, but also modify triple's
environment. For example, for `mips-linux-gnu` triple and `-mabi=n32`
option a correct final triple is `mips64-linux-gnuabin32`.

llvm-svn: 344603
This commit is contained in:
Simon Atanasyan 2018-10-16 10:19:06 +00:00
parent ac58636ec5
commit e60eae4256
2 changed files with 22 additions and 9 deletions

View File

@ -486,12 +486,25 @@ 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())
Target = llvm::StringSwitch<llvm::Triple>(A->getValue())
.Case("32", Target.get32BitArchVariant())
.Case("n32", Target.get64BitArchVariant())
.Case("64", Target.get64BitArchVariant())
.Default(Target);
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);
}
}
return Target;
}

View File

@ -164,7 +164,7 @@
// MIPS-ARCH-UNKNOWN: error: unknown target CPU 'unknown'
// Check adjusting of target triple accordingly to `-mabi` option.
// RUN: %clang -target mips64-linux-gnu -mabi=32 -### %s 2>&1 \
// RUN: %clang -target mips64-linux-gnuabi64 -mabi=32 -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=TARGET-O32 %s
// TARGET-O32: "-triple" "mips-unknown-linux-gnu"
// TARGET-O32: "-target-cpu" "mips32r2"
@ -174,7 +174,7 @@
// RUN: %clang -target mips-linux-gnu -mabi=n32 -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=TARGET-N32 %s
// TARGET-N32: "-triple" "mips64-unknown-linux-gnu"
// TARGET-N32: "-triple" "mips64-unknown-linux-gnuabin32"
// TARGET-N32: "-target-cpu" "mips64r2"
// TARGET-N32: "-target-abi" "n32"
// TARGET-N32: ld{{(.exe)?}}"
@ -182,7 +182,7 @@
// RUN: %clang -target mips-linux-gnu -mabi=64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=TARGET-N64 %s
// TARGET-N64: "-triple" "mips64-unknown-linux-gnu"
// TARGET-N64: "-triple" "mips64-unknown-linux-gnuabi64"
// TARGET-N64: "-target-cpu" "mips64r2"
// TARGET-N64: "-target-abi" "n64"
// TARGET-N64: ld{{(.exe)?}}"