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: