[compiler-rt] 0e1d200 - [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 21:36:15 PDT 2022
Author: Dominic Chen
Date: 2022-03-28T21:35:49-07:00
New Revision: 0e1d2007aa3c63597c6965dd265055da78bf7c51
URL: https://github.com/llvm/llvm-project/commit/0e1d2007aa3c63597c6965dd265055da78bf7c51
DIFF: https://github.com/llvm/llvm-project/commit/0e1d2007aa3c63597c6965dd265055da78bf7c51.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..f0468391deeb4 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -113,6 +113,19 @@ void mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
}
}
+// Template specialization to avoid producing zero-length array
+template <typename T, size_t Size> class NonZeroLengthArray {
+public:
+ T &operator[](uptr Idx) { return values[Idx]; }
+
+private:
+ T values[Size];
+};
+template <typename T> class NonZeroLengthArray<T, 0> {
+public:
+ T &operator[](uptr UNUSED Idx) { UNREACHABLE("Unsupported!"); }
+};
+
template <typename Config> class MapAllocatorCache {
public:
// Ensure the default maximum specified fits the array.
@@ -395,7 +408,8 @@ template <typename Config> class MapAllocatorCache {
atomic_s32 ReleaseToOsIntervalMs = {};
CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {};
- CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {};
+ NonZeroLengthArray<CachedBlock, Config::SecondaryCacheQuarantineSize>
+ Quarantine = {};
};
template <typename Config> class MapAllocator {
More information about the llvm-commits
mailing list