diff --git a/test_conformance/c11_atomics/host_atomics.h b/test_conformance/c11_atomics/host_atomics.h index 4a65d8da..15f369fc 100644 --- a/test_conformance/c11_atomics/host_atomics.h +++ b/test_conformance/c11_atomics/host_atomics.h @@ -17,6 +17,7 @@ #define HOST_ATOMICS_H_ #include "harness/testHarness.h" +#include #include #include "CL/cl_half.h" @@ -281,13 +282,15 @@ bool host_atomic_compare_exchange(volatile AtomicType *a, CorrespondingType *exp { static std::mutex mtx; std::lock_guard lock(mtx); - tmp = static_cast(*a); - if (tmp == *expected) + // this is necessary so that (*a == *exp) evaluates to true when + // comparing NANs + if (std::memcmp((const void *)a, expected, sizeof(CorrespondingType)) + == 0) { *a = static_cast(desired); return true; } - *expected = tmp; + *expected = *a; } else { @@ -299,7 +302,9 @@ bool host_atomic_compare_exchange(volatile AtomicType *a, CorrespondingType *exp log_info("Host function not implemented: atomic_compare_exchange\n"); tmp = 0; #endif - if (tmp == *expected) return true; + if (std::memcmp((const void *)&tmp, expected, sizeof(CorrespondingType)) + == 0) + return true; *expected = tmp; } return false; diff --git a/test_conformance/c11_atomics/test_atomics.cpp b/test_conformance/c11_atomics/test_atomics.cpp index b9da728e..b9fbcd7a 100644 --- a/test_conformance/c11_atomics/test_atomics.cpp +++ b/test_conformance/c11_atomics/test_atomics.cpp @@ -3740,7 +3740,10 @@ public: } cl_uint NumResults(cl_uint threadCount, cl_device_id deviceID) override { - if constexpr (std::is_same_v) + if constexpr ( + std::is_same_v< + HostDataType, + HOST_DOUBLE> || std::is_same_v) { return threadCount; }