From 0626363895df2d7ff6757a4a8d5ae2d91a65d178 Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Wed, 16 Jun 2021 06:21:58 +0100 Subject: [PATCH] Adds flags for memory and address sanitizer --- CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2b09ee..8d35d74f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,23 @@ if(CLANG) -Wmissing-variable-declarations") endif() +# Build with address sanitizer +if(ADDRSAN) + set(CLANG 1) + set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer") + set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak") +endif() + +# Build with memory sanitizer +if(MEMSAN) + if(ADDRSAN) + message(FATAL_ERROR "Can't use MSAN and ASAN") + endif() + + set(CLANG 1) + set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") +endif() + include(.cmake/common.mk) # Control Debug/Release mode