Skip to content

Commit e5a2712

Browse files
committed
Annotate trailing_zeroes with no_sanitize_undefined
Zero is sometimes passed to ctz() by the indexer, but the result is discarded as the tape is advanced based on the result of popcnt().
1 parent 75269fb commit e5a2712

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

.github/workflows/build-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
build_type: Debug
1919
build_tool_options: -j 4
2020
analyzer: off
21-
sanitizer: address
21+
sanitizer: address,undefined
2222
- os: macos-12
2323
build_type: Debug
2424
build_tool_options: -j 4

src/attributes.h

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# define really_inline __forceinline
1919
# define never_inline __declspec(noinline)
2020
# define warn_unused_result
21+
# define no_sanitize_undefined
2122

2223
# define likely(params) (params)
2324
# define unlikely(params) (params)
@@ -46,6 +47,17 @@
4647
# define warn_unused_result
4748
# endif
4849

50+
# if zone_has_attribute(no_sanitize)
51+
// GCC 8.1 added the no_sanitize function attribute.
52+
# define no_sanitize_undefined __attribute__((no_sanitize("undefined")))
53+
# elif zone_has_attribute(no_sanitize_undefined)
54+
// GCC 4.9.0 added the UndefinedBehaviorSanitizer (ubsan) and the
55+
// no_sanitize_undefined function attribute.
56+
# define no_sanitize_undefined
57+
# else
58+
# define no_sanitize_undefined
59+
# endif
60+
4961
# define likely(params) __builtin_expect(!!(params), 1)
5062
# define unlikely(params) __builtin_expect(!!(params), 0)
5163
#endif

src/haswell/bits.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static inline uint64_t count_ones(uint64_t bits) {
2121
return (uint64_t)_mm_popcnt_u64(bits);
2222
}
2323

24+
no_sanitize_undefined
2425
static inline uint64_t trailing_zeroes(uint64_t bits) {
2526
return (uint64_t)__builtin_ctzll(bits);
2627
}

src/westmere/bits.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static inline uint64_t count_ones(uint64_t input_num) {
2020
return (uint64_t)_mm_popcnt_u64(input_num);
2121
}
2222

23+
no_sanitize_undefined
2324
static inline uint64_t trailing_zeroes(uint64_t input_num) {
2425
return (uint64_t)__builtin_ctzll(input_num);
2526
}

0 commit comments

Comments
 (0)