[PATCH] [Mips] Generate warning for invalid combination of '-mnan' and '-march' options.

Vladimir Radosavljevic vladimir.radosavljevic at rt-rk.com
Mon Mar 9 08:24:48 PDT 2015


Hi dsanders, petarj,

This patch generates warning for invalid combination of '-mnan' and '-march' options, and sets properly NaN encoding for a given '-march'.

http://reviews.llvm.org/D8170

Files:
  lib/Basic/Targets.cpp
  test/CodeGen/mips-unsupported-nan.c

Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -5715,10 +5715,22 @@
     TheCXXABI.set(TargetCXXABI::GenericMIPS);
   }
 
-  bool isNaN2008Default() const {
+  bool hasOnlyNaN2008Encoding() const {
     return CPU == "mips32r6" || CPU == "mips64r6";
   }
 
+  bool hasOnlyNaNLegacyEncoding() const {
+    return llvm::StringSwitch<bool>(CPU)
+        .Case("mips1", true)
+        .Case("mips2", true)
+        .Case("mips3", true)
+        .Case("mips4", true)
+        .Case("mips5", true)
+        .Case("mips32", true)
+        .Case("mips64", true)
+        .Default(false);
+  }
+
   bool isFP64Default() const {
     return CPU == "mips32r6" || ABI == "n32" || ABI == "n64" || ABI == "64";
   }
@@ -5921,7 +5933,7 @@
                             DiagnosticsEngine &Diags) override {
     IsMips16 = false;
     IsMicromips = false;
-    IsNan2008 = isNaN2008Default();
+    IsNan2008 = hasOnlyNaN2008Encoding();
     IsSingleFloat = false;
     FloatABI = HardFloat;
     DspRev = NoDSP;
@@ -5947,10 +5959,21 @@
         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 (hasOnlyNaNLegacyEncoding()) {
+          unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
+                    "the '%0' architecture does not support '-mnan=2008'");
+          Diags.Report(DiagID) << CPU;
+        } else
+          IsNan2008 = true;
+      } else if (*it == "-nan2008") {
+        if (hasOnlyNaN2008Encoding()) {
+          unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
+                    "the '%0' architecture does not support '-mnan=legacy'");
+          Diags.Report(DiagID) << CPU;
+        } else
+          IsNan2008 = false;
+      }
     }
 
     // Remove front-end specific options.
Index: test/CodeGen/mips-unsupported-nan.c
===================================================================
--- /dev/null
+++ test/CodeGen/mips-unsupported-nan.c
@@ -0,0 +1,12 @@
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-WARNING -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-WARNING -check-prefix=CHECK-LEGACY %s
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-WARNING -check-prefix=CHECK-LEGACY %s
+// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-WARNING -check-prefix=CHECK-2008 %s
+// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-WARNING -check-prefix=CHECK-2008 %s
+// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-WARNING -check-prefix=CHECK-LEGACY %s
+
+// CHECK-WARNING: warning: the '{{mips.*}}' architecture does not support '-mnan={{2008|legacy}}'
+// CHECK-LEGACY: float 0x7FF4000000000000
+// CHECK-2008: float 0x7FF8000000000000
+
+float f =  __builtin_nan("");

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8170.21489.patch
Type: text/x-patch
Size: 3455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150309/5288ebe6/attachment.bin>


More information about the cfe-commits mailing list