================
@@ -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);
----------------
xlauko wrote:

```suggestion
    unsigned requiredCapacity = usedCapacity + size;
    unsigned newCapacity = llvm::PowerOf2Ceil(std::max(requiredCapacity, 
currentCapacity));
```

https://github.com/llvm/llvm-project/pull/152215
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to