Auto-detect ASan at compile time (#638)

Fixes: https://github.com/quickjs-ng/quickjs/issues/636
This commit is contained in:
Ben Noordhuis 2024-10-29 19:54:33 +01:00 committed by GitHub
parent eae9b23843
commit 56e5ffa2db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -123,9 +123,6 @@ xoption(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
if(CONFIG_ASAN)
message(STATUS "Building with ASan")
add_compile_definitions(
__ASAN__=1
)
add_compile_options(
-fsanitize=address
-fno-sanitize-recover=all
@ -168,6 +165,7 @@ endif()
if(CONFIG_UBSAN)
message(STATUS "Building with UBSan")
# __has_feature(undefined_sanitizer) or __SANITIZE_UNDEFINED__ don't exist
add_compile_definitions(
__UBSAN__=1
)

View file

@ -54,6 +54,14 @@ extern "C" {
#include <pthread.h>
#endif
#if defined(__SANITIZE_ADDRESS__)
# define __ASAN__ 1
#elif defined(__has_feature)
# if __has_feature(address_sanitizer)
# define __ASAN__ 1
# endif
#endif
#if defined(_MSC_VER) && !defined(__clang__)
# define likely(x) (x)
# define unlikely(x) (x)