diff --git a/stl/inc/__msvc_string_view.hpp b/stl/inc/__msvc_string_view.hpp index 3e11c510ad0..cc82be25c53 100644 --- a/stl/inc/__msvc_string_view.hpp +++ b/stl/inc/__msvc_string_view.hpp @@ -360,18 +360,23 @@ struct _WChar_traits : private _Char_traits<_Elem, unsigned short> { _NODISCARD static _CONSTEXPR17 int compare(_In_reads_(_Count) const _Elem* const _First1, _In_reads_(_Count) const _Elem* const _First2, const size_t _Count) noexcept /* strengthened */ { // compare [_First1, _First1 + _Count) with [_First2, ...) -#if _HAS_CXX17 - if (_STD _Is_constant_evaluated()) { - if constexpr (is_same_v<_Elem, wchar_t>) { - return __builtin_wmemcmp(_First1, _First2, _Count); +#if _USE_STD_VECTOR_ALGORITHMS + if (!_STD _Is_constant_evaluated()) { + // TRANSITION, GH-2289: Use vectorized algorithms for better performance than __builtin_wmemcmp. + const size_t _Pos = _Mismatch_vectorized(_First1, _First2, _Count); + if (_Pos == _Count) { + return 0; } else { - return _Primary_char_traits::compare(_First1, _First2, _Count); + return _First1[_Pos] < _First2[_Pos] ? -1 : +1; } } -#endif // _HAS_CXX17 +#endif // ^^^ _USE_STD_VECTOR_ALGORITHMS ^^^ - return _CSTD wmemcmp( - reinterpret_cast(_First1), reinterpret_cast(_First2), _Count); + if constexpr (is_same_v<_Elem, wchar_t>) { + return __builtin_wmemcmp(_First1, _First2, _Count); + } else { + return _Primary_char_traits::compare(_First1, _First2, _Count); + } } _NODISCARD static _CONSTEXPR17 size_t length(_In_z_ const _Elem* _First) noexcept /* strengthened */ { diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index d85b93690d2..ad371a4d257 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -23,8 +23,6 @@ using namespace std; using namespace chrono; -constexpr auto intmax_max = numeric_limits::max(); - template [[nodiscard]] constexpr const CharT* choose_literal(const char* const str, const wchar_t* const wstr) noexcept { if constexpr (is_same_v) { @@ -252,8 +250,6 @@ void empty_braces_helper( template void test_duration_formatter() { - using LongRatio = ratio; - empty_braces_helper(seconds{5}, STR("5s")); empty_braces_helper(minutes{7}, STR("7min")); empty_braces_helper(hours{9}, STR("9h")); @@ -266,8 +262,13 @@ void test_duration_formatter() { empty_braces_helper(duration>{40}, STR("40[22/7]s")); empty_braces_helper(duration>{40}, STR("40[53/101]s")); empty_braces_helper(duration>{40}, STR("40[201/2147483647]s")); - // TRANSITION, LWG-3921: duration_cast used in formatting may raise UB + +#if 0 // TRANSITION, LWG-3921: Our duration formatting constructs an hh_mm_ss, which calls duration_cast, + // which triggers signed integer overflow when a duration has a pathological ratio, like this: + constexpr auto intmax_max = numeric_limits::max(); + using LongRatio = ratio; empty_braces_helper(duration{1}, STR("1[9223372036854775806/9223372036854775807]s")); +#endif // ^^^ disabled test due to undefined behavior ^^^ // formatting small types needs to work as iostreams << VSO-1521926 empty_braces_helper(duration{123}, STR("123as")); diff --git a/tests/std/tests/VSO_0000000_vector_algorithms_floats/env.lst b/tests/std/tests/VSO_0000000_vector_algorithms_floats/env.lst index 00b11163539..ff9d0c464bb 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms_floats/env.lst +++ b/tests/std/tests/VSO_0000000_vector_algorithms_floats/env.lst @@ -46,8 +46,7 @@ PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsin 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 /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" diff --git a/tests/std/tests/VSO_0000000_vector_algorithms_mismatch_and_lex_compare/test.cpp b/tests/std/tests/VSO_0000000_vector_algorithms_mismatch_and_lex_compare/test.cpp index 458d4314076..de4c334342d 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms_mismatch_and_lex_compare/test.cpp +++ b/tests/std/tests/VSO_0000000_vector_algorithms_mismatch_and_lex_compare/test.cpp @@ -172,9 +172,19 @@ namespace test_mismatch_sizes_and_alignments { template char stack_array_various_alignments_impl() { +#ifdef __clang__ +#if __has_feature(undefined_behavior_sanitizer) +#define TESTING_UBSAN +#endif +#endif + +#ifdef TESTING_UBSAN + // Avoid testing misaligned inputs, which UBSan would reject. +#else // ^^^ UBSan / no UBSan vvv with_pad a = {}; with_pad b = {}; assert(mismatch(begin(a.v), end(a.v), begin(b.v), end(b.v)) == make_pair(end(a.v), end(b.v))); +#endif // ^^^ no UBSan ^^^ return 0; } diff --git a/tests/std/tests/usual_matrix.lst b/tests/std/tests/usual_matrix.lst index b8200e3ad22..07b2a1f63a9 100644 --- a/tests/std/tests/usual_matrix.lst +++ b/tests/std/tests/usual_matrix.lst @@ -53,5 +53,4 @@ PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsin 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- /fp:strict /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 /EHsc /MT /std:c++latest /permissive- /fp:strict /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- /fp:strict /w14640 /Zc:threadSafeInit- -fsanitize=undefined -fno-sanitize-recover=undefined --start-no-unused-arguments" diff --git a/tests/utils/stl/test/features.py b/tests/utils/stl/test/features.py index 4142664ef98..1a464ace9d4 100644 --- a/tests/utils/stl/test/features.py +++ b/tests/utils/stl/test/features.py @@ -52,8 +52,7 @@ def getDefaultFeatures(config, litConfig): DEFAULT_FEATURES.append(Feature(name='x86')) elif litConfig.target_arch.casefold() == 'x64'.casefold(): - # TRANSITION, GH-3568 - # DEFAULT_FEATURES.append(Feature(name='ubsan')) + DEFAULT_FEATURES.append(Feature(name='ubsan')) DEFAULT_FEATURES.append(Feature(name='edg')) DEFAULT_FEATURES.append(Feature(name='arch_avx2')) DEFAULT_FEATURES.append(Feature(name='x64'))