[clang] [CIR] Upstream EHScopeStack memory allocator (PR #152215)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 7 08:29:03 PDT 2025
================
@@ -33,6 +34,54 @@ using namespace clang::CIRGen;
void EHScopeStack::Cleanup::anchor() {}
+/// Push an entry of the given size onto this protected-scope stack.
+char *EHScopeStack::allocate(size_t size) {
+ size = llvm::alignTo(size, ScopeStackAlignment);
+ if (!startOfBuffer) {
+ unsigned capacity = 1024;
+ while (capacity < size)
+ capacity *= 2;
+ startOfBuffer = new char[capacity];
+ startOfData = endOfBuffer = startOfBuffer + capacity;
+ } else if (static_cast<size_t>(startOfData - startOfBuffer) < size) {
+ unsigned currentCapacity = endOfBuffer - startOfBuffer;
+ unsigned usedCapacity = currentCapacity - (startOfData - startOfBuffer);
+
+ unsigned newCapacity = currentCapacity;
+ do {
+ newCapacity *= 2;
+ } while (newCapacity < usedCapacity + size);
+
+ char *newStartOfBuffer = new char[newCapacity];
+ char *newEndOfBuffer = newStartOfBuffer + newCapacity;
+ char *newStartOfData = newEndOfBuffer - usedCapacity;
+ memcpy(newStartOfData, startOfData, usedCapacity);
+ delete[] startOfBuffer;
----------------
mmha wrote:
Can we use unique_ptr at least within this function?
https://github.com/llvm/llvm-project/pull/152215
More information about the cfe-commits
mailing list