I want to clear a false positive on FD_ZERO
and FD_SET
when the memory sanitizer is in use. Clearing it is somewhat easy:
#include <sanitizer/msan_interface.h>
...
__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));
However, I don't know how to detect when the memory sanitizer is in use. That is, detect when -fsanitize=memory
was specified on the command line. The preprocessor does not seem to be helping:
$ clang -dM -E -fsanitize=memory - </dev/null | egrep -i 'memory|sanitize|msan'
$
How can I determine when -fsanitize=memory
is in use?
According to Konstantin Serebryany on the Memory Sanitizer mailing list, there is no preprocessor macro. The __has_feature(memory_sanitizer) should be used:
#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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With