diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp --- a/compiler-rt/lib/msan/msan.cpp +++ b/compiler-rt/lib/msan/msan.cpp @@ -527,9 +527,13 @@ sptr __msan_test_shadow(const void *x, uptr size) { if (!MEM_IS_APP(x)) return -1; unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x); - for (uptr i = 0; i < size; ++i) - if (s[i]) - return i; + bool poisoned = !__sanitizer::mem_is_zero((const char *)s, size); + if (poisoned) { + // Slow path: loop through again to find the location. + for (uptr i = 0; i < size; ++i) + if (s[i]) + return i; + } return -1; }