[PATCH] D61200: [sanitizer] NFC: add static_assert to confirm that we use optimal ByteMap type
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 26 19:11:19 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359364: [sanitizer] NFC: add static_assert to confirm that we use reasonable ByteMap… (authored by vitalybuka, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D61200?vs=196940&id=196941#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61200/new/
https://reviews.llvm.org/D61200
Files:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -45,8 +45,22 @@
};
};
+// 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 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61200.196941.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190427/b0471861/attachment.bin>
More information about the llvm-commits
mailing list