Fix: Handle NaN inputs in round_to_int_and_clamp (#2658)
Some checks failed
Presubmit / Build ubuntu-22.04 gl (push) Failing after 1s
Presubmit / Build ubuntu-22.04 aarch64 debug (push) Failing after 1s
Presubmit / Build ubuntu-22.04 android-aarch64 (push) Failing after 1s
Presubmit / Check code format (push) Failing after 1s
Presubmit / Build macos-latest (push) Has been cancelled
Presubmit / Build windows-11-arm (push) Has been cancelled
Presubmit / Build windows-latest (push) Has been cancelled

Check for NaN before casting to long long to prevent SIGILL crashes due
to undefined behavior.

Returns 0 for NaN inputs as defined in the specification.
This commit is contained in:
Romaric Jodin 2026-04-28 18:56:30 +02:00 committed by GitHub
parent b8eca0fe03
commit f0f4c44a79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,6 +35,7 @@ extern roundingMode qcom_rm;
#include "harness/rounding_mode.h"
#include "harness/typeWrappers.h"
#include <cmath>
#include <vector>
#if defined(__linux__)
@ -367,6 +368,8 @@ DataInfoSpec<InType, OutType, InFP, OutFP>::round_to_int_and_clamp(double f)
static const double magic[2] = { MAKE_HEX_DOUBLE(0x1.0p52, 0x1LL, 52),
MAKE_HEX_DOUBLE(-0x1.0p52, -0x1LL, 52) };
if (std::isnan(f)) return 0;
if (f >= -(double)LLONG_MIN) return LLONG_MAX;
if (f <= (double)LLONG_MIN) return LLONG_MIN;