Skip to content

Commit

Permalink
Add flags -DUBSAN and -DASAN to cmake to toggle address and undefined…
Browse files Browse the repository at this point in the history
… behaviour sanitizers

Add helper scripts to more quickly toggle between sanitization modes.
  • Loading branch information
vkoskiv committed Jan 17, 2020
1 parent 2380e7d commit ab322b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,21 @@ if (MSVC)
else()
# set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wconversion -std=gnu99")
set(CMAKE_C_FLAGS "-Wall -std=gnu99")
set(CMAKE_C_FLAGS_DEBUG "-fsanitize=address -O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O3 -ftree-vectorize")
if (ASAN)
unset(UBSAN CACHE)
unset(ASAN CACHE)
set(CMAKE_C_FLAGS_DEBUG "-fsanitize=address -O0 -g")
message(STATUS "Address sanitizer enabled")
elseif(UBSAN)
unset(ASAN CACHE)
unset(UBSAN CACHE)
set(CMAKE_C_FLAGS_DEBUG "-fsanitize=undefined -O0 -g")
message(STATUS "Undefined behaviour sanitizer enabled")
else()
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
message(STATUS "No sanitizations")
endif()
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
Expand Down
3 changes: 3 additions & 0 deletions asan
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/local/bin/fish

cmake . -DCMAKE_BUILD_TYPE=Debug -DASAN=True; and make
3 changes: 3 additions & 0 deletions ubsan
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/local/bin/fish

cmake . -DCMAKE_BUILD_TYPE=Debug -DUBSAN=True; and make

0 comments on commit ab322b9

Please sign in to comment.