summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGBlocks.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2013-03-29 19:20:35 +0000
committerAdrian Prantl <aprantl@apple.com>2013-03-29 19:20:35 +0000
commit0f6df00e4d64e74ebb9621edf9beb0ced42e1697 (patch)
tree8ddd4cc1132bd9eac56902b7fc859c4b6b6c8e85 /clang/lib/CodeGen/CGBlocks.cpp
parentde17db30d8448db181dadbeb9f5e2479cbf17cca (diff)
downloadbcm5719-llvm-0f6df00e4d64e74ebb9621edf9beb0ced42e1697.tar.gz
bcm5719-llvm-0f6df00e4d64e74ebb9621edf9beb0ced42e1697.zip
Bugfix/Followup for r177086.
* Store the .block_descriptor (instead of self) in the alloca so we can guarantee that all captured variables are available at -O0. * Add the missing OpDeref for the alloca. rdar://problem/12767564 llvm-svn: 178361
Diffstat (limited to 'clang/lib/CodeGen/CGBlocks.cpp')
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 77e29bd1193..d702b856cdc 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1138,6 +1138,18 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
BlockPointer = Builder.CreateBitCast(blockAddr,
blockInfo.StructureType->getPointerTo(),
"block");
+ // At -O0 we generate an explicit alloca for the BlockPointer, so the RA
+ // won't delete the dbg.declare intrinsics for captured variables.
+ llvm::Value *BlockPointerDbgLoc = BlockPointer;
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+ // Allocate a stack slot for it, so we can point the debugger to it
+ llvm::AllocaInst *Alloca = CreateTempAlloca(BlockPointer->getType(),
+ "block.addr");
+ unsigned Align = getContext().getDeclAlign(&selfDecl).getQuantity();
+ Alloca->setAlignment(Align);
+ Builder.CreateAlignedStore(BlockPointer, Alloca, Align);
+ BlockPointerDbgLoc = Alloca;
+ }
// If we have a C++ 'this' reference, go ahead and force it into
// existence now.
@@ -1161,20 +1173,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
llvm::Value *selfAddr = Builder.CreateStructGEP(BlockPointer,
capture.getIndex(),
"block.captured-self");
-
- // 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;
+ LocalDeclMap[self] = selfAddr;
}
}
@@ -1230,7 +1229,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
continue;
}
- DI->EmitDeclareOfBlockDeclRefVariable(variable, BlockPointer,
+ DI->EmitDeclareOfBlockDeclRefVariable(variable, BlockPointerDbgLoc,
Builder, blockInfo);
}
}
OpenPOWER on IntegriCloud