]> granicus.if.org Git - clang/commitdiff
Use the new cleanup infrastructure for VLAs. The next iteration of patches will remov...
authorAnders Carlsson <andersca@mac.com>
Mon, 9 Feb 2009 20:41:50 +0000 (20:41 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 9 Feb 2009 20:41:50 +0000 (20:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64161 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp

index eba4d319efcf344426f396a9786d4303b11fb937..ce76ed56bbfe1fdc3651971cac4f79b6cffe98cc 100644 (file)
@@ -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 =