From 2ff930ae429ef49870f76b6f76bceabe55ac8dd8 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Fri, 25 Jan 2019 15:05:33 +0000 Subject: [PATCH] [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/trunk@352204 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/JSON.h | 1 + lib/Support/JSON.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/llvm/Support/JSON.h b/include/llvm/Support/JSON.h index 74d396708f6..e3cb9506632 100644 --- a/include/llvm/Support/JSON.h +++ b/include/llvm/Support/JSON.h @@ -480,6 +480,7 @@ private: mutable llvm::AlignedCharArrayUnion Union; + friend bool operator==(const Value &, const Value &); }; bool operator==(const Value &, const Value &); diff --git a/lib/Support/JSON.cpp b/lib/Support/JSON.cpp index 4b67536ce4c..790b28f6e31 100644 --- a/lib/Support/JSON.cpp +++ b/lib/Support/JSON.cpp @@ -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(); -- 2.50.1