[cfe-commits] r67075 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/cleanup-stack.c

Anders Carlsson andersca at mac.com
Mon Mar 16 22:53:36 PDT 2009


Author: andersca
Date: Tue Mar 17 00:53:35 2009
New Revision: 67075

URL: http://llvm.org/viewvc/llvm-project?rev=67075&view=rev
Log:
Initialize the cleanup.dst variable if necessary. Fixes PR3789.

Added:
    cfe/trunk/test/CodeGen/cleanup-stack.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=67075&r1=67074&r2=67075&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Mar 17 00:53:35 2009
@@ -549,7 +549,7 @@
     EndBlock = createBasicBlock("cleanup.end");
     
     llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
-
+    
     Builder.SetInsertPoint(SwitchBlock);
 
     llvm::Value *DestCodePtr = CreateTempAlloca(llvm::Type::Int32Ty, 
@@ -561,9 +561,14 @@
                                                 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) {

Added: cfe/trunk/test/CodeGen/cleanup-stack.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cleanup-stack.c?rev=67075&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/cleanup-stack.c (added)
+++ cfe/trunk/test/CodeGen/cleanup-stack.c Tue Mar 17 00:53:35 2009
@@ -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;
+}





More information about the cfe-commits mailing list