Skip to content

Commit 9dfab9d

Browse files
vitlibarlemire
authored andcommitted
Disable UBSan error in trailing_zeroes(). (simdjson#266)
simdjson#265
1 parent b63ae1f commit 9dfab9d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

include/simdjson/portability.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
#endif
5353
#endif
5454

55+
#if defined(__clang__)
56+
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
57+
#elif defined(__GNUC__)
58+
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
59+
#else
60+
#define NO_SANITIZE_UNDEFINED
61+
#endif
62+
5563
#ifdef _MSC_VER
5664
/* Microsoft C/C++-compatible compiler */
5765
#include <cstdint>
@@ -106,7 +114,7 @@ static inline bool mul_overflow(uint64_t value1, uint64_t value2,
106114
}
107115

108116
/* result might be undefined when input_num is zero */
109-
static inline int trailing_zeroes(uint64_t input_num) {
117+
static inline NO_SANITIZE_UNDEFINED int trailing_zeroes(uint64_t input_num) {
110118
#ifdef __BMI__ // tzcnt is BMI1
111119
return _tzcnt_u64(input_num);
112120
#else

0 commit comments

Comments
 (0)