Skip to content

Commit 3ea8892

Browse files
authored
Merge pull request #7767 from eeckstein/fix-assert
2 parents daac020 + 2f8b626 commit 3ea8892

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

include/swift/Basic/Demangler.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class NodeFactory {
8888

8989
/// Allocates an object of type T or an array of objects of type T.
9090
template<typename T> T *Allocate(size_t NumObjects = 1) {
91-
static_assert(alignof(T) <= alignof(Slab *), "alignment not supported");
9291
size_t ObjectSize = NumObjects * sizeof(T);
9392
CurPtr = align(CurPtr, alignof(T));
9493
#ifdef NODE_FACTORY_DEBUGGING
@@ -100,7 +99,7 @@ class NodeFactory {
10099
if (CurPtr + ObjectSize > End) {
101100
// No. We have to malloc a new slab.
102101
// We doulbe the slab size for each allocated slab.
103-
SlabSize = std::max(SlabSize * 2, ObjectSize);
102+
SlabSize = std::max(SlabSize * 2, ObjectSize + alignof(T));
104103
size_t AllocSize = sizeof(Slab) + SlabSize;
105104
Slab *newSlab = (Slab *)malloc(AllocSize);
106105

@@ -109,15 +108,14 @@ class NodeFactory {
109108
CurrentSlab = newSlab;
110109

111110
// Initialize the pointers to the new slab.
112-
CurPtr = (char *)(newSlab + 1);
113-
assert(align(CurPtr, alignof(T)) == CurPtr);
114-
End = CurPtr + SlabSize;
111+
CurPtr = align((char *)(newSlab + 1), alignof(T));
112+
End = (char *)newSlab + AllocSize;
113+
assert(CurPtr + ObjectSize <= End);
115114
#ifdef NODE_FACTORY_DEBUGGING
116115
std::cerr << " ** new slab " << newSlab << ", allocsize = "
117116
<< AllocSize << ", CurPtr = " << (void *)CurPtr
118117
<< ", End = " << (void *)End << "\n";
119118
#endif
120-
assert(End == (char *)newSlab + AllocSize);
121119
}
122120
T *AllocatedObj = (T *)CurPtr;
123121
CurPtr += ObjectSize;

0 commit comments

Comments
 (0)