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 @@ -129,7 +129,11 @@ } 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);