Skip to content

Commit f64550b

Browse files
committed
[Mips] Convert -mnan=legacy to nan2008 when architecture support nan2008
Because we now do not really support legacy, so let us do the following: a. Convert -mnan=legacy to nan2008 when architecture support nan2008; b. Ignore -mnan=legacy when architecture does not support nan2008; c. All the above report a warning. Fix #100495.
1 parent bf2f241 commit f64550b

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ def warn_target_unsupported_nan2008 : Warning<
620620
def warn_target_unsupported_nanlegacy : Warning<
621621
"ignoring '-mnan=legacy' option because the '%0' architecture does not support it">,
622622
InGroup<UnsupportedNan>;
623+
def warn_target_unsupported_convertnanlegacytonan2008 : Warning<
624+
"ignoring unsupported '-mnan=legacy' option and instead set to `-mnan=2008` option "
625+
"because the '%0' architecture supports it">,
626+
InGroup<UnsupportedNan>;
623627
def warn_target_unsupported_abslegacy : Warning<
624628
"ignoring '-mabs=legacy' option because the '%0' architecture does not support it">,
625629
InGroup<UnsupportedAbs>;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,13 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
301301
D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
302302
}
303303
} else if (Val == "legacy") {
304-
if (mips::getIEEE754Standard(CPUName) & mips::Legacy)
305-
Features.push_back("-nan2008");
306-
else {
304+
if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
307305
Features.push_back("+nan2008");
306+
HasNaN2008Opt = true;
307+
D.Diag(diag::warn_target_unsupported_convertnanlegacytonan2008)
308+
<< CPUName;
309+
} else {
310+
Features.push_back("-nan2008");
308311
D.Diag(diag::warn_target_unsupported_nanlegacy) << CPUName;
309312
}
310313
} else

clang/test/CodeGen/builtin-nan-legacy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -emit-llvm -S %s -o - | FileCheck %s
2-
// CHECK: float 0x7FFC000000000000, float 0x7FF8000000000000
3-
// CHECK: double 0x7FF4000000000000, double 0x7FF8000000000000
2+
// CHECK: float 0x7FF8000000000000, float 0x7FFC000000000000
3+
// CHECK: double 0x7FF8000000000000, double 0x7FF4000000000000
44

55
// The first line shows an unintended consequence.
66
// __builtin_nan() creates a legacy QNAN double with an empty payload

clang/test/CodeGen/mips-unsupported-nan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
// CHECK-MIPS3: warning: ignoring '-mnan=2008' option because the 'mips3' architecture does not support it
3636
// CHECK-MIPS4: warning: ignoring '-mnan=2008' option because the 'mips4' architecture does not support it
3737
// CHECK-MIPS32: warning: ignoring '-mnan=2008' option because the 'mips32' architecture does not support it
38-
// CHECK-MIPS32R6: warning: ignoring '-mnan=legacy' option because the 'mips32r6' architecture does not support it
38+
// CHECK-MIPS32R6: warning: ignoring unsupported '-mnan=legacy' option and instead set to `-mnan=2008` option because the 'mips32r6' architecture supports it
3939
// CHECK-MIPS64: warning: ignoring '-mnan=2008' option because the 'mips64' architecture does not support it
40-
// CHECK-MIPS64R6: warning: ignoring '-mnan=legacy' option because the 'mips64r6' architecture does not support it
40+
// CHECK-MIPS64R6: warning: ignoring unsupported '-mnan=legacy' option and instead set to `-mnan=2008` option because the 'mips64r6' architecture supports it
4141

4242
// This call creates a QNAN double with an empty payload.
4343
// The quiet bit is inverted in legacy mode: it is clear to indicate QNAN,

clang/test/Driver/mips-as.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
// RUN: -fno-integrated-as -fno-pic -c %s 2>&1 \
247247
// RUN: | FileCheck -check-prefix=MIPS-NAN-LEGACY %s
248248
// MIPS-NAN-LEGACY: as{{(.exe)?}}"
249-
// MIPS-NAN-LEGACY-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mnan={{.*}}"
249+
// MIPS-NAN-LEGACY: "-target-feature" "+nan2008" "-target-feature" "+abs2008"
250250
//
251251
// RUN: %clang --target=mips-linux-gnu -mfp64 -mfpxx -mfp32 -### \
252252
// RUN: -fno-integrated-as -fno-pic -c %s 2>&1 \

clang/test/Driver/mips-features.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,10 @@
227227
// RUN: | FileCheck --check-prefix=CHECK-ABSLEGACYNAN2008 %s
228228
// CHECK-ABSLEGACYNAN2008: "-target-feature" "+nan2008" "-target-feature" "-abs2008"
229229
//
230-
// -mnan=legacy
230+
// -mnan=2008
231231
// RUN: %clang --target=mips-linux-gnu -march=mips32r3 -### -c %s \
232232
// RUN: -mnan=2008 -mnan=legacy 2>&1 \
233-
// RUN: | FileCheck --check-prefix=CHECK-NANLEGACY %s
234-
// CHECK-NANLEGACY: "-target-feature" "-nan2008"
233+
// RUN: | FileCheck --check-prefix=CHECK-NAN2008 %s
235234
//
236235
// -mabs=2008 on pre R2
237236
// RUN: %clang --target=mips-linux-gnu -march=mips32 -### -c %s \

clang/test/Driver/mips-integrated-as.s

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
// NAN-DEFAULT-NOT: "-target-feature" "{{[-+]}}nan2008"
5959

6060
// RUN: %clang --target=mips-linux-gnu -### -fintegrated-as -c %s -mnan=legacy 2>&1 | \
61-
// RUN: FileCheck -check-prefix=NAN-LEGACY %s
62-
// NAN-LEGACY: -cc1as
63-
// NAN-LEGACY: "-target-feature" "-nan2008"
61+
// RUN: FileCheck -check-prefix=NAN-2008 %s
6462

6563
// RUN: %clang --target=mips-linux-gnu -march=mips32r6 -### -fintegrated-as -c %s -mnan=2008 2>&1 | \
6664
// RUN: FileCheck -check-prefix=NAN-2008 %s

0 commit comments

Comments
 (0)