diff options
author | Thomas Lively <tlively@google.com> | 2022-11-29 15:41:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-29 13:41:42 -0800 |
commit | 0c97bb81325ae29f53de9372adad2971d6ef9509 (patch) | |
tree | ddf3eaef6a89cad68ad59b63df3331665cdcc9c4 /src | |
parent | 2080165d06bce06f0ac3a3aa85f6a7a4c5e8ff04 (diff) | |
download | binaryen-0c97bb81325ae29f53de9372adad2971d6ef9509.tar.gz binaryen-0c97bb81325ae29f53de9372adad2971d6ef9509.tar.bz2 binaryen-0c97bb81325ae29f53de9372adad2971d6ef9509.zip |
[Parser] Do not assume `NAN` is positive (#5302)
It turns out that this assumption does not necessarily hold on Windows with
Visual Studio 2019. Instead of using `NAN` and `-NAN`, explicitly construct
positive and negative NaN values with `std::copysign`, which should be portable.
Fixes #5291.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wat-lexer.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/wasm/wat-lexer.cpp b/src/wasm/wat-lexer.cpp index 80dda44b0..befa9f6ab 100644 --- a/src/wasm/wat-lexer.cpp +++ b/src/wasm/wat-lexer.cpp @@ -219,18 +219,19 @@ struct LexFloatCtx : LexCtx { LexFloatCtx(std::string_view in) : LexCtx(in) {} std::optional<LexFloatResult> lexed() { - assert(!std::signbit(NAN) && "Expected NAN to be positive"); + const double posNan = std::copysign(NAN, 1.0); + const double negNan = std::copysign(NAN, -1.0); auto basic = LexCtx::lexed(); if (!basic) { return {}; } if (nanPayload) { - double nan = basic->span[0] == '-' ? -NAN : NAN; + double nan = basic->span[0] == '-' ? negNan : posNan; return LexFloatResult{*basic, nanPayload, nan}; } // strtod does not return -NAN for "-nan" on all platforms. if (basic->span == "-nan"sv) { - return LexFloatResult{*basic, nanPayload, -NAN}; + return LexFloatResult{*basic, nanPayload, negNan}; } // Do not try to implement fully general and precise float parsing // ourselves. Instead, call out to std::strtod to do our parsing. This means |