summaryrefslogtreecommitdiff
path: root/py/misc.h
diff options
context:
space:
mode:
Diffstat (limited to 'py/misc.h')
-rw-r--r--py/misc.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/py/misc.h b/py/misc.h
index 5c1cc2f7a..081163cad 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -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