[MSVC] Workaround missing search path for sanitizer headers.

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 and visual studio 2022 v17.0.5

Reviewed By: aaron.ballman, rnk

Differential Revision: https://reviews.llvm.org/D118624
This commit is contained in:
Pierre Gousseau 2022-02-02 10:54:22 +00:00
parent 513ba61ca1
commit 83b74544c6
1 changed files with 17 additions and 0 deletions

View File

@ -39,6 +39,10 @@
# define __has_builtin(x) 0 # define __has_builtin(x) 0
#endif #endif
#ifndef __has_include
# define __has_include(x) 0
#endif
// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in // Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid. // C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
#ifndef LLVM_HAS_CPP_ATTRIBUTE #ifndef LLVM_HAS_CPP_ATTRIBUTE
@ -444,8 +448,21 @@
/// Whether LLVM itself is built with AddressSanitizer instrumentation. /// Whether LLVM itself is built with AddressSanitizer instrumentation.
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
# define LLVM_ADDRESS_SANITIZER_BUILD 1 # define LLVM_ADDRESS_SANITIZER_BUILD 1
#if __has_include(<sanitizer/asan_interface.h>)
# include <sanitizer/asan_interface.h> # include <sanitizer/asan_interface.h>
#else #else
// These declarations exist to support ASan with MSVC. If MSVC eventually ships
// asan_interface.h in their headers, then we can remove this.
#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 LLVM_ADDRESS_SANITIZER_BUILD 0
# define __asan_poison_memory_region(p, size) # define __asan_poison_memory_region(p, size)
# define __asan_unpoison_memory_region(p, size) # define __asan_unpoison_memory_region(p, size)