diff --git a/CMakeLists.txt b/CMakeLists.txt index 58d2ee4e..084d11fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(target_outputs) option(ENABLE_ASAN "Build with address sanitizer" OFF) if(ENABLE_ASAN) message(STATUS "Instrumenting with Address Sanitizer") + set(CMAKE_BUILD_TYPE "RelWithDebInfo") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") @@ -66,6 +67,23 @@ if(ENABLE_TSAN) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TSAN_FLAGS} -pie -Qunused-arguments") endif() +option(ENABLE_UBSAN "Build with undefined behavior sanitizer" OFF) +if(ENABLE_UBSAN) + message(STATUS "Instrumenting with Undefined Behavior Sanitizer") + set(CMAKE_BUILD_TYPE "RelWithDebInfo") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fno-omit-frame-pointer") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=undefined") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=implicit-conversion") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=implicit-integer-truncation") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=integer") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=nullability") + set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=vptr") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${UBSAN_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UBSAN_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${UBSAN_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${UBSAN_FLAGS}") +endif() + option(ENABLE_INTRINSICS "Build using compiler intrinsics for atomic ops" OFF) if(ENABLE_INTRINSICS) message(STATUS "Using compiler intrinsics for atomic ops")