Index: include/clang/Basic/DiagnosticCommonKinds.td =================================================================== --- include/clang/Basic/DiagnosticCommonKinds.td +++ include/clang/Basic/DiagnosticCommonKinds.td @@ -142,6 +142,10 @@ "the '%0' unit is not supported with this instruction set">; def err_target_unsupported_unaligned : Error< "the %0 sub-architecture does not support unaligned accesses">; +def warn_target_unsupported_nan2008 : Warning< + "ignoring '-mnan=2008' option because the '%0' architecture does not support it">; +def warn_target_unsupported_nanlegacy : Warning< + "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">; // Source manager def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal; Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -5737,6 +5737,10 @@ enum DspRevEnum { NoDSP, DSP1, DSP2 } DspRev; + typedef enum { + NanLegacy = 1, + Nan2008 = 2 + } NanEncoding; bool HasMSA; protected: @@ -5752,8 +5756,24 @@ TheCXXABI.set(TargetCXXABI::GenericMIPS); } - bool isNaN2008Default() const { - return CPU == "mips32r6" || CPU == "mips64r6"; + NanEncoding getSupportedNanEncoding() const { + return (NanEncoding)llvm::StringSwitch(CPU) + .Case("mips1", NanLegacy) + .Case("mips2", NanLegacy) + .Case("mips3", NanLegacy) + .Case("mips4", NanLegacy) + .Case("mips5", NanLegacy) + .Case("mips32", NanLegacy) + .Case("mips32r2", NanLegacy) + .Case("mips32r3", NanLegacy | Nan2008) + .Case("mips32r5", NanLegacy | Nan2008) + .Case("mips32r6", Nan2008) + .Case("mips64", NanLegacy) + .Case("mips64r2", NanLegacy) + .Case("mips64r3", NanLegacy | Nan2008) + .Case("mips64r5", NanLegacy | Nan2008) + .Case("mips64r6", Nan2008) + .Default(NanLegacy); } bool isFP64Default() const { @@ -5958,7 +5978,7 @@ DiagnosticsEngine &Diags) override { IsMips16 = false; IsMicromips = false; - IsNan2008 = isNaN2008Default(); + IsNan2008 = getSupportedNanEncoding() == Nan2008; IsSingleFloat = false; FloatABI = HardFloat; DspRev = NoDSP; @@ -5984,10 +6004,17 @@ HasFP64 = true; else if (*it == "-fp64") HasFP64 = false; - else if (*it == "+nan2008") - IsNan2008 = true; - else if (*it == "-nan2008") - IsNan2008 = false; + else if (*it == "+nan2008") { + if (getSupportedNanEncoding() & Nan2008) + IsNan2008 = true; + else + Diags.Report(diag::warn_target_unsupported_nan2008) << CPU; + } else if (*it == "-nan2008") { + if (getSupportedNanEncoding() & NanLegacy) + IsNan2008 = false; + else + Diags.Report(diag::warn_target_unsupported_nanlegacy) << CPU; + } } // Remove front-end specific options. Index: test/CodeGen/mips-unsupported-nan.c =================================================================== --- /dev/null +++ test/CodeGen/mips-unsupported-nan.c @@ -0,0 +1,22 @@ +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS2 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R2 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-MIPS32R2 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-MIPS32R3 -check-prefix=CHECK-2008 %s +// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R6 -check-prefix=CHECK-2008 %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R2 -check-prefix=CHECK-LEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R6 -check-prefix=CHECK-2008 %s + +// CHECK-MIPS2: warning: ignoring '-mnan=2008' option because the 'mips2' architecture does not support it +// CHECK-MIPS32: warning: ignoring '-mnan=2008' option because the 'mips32' architecture does not support it +// CHECK-MIPS32R2: warning: ignoring '-mnan=2008' option because the 'mips32r2' architecture does not support it +// CHECK-MIPS32R3: warning: ignoring '-mnan=2008' option because the 'mips32r3' architecture does not support it +// CHECK-MIPS32R6: warning: ignoring '-mnan=legacy' option because the 'mips32r6' architecture does not support it +// CHECK-MIPS64: warning: ignoring '-mnan=2008' option because the 'mips64' architecture does not support it +// CHECK-MIPS64R2: warning: ignoring '-mnan=2008' option because the 'mips64r2' architecture does not support it +// CHECK-MIPS64R6: warning: ignoring '-mnan=legacy' option because the 'mips64r6' architecture does not support it +// CHECK-LEGACY: float 0x7FF4000000000000 +// CHECK-2008: float 0x7FF8000000000000 + +float f = __builtin_nan(""); Index: test/Misc/warning-flags.c =================================================================== --- test/Misc/warning-flags.c +++ test/Misc/warning-flags.c @@ -18,7 +18,7 @@ The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (94): +CHECK: Warnings without flags (96): CHECK-NEXT: ext_excess_initializers CHECK-NEXT: ext_excess_initializers_in_char_array_initializer CHECK-NEXT: ext_expected_semi_decl_list @@ -103,6 +103,8 @@ CHECK-NEXT: warn_register_objc_catch_parm CHECK-NEXT: warn_related_result_type_compatibility_class CHECK-NEXT: warn_related_result_type_compatibility_protocol +CHECK-NEXT: warn_target_unsupported_nan2008 +CHECK-NEXT: warn_target_unsupported_nanlegacy CHECK-NEXT: warn_template_export_unsupported CHECK-NEXT: warn_template_spec_extra_headers CHECK-NEXT: warn_tentative_incomplete_array Index: test/Preprocessor/init.c =================================================================== --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -4416,11 +4416,6 @@ // RUN: | FileCheck -check-prefix MIPS-MSA %s // MIPS-MSA:#define __mips_msa 1 // -// RUN: %clang_cc1 -target-feature +nan2008 \ -// RUN: -E -dM -triple=mips-none-none < /dev/null \ -// RUN: | FileCheck -check-prefix MIPS-NAN2008 %s -// MIPS-NAN2008:#define __mips_nan2008 1 -// // RUN: %clang_cc1 -target-feature -fp64 \ // RUN: -E -dM -triple=mips-none-none < /dev/null \ // RUN: | FileCheck -check-prefix MIPS32-MFP32 %s