diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -162,9 +162,6 @@ } return reinterpret_cast(Beg() - RZLog2Size(rz_log)); } - bool AddrIsInside(uptr addr, bool locked_version = false) { - return (addr >= Beg()) && (addr < Beg() + UsedSize(locked_version)); - } }; struct QuarantineCallback { @@ -1172,16 +1169,14 @@ IgnoreObjectResult IgnoreObjectLocked(const void *p) { uptr addr = reinterpret_cast(p); __asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddr(addr); - if (!m) return kIgnoreObjectInvalid; - if ((atomic_load(&m->chunk_state, memory_order_acquire) == - __asan::CHUNK_ALLOCATED) && - m->AddrIsInside(addr)) { - if (m->lsan_tag == kIgnored) - return kIgnoreObjectAlreadyIgnored; - m->lsan_tag = __lsan::kIgnored; - return kIgnoreObjectSuccess; + if (!m || (atomic_load(&m->chunk_state, memory_order_acquire) != + __asan::CHUNK_ALLOCATED)) { + return kIgnoreObjectInvalid; } - return kIgnoreObjectInvalid; + if (m->lsan_tag == kIgnored) + return kIgnoreObjectAlreadyIgnored; + m->lsan_tag = __lsan::kIgnored; + return kIgnoreObjectSuccess; } } // namespace __lsan diff --git a/compiler-rt/test/asan/TestCases/lsan_annotations.cpp b/compiler-rt/test/asan/TestCases/lsan_annotations.cpp --- a/compiler-rt/test/asan/TestCases/lsan_annotations.cpp +++ b/compiler-rt/test/asan/TestCases/lsan_annotations.cpp @@ -5,12 +5,20 @@ #include #include +int *x, *y, *z; + int main() { - int *x = new int; + x = new int; __lsan_ignore_object(x); + { __lsan::ScopedDisabler disabler; - double *y = new double; + y = new int; } + + z = new int; + __lsan_ignore_object(z - 1); + + x = y = z = nullptr; return 0; }