[compiler-rt] [compiler-rt] [sanitizer] avoid UB in allocator (PR #126977)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 14:38:02 PST 2025


================
@@ -166,7 +166,11 @@ struct SizeClassAllocator32LocalCache {
       DCHECK_GT(c->count, 0);
     }
     void *res = c->batch[--c->count];
-    PREFETCH(c->batch[c->count - 1]);
+    // By not doing pointer arithmetic, we avoid the OOB if c->count = 0.
+    // We just prefetch the previous member of the PerClass struct, which
+    // doesn't do harm.
+    PREFETCH(reinterpret_cast<uptr>(c->batch) +
----------------
fmayer wrote:

ah, i guess it's not a real branch on arm64 or x86_64: https://godbolt.org/z/1a11vz6Yr

https://github.com/llvm/llvm-project/pull/126977


More information about the llvm-commits mailing list