From 99dfcfd14c1fef46891ba7aa7e0bf5ffad1f0de9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Markus=20B=C3=B6ck?= Date: Mon, 8 Feb 2021 23:04:04 +0200 Subject: [PATCH] [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 --- llvm/cmake/modules/HandleLLVMOptions.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index 5d4d692..63fe83a 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -793,6 +793,21 @@ if(LLVM_USE_SANITIZER) else() message(FATAL_ERROR "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") endif() + elseif(MINGW) + if (LLVM_USE_SANITIZER STREQUAL "Address") + append_common_sanitizer_flags() + append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") + append_common_sanitizer_flags() + append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR + LLVM_USE_SANITIZER STREQUAL "Undefined;Address") + append_common_sanitizer_flags() + append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + else() + message(FATAL_ERROR "This sanitizer not yet supported in a MinGW environment: ${LLVM_USE_SANITIZER}") + endif() elseif(MSVC) if (LLVM_USE_SANITIZER STREQUAL "Address") append_common_sanitizer_flags() -- 2.7.4