Skip to content

Commit 4e1b075

Browse files
YunQiang Suwzssyqa
authored andcommitted
Clang/MIPS: Use -mnan value for -mabs if not specified
On most hardware, FCSR.ABS2008 is set the value same with FCSR.NAN2008. Let's use this behaivor by default. With this commit, `clang -target mips -mnan=2008 -c fabs.c` will imply `-mabs=2008`. And of course, `clang -mnan=2008 -mabs=legacy` can continue workable like previous.
1 parent 3356575 commit 4e1b075

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/Driver/ToolChains/Arch/Mips.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
221221
bool IsN64 = ABIName == "64";
222222
bool IsPIC = false;
223223
bool NonPIC = false;
224+
bool HasNaN2008Opt = false;
224225

225226
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
226227
options::OPT_fpic, options::OPT_fno_pic,
@@ -285,9 +286,10 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
285286
if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
286287
StringRef Val = StringRef(A->getValue());
287288
if (Val == "2008") {
288-
if (mips::getIEEE754Standard(CPUName) & mips::Std2008)
289+
if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
289290
Features.push_back("+nan2008");
290-
else {
291+
HasNaN2008Opt = true;
292+
} else {
291293
Features.push_back("-nan2008");
292294
D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
293295
}
@@ -323,6 +325,8 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
323325
D.Diag(diag::err_drv_unsupported_option_argument)
324326
<< A->getSpelling() << Val;
325327
}
328+
} else if (HasNaN2008Opt) {
329+
Features.push_back("+abs2008");
326330
}
327331

328332
AddTargetFeature(Args, Features, options::OPT_msingle_float,

clang/test/Driver/mips-features.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@
213213
// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
214214
// RUN: -mnan=legacy -mnan=2008 2>&1 \
215215
// RUN: | FileCheck --check-prefix=CHECK-NAN2008 %s
216-
// CHECK-NAN2008: "-target-feature" "+nan2008"
216+
// CHECK-NAN2008: "-target-feature" "+nan2008" "-target-feature" "+abs2008"
217+
//
218+
// -mnan=2008 -mabs=legacy
219+
// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
220+
// RUN: -mabs=legacy -mnan=2008 2>&1 \
221+
// RUN: | FileCheck --check-prefix=CHECK-ABSLEGACYNAN2008 %s
222+
// CHECK-ABSLEGACYNAN2008: "-target-feature" "+nan2008" "-target-feature" "-abs2008"
217223
//
218224
// -mnan=legacy
219225
// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \

0 commit comments

Comments
 (0)