From 990ff24487fd0b6998231894825eb9cd4610494e Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Sat, 16 Nov 2019 22:38:34 -0800 Subject: [PATCH] Add support for ThreadSanitizer instrumentation (#3467) This commit adds support for compiling CVC4 with ThreadSanitizer instrumentation. This is useful for debugging issues when CVC4 is used in a multi-threaded context (e.g. #3292). --- CMakeLists.txt | 15 +++++++++++++-- configure.sh | 7 +++++++ src/base/configuration.cpp | 2 ++ src/base/configuration.h | 2 ++ src/base/configuration_private.h | 16 ++++++++++++++++ src/options/options_handler.cpp | 1 + 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 294286e30..fbdd05c95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ option(ENABLE_GPL "Enable GPL dependencies") # > only necessary for options set for build types cvc4_option(ENABLE_ASAN "Enable ASAN build") cvc4_option(ENABLE_UBSAN "Enable UBSan build") +cvc4_option(ENABLE_TSAN "Enable TSan build") cvc4_option(ENABLE_ASSERTIONS "Enable assertions") cvc4_option(ENABLE_COMP_INC_TRACK "Enable optimizations for incremental SMT-COMP tracks") @@ -156,7 +157,7 @@ endif() # to cmake standards (first letter uppercase). set(BUILD_TYPES Production Debug Testing Competition) -if(ENABLE_ASAN OR ENABLE_UBSAN) +if(ENABLE_ASAN OR ENABLE_UBSAN OR ENABLE_TSAN) set(CMAKE_BUILD_TYPE Debug) endif() @@ -302,6 +303,14 @@ if(ENABLE_UBSAN) add_definitions(-DCVC4_USE_UBSAN) endif() +if(ENABLE_TSAN) + # -fsanitize=thread requires CMAKE_REQUIRED_FLAGS to be explicitely set, + # otherwise the -fsanitize=thread check will fail while linking. + set(CMAKE_REQUIRED_FLAGS -fsanitize=thread) + add_required_c_cxx_flag("-fsanitize=thread") + unset(CMAKE_REQUIRED_FLAGS) +endif() + if(ENABLE_ASSERTIONS) add_definitions(-DCVC4_ASSERTIONS) else() @@ -542,7 +551,9 @@ print_config("Replay :" ENABLE_REPLAY) print_config("Statistics :" ENABLE_STATISTICS) print_config("Tracing :" ENABLE_TRACING) message("") -print_config("Asan :" ENABLE_ASAN) +print_config("ASan :" ENABLE_ASAN) +print_config("UBSan :" ENABLE_UBSAN) +print_config("TSan :" ENABLE_TSAN) print_config("Coverage (gcov) :" ENABLE_COVERAGE) print_config("Profiling (gprof) :" ENABLE_PROFILING) print_config("Unit tests :" ENABLE_UNIT_TESTING) diff --git a/configure.sh b/configure.sh index 701744570..5763fa7ce 100755 --- a/configure.sh +++ b/configure.sh @@ -46,6 +46,7 @@ The following flags enable optional features (disable with --no-