Skip to content

Commit

Permalink
Added checks to avoid bad sanitizer combinations.
Browse files Browse the repository at this point in the history
Some sanitizers are not compatible with other sanitizers. Added some checks to
avoid these combinations at configuration time.
  • Loading branch information
alehaa committed Apr 12, 2016
1 parent 6975d64 commit f566e2b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
11 changes: 10 additions & 1 deletion cmake/FindASan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ set(FLAG_CANDIDATES
)


if (SANITIZE_ADDRESS AND (SANITIZE_THREAD OR SANITIZE_MEMORY))
message(FATAL_ERROR "AddressSanitizer is not compatible with "
"ThreadSanitizer or MemorySanitizer.")
endif ()


include(sanitize-helpers)

sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer" "ASan")
if (SANITIZE_ADDRESS)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer"
"ASan")
endif ()

function (add_sanitize_address TARGET)
if (NOT SANITIZE_ADDRESS)
Expand Down
19 changes: 0 additions & 19 deletions cmake/FindSanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


# The following options will enable the desired sanitizers.
option(SANITIZE "Enable all available sanitizers for sanitized targets." OFF)

# If option SANITIZE is enabled, enable all available sanitizers.
if (SANITIZE)
set(SANITIZE_ADDRESS ON CACHE BOOL
"Enable AddressSanitizer for sanitized targets." FORCE)
set(SANITIZE_THREAD ON CACHE BOOL
"Enable ThreadSanitizer for sanitized targets." FORCE)
set(SANITIZE_MEMORY ON CACHE BOOL
"Enable MemorySanitizer for sanitized targets." FORCE)
set(SANITIZE_UNDEFINED ON CACHE BOOL
"Enable UndefinedBehaviorSanitizer for sanitized targets." FORCE)
endif (SANITIZE)




set(FIND_QUIETLY_FLAG "")
if (DEFINED Sanitizers_FIND_QUIETLY)
set(FIND_QUIETLY_FLAG "QUIET")
Expand Down
7 changes: 7 additions & 0 deletions cmake/FindTSan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ set(FLAG_CANDIDATES
)


# ThreadSanitizer is not compatible with MemorySanitizer.
if (SANITIZE_THREAD AND SANITIZE_MEMORY)
message(FATAL_ERROR "ThreadSanitizer is not compatible with "
"MemorySanitizer.")
endif ()


include(sanitize-helpers)

if (SANITIZE_THREAD)
Expand Down
6 changes: 4 additions & 2 deletions cmake/FindUBSan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ set(FLAG_CANDIDATES

include(sanitize-helpers)

sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "UndefinedBehaviorSanitizer"
"UBSan")
if (SANITIZE_UNDEFINED)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}"
"UndefinedBehaviorSanitizer" "UBSan")
endif ()

function (add_sanitize_undefined TARGET)
if (NOT SANITIZE_UNDEFINED)
Expand Down

0 comments on commit f566e2b

Please sign in to comment.