[PATCH] D146818: [support] Attempt to fix PrintNumber test for Solaris

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 09:06:49 PDT 2023


paulkirth created this revision.
paulkirth added reviewers: ro, jhenderson, abhina.sreeskantharajan.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

NaN and Inf are still causing some problems in a formatting test.
This patch makes the checked format string exactly match the internal
JSON format string. If there are still problems, we should disable
testing Inf and NaN values until we can come to a portable solution.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146818

Files:
  llvm/unittests/Support/ScopedPrinterTest.cpp


Index: llvm/unittests/Support/ScopedPrinterTest.cpp
===================================================================
--- llvm/unittests/Support/ScopedPrinterTest.cpp
+++ llvm/unittests/Support/ScopedPrinterTest.cpp
@@ -572,7 +572,7 @@
     W.printNumber("float-42.0", 42.0f);
     W.printNumber("float-42.5625", 42.5625f);
 
-        W.printNumber("double-max", MaxDouble);
+    W.printNumber("double-max", MaxDouble);
     W.printNumber("double-min", MinDouble);
     W.printNumber("double-inf", InfDouble);
     W.printNumber("double-nan", NaNDouble);
@@ -610,6 +610,19 @@
   format("%5.1f", NaNDouble).snprint(Buf, sizeof(Buf));
   std::string NaNDoubleStr(Buf);
 
+  format("%.*g", InfFloat).snprint(Buf, sizeof(Buf));
+  std::string JsonInfFloatStr(Buf);
+
+  format("%.*g", InfDouble).snprint(Buf, sizeof(Buf));
+  std::string JsonInfDoubleStr(Buf);
+
+  format("%.*g", NaNFloat).snprint(Buf, sizeof(Buf));
+  std::string JsonNaNFloatStr(Buf);
+
+  format("%.*g", NaNDouble).snprint(Buf, sizeof(Buf));
+  std::string JsonNaNDoubleStr(Buf);
+
+
   std::string ExpectedOut = Twine(
                                 R"(uint64_t-max: 18446744073709551615
 uint64_t-min: 0
@@ -669,14 +682,14 @@
   },
   "float-max": 3.4028234663852886e+38,
   "float-min": 1.1754943508222875e-38,
-  "float-inf": )" + std::to_string(InfFloat) + R"(,
-  "float-nan": )" + std::to_string(NaNFloat) + R"(,
+  "float-inf": )" + JsonInfFloatStr + R"(,
+  "float-nan": )" + JsonNaNFloatStr + R"(,
   "float-42.0": 42,
   "float-42.5625": 42.5625,
   "double-max": 1.7976931348623157e+308,
   "double-min": 2.2250738585072014e-308,
-  "double-inf": )" + std::to_string(InfDouble) + R"(,
-  "double-nan": )" + std::to_string(NaNDouble) + R"(,
+  "double-inf": )" + JsonInfDoubleStr + R"(,
+  "double-nan": )" + JsonNaNDoubleStr + R"(,
   "double-42.0": 42,
   "double-42.5625": 42.5625
 })").str();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146818.508122.patch
Type: text/x-patch
Size: 1879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230324/e9240ac3/attachment.bin>


More information about the llvm-commits mailing list