[PATCH] D57237: [JSON] Work around excess-precision issue when comparing T_Integer numbers.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 25 07:05:46 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL352204: [JSON] Work around excess-precision issue when comparing T_Integer numbers. (authored by sammccall, committed by ).

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57237/new/

https://reviews.llvm.org/D57237

Files:
  llvm/trunk/include/llvm/Support/JSON.h
  llvm/trunk/lib/Support/JSON.cpp


Index: llvm/trunk/lib/Support/JSON.cpp
===================================================================
--- llvm/trunk/lib/Support/JSON.cpp
+++ llvm/trunk/lib/Support/JSON.cpp
@@ -181,6 +181,12 @@
   case Value::Boolean:
     return *L.getAsBoolean() == *R.getAsBoolean();
   case Value::Number:
+    // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
+    // The same integer must convert to the same double, per the standard.
+    // However we see 64-vs-80-bit precision comparisons with gcc-7 -O3 -m32.
+    // So we avoid floating point promotion for exact comparisons.
+    if (L.Type == Value::T_Integer || R.Type == Value::T_Integer)
+      return L.getAsInteger() == R.getAsInteger();
     return *L.getAsNumber() == *R.getAsNumber();
   case Value::String:
     return *L.getAsString() == *R.getAsString();
Index: llvm/trunk/include/llvm/Support/JSON.h
===================================================================
--- llvm/trunk/include/llvm/Support/JSON.h
+++ llvm/trunk/include/llvm/Support/JSON.h
@@ -480,6 +480,7 @@
   mutable llvm::AlignedCharArrayUnion<bool, double, int64_t, llvm::StringRef,
                                       std::string, json::Array, json::Object>
       Union;
+  friend bool operator==(const Value &, const Value &);
 };
 
 bool operator==(const Value &, const Value &);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57237.183537.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190125/e93c9a03/attachment.bin>


More information about the llvm-commits mailing list