Skip to content

Commit

Permalink
fix: UNDEFINED_BEHAVIOR -> UNDEFINED
Browse files Browse the repository at this point in the history
  • Loading branch information
FeignClaims committed Oct 4, 2024
1 parent 5c4c355 commit ac6c7bc
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 19 deletions.
17 changes: 15 additions & 2 deletions src/DynamicProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ macro(dynamic_project_options)
)
endif()

# Fallback for ENABLE_SANITIZER_UNDEFINED_BEHAVIOR option
foreach(default_type IN ITEMS DEFAULT DEVELOPER_DEFAULT USER_DEFAULT)
if(DEFINED ENABLE_SANITIZER_UNDEFINED_BEHAVIOR_${default_type})
if(DEFINED ENABLE_SANITIZER_UNDEFINED_${default_type})
message(WARNING "Don't set both ENABLE_SANITIZER_UNDEFINED_BEHAVIOR_${default_type} and ENABLE_SANITIZER_UNDEFINED_${default_type}. Use ENABLE_SANITIZER_UNDEFINED_${default_type} only.")
else()
message(DEPRECATION "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR_${default_type} is deprecated. Use ENABLE_SANITIZER_UNDEFINED_${default_type} instead.")
endif()

set(ENABLE_SANITIZER_UNDEFINED_${default_type} ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR_${default_type}})
endif()
endforeach()

# ccache, clang-tidy, cppcheck are only supported with Ninja and Makefile based generators
# note that it is possible to use Ninja with cl, so this still allows clang-tidy on Windows
# with CL.
Expand Down Expand Up @@ -143,7 +156,7 @@ macro(dynamic_project_options)
"0\;ENABLE_UNITY\;OFF\;OFF\;Merge C++ files into larger C++ files, can speed up compilation sometimes"
"0\;ENABLE_SANITIZER_ADDRESS\;OFF\;ON\;Make memory errors into hard runtime errors (windows/linux/macos)"
"0\;ENABLE_SANITIZER_LEAK\;OFF\;OFF\;Make memory leaks into hard runtime errors"
"0\;ENABLE_SANITIZER_UNDEFINED_BEHAVIOR\;OFF\;ON\;Make certain types (numeric mostly) of undefined behavior into runtime errors"
"0\;ENABLE_SANITIZER_UNDEFINED\;OFF\;ON\;Make certain types (numeric mostly) of undefined behavior into runtime errors"
"0\;ENABLE_SANITIZER_THREAD\;OFF\;OFF\;Make thread race conditions into hard runtime errors"
"0\;ENABLE_SANITIZER_MEMORY\;OFF\;OFF\;Make other memory errors into runtime errors"
"0\;ENABLE_CONTROL_FLOW_PROTECTION\;OFF\;OFF\;Enable control flow protection instrumentation"
Expand Down Expand Up @@ -255,7 +268,7 @@ macro(dynamic_project_options)
${ENABLE_UNITY_VALUE}
${ENABLE_SANITIZER_ADDRESS_VALUE}
${ENABLE_SANITIZER_LEAK_VALUE}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR_VALUE}
${ENABLE_SANITIZER_UNDEFINED_VALUE}
${ENABLE_SANITIZER_THREAD_VALUE}
${ENABLE_SANITIZER_MEMORY_VALUE}
${ENABLE_CONTROL_FLOW_PROTECTION_VALUE}
Expand Down
16 changes: 14 additions & 2 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ macro(project_options)
ENABLE_UNITY
ENABLE_SANITIZER_ADDRESS
ENABLE_SANITIZER_LEAK
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
ENABLE_SANITIZER_UNDEFINED
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR # deprecated, ENABLE_SANITIZER_UNDEFINED
ENABLE_SANITIZER_THREAD
ENABLE_SANITIZER_MEMORY
ENABLE_SANITIZER_POINTER_COMPARE
Expand Down Expand Up @@ -260,12 +261,23 @@ macro(project_options)
enable_coverage(${_options_target})
endif()

# Fallback for deprecated ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
if(ProjectOptions_ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
if(ProjectOptions_ENABLE_SANITIZER_UNDEFINED)
message(WARNING "Don't switch on both ENABLE_SANITIZER_UNDEFINED_BEHAVIOR and ENABLE_SANITIZER_UNDEFINED. Use ENABLE_SANITIZER_UNDEFINED only.")
else()
message(DEPRECATION "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR is deprecated. Use ENABLE_SANITIZER_UNDEFINED instead.")
endif()

set(ProjectOptions_ENABLE_SANITIZER_UNDEFINED ${ProjectOptions_ENABLE_SANITIZER_UNDEFINED_BEHAVIOR})
endif()

# sanitizer options if supported by compiler
enable_sanitizers(
${_options_target}
${ProjectOptions_ENABLE_SANITIZER_ADDRESS}
${ProjectOptions_ENABLE_SANITIZER_LEAK}
${ProjectOptions_ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ProjectOptions_ENABLE_SANITIZER_UNDEFINED}
${ProjectOptions_ENABLE_SANITIZER_THREAD}
${ProjectOptions_ENABLE_SANITIZER_MEMORY}
${ProjectOptions_ENABLE_SANITIZER_POINTER_COMPARE}
Expand Down
6 changes: 3 additions & 3 deletions src/Sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function(
_project_name
ENABLE_SANITIZER_ADDRESS
ENABLE_SANITIZER_LEAK
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
ENABLE_SANITIZER_UNDEFINED
ENABLE_SANITIZER_THREAD
ENABLE_SANITIZER_MEMORY
ENABLE_SANITIZER_POINTER_COMPARE
Expand All @@ -18,7 +18,7 @@ function(
# check if the sanitizers are supported
check_sanitizers_support(
SUPPORTS_SANITIZER_ADDRESS
SUPPORTS_SANITIZER_UNDEFINED_BEHAVIOR
SUPPORTS_SANITIZER_UNDEFINED
SUPPORTS_SANITIZER_LEAK
SUPPORTS_SANITIZER_THREAD
SUPPORTS_SANITIZER_MEMORY
Expand Down Expand Up @@ -161,7 +161,7 @@ Output variables:
function(
check_sanitizers_support
ENABLE_SANITIZER_ADDRESS
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
ENABLE_SANITIZER_UNDEFINED
ENABLE_SANITIZER_LEAK
ENABLE_SANITIZER_THREAD
ENABLE_SANITIZER_MEMORY
Expand Down
4 changes: 2 additions & 2 deletions tests/install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ project(anotherproj VERSION 0.1.0 LANGUAGES CXX C)
option(FEATURE_TESTS "Enable the tests" ON)
if(FEATURE_TESTS)
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
endif()

# Initialize project_options
Expand All @@ -33,7 +33,7 @@ project_options(
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
# ${ENABLE_SANITIZER_LEAK}
# ${ENABLE_SANITIZER_THREAD}
# ${ENABLE_SANITIZER_MEMORY}
Expand Down
4 changes: 2 additions & 2 deletions tests/minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if(ENABLE_TESTING)
if(NOT DISABLE_SANITIZER)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
else()
# or it is MSVC and has run vcvarsall
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
Expand All @@ -64,7 +64,7 @@ project_options(
ENABLE_VS_ANALYSIS
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
# DISABLE_EXCEPTIONS
# DISABLE_RTTI
# Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors
Expand Down
4 changes: 2 additions & 2 deletions tests/myproj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ option(FEATURE_TESTS "Enable the tests" ON)
if(FEATURE_TESTS)
# Enable sanitizers and static analyzers when running the tests
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
set(ENABLE_SANITIZER_POINTER_COMPARE "ENABLE_SANITIZER_POINTER_COMPARE")
set(ENABLE_SANITIZER_POINTER_SUBTRACT "ENABLE_SANITIZER_POINTER_SUBTRACT")
endif()
Expand Down Expand Up @@ -71,7 +71,7 @@ project_options(
# ENABLE_UNITY
${ENABLE_SANITIZER_ADDRESS}
# ${ENABLE_SANITIZER_LEAK}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
${ENABLE_SANITIZER_POINTER_COMPARE}
${ENABLE_SANITIZER_POINTER_SUBTRACT}
# ${ENABLE_SANITIZER_THREAD}
Expand Down
4 changes: 2 additions & 2 deletions tests/rpi3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(ENABLE_TESTING)
if(NOT DISABLE_SANITIZER)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
else()
# or it is MSVC and has run vcvarsall
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
Expand All @@ -90,7 +90,7 @@ project_options(
ENABLE_VS_ANALYSIS
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
DISABLE_EXCEPTIONS
DISABLE_RTTI
# Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors
Expand Down
4 changes: 2 additions & 2 deletions tests/rpi4-vcpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if(ENABLE_TESTING)
if(NOT DISABLE_SANITIZER)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
else()
# or it is MSVC and has run vcvarsall
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
Expand All @@ -64,7 +64,7 @@ project_options(
ENABLE_VS_ANALYSIS
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
# DISABLE_EXCEPTIONS
# DISABLE_RTTI
# Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors
Expand Down
4 changes: 2 additions & 2 deletions tests/rpi4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(ENABLE_TESTING)
if(NOT DISABLE_SANITIZER)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
set(ENABLE_SANITIZER_UNDEFINED "ENABLE_SANITIZER_UNDEFINED")
else()
# or it is MSVC and has run vcvarsall
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
Expand All @@ -82,7 +82,7 @@ project_options(
ENABLE_VS_ANALYSIS
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
${ENABLE_SANITIZER_UNDEFINED}
DISABLE_EXCEPTIONS
DISABLE_RTTI
# Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors
Expand Down

0 comments on commit ac6c7bc

Please sign in to comment.