From a15fcb1e76444f7d464b263ad37bf3b5fbfdf33e Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 26 Oct 2017 12:15:55 -0700 Subject: [PATCH] Just use a volatile static in Malloc.h Summary: As suggested late in the initial diff (D5840883), just mark it volatile, as it works under all supported platforms. Reviewed By: davidtgoldblatt, yfeldblum Differential Revision: D6155241 fbshipit-source-id: 00c07a11dc7fc2e33c2d1f9a45fd28006eeff6f9 --- folly/memory/Malloc.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/folly/memory/Malloc.h b/folly/memory/Malloc.h index 2726c9d8..5bad7484 100644 --- a/folly/memory/Malloc.h +++ b/folly/memory/Malloc.h @@ -183,15 +183,12 @@ FOLLY_MALLOC_NOINLINE inline bool usingJEMalloc() noexcept { uint64_t origAllocated = *counter; - const void* ptr = malloc(1); + static const void* volatile ptr = malloc(1); if (!ptr) { // wtf, failing to allocate 1 byte return false; } - /* Avoid optimizing away the malloc. */ - asm volatile("" ::"m"(ptr) : "memory"); - return (origAllocated != *counter); }(); -- 2.34.1