We need to compile our code with particular flags to take advantage of ASan. Then, we will run tests and submit them to the dashboard. Let us take a look at how to do this:
- The buggy library is defined in src/CMakeLists.txt:
add_library(buggy "")target_sources(buggy PRIVATE buggy.cpp PUBLIC ${CMAKE_CURRENT_LIST_DIR}/buggy.hpp )target_include_directories(buggy PUBLIC ${CMAKE_CURRENT_LIST_DIR} )
- To the file src/CMakeLists.txt, we will add an option and code to sanitize using ASan:
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)if(ENABLE_ASAN) if(CMAKE_CXX_COMPILER_ID MATCHES GNU) message(STATUS "AddressSanitizer enabled") target_compile_options(buggy PUBLIC -g -O1 -fsanitize=address -fno-omit-frame-pointer ) target_link_libraries(buggy ...