Skip to content

Commit

Permalink
<cmath>, <limits>: Locally disable -Wnan-infinity-disabled for …
Browse files Browse the repository at this point in the history
…Clang (#4990)

Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
frederick-vs-ja and StephanTLavavej authored Oct 12, 2024
1 parent de79d09 commit 4a08b52
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions stl/inc/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -669,24 +669,30 @@ _STD _Common_float_type_t<_Ty1, _Ty2> remquo(_Ty1 _Left, _Ty2 _Right, int* _Pquo
_CLANG_BUILTIN2_ARG(NAME, double) \
_CLANG_BUILTIN2_ARG(NAME, long double)

_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_CLANG_BUILTIN1(isfinite)
_CLANG_BUILTIN1(isinf)
_CLANG_BUILTIN1(isnan)
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED
_CLANG_BUILTIN1(isnormal)

_CLANG_BUILTIN2(isgreater)
_CLANG_BUILTIN2(isgreaterequal)
_CLANG_BUILTIN2(isless)
_CLANG_BUILTIN2(islessequal)
_CLANG_BUILTIN2(islessgreater)
_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_CLANG_BUILTIN2(isunordered)
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED

_CLANG_BUILTIN2_TEMPLATED(isgreater)
_CLANG_BUILTIN2_TEMPLATED(isgreaterequal)
_CLANG_BUILTIN2_TEMPLATED(isless)
_CLANG_BUILTIN2_TEMPLATED(islessequal)
_CLANG_BUILTIN2_TEMPLATED(islessgreater)
_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_CLANG_BUILTIN2_TEMPLATED(isunordered)
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED

#undef _CLANG_BUILTIN1_ARG
#undef _CLANG_BUILTIN2_ARG
Expand Down
6 changes: 6 additions & 0 deletions stl/inc/limits
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ public:
return FLT_TRUE_MIN;
}

_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_NODISCARD static constexpr float infinity() noexcept {
return __builtin_huge_valf();
}
Expand All @@ -886,6 +887,7 @@ public:
_NODISCARD static constexpr float signaling_NaN() noexcept {
return __builtin_nansf("1");
}
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED

static constexpr int digits = FLT_MANT_DIG;
static constexpr int digits10 = FLT_DIG;
Expand Down Expand Up @@ -923,6 +925,7 @@ public:
return DBL_TRUE_MIN;
}

_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_NODISCARD static constexpr double infinity() noexcept {
return __builtin_huge_val();
}
Expand All @@ -934,6 +937,7 @@ public:
_NODISCARD static constexpr double signaling_NaN() noexcept {
return __builtin_nans("1");
}
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED

static constexpr int digits = DBL_MANT_DIG;
static constexpr int digits10 = DBL_DIG;
Expand Down Expand Up @@ -971,6 +975,7 @@ public:
return LDBL_TRUE_MIN;
}

_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
_NODISCARD static constexpr long double infinity() noexcept {
return __builtin_huge_val();
}
Expand All @@ -982,6 +987,7 @@ public:
_NODISCARD static constexpr long double signaling_NaN() noexcept {
return __builtin_nans("1");
}
_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED

static constexpr int digits = LDBL_MANT_DIG;
static constexpr int digits10 = LDBL_DIG;
Expand Down
24 changes: 24 additions & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,30 @@
#endif // ^^^ !defined(__clang__) ^^^
#endif // !defined(_STL_RESTORE_CLANG_WARNINGS)

// warning: use of NaN is undefined behavior due to the currently enabled
// floating-point options [-Wnan-infinity-disabled]
// warning: use of infinity is undefined behavior due to the currently enabled
// floating-point options [-Wnan-infinity-disabled]
#ifndef _STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
#ifdef __clang__
// clang-format off
#define _STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnan-infinity-disabled\"")
// clang-format on
#else // ^^^ defined(__clang__) / !defined(__clang__) vvv
#define _STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED
#endif // ^^^ !defined(__clang__) ^^^
#endif // !defined(_STL_DISABLE_CLANG_WARNING_NAN_INF_DISABLED)

#ifndef _STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED
#ifdef __clang__
#define _STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED _Pragma("clang diagnostic pop")
#else // ^^^ defined(__clang__) / !defined(__clang__) vvv
#define _STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED
#endif // ^^^ !defined(__clang__) ^^^
#endif // !defined(_STL_RESTORE_CLANG_WARNING_NAN_INF_DISABLED)

// clang-format off
#ifndef _STL_DISABLE_DEPRECATED_WARNING
#ifdef __clang__
Expand Down
10 changes: 5 additions & 5 deletions tests/std/tests/VSO_0000000_vector_algorithms_floats/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ PM_CL="/BE /c /EHsc /MD /std:c++14 /w14640 /Zc:threadSafeInit-"
PM_CL="/BE /c /EHsc /MDd /std:c++17 /permissive- /w14640 /Zc:threadSafeInit-"
PM_CL="/BE /c /EHsc /MT /std:c++20 /permissive- /w14640 /Zc:threadSafeInit-"
PM_CL="/BE /c /EHsc /MTd /std:c++latest /permissive- /w14640 /Zc:threadSafeInit-"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call -Wno-nan-infinity-disabled /EHsc /MD /std:c++14 /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call -Wno-nan-infinity-disabled /EHsc /MDd /std:c++17 /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call -Wno-nan-infinity-disabled /EHsc /MT /std:c++20 /permissive- /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call -Wno-nan-infinity-disabled /EHsc /MTd /std:c++latest /permissive- /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MD /std:c++14 /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MDd /std:c++17 /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++20 /permissive- /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MTd /std:c++latest /permissive- /w14640 /Zc:threadSafeInit- --start-no-unused-arguments"
# TRANSITION, GH-3568
# PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call -Wno-nan-infinity-disabled /EHsc /MT /std:c++latest /permissive- /w14640 /Zc:threadSafeInit- -fsanitize=undefined -fno-sanitize-recover=undefined --start-no-unused-arguments"
# PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++latest /permissive- /w14640 /Zc:threadSafeInit- -fsanitize=undefined -fno-sanitize-recover=undefined --start-no-unused-arguments"
RUNALL_CROSSLIST
* PM_CL="/fp:strict"
* PM_CL="/fp:precise"
Expand Down

0 comments on commit 4a08b52

Please sign in to comment.