blob: 045f7338e005f3a367e0e6ea31f2533f6c7c4e38 [file] [log] [blame]
Anders Carlssond2a889b2009-02-12 00:39:25 +00001//===--- CGBlocks.cpp - Emit LLVM Code for declarations -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This contains code to emit blocks.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenFunction.h"
15#include "CodeGenModule.h"
16#include "llvm/Module.h"
Anders Carlsson1f1cd392009-02-12 17:55:02 +000017#include "llvm/Target/TargetData.h"
Anders Carlssond2a889b2009-02-12 00:39:25 +000018
19#include <algorithm>
20
21using namespace clang;
22using namespace CodeGen;
23
Anders Carlsson1f1cd392009-02-12 17:55:02 +000024enum {
Mike Stumpb95bc002009-02-13 16:19:19 +000025 BLOCK_NEEDS_FREE = (1 << 24),
26 BLOCK_HAS_COPY_DISPOSE = (1 << 25),
27 BLOCK_HAS_CXX_OBJ = (1 << 26),
28 BLOCK_IS_GC = (1 << 27),
29 BLOCK_IS_GLOBAL = (1 << 28),
30 BLOCK_HAS_DESCRIPTOR = (1 << 29)
Anders Carlsson1f1cd392009-02-12 17:55:02 +000031};
32
Mike Stumpb95bc002009-02-13 16:19:19 +000033llvm::Constant *CodeGenFunction::BuildDescriptorBlockDecl() {
34 // FIXME: Push up.
35 bool BlockHasCopyDispose = false;
36
37 const llvm::PointerType *PtrToInt8Ty
38 = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Mike Stumpff8f0872009-02-13 16:55:51 +000039 const llvm::Type *UnsignedLongTy
40 = CGM.getTypes().ConvertType(getContext().UnsignedLongTy);
Mike Stumpb95bc002009-02-13 16:19:19 +000041 llvm::Constant *C;
42 std::vector<llvm::Constant*> Elts;
43
44 // reserved
Mike Stumpff8f0872009-02-13 16:55:51 +000045 C = llvm::ConstantInt::get(UnsignedLongTy, 0);
Mike Stumpb95bc002009-02-13 16:19:19 +000046 Elts.push_back(C);
47
48 // Size
Mike Stumpac9b4df2009-02-13 17:03:17 +000049 int sz = CGM.getTargetData()
50 .getTypeStoreSizeInBits(CGM.getGenericBlockLiteralType()) / 8;
51 C = llvm::ConstantInt::get(UnsignedLongTy, sz);
Mike Stumpb95bc002009-02-13 16:19:19 +000052 Elts.push_back(C);
53
54 if (BlockHasCopyDispose) {
55 // copy_func_helper_decl
Mike Stumpff8f0872009-02-13 16:55:51 +000056 C = llvm::ConstantInt::get(UnsignedLongTy, 0);
Mike Stumpb95bc002009-02-13 16:19:19 +000057 C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
58 Elts.push_back(C);
59
60 // destroy_func_decl
Mike Stumpff8f0872009-02-13 16:55:51 +000061 C = llvm::ConstantInt::get(UnsignedLongTy, 0);
Mike Stumpb95bc002009-02-13 16:19:19 +000062 C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
63 Elts.push_back(C);
64 }
65
66 C = llvm::ConstantStruct::get(Elts);
67
68 // FIXME: Should be in module?
69 static int desc_unique_count;
70 char Name[32];
71 sprintf(Name, "__block_descriptor_tmp_%d", ++desc_unique_count);
72 C = new llvm::GlobalVariable(C->getType(), true,
73 llvm::GlobalValue::InternalLinkage,
74 C, Name, &CGM.getModule());
75 return C;
76}
77
Mike Stump5f87e9d2009-02-13 17:23:42 +000078llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() {
79 if (NSConcreteGlobalBlock)
80 return NSConcreteGlobalBlock;
81
82 const llvm::PointerType *PtrToInt8Ty
83 = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
84 // FIXME: Wee should have a CodeGenModule::AddRuntimeVariable that does the
85 // same thing as CreateRuntimeFunction if there's already a variable with
86 // the same name.
87 NSConcreteGlobalBlock
88 = new llvm::GlobalVariable(PtrToInt8Ty, false,
89 llvm::GlobalValue::ExternalLinkage,
90 0, "_NSConcreteGlobalBlock",
91 &getModule());
92
93 return NSConcreteGlobalBlock;
94}
95
Mike Stumpb95bc002009-02-13 16:19:19 +000096llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
97 // FIXME: Push up
98 bool BlockHasCopyDispose = false;
99 bool insideFunction = false;
100 bool BlockRefDeclList = false;
101 bool BlockByrefDeclList = false;
102
103 std::vector<llvm::Constant*> Elts;
104 llvm::Constant *C;
105
106 bool staticBlockTmp = (BlockRefDeclList == 0
107 && BlockByrefDeclList == 0);
108
109 {
110 // C = BuildBlockStructInitlist();
111 unsigned int flags = BLOCK_HAS_DESCRIPTOR;
112
113 if (BlockHasCopyDispose)
114 flags |= BLOCK_HAS_COPY_DISPOSE;
115
116 const llvm::PointerType *PtrToInt8Ty
117 = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
118 // FIXME: static? What if we start up a new, unrelated module?
119 // logically we want 1 per module.
Mike Stumpb95bc002009-02-13 16:19:19 +0000120 static llvm::Constant *NSConcreteStackBlock_decl
121 = new llvm::GlobalVariable(PtrToInt8Ty, false,
122 llvm::GlobalValue::ExternalLinkage,
123 0, "_NSConcreteStackBlock",
124 &CGM.getModule());
125 C = NSConcreteStackBlock_decl;
126 if (!insideFunction ||
127 (!BlockRefDeclList && !BlockByrefDeclList)) {
Mike Stump5f87e9d2009-02-13 17:23:42 +0000128 C = CGM.getNSConcreteGlobalBlock();
Mike Stumpb95bc002009-02-13 16:19:19 +0000129 flags |= BLOCK_IS_GLOBAL;
130 }
131 C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
132 Elts.push_back(C);
133
134 // __flags
135 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
136 CGM.getTypes().ConvertType(CGM.getContext().IntTy));
137 C = llvm::ConstantInt::get(IntTy, flags);
138 Elts.push_back(C);
139
140 // __reserved
141 C = llvm::ConstantInt::get(IntTy, 0);
142 Elts.push_back(C);
143
144 // __FuncPtr
145 // FIXME: Build this up.
146 Elts.push_back(C);
147
148 // __descriptor
149 Elts.push_back(BuildDescriptorBlockDecl());
150
151 // FIXME: Add block_original_ref_decl_list and block_byref_decl_list.
152 }
153
154 C = llvm::ConstantStruct::get(Elts);
155
156 char Name[32];
Mike Stumpef2c82f2009-02-13 18:36:05 +0000157 sprintf(Name, "__block_holder_tmp_%d", CGM.getGlobalUniqueCount());
Mike Stumpb95bc002009-02-13 16:19:19 +0000158 C = new llvm::GlobalVariable(C->getType(), true,
159 llvm::GlobalValue::InternalLinkage,
160 C, Name, &CGM.getModule());
161 return C;
162}
163
164
165
166
Mike Stump95e54802009-02-13 15:16:56 +0000167const llvm::Type *CodeGenModule::getBlockDescriptorType() {
168 if (BlockDescriptorType)
169 return BlockDescriptorType;
170
Mike Stumpc4ae9632009-02-13 15:32:32 +0000171 const llvm::Type *UnsignedLongTy =
Mike Stump95e54802009-02-13 15:16:56 +0000172 getTypes().ConvertType(getContext().UnsignedLongTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000173
Mike Stump95e54802009-02-13 15:16:56 +0000174 // struct __block_descriptor {
175 // unsigned long reserved;
176 // unsigned long block_size;
177 // };
Mike Stumpc4ae9632009-02-13 15:32:32 +0000178 BlockDescriptorType = llvm::StructType::get(UnsignedLongTy,
179 UnsignedLongTy,
Mike Stump95e54802009-02-13 15:16:56 +0000180 NULL);
181
182 getModule().addTypeName("struct.__block_descriptor",
183 BlockDescriptorType);
184
185 return BlockDescriptorType;
Anders Carlssond2a889b2009-02-12 00:39:25 +0000186}
187
Mike Stump0dffa462009-02-13 15:25:34 +0000188const llvm::Type *
189CodeGenModule::getGenericBlockLiteralType() {
190 if (GenericBlockLiteralType)
191 return GenericBlockLiteralType;
192
Mike Stumpc4ae9632009-02-13 15:32:32 +0000193 const llvm::Type *Int8PtrTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000194 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000195
196 const llvm::Type *BlockDescPtrTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000197 llvm::PointerType::getUnqual(getBlockDescriptorType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000198
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000199 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
200 getTypes().ConvertType(getContext().IntTy));
201
Mike Stump0dffa462009-02-13 15:25:34 +0000202 // struct __block_literal_generic {
203 // void *isa;
204 // int flags;
205 // int reserved;
206 // void (*invoke)(void *);
207 // struct __block_descriptor *descriptor;
208 // };
209 GenericBlockLiteralType = llvm::StructType::get(Int8PtrTy,
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000210 IntTy,
211 IntTy,
Mike Stump0dffa462009-02-13 15:25:34 +0000212 Int8PtrTy,
213 BlockDescPtrTy,
214 NULL);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000215
Mike Stump0dffa462009-02-13 15:25:34 +0000216 getModule().addTypeName("struct.__block_literal_generic",
217 GenericBlockLiteralType);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000218
Mike Stump0dffa462009-02-13 15:25:34 +0000219 return GenericBlockLiteralType;
Anders Carlssond2a889b2009-02-12 00:39:25 +0000220}
221
Mike Stumpc4ae9632009-02-13 15:32:32 +0000222/// getBlockFunctionType - Given a BlockPointerType, will return the
Anders Carlssond2a889b2009-02-12 00:39:25 +0000223/// function type for the block, including the first block literal argument.
224static QualType getBlockFunctionType(ASTContext &Ctx,
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000225 const BlockPointerType *BPT) {
Anders Carlssond2a889b2009-02-12 00:39:25 +0000226 const FunctionTypeProto *FTy = cast<FunctionTypeProto>(BPT->getPointeeType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000227
Anders Carlssond2a889b2009-02-12 00:39:25 +0000228 llvm::SmallVector<QualType, 8> Types;
229 Types.push_back(Ctx.getPointerType(Ctx.VoidTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000230
Anders Carlssond2a889b2009-02-12 00:39:25 +0000231 for (FunctionTypeProto::arg_type_iterator i = FTy->arg_type_begin(),
232 e = FTy->arg_type_end(); i != e; ++i)
233 Types.push_back(*i);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000234
Anders Carlssond2a889b2009-02-12 00:39:25 +0000235 return Ctx.getFunctionType(FTy->getResultType(),
Mike Stumpc4ae9632009-02-13 15:32:32 +0000236 &Types[0], Types.size(),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000237 FTy->isVariadic(), 0);
238}
239
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000240RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
Mike Stumpc4ae9632009-02-13 15:32:32 +0000241 const BlockPointerType *BPT =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000242 E->getCallee()->getType()->getAsBlockPointerType();
Mike Stumpc4ae9632009-02-13 15:32:32 +0000243
Anders Carlssond2a889b2009-02-12 00:39:25 +0000244 llvm::Value *Callee = EmitScalarExpr(E->getCallee());
245
246 // Get a pointer to the generic block literal.
247 const llvm::Type *BlockLiteralTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000248 llvm::PointerType::getUnqual(CGM.getGenericBlockLiteralType());
Anders Carlssond2a889b2009-02-12 00:39:25 +0000249
250 // Bitcast the callee to a block literal.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000251 llvm::Value *BlockLiteral =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000252 Builder.CreateBitCast(Callee, BlockLiteralTy, "block.literal");
253
254 // Get the function pointer from the literal.
255 llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp");
256 llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp");
257
258 // Cast the function pointer to the right type.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000259 const llvm::Type *BlockFTy =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000260 ConvertType(getBlockFunctionType(getContext(), BPT));
261 const llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
262 Func = Builder.CreateBitCast(Func, BlockFTyPtr);
263
Mike Stumpc4ae9632009-02-13 15:32:32 +0000264 BlockLiteral =
265 Builder.CreateBitCast(BlockLiteral,
Anders Carlssond2a889b2009-02-12 00:39:25 +0000266 llvm::PointerType::getUnqual(llvm::Type::Int8Ty),
267 "tmp");
Mike Stumpc4ae9632009-02-13 15:32:32 +0000268
Anders Carlssond2a889b2009-02-12 00:39:25 +0000269 // Add the block literal.
270 QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy);
271 CallArgList Args;
272 Args.push_back(std::make_pair(RValue::get(BlockLiteral), VoidPtrTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000273
Anders Carlssond2a889b2009-02-12 00:39:25 +0000274 // And the rest of the arguments.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000275 for (CallExpr::const_arg_iterator i = E->arg_begin(), e = E->arg_end();
Anders Carlssond2a889b2009-02-12 00:39:25 +0000276 i != e; ++i)
Mike Stumpc4ae9632009-02-13 15:32:32 +0000277 Args.push_back(std::make_pair(EmitAnyExprToTemp(*i),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000278 i->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000279
Anders Carlssond2a889b2009-02-12 00:39:25 +0000280 // And call the block.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000281 return EmitCall(CGM.getTypes().getFunctionInfo(E->getType(), Args),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000282 Func, Args);
283}
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000284
285llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000286 // Generate the block descriptor.
287 const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000288 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
289 getTypes().ConvertType(getContext().IntTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000290
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000291 llvm::Constant *DescriptorFields[2];
Mike Stumpc4ae9632009-02-13 15:32:32 +0000292
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000293 // Reserved
294 DescriptorFields[0] = llvm::Constant::getNullValue(UnsignedLongTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000295
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000296 // Block literal size. For global blocks we just use the size of the generic
297 // block literal struct.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000298 uint64_t BlockLiteralSize =
Mike Stump0dffa462009-02-13 15:25:34 +0000299 TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8;
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000300 DescriptorFields[1] = llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000301
302 llvm::Constant *DescriptorStruct =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000303 llvm::ConstantStruct::get(&DescriptorFields[0], 2);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000304
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000305 llvm::GlobalVariable *Descriptor =
306 new llvm::GlobalVariable(DescriptorStruct->getType(), true,
Mike Stumpc4ae9632009-02-13 15:32:32 +0000307 llvm::GlobalVariable::InternalLinkage,
308 DescriptorStruct, "__block_descriptor_global",
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000309 &getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000310
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000311 // Generate the constants for the block literal.
312 llvm::Constant *LiteralFields[5];
Mike Stumpc4ae9632009-02-13 15:32:32 +0000313
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000314 CodeGenFunction::BlockInfo Info(0, "global");
315 llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000316
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000317 // isa
Mike Stump5f87e9d2009-02-13 17:23:42 +0000318 LiteralFields[0] = getNSConcreteGlobalBlock();
Mike Stumpc4ae9632009-02-13 15:32:32 +0000319
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000320 // Flags
Mike Stumpb95bc002009-02-13 16:19:19 +0000321 LiteralFields[1] = llvm::ConstantInt::get(IntTy, BLOCK_IS_GLOBAL);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000322
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000323 // Reserved
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000324 LiteralFields[2] = llvm::Constant::getNullValue(IntTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000325
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000326 // Function
327 LiteralFields[3] = Fn;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000328
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000329 // Descriptor
330 LiteralFields[4] = Descriptor;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000331
332 llvm::Constant *BlockLiteralStruct =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000333 llvm::ConstantStruct::get(&LiteralFields[0], 5);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000334
335 llvm::GlobalVariable *BlockLiteral =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000336 new llvm::GlobalVariable(BlockLiteralStruct->getType(), true,
Mike Stumpc4ae9632009-02-13 15:32:32 +0000337 llvm::GlobalVariable::InternalLinkage,
338 BlockLiteralStruct, "__block_literal_global",
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000339 &getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000340
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000341 return BlockLiteral;
342}
343
344llvm::Function *CodeGenFunction::GenerateBlockFunction(const BlockExpr *Expr,
345 const BlockInfo& Info)
346{
Mike Stumpc4ae9632009-02-13 15:32:32 +0000347 const FunctionTypeProto *FTy =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000348 cast<FunctionTypeProto>(Expr->getFunctionType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000349
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000350 FunctionArgList Args;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000351
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000352 const BlockDecl *BD = Expr->getBlockDecl();
353
354 // FIXME: This leaks
Mike Stumpc4ae9632009-02-13 15:32:32 +0000355 ImplicitParamDecl *SelfDecl =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000356 ImplicitParamDecl::Create(getContext(), 0,
357 SourceLocation(), 0,
358 getContext().getPointerType(getContext().VoidTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000359
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000360 Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000361
362 for (BlockDecl::param_iterator i = BD->param_begin(),
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000363 e = BD->param_end(); i != e; ++i)
364 Args.push_back(std::make_pair(*e, (*e)->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000365
366 const CGFunctionInfo &FI =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000367 CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
368
369 std::string Name = std::string("__block_function_") + Info.NameSuffix;
370
371 CodeGenTypes &Types = CGM.getTypes();
372 const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000373
374 llvm::Function *Fn =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000375 llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
376 Name,
377 &CGM.getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000378
379 StartFunction(BD, FTy->getResultType(), Fn, Args,
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000380 Expr->getBody()->getLocEnd());
381 EmitStmt(Expr->getBody());
382 FinishFunction(cast<CompoundStmt>(Expr->getBody())->getRBracLoc());
383
384 return Fn;
385}