From f67fc3acad70c20d8088b72ee9563690c8ab9be0 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 6 Jul 2022 19:22:48 -0700 Subject: [PATCH] [sanitizer] Extract check_mem_is_good into header Reviewed By: kstoimenov Differential Revision: https://reviews.llvm.org/D129245 --- .../TestCases/Linux/open_memstream.cpp | 18 +--------------- .../test/sanitizer_common/lit.common.cfg.py | 1 + .../test/sanitizer_common/sanitizer_specific.h | 24 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 compiler-rt/test/sanitizer_common/sanitizer_specific.h diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/open_memstream.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/open_memstream.cpp index cf31f44..196f39e 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/open_memstream.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/open_memstream.cpp @@ -7,23 +7,7 @@ #include #include -#ifndef __has_feature -#define __has_feature(x) 0 -#endif - -#if __has_feature(memory_sanitizer) -#include -static void check_mem_is_good(void *p, size_t s) { - __msan_check_mem_is_initialized(p, s); -} -#elif __has_feature(address_sanitizer) -#include -static void check_mem_is_good(void *p, size_t s) { - assert(__asan_region_is_poisoned(p, s) == 0); -} -#else -static void check_mem_is_good(void *p, size_t s) {} -#endif +#include "sanitizer_common/sanitizer_specific.h" static void run(bool flush) { char *buf; diff --git a/compiler-rt/test/sanitizer_common/lit.common.cfg.py b/compiler-rt/test/sanitizer_common/lit.common.cfg.py index 110314b..13a21c6 100644 --- a/compiler-rt/test/sanitizer_common/lit.common.cfg.py +++ b/compiler-rt/test/sanitizer_common/lit.common.cfg.py @@ -57,6 +57,7 @@ if config.host_os in ['Linux']: extra_link_flags += ["-ldl"] clang_cflags = config.debug_info_flags + tool_cflags + [config.target_cflags] +clang_cflags += ["-I%s" % os.path.dirname(os.path.dirname(__file__))] clang_cflags += extra_link_flags clang_cxxflags = config.cxx_mode_flags + clang_cflags diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h b/compiler-rt/test/sanitizer_common/sanitizer_specific.h new file mode 100644 index 0000000..1a80202 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h @@ -0,0 +1,24 @@ +#ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__ +#define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__ + +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +#if __has_feature(memory_sanitizer) +# include +static void check_mem_is_good(void *p, size_t s) { + __msan_check_mem_is_initialized(p, s); +} +#elif __has_feature(address_sanitizer) +# include +# include +static void check_mem_is_good(void *p, size_t s) { + if (__asan_region_is_poisoned(p, s)) + abort(); +} +#else +static void check_mem_is_good(void *p, size_t s) {} +#endif + +#endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__ \ No newline at end of file -- 2.7.4