From 836e7c9357b312fd1ee5c90898ce2c81bb384997 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 14 Mar 2013 17:53:33 +0000 Subject: 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 --- lib/CodeGen/CGBlocks.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/CGBlocks.cpp') 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; } -- cgit v1.2.3-70-g09d2