summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-03-17 05:53:35 +0000
committerAnders Carlsson <andersca@mac.com>2009-03-17 05:53:35 +0000
commite73e3ecc040425ff60404e6c62529f8e95fd8df5 (patch)
tree727a55867f5b43fa24eec397eed38e1bd967ff4f /clang
parente8911a9a1327a4e93779cc092f8eb126dd7482f2 (diff)
downloadbcm5719-llvm-e73e3ecc040425ff60404e6c62529f8e95fd8df5.tar.gz
bcm5719-llvm-e73e3ecc040425ff60404e6c62529f8e95fd8df5.zip
Initialize the cleanup.dst variable if necessary. Fixes PR3789.
llvm-svn: 67075
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp11
-rw-r--r--clang/test/CodeGen/cleanup-stack.c15
2 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index a54f9bd235f..441c9fcdbf6 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -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/clang/test/CodeGen/cleanup-stack.c b/clang/test/CodeGen/cleanup-stack.c
new file mode 100644
index 00000000000..360f6e701be
--- /dev/null
+++ b/clang/test/CodeGen/cleanup-stack.c
@@ -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;
+}
OpenPOWER on IntegriCloud