]> granicus.if.org Git - llvm/commitdiff
[JSON] Work around excess-precision issue when comparing T_Integer numbers.
authorSam McCall <sam.mccall@gmail.com>
Fri, 25 Jan 2019 15:05:33 +0000 (15:05 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 25 Jan 2019 15:05:33 +0000 (15:05 +0000)
Reviewers: bkramer

Subscribers: kristina, llvm-commits

Differential Revision: https://reviews.llvm.org/D57237

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352204 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/JSON.h
lib/Support/JSON.cpp

index 74d396708f6fc3aaedfc757a2046b1e1611df341..e3cb950663232d0df6aa93bb184da86a6cde3370 100644 (file)
@@ -480,6 +480,7 @@ private:
   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 &);
index 4b67536ce4c1a97b4a28f3b695c1ef5b9cae08e5..790b28f6e316b72c294d8a326446158dd0c4996b 100644 (file)
@@ -181,6 +181,12 @@ bool operator==(const Value &L, const Value &R) {
   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();