aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGBlocks.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2013-03-14 17:53:33 +0000
committerAdrian Prantl <aprantl@apple.com>2013-03-14 17:53:33 +0000
commit836e7c9357b312fd1ee5c90898ce2c81bb384997 (patch)
tree74e423d21f912877da6b6330660592f06bfb0924 /lib/CodeGen/CGBlocks.cpp
parent4a374f9a58a5b350ec2e4123b20c9884ed1f5f15 (diff)
Allocate stack storage for .block_descriptor and captured self at -O0.
This way the register allocator will not optimize away the debug info for captured variables. Fixes rdar://problem/12767564 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGBlocks.cpp')
-rw-r--r--lib/CodeGen/CGBlocks.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index c521bf9472..77e29bd119 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -1157,10 +1157,24 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
// There might not be a capture for 'self', but if there is...
if (blockInfo.Captures.count(self)) {
const CGBlockInfo::Capture &capture = blockInfo.getCapture(self);
+
llvm::Value *selfAddr = Builder.CreateStructGEP(BlockPointer,
capture.getIndex(),
"block.captured-self");
- LocalDeclMap[self] = selfAddr;
+
+ // At -O0 we generate an explicit alloca for self to facilitate debugging.
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+ llvm::Value *load = Builder.CreateLoad(selfAddr);
+
+ // Allocate a stack slot for it, so we can generate debug info for it
+ llvm::AllocaInst *alloca = CreateTempAlloca(load->getType(),
+ "block.captured-self.addr");
+ unsigned align = getContext().getDeclAlign(self).getQuantity();
+ alloca->setAlignment(align);
+ Builder.CreateAlignedStore(load, alloca, align);
+ LocalDeclMap[self] = alloca;
+ } else
+ LocalDeclMap[self] = selfAddr;
}
}
@@ -1177,7 +1191,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
CreateMemTemp(variable->getType(), "block.captured-const");
alloca->setAlignment(align);
- Builder.CreateStore(capture.getConstant(), alloca, align);
+ Builder.CreateAlignedStore(capture.getConstant(), alloca, align);
LocalDeclMap[variable] = alloca;
}