summaryrefslogtreecommitdiff
path: root/sal/qa
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-02-25 13:20:14 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-02-25 22:47:21 +0100
commit7025ca508b427fdf5eee7410d7e636adac9f0a94 (patch)
tree27e22d4d8ea7e3660e89801d14c605e87f7e81b2 /sal/qa
parentb14bb255199e7d6db6ec9155b5d9237cb35fdba7 (diff)
Make an -fsanitize=undefined workaround conditional
...that had been introduced with b5cb4935c268f12e63b61e035b455b0a59e67aa2 "Work around undef conversion of large double to float" but should no longer be necessary with <https://github.com/llvm/llvm-project/commit/9e52c43090f8cd980167bbd2719878ae36bcf6b5> "Treat the range of representable values of floating-point types as [-inf, +inf] not as [-max, +max]" added towards Clang 9. Thanks to Mike Kaganski for pointing me at this old code and at Richard Smith's comment at <https://cplusplusmusings.wordpress.com/2013/03/26/testing-libc-with-fsanitizeundefined/>. Change-Id: I8ecf115fcf6b1ebf621cb4567f8d31ac9b10ef1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130531 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/qa')
-rw-r--r--sal/qa/rtl/oustring/rtl_OUString2.cxx11
1 files changed, 10 insertions, 1 deletions
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 0e85a066f33f..0ce047e9fb32 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -30,6 +30,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
+#include <config_options.h>
#include <o3tl/cppunittraitshelper.hxx>
#include <stringhelper.hxx>
@@ -41,14 +42,22 @@ namespace rtl_OUString
namespace {
// Avoid -fsanitize=undefined warning e.g. "runtime error: value 1e+99 is
-// outside the range of representable values of type 'float'":
+// outside the range of representable values of type 'float'" with Clang prior to
+// <https://github.com/llvm/llvm-project/commit/9e52c43090f8cd980167bbd2719878ae36bcf6b5> "Treat the
+// range of representable values of floating-point types as [-inf, +inf] not as [-max, +max]"
+// (ENABLE_RUNTIME_OPTIMIZATIONS is an approximation for checking whether building is done without
+// -fsanitize=undefined):
float doubleToFloat(double x) {
+#if !defined __clang__ || __clang_major__ >= 9 || ENABLE_RUNTIME_OPTIMIZATIONS
+ return static_cast<float>(x);
+#else
return
x < -std::numeric_limits<float>::max()
? -std::numeric_limits<float>::infinity()
: x > std::numeric_limits<float>::max()
? std::numeric_limits<float>::infinity()
: static_cast<float>(x);
+#endif
}
}