[compiler-rt] 7dda44c - [scudo] Use template specialization on Quarantine to avoid zero-length array

Dominic Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 16:36:39 PDT 2022


Author: Dominic Chen
Date: 2022-03-28T16:36:25-07:00
New Revision: 7dda44c189d74ec0a1bbe7dfff7c4d5f6b0e96d4

URL: https://github.com/llvm/llvm-project/commit/7dda44c189d74ec0a1bbe7dfff7c4d5f6b0e96d4
DIFF: https://github.com/llvm/llvm-project/commit/7dda44c189d74ec0a1bbe7dfff7c4d5f6b0e96d4.diff

LOG: [scudo] Use template specialization on Quarantine to avoid zero-length array

Use a separate templated QuarantineBlocks class to avoid a zero-length array

Differential Revision: https://reviews.llvm.org/D122518

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/secondary.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index abb58a2882aff..0f8fafe0a6b90 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -362,6 +362,18 @@ template <typename Config> class MapAllocatorCache {
     u64 Time;
   };
 
+  // Template specialization to avoid producing zero-length array
+  template <size_t Size> class QuarantineBlocks {
+  public:
+    CachedBlock &operator[](uptr Idx) { return Blocks[Idx]; }
+  private:
+    CachedBlock Blocks[Size];
+  };
+  template <> class QuarantineBlocks<0> {
+  public:
+    CachedBlock &operator[](uptr UNUSED Idx) { UNREACHABLE("Unsupported!"); }
+  };
+
   void releaseIfOlderThan(CachedBlock &Entry, u64 Time) {
     if (!Entry.CommitBase || !Entry.Time)
       return;
@@ -395,7 +407,7 @@ template <typename Config> class MapAllocatorCache {
   atomic_s32 ReleaseToOsIntervalMs = {};
 
   CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {};
-  CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {};
+  QuarantineBlocks<Config::SecondaryCacheQuarantineSize> Quarantine = {};
 };
 
 template <typename Config> class MapAllocator {


        


More information about the llvm-commits mailing list