# Source this file, then use configure / make / make check as usual to work in the sanitizer
# environment.

# Prefix the prompt to make it more obvious this file was sourced.
PS1="(cool-san) $PS1"

# Set up environment variables and compiler flags for a combined ASan and UBSan build.
export ASAN_OPTIONS=strip_path_prefix=$(pwd):handle_ioctl=1:detect_leaks=0:allow_user_segv_handler=1:use_sigaltstack=0:detect_deadlocks=1:intercept_tls_get_addr=1:check_initialization_order=1:detect_stack_use_after_return=1:strict_init_order=1:detect_invalid_pointer_pairs=1
export LSAN_OPTIONS=suppressions=$(pwd)/engine/leak-suppress.txt:print_suppressions=0:report_objects=1
export UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1:suppressions=$(pwd)/engine/solenv/sanitizers/ubsan-suppressions
export SAN_CFLAGS="-fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=local-bounds -fsanitize-blacklist=$(pwd)/engine/sanitize-ubsan-excludelist"
export SAN_CXXFLAGS="-fsized-deallocation -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=local-bounds -fsanitize-blacklist=$(pwd)/engine/sanitize-ubsan-excludelist"
export CCACHE_CPP2=YES

# Finally default to using system-clang, which can be customized after sourcing this file.
export CC="clang $SAN_CFLAGS"
export CXX="clang++ $SAN_CXXFLAGS"
