Skip to content

Commit 99dfcfd

Browse files
zero9178mstorsjo
authored andcommitted
[CMake] [MinGW] Enable use of LLVM_USE_SANITIZER in a MinGW environment
Currently using LLVM_USE_SANITIZER with a MinGW target leads to a fatal configuration error due to an unsupported platform. MinGW targets on clang however implement a few sanitizers, currently ASAN and UBSAN. This patch enables LLVM_USE_SANITIZER in a MinGW environment as well. Differential Revision: https://reviews.llvm.org/D95750
1 parent ec41ed5 commit 99dfcfd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,21 @@ if(LLVM_USE_SANITIZER)
793793
else()
794794
message(FATAL_ERROR "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
795795
endif()
796+
elseif(MINGW)
797+
if (LLVM_USE_SANITIZER STREQUAL "Address")
798+
append_common_sanitizer_flags()
799+
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
800+
elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
801+
append_common_sanitizer_flags()
802+
append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
803+
elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
804+
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
805+
append_common_sanitizer_flags()
806+
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
807+
append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
808+
else()
809+
message(FATAL_ERROR "This sanitizer not yet supported in a MinGW environment: ${LLVM_USE_SANITIZER}")
810+
endif()
796811
elseif(MSVC)
797812
if (LLVM_USE_SANITIZER STREQUAL "Address")
798813
append_common_sanitizer_flags()

0 commit comments

Comments
 (0)