[compiler-rt] b42fa0c - Revert "[Asan] Fix false leak report"
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 00:26:46 PDT 2020
Author: Vitaly Buka
Date: 2020-09-16T00:26:32-07:00
New Revision: b42fa0c040961b3704e826ddc969c0e98238c3ba
URL: https://github.com/llvm/llvm-project/commit/b42fa0c040961b3704e826ddc969c0e98238c3ba
DIFF: https://github.com/llvm/llvm-project/commit/b42fa0c040961b3704e826ddc969c0e98238c3ba.diff
LOG: Revert "[Asan] Fix false leak report"
Additional investigated confirmed that issue is not about
AddrIsInside, but missing registers.
This reverts commit 9d01612db48fa27d18c6320974b8d711572e5c67.
Added:
Modified:
compiler-rt/lib/asan/asan_allocator.cpp
Removed:
compiler-rt/test/asan/TestCases/redzone_noleak.cpp
################################################################################
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index b1d99699a6e6..691f64c0ef36 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -158,6 +158,9 @@ enum {
class AsanChunk : public ChunkBase {
public:
uptr Beg() { return reinterpret_cast<uptr>(this) + kChunkHeaderSize; }
+ bool AddrIsInside(uptr addr) {
+ return (addr >= Beg()) && (addr < Beg() + UsedSize());
+ }
};
class LargeChunkHeader {
@@ -1113,11 +1116,12 @@ uptr PointsIntoChunk(void *p) {
if (!m || atomic_load(&m->chunk_state, memory_order_acquire) !=
__asan::CHUNK_ALLOCATED)
return 0;
- // AsanChunk presence means that we point into some block from underlying
- // allocators. Don't check whether p points into user memory, since until
- // the return from AsanAllocator::Allocator we may have no such
- // pointer anywhere. But we must already have a pointer to GetBlockBegin().
- return m->Beg();
+ uptr chunk = m->Beg();
+ if (m->AddrIsInside(addr))
+ return chunk;
+ if (IsSpecialCaseOfOperatorNew0(chunk, m->UsedSize(), addr))
+ return chunk;
+ return 0;
}
uptr GetUserBegin(uptr chunk) {
diff --git a/compiler-rt/test/asan/TestCases/redzone_noleak.cpp b/compiler-rt/test/asan/TestCases/redzone_noleak.cpp
deleted file mode 100644
index f122c05e5108..000000000000
--- a/compiler-rt/test/asan/TestCases/redzone_noleak.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// Test whether pointers into left redzone count memory are reachable.
-// If user thread is inside asan allocator code then we may have no
-// pointers into user part of memory yet. However we should have a pointer
-// into the allocated memory chunk.
-//
-// RUN: %clangxx_asan %s -o %t
-// RUN: %run %t 2>&1
-
-#include <cstdlib>
-#include <stdio.h>
-#include <thread>
-
-void *pointers[1000];
-void **cur = pointers;
-
-void leak(int n, int offset) {
- printf("%d %d\n", n, offset);
- for (int i = 0; i < 3; ++i)
- *(cur++) = (new int[n]) + offset;
-}
-
-int main(int argc, char **argv) {
- for (int n = 1; n < 10000000; n = n * 2) {
- leak(n, 0);
- leak(n, -1);
- }
- return 0;
-}
More information about the llvm-commits
mailing list