]> granicus.if.org Git - llvm/commitdiff
Merging r352204:
authorHans Wennborg <hans@hanshq.net>
Fri, 25 Jan 2019 19:31:17 +0000 (19:31 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 25 Jan 2019 19:31:17 +0000 (19:31 +0000)
------------------------------------------------------------------------
r352204 | sammccall | 2019-01-25 16:05:33 +0100 (Fri, 25 Jan 2019) | 7 lines

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

Reviewers: bkramer

Subscribers: kristina, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_80@352233 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7a04fd52bc50e4f052f791334823e4113fe0364f..2b95a174e018cb62912a3650ef9c0901715eaeae 100644 (file)
@@ -481,6 +481,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 d468013fb94a53e0e5e8927685cefeca6ce2399e..07a556814915d17ac4e065a92377f59c1564c3c9 100644 (file)
@@ -182,6 +182,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();