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

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7dda44c189d7: [scudo] Use template specialization on Quarantine to avoid zero-length array (authored by ddcc).

Changed prior to commit:
  https://reviews.llvm.org/D122518?vs=418359&id=418727#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122518/new/

https://reviews.llvm.org/D122518

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


Index: compiler-rt/lib/scudo/standalone/secondary.h
===================================================================
--- compiler-rt/lib/scudo/standalone/secondary.h
+++ compiler-rt/lib/scudo/standalone/secondary.h
@@ -362,6 +362,18 @@
     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 @@
   atomic_s32 ReleaseToOsIntervalMs = {};
 
   CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {};
-  CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {};
+  QuarantineBlocks<Config::SecondaryCacheQuarantineSize> Quarantine = {};
 };
 
 template <typename Config> class MapAllocator {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122518.418727.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220328/c12bc7cd/attachment.bin>


More information about the llvm-commits mailing list