diff options
author | Vitaly Buka <vitalybuka@google.com> | 2019-04-27 02:13:26 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2019-04-27 02:13:26 +0000 |
commit | 308ab63c0c1fe152d323dde2bf877dc58ce0d0d8 (patch) | |
tree | 395d98af5439ae752ac96478e240cc09ce069b77 | |
parent | dc8b1beec18ce9aa26f17c0366c1d670475b47c4 (diff) | |
download | compiler-rt-308ab63c0c1fe152d323dde2bf877dc58ce0d0d8.tar.gz |
[sanitizer] NFC: add static_assert to confirm that we use reasonable ByteMap type
Summary: If bots work we can replace #ifs with template specialization by TwoLevelByteMapSize1.
There is known users of TwoLevelByteMap with TwoLevelByteMapSize1 equal 8,
and users of FlatByteMap with TwoLevelByteMapSize1 equal 2.
Reviewers: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D61200
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359364 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator_primary32.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_primary32.h b/lib/sanitizer_common/sanitizer_allocator_primary32.h index d773815f9..cb0cdbe1a 100644 --- a/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -45,8 +45,22 @@ struct SizeClassAllocator32FlagMasks { // Bit masks. }; }; +// This template is not necessary but t helps to see values if static_assert +// fails. +// FIXME: Replace check with automatic type detection. D61206 +template <bool Expected, u64 MinSize, u64 ActualSize> +struct CheckTwoLevelByteMapSize { + static_assert((ActualSize >= MinSize) == Expected, + "Unexpected ByteMap type for the size"); +}; + template <class Params> class SizeClassAllocator32 { + private: + static const u64 TwoLevelByteMapSize1 = + (Params::kSpaceSize >> Params::kRegionSizeLog) >> 12; + static const u64 kMinFirstMapSizeTwoLevelByteMap = 4; + public: using AddressSpaceView = typename Params::AddressSpaceView; static const uptr kSpaceBeg = Params::kSpaceBeg; @@ -58,12 +72,16 @@ class SizeClassAllocator32 { typedef typename Params::MapUnmapCallback MapUnmapCallback; #if SANITIZER_WORDSIZE == 32 + CheckTwoLevelByteMapSize<false, kMinFirstMapSizeTwoLevelByteMap, + TwoLevelByteMapSize1> + Check; using BM = FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog), AddressSpaceView>; #elif SANITIZER_WORDSIZE == 64 - using BM = - TwoLevelByteMap<((Params::kSpaceSize >> Params::kRegionSizeLog) >> 12), - 1 << 12, AddressSpaceView>; + CheckTwoLevelByteMapSize<true, kMinFirstMapSizeTwoLevelByteMap, + TwoLevelByteMapSize1> + Check; + using BM = TwoLevelByteMap<TwoLevelByteMapSize1, 1 << 12, AddressSpaceView>; #endif static_assert((Params::kFlags & SizeClassAllocator32FlagMasks::kForTest) || is_same<BM, ByteMap>::value, |