diff options
| author | Angus Gratton <angus@redyak.com.au> | 2025-08-06 10:19:43 +1000 |
|---|---|---|
| committer | Angus Gratton <angus@redyak.com.au> | 2025-08-19 10:33:40 +1000 |
| commit | 3faf2298537ee34648d27a662529ff2aa73cec1c (patch) | |
| tree | f12a1e6ea5cc97c6b249e80a3c6a6d9ec03fa082 /py | |
| parent | d81d56cc4d7c44978761f967841bcb6e8e84b54d (diff) | |
py/misc: Add a way to detect sanitizer builds.
Clang and gcc>=14 can use __has_feature() to detect if a sanitizer
is enabled, but older GCC has no mechanism - need to set a macro
explicitly for this to be recognised.
Necessary for increasing some resource limits in sanitizer builds.
Important not to use to avoid real issues!
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py')
| -rw-r--r-- | py/misc.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -43,6 +43,11 @@ typedef unsigned int uint; #ifndef __has_builtin #define __has_builtin(x) (0) #endif +#ifndef __has_feature +// This macro is supported by Clang and gcc>=14 +#define __has_feature(x) (0) +#endif + /** generic ops *************************************************/ @@ -538,4 +543,23 @@ inline static bool mp_sub_ll_overflow(long long int lhs, long long int rhs, long } #endif + +// Helper macros for detecting if sanitizers are enabled +// +// Use sparingly, not for masking issues reported by sanitizers! +// +// Can be detected automatically in Clang and gcc>=14, need to be +// set manually otherwise. +#ifndef MP_UBSAN +#define MP_UBSAN __has_feature(undefined_behavior_sanitizer) +#endif + +#ifndef MP_ASAN +#define MP_ASAN __has_feature(address_sanitizer) +#endif + +#ifndef MP_SANITIZER_BUILD +#define MP_SANITIZER_BUILD (MP_UBSAN || MP_ASAN) +#endif + #endif // MICROPY_INCLUDED_PY_MISC_H |
