Skip to content

Commit

Permalink
Auto-detect ASan at compile time (#638)
Browse files Browse the repository at this point in the history
Fixes: #636
  • Loading branch information
bnoordhuis authored Oct 29, 2024
1 parent eae9b23 commit 56e5ffa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
8 changes: 8 additions & 0 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 56e5ffa

Please sign in to comment.