[PATCH] D118624: [MSVC] Workaround missing search path for sanitizer headers.

pierre gousseau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 31 09:08:32 PST 2022


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

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

asan_interface.h is not available in MSVC's search path, instead it is located under %VCToolsInstallDir%/crt/src/sanitizer

This is an alternate solution to https://reviews.llvm.org/D118159 , to avoid adding all internal crt sources to the header search paths.

Tested with visual studio 2019 v16.9.6


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118624

Files:
  llvm/include/llvm/Support/Compiler.h


Index: llvm/include/llvm/Support/Compiler.h
===================================================================
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -439,8 +439,22 @@
 /// Whether LLVM itself is built with AddressSanitizer instrumentation.
 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
 # define LLVM_ADDRESS_SANITIZER_BUILD 1
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+#if __has_include(<sanitizer/asan_interface.h>)
 # include <sanitizer/asan_interface.h>
 #else
+#ifdef __cplusplus
+extern "C" {
+#endif
+void __asan_poison_memory_region(void const volatile *addr, size_t size);
+void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+#endif
+#else
 # define LLVM_ADDRESS_SANITIZER_BUILD 0
 # define __asan_poison_memory_region(p, size)
 # define __asan_unpoison_memory_region(p, size)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118624.404559.patch
Type: text/x-patch
Size: 949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220131/04160d99/attachment.bin>


More information about the llvm-commits mailing list