Add __attribute__((no_sanitize("undefined"))) to the float/double
to integer conversion functions.

C17 6.3.1.4p1 only defines float-to-integer conversion for finite
values whose integral part fits in the destination type; it discards
the fractional part and explicitly makes it UB if the integral part
doesn't fit.

These tests intentionally exercise both of those UB cases, so we'll suppress
it to get a clean ubsan run on the TCG test suite.

Signed-off-by: Brian Cain <[email protected]>
---
 tests/tcg/multiarch/float_convd.c | 1 +
 tests/tcg/multiarch/float_convs.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tests/tcg/multiarch/float_convd.c 
b/tests/tcg/multiarch/float_convd.c
index 58d7f8b4c58..cb3884df974 100644
--- a/tests/tcg/multiarch/float_convd.c
+++ b/tests/tcg/multiarch/float_convd.c
@@ -62,6 +62,7 @@ static void convert_double_to_single(double input)
 #define str(a) #a
 
 #define CONVERT_DOUBLE_TO_INT(TYPE, FMT)                            \
+    __attribute__((no_sanitize("undefined")))                       \
     static void convert_double_to_ ## TYPE(double input)            \
     {                                                               \
         TYPE ## _t output;                                          \
diff --git a/tests/tcg/multiarch/float_convs.c 
b/tests/tcg/multiarch/float_convs.c
index cb1fdd439e3..584ce89aa17 100644
--- a/tests/tcg/multiarch/float_convs.c
+++ b/tests/tcg/multiarch/float_convs.c
@@ -62,6 +62,7 @@ static void convert_single_to_double(float input)
 #define str(a) #a
 
 #define CONVERT_SINGLE_TO_INT(TYPE, FMT)                            \
+    __attribute__((no_sanitize("undefined")))                       \
     static void convert_single_to_ ## TYPE(float input)             \
     {                                                               \
         TYPE ## _t output;                                          \
-- 
2.34.1

Reply via email to