[libcxx-commits] [libcxx] [libc++][math] Fix undue overflowing of `std::hypot(x, y, z)` (PR #93350)
Mitch Phillips via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 24 04:01:09 PDT 2024
hctim wrote:
And, for your reference, this only breaks when building libcxx on PowerPC (as far as we're aware). The sanitizer buildbots are okay on other architectures (x86, arm64):
```
[1683/1855] Building CXX object libcxx/src/CMakeFiles/cxx_static.dir/valarray.cpp.o
FAILED: libcxx/src/CMakeFiles/cxx_static.dir/valarray.cpp.o
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang++ --target=powerpc64le-unknown-linux-gnu -DLIBCXX_BUILDING_LIBCXXABI -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB -D_LIBCPP_LINK_RT_LIB -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/libcxx/src -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/powerpc64le-unknown-linux-gnu/c++/v1 -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1 -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/libcxxabi/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++23 -UNDEBUG -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -fsized-deallocation -Wall -Wextra -Wnewline-eof -Wshadow -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -MD -MT libcxx/src/CMakeFiles/cxx_static.dir/valarray.cpp.o -MF libcxx/src/CMakeFiles/cxx_static.dir/valarray.cpp.o.d -o libcxx/src/CMakeFiles/cxx_static.dir/valarray.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/libcxx/src/valarray.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/libcxx/src/valarray.cpp:9:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/valarray:363:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/cmath:316:
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/__math/hypot.h:60:17: error: static assertion failed due to requirement 'std::numeric_limits<long double>::is_iec559'
60 | static_assert(std::numeric_limits<_Real>::is_iec559);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/__math/hypot.h:94:65: note: in instantiation of function template specialization 'std::__math::__hypot_factors<long double>' requested here
94 | const auto [__overflow_threshold, __overflow_scale] = __math::__hypot_factors<_Real>();
| ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/__math/hypot.h:116:18: note: in instantiation of function template specialization 'std::__math::__hypot<long double>' requested here
116 | return __math::__hypot(__x, __y, __z);
| ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/__math/hypot.h:76:19: error: static assertion failed due to requirement 'sizeof(long double) == sizeof(double)'
76 | static_assert(sizeof(_Real) == sizeof(double));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include/c++/v1/__math/hypot.h:76:33: note: expression evaluates to '16 == 8'
76 | static_assert(sizeof(_Real) == sizeof(double));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
2 errors generated.
```
https://github.com/llvm/llvm-project/pull/93350
More information about the libcxx-commits
mailing list