Skip to content

Commit

Permalink
Merge pull request #2706 from TomFischer/AddGCCSanitizer
Browse files Browse the repository at this point in the history
[scripts] Options for enabling gcc sanitizer flags.
  • Loading branch information
renchao-lu authored Oct 30, 2019
2 parents 7b78f08 + 7762660 commit 3a89d4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/cmake/CompilerSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ if(COMPILER_IS_GCC OR COMPILER_IS_CLANG OR COMPILER_IS_INTEL)
using ${CMAKE_CXX_COMPILER_VERSION}.")
endif()
add_compile_options(-fext-numeric-literals)
include(GCCSanitizer)
endif()

if(COMPILER_IS_CLANG)
Expand Down
16 changes: 16 additions & 0 deletions scripts/cmake/GCCSanitizer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
option(OGS_ADDRESS_SANITIZER OFF "Use GCCs AddressSanitizer")
option(OGS_UNDEFINED_BEHAVIOR_SANITIZER OFF "Use GCCs UndefinedBehaviorSanitizer")

if(OGS_ADDRESS_SANITIZER)
set(SANITIZE_FLAG_VALUE "address")
set(ADDITIONAL_FLAGS "-fno-omit-frame-pointer")
endif()

if(OGS_UNDEFINED_BEHAVIOR_SANITIZER)
set(SANITIZE_FLAG_VALUE "${SANITIZE_FLAG_VALUE},undefined,unreachable,integer-divide-by-zero,vla-bound,bounds,null")
endif()

if(DEFINED SANITIZE_FLAG_VALUE)
add_compile_options(-fsanitize=${SANITIZE_FLAG_VALUE} ${ADDITIONAL_FLAGS})
link_libraries(-fsanitize=${SANITIZE_FLAG_VALUE} ${ADDITIONAL_FLAGS})
endif()

0 comments on commit 3a89d4d

Please sign in to comment.