From: Anders Carlsson Date: Mon, 9 Feb 2009 20:41:50 +0000 (+0000) Subject: Use the new cleanup infrastructure for VLAs. The next iteration of patches will remov... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ecb1b9377a6408486df5a10538bdc932706e053;p=clang 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 eba4d319ef..ce76ed56bb 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -178,7 +178,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { 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 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { llvm::Value *V = Builder.CreateCall(F); Builder.CreateStore(V, Stack); + + DidCallStackSave = true; + + { + // Push a cleanup block and restore the stack there. + CleanupScope scope(*this); - StackSaveValues.back() = StackDepth = Stack; + 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 =