Just use a volatile static in Malloc.h
authorChristopher Dykes <cdykes@fb.com>
Thu, 26 Oct 2017 19:15:55 +0000 (12:15 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 26 Oct 2017 19:21:37 +0000 (12:21 -0700)
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

index 2726c9d8f12575637966d1abb4b88c997a1c2257..5bad7484a9a5dc2a524bb3d38e94a513061a45e7 100644 (file)
@@ -183,15 +183,12 @@ FOLLY_MALLOC_NOINLINE inline bool usingJEMalloc() noexcept {
 
     uint64_t origAllocated = *counter;
 
 
     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;
     }
 
     if (!ptr) {
       // wtf, failing to allocate 1 byte
       return false;
     }
 
-    /* Avoid optimizing away the malloc.  */
-    asm volatile("" ::"m"(ptr) : "memory");
-
     return (origAllocated != *counter);
   }();
 
     return (origAllocated != *counter);
   }();