[llvm] 99dfcfd - [CMake] [MinGW] Enable use of LLVM_USE_SANITIZER in a MinGW environment

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 13:05:28 PST 2021


Author: Markus Böck
Date: 2021-02-08T23:04:50+02:00
New Revision: 99dfcfd14c1fef46891ba7aa7e0bf5ffad1f0de9

URL: https://github.com/llvm/llvm-project/commit/99dfcfd14c1fef46891ba7aa7e0bf5ffad1f0de9
DIFF: https://github.com/llvm/llvm-project/commit/99dfcfd14c1fef46891ba7aa7e0bf5ffad1f0de9.diff

LOG: [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

Added: 
    

Modified: 
    llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5d4d692a70ac..63fe83af0f02 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()


        


More information about the llvm-commits mailing list