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

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 25 11:31:17 PST 2019


Merged to 8.0 in r352233.

On Fri, Jan 25, 2019 at 7:05 AM Sam McCall via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: sammccall
> Date: Fri Jan 25 07:05:33 2019
> New Revision: 352204
>
> URL: http://llvm.org/viewvc/llvm-project?rev=352204&view=rev
> Log:
> [JSON] Work around excess-precision issue when comparing T_Integer numbers.
>
> Reviewers: bkramer
>
> Subscribers: kristina, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D57237
>
> Modified:
>     llvm/trunk/include/llvm/Support/JSON.h
>     llvm/trunk/lib/Support/JSON.cpp
>
> Modified: llvm/trunk/include/llvm/Support/JSON.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/JSON.h?rev=352204&r1=352203&r2=352204&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/JSON.h (original)
> +++ llvm/trunk/include/llvm/Support/JSON.h Fri Jan 25 07:05:33 2019
> @@ -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 &);
>
> Modified: llvm/trunk/lib/Support/JSON.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/JSON.cpp?rev=352204&r1=352203&r2=352204&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/JSON.cpp (original)
> +++ llvm/trunk/lib/Support/JSON.cpp Fri Jan 25 07:05:33 2019
> @@ -181,6 +181,12 @@ bool operator==(const Value &L, const Va
>    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();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list