]> granicus.if.org Git - clang/commitdiff
Initialize the cleanup.dst variable if necessary. Fixes PR3789.
authorAnders Carlsson <andersca@mac.com>
Tue, 17 Mar 2009 05:53:35 +0000 (05:53 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 17 Mar 2009 05:53:35 +0000 (05:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67075 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
test/CodeGen/cleanup-stack.c [new file with mode: 0644]

index a54f9bd235fc1b9198c8652ad2b0bdcd0c1f4d52..441c9fcdbf6ebc3448ce6d05320878aeb2d4c341 100644 (file)
@@ -549,7 +549,7 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
     EndBlock = createBasicBlock("cleanup.end");
     
     llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
-
+    
     Builder.SetInsertPoint(SwitchBlock);
 
     llvm::Value *DestCodePtr = CreateTempAlloca(llvm::Type::Int32Ty, 
@@ -561,9 +561,14 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
                                                 BranchFixups.size());
 
     // Restore the current basic block (if any)
-    if (CurBB)
+    if (CurBB) {
       Builder.SetInsertPoint(CurBB);
-    else
+      
+      // If we had a current basic block, we also need to emit an instruction
+      // to initialize the cleanup destination.
+      Builder.CreateStore(llvm::Constant::getNullValue(llvm::Type::Int32Ty),
+                          DestCodePtr);
+    } else
       Builder.ClearInsertionPoint();
 
     for (size_t i = 0, e = BranchFixups.size(); i != e; ++i) {
diff --git a/test/CodeGen/cleanup-stack.c b/test/CodeGen/cleanup-stack.c
new file mode 100644 (file)
index 0000000..360f6e7
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: clang -emit-llvm %s -o %t &&
+// RUN: grep "store i32 0, i32* %cleanup" %t | count 2
+void f(int n) {
+  int a[n];
+  
+  {
+    int b[n];
+    
+    if (n)
+      return;
+  }
+  
+  if (n)
+    return;
+}