Skip to content

Commit 4411d1e

Browse files
authored
[sanitizer] Remove GetCurrentThread nullness checks from Allocate
The nullness check is unreachable. * For the main thead and pthread_create created threads, the `*Allocate` functions must be called after `*_current_thread` is set. set. * For threads created by Linux's `clone`, static TLS is either reused or set to a new value (CLONE_SETTLS). Make this change for asan/msan and possibly extend the change to other sanitizers. (asan supports many platforms and I am not 100% certain that all platforms have the property.) Pull Request: llvm#102828
1 parent 5873aa8 commit 4411d1e

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,8 @@ struct Allocator {
576576
}
577577

578578
AsanThread *t = GetCurrentThread();
579-
void *allocated;
580-
if (t) {
581-
AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
582-
allocated = allocator.Allocate(cache, needed_size, 8);
583-
} else {
584-
SpinMutexLock l(&fallback_mutex);
585-
AllocatorCache *cache = &fallback_allocator_cache;
586-
allocated = allocator.Allocate(cache, needed_size, 8);
587-
}
579+
void *allocated = allocator.Allocate(
580+
GetAllocatorCache(&t->malloc_storage()), needed_size, 8);
588581
if (UNLIKELY(!allocated)) {
589582
SetAllocatorOutOfMemory();
590583
if (AllocatorMayReturnNull())

compiler-rt/lib/msan/msan_allocator.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,8 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
199199
ReportRssLimitExceeded(stack);
200200
}
201201
MsanThread *t = GetCurrentThread();
202-
void *allocated;
203-
if (t) {
204-
AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
205-
allocated = allocator.Allocate(cache, size, alignment);
206-
} else {
207-
SpinMutexLock l(&fallback_mutex);
208-
AllocatorCache *cache = &fallback_allocator_cache;
209-
allocated = allocator.Allocate(cache, size, alignment);
210-
}
202+
void *allocated = allocator.Allocate(GetAllocatorCache(&t->malloc_storage()),
203+
size, alignment);
211204
if (UNLIKELY(!allocated)) {
212205
SetAllocatorOutOfMemory();
213206
if (AllocatorMayReturnNull())

0 commit comments

Comments
 (0)