[PATCH] [ADT] IntervalMap: use AlignedCharArray.

Frederic Riss friss at apple.com
Wed Mar 11 14:45:13 PDT 2015


Hi dblaikie,

Currently IntervalMap would assert when used with keys bigger than host
pointers. This patch uses the AlignedCharArray functionality to overcome
that limitation.

The patch looks trivial enough, but the comment I'm removing was pretty
explicit about not supporting keys with bigger alignment than pointers,
thus I'm wondering if I'm not missing something.

http://reviews.llvm.org/D8268

Files:
  include/llvm/ADT/IntervalMap.h

Index: include/llvm/ADT/IntervalMap.h
===================================================================
--- include/llvm/ADT/IntervalMap.h
+++ include/llvm/ADT/IntervalMap.h
@@ -101,6 +101,7 @@
 
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/RecyclingAllocator.h"
 #include <iterator>
@@ -966,13 +967,7 @@
 
 private:
   // The root data is either a RootLeaf or a RootBranchData instance.
-  // We can't put them in a union since C++03 doesn't allow non-trivial
-  // constructors in unions.
-  // Instead, we use a char array with pointer alignment. The alignment is
-  // ensured by the allocator member in the class, but still verified in the
-  // constructor. We don't support keys or values that are more aligned than a
-  // pointer.
-  char data[RootDataSize];
+  AlignedCharArray<AlignOf<RootLeaf>::Alignment, RootDataSize> data;
 
   // Tree height.
   // 0: Leaves in root.
@@ -993,7 +988,7 @@
       const char *d;
       T *t;
     } u;
-    u.d = data;
+    u.d = data.buffer;
     return *u.t;
   }
 
@@ -1051,7 +1046,7 @@
 
 public:
   explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
-    assert((uintptr_t(data) & (alignOf<RootLeaf>() - 1)) == 0 &&
+    assert((uintptr_t(data.buffer) & (alignOf<RootLeaf>() - 1)) == 0 &&
            "Insufficient alignment");
     new(&rootLeaf()) RootLeaf();
   }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8268.21770.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150311/9a3a796e/attachment.bin>


More information about the llvm-commits mailing list