如何确定何时使用 -fsanitize=memory?

How to determine when -fsanitize=memory is in use?

我想在使用内存清理器时清除 FD_ZEROFD_SET 上的误报。清除它有点容易:

#include <sanitizer/msan_interface.h>
...

__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));

但是,我不知道如何检测何时使用内存清理程序。也就是说,检测何时在命令行上指定了 -fsanitize=memory。预处理器似乎没有帮助:

$ clang -dM -E -fsanitize=memory - </dev/null | egrep -i 'memory|sanitize|msan'
$

如何确定 -fsanitize=memory 何时被使用?

根据 Konstantin Serebryany 在 Memory Sanitizer mailing list, there is no preprocessor macro. The __has_feature(memory_sanitizer) 上的说法,应该使用:

#if defined(__has_feature)
#  if __has_feature(memory_sanitizer)
#    define MEMORY_SANITIZER 1
#  endif
#endif
...

#ifdef MEMORY_SANITIZER
#  include <sanitizer/msan_interface.h>
#endif
...

#ifdef MEMORY_SANITIZER
__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));
#endif
...