[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 19:11:42 PDT 2022
ddcc updated this revision to Diff 418758.
ddcc added a comment.
Move definitions out of class
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
@@ -113,6 +113,28 @@
}
}
+struct CachedBlock {
+ uptr CommitBase;
+ uptr CommitSize;
+ uptr MapBase;
+ uptr MapSize;
+ uptr BlockBegin;
+ [[no_unique_address]] MapPlatformData Data;
+ 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!"); }
+};
+
template <typename Config> class MapAllocatorCache {
public:
// Ensure the default maximum specified fits the array.
@@ -352,16 +374,6 @@
&MapInfo[I].Data);
}
- struct CachedBlock {
- uptr CommitBase;
- uptr CommitSize;
- uptr MapBase;
- uptr MapSize;
- uptr BlockBegin;
- [[no_unique_address]] MapPlatformData Data;
- u64 Time;
- };
-
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.418758.patch
Type: text/x-patch
Size: 1623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220329/16a38c3e/attachment.bin>
More information about the llvm-commits
mailing list