[PATCH] D25900: [ADT] static_assert that SmallDenseMap is instantiated with a power-of-two number of inline buckets.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 23 10:56:44 PDT 2016


jlebar created this revision.
jlebar added reviewers: bkramer, qcolombet, escha.
jlebar added a subscriber: llvm-commits.

If you try to instantiate it with a non-power-of-two buckets, DenseMap
will assert at runtime (!) if we ever outgrow our inline storage.

I believe using a constexpr function inside of a static_assert is safe
now that we've unsupported MSVC 2013 and GCC < 4.8.


https://reviews.llvm.org/D25900

Files:
  llvm/include/llvm/ADT/DenseMap.h


Index: llvm/include/llvm/ADT/DenseMap.h
===================================================================
--- llvm/include/llvm/ADT/DenseMap.h
+++ llvm/include/llvm/ADT/DenseMap.h
@@ -742,6 +742,8 @@
   // simplicity of referring to them.
   typedef DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT> BaseT;
   friend class DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+  static_assert(isPowerOf2_64(InlineBuckets),
+                "InlineBuckets must be a power of 2.");
 
   unsigned Small : 1;
   unsigned NumEntries : 31;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25900.75546.patch
Type: text/x-patch
Size: 556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161023/83855846/attachment.bin>


More information about the llvm-commits mailing list