Use the new cleanup infrastructure for VLAs. The next iteration of patches will remove the old Obj-C EH cleanup code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64161 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index eba4d31..ce76ed5 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -178,7 +178,7 @@
if (Ty->isVariablyModifiedType())
EmitVLASize(Ty);
} else {
- if (!StackSaveValues.back()) {
+ if (!DidCallStackSave) {
// Save the stack.
const llvm::Type *LTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
llvm::Value *Stack = CreateTempAlloca(LTy, "saved_stack");
@@ -187,9 +187,19 @@
llvm::Value *V = Builder.CreateCall(F);
Builder.CreateStore(V, Stack);
+
+ DidCallStackSave = true;
- StackSaveValues.back() = StackDepth = Stack;
+ {
+ // Push a cleanup block and restore the stack there.
+ CleanupScope scope(*this);
+
+ V = Builder.CreateLoad(Stack, "tmp");
+ llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stackrestore);
+ Builder.CreateCall(F, V);
+ }
}
+
// Get the element type.
const llvm::Type *LElemTy = ConvertType(Ty);
const llvm::Type *LElemPtrTy =