diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h @@ -102,7 +102,7 @@ bool contains(uptr idx) const { CHECK_LT(idx, kSize1 * kSize2); - return Get(idx / kSize2); + return atomic_load(&map1_[idx / kSize2], memory_order_acquire); } const T &operator[](uptr idx) const { @@ -122,14 +122,12 @@ return RoundUpTo(kSize2 * sizeof(T), GetPageSizeCached()); } - T *Get(uptr idx) const { - DCHECK_LT(idx, kSize1); - return reinterpret_cast( - atomic_load(&map1_[idx], memory_order_acquire)); - } - T *GetOrCreate(uptr idx) const { - T *res = Get(idx); + DCHECK_LT(idx, kSize1); + // If relaxed load fails to see stored ptr, the code will fall back to + // Create() and reload the value again with locked mutex as a memory + // barrier. + T *res = reinterpret_cast(atomic_load_relaxed(&map1_[idx])); if (LIKELY(res)) return res; return Create(idx);