[PATCH] D118159: [CMake][MSVC] Add include path to crt headers when enabling sanitizers.

pierre gousseau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 25 09:24:15 PST 2022


pgousseau created this revision.
pgousseau added reviewers: rnk, thakis, vitalybuka, kcc.
Herald added a subscriber: mgorny.
pgousseau requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This change is to fix build errors “Cannot open include file: 'sanitizer/asan_interface.h'” when building LLVM with MSVC and LLVM_USE_SANITIZER=Address.

I have used the VCToolsInstallDir environment variable to generate the path, let me know if there is a better alternative.

Tested with visual studio 2019 v16.9.6


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118159

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -806,6 +806,17 @@
     # Always ask the linker to produce symbols with asan.
     append("/Z7" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
     append("-debug" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+  elseif (MSVC)
+    check_cxx_source_compiles(
+      "#include <sanitizer/asan_interface.h> int main() { return 0; }"
+      msvc_sanitizer_include_enabled)
+    if(NOT msvc_sanitizer_include_enabled)
+      file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}/crt/src" MSVC_CRT_SRC_DIR)
+      if(NOT EXISTS "${MSVC_CRT_SRC_DIR}/sanitizer")
+        message(WARNING "Sanitizer include directory not found in ${MSVC_CRT_SRC_DIR}")
+      endif()
+      include_directories(SYSTEM ${MSVC_CRT_SRC_DIR})
+    endif()
   endif()
 endmacro()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118159.402851.patch
Type: text/x-patch
Size: 971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220125/09ca3040/attachment.bin>


More information about the llvm-commits mailing list