Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -481,6 +481,17 @@ Target.setVendorName("intel"); } + // If target is MIPS and there is no explicit `-target` option, + // adjust the target triple accordingly to provided ABI name. + if (Target.isMIPS() && !Args.getLastArg(options::OPT_target)) { + if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) + Target = llvm::StringSwitch(A->getValue()) + .Case("32", Target.get32BitArchVariant()) + .Case("n32", Target.get64BitArchVariant()) + .Case("64", Target.get64BitArchVariant()) + .Default(Target); + } + return Target; } Index: test/Driver/mips-target-abi.c =================================================================== --- /dev/null +++ test/Driver/mips-target-abi.c @@ -0,0 +1,24 @@ +// Check default target triple adjusting by ABI option. +// +// REQUIRES: mips-default-target +// +// RUN: %clang -mabi=32 -### %s 2>&1 | FileCheck -check-prefix=O32 %s +// O32: "-triple" "mips{{[^"]*}}" +// O32: "-target-cpu" "mips32r2" +// O32: "-target-abi" "o32" +// O32: ld{{.*}}" +// O32: "-m" "elf32btsmip" + +// RUN: %clang -mabi=n32 -### %s 2>&1 | FileCheck -check-prefix=N32 %s +// N32: "-triple" "mips64{{[^"]*}}" +// N32: "-target-cpu" "mips64r2" +// N32: "-target-abi" "n32" +// N32: ld{{.*}}" +// N32: "-m" "elf32btsmipn32" + +// RUN: %clang -mabi=64 -### %s 2>&1 | FileCheck -check-prefix=N64 %s +// N64: "-triple" "mips64{{[^"]*}}" +// N64: "-target-cpu" "mips64r2" +// N64: "-target-abi" "n64" +// N64: ld{{.*}}" +// N64: "-m" "elf64btsmip" Index: test/lit.cfg.py =================================================================== --- test/lit.cfg.py +++ test/lit.cfg.py @@ -136,6 +136,10 @@ if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']: config.available_features.add('dev-fd-fs') +# Test that default target triple is mips* +if re.match(r'^mips*', config.target_triple): + config.available_features.add('mips-default-target') + # Not set on native MS environment. if not re.match(r'.*-(windows-msvc)$', config.target_triple): config.available_features.add('non-ms-sdk')