Added option to enable UndefinedBehaviorSanitizer on Clang and GCC.

This commit is contained in:
Lukáš Hejl 2022-01-28 14:51:34 +01:00
parent 46c827c7fc
commit 5f0fea4d58
5 changed files with 70 additions and 0 deletions

View file

@ -120,6 +120,12 @@ set(_build_cmd ${_build_cmd}
set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# When Clang is used with enabled UndefinedBehaviorSanitizer, it produces "undefined reference to '__muloti4'" when __int128 is used.
# Because of that, UndefinedBehaviorSanitizer is disabled for those functions that use __int128.
list(APPEND _patch_command COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/Boost.patch)
endif ()
ExternalProject_Add(
dep_Boost
URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"

23
deps/Boost/Boost.patch vendored Normal file
View file

@ -0,0 +1,23 @@
diff -u ../boost_1_75_0-orig/boost/rational.hpp ./boost/rational.hpp
--- ../boost_1_75_0-orig/boost/rational.hpp 2020-12-03 06:02:19.000000000 +0100
+++ ./boost/rational.hpp 2022-01-27 16:02:27.993848905 +0100
@@ -302,6 +302,9 @@
return *this;
}
template <class T>
+ #if defined(__clang__)
+ __attribute__((no_sanitize("undefined")))
+ #endif
BOOST_CXX14_CONSTEXPR typename boost::enable_if_c<rational_detail::is_compatible_integer<T, IntType>::value, rational&>::type operator*= (const T& i)
{
// Avoid overflow and preserve normalization
@@ -311,6 +314,9 @@
return *this;
}
template <class T>
+ #if defined(__clang__)
+ __attribute__((no_sanitize("undefined")))
+ #endif
BOOST_CXX14_CONSTEXPR typename boost::enable_if_c<rational_detail::is_compatible_integer<T, IntType>::value, rational&>::type operator/= (const T& i)
{
// Avoid repeated construction