Skip to content

Commit 83b7454

Browse files
committed
[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
1 parent 513ba61 commit 83b7454

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llvm/include/llvm/Support/Compiler.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
# define __has_builtin(x) 0
4040
#endif
4141

42+
#ifndef __has_include
43+
# define __has_include(x) 0
44+
#endif
45+
4246
// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
4347
// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
4448
#ifndef LLVM_HAS_CPP_ATTRIBUTE
@@ -444,8 +448,21 @@
444448
/// Whether LLVM itself is built with AddressSanitizer instrumentation.
445449
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
446450
# define LLVM_ADDRESS_SANITIZER_BUILD 1
451+
#if __has_include(<sanitizer/asan_interface.h>)
447452
# include <sanitizer/asan_interface.h>
448453
#else
454+
// These declarations exist to support ASan with MSVC. If MSVC eventually ships
455+
// asan_interface.h in their headers, then we can remove this.
456+
#ifdef __cplusplus
457+
extern "C" {
458+
#endif
459+
void __asan_poison_memory_region(void const volatile *addr, size_t size);
460+
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
461+
#ifdef __cplusplus
462+
} // extern "C"
463+
#endif
464+
#endif
465+
#else
449466
# define LLVM_ADDRESS_SANITIZER_BUILD 0
450467
# define __asan_poison_memory_region(p, size)
451468
# define __asan_unpoison_memory_region(p, size)

0 commit comments

Comments
 (0)