blob: be79a1a1ac1d362557d0c0985145a7bfc76082cb [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
Mike Stumpb95bc002009-02-13 16:19:19 +0000106 {
107 // C = BuildBlockStructInitlist();
108 unsigned int flags = BLOCK_HAS_DESCRIPTOR;
109
110 if (BlockHasCopyDispose)
111 flags |= BLOCK_HAS_COPY_DISPOSE;
112
113 const llvm::PointerType *PtrToInt8Ty
114 = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
115 // FIXME: static? What if we start up a new, unrelated module?
116 // logically we want 1 per module.
Mike Stumpb95bc002009-02-13 16:19:19 +0000117 static llvm::Constant *NSConcreteStackBlock_decl
118 = new llvm::GlobalVariable(PtrToInt8Ty, false,
119 llvm::GlobalValue::ExternalLinkage,
120 0, "_NSConcreteStackBlock",
121 &CGM.getModule());
122 C = NSConcreteStackBlock_decl;
123 if (!insideFunction ||
124 (!BlockRefDeclList && !BlockByrefDeclList)) {
Mike Stump5f87e9d2009-02-13 17:23:42 +0000125 C = CGM.getNSConcreteGlobalBlock();
Mike Stumpb95bc002009-02-13 16:19:19 +0000126 flags |= BLOCK_IS_GLOBAL;
127 }
128 C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
129 Elts.push_back(C);
130
131 // __flags
132 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
133 CGM.getTypes().ConvertType(CGM.getContext().IntTy));
134 C = llvm::ConstantInt::get(IntTy, flags);
135 Elts.push_back(C);
136
137 // __reserved
138 C = llvm::ConstantInt::get(IntTy, 0);
139 Elts.push_back(C);
140
141 // __FuncPtr
142 // FIXME: Build this up.
143 Elts.push_back(C);
144
145 // __descriptor
146 Elts.push_back(BuildDescriptorBlockDecl());
147
148 // FIXME: Add block_original_ref_decl_list and block_byref_decl_list.
149 }
150
151 C = llvm::ConstantStruct::get(Elts);
152
153 char Name[32];
Mike Stumpef2c82f2009-02-13 18:36:05 +0000154 sprintf(Name, "__block_holder_tmp_%d", CGM.getGlobalUniqueCount());
Mike Stumpb95bc002009-02-13 16:19:19 +0000155 C = new llvm::GlobalVariable(C->getType(), true,
156 llvm::GlobalValue::InternalLinkage,
157 C, Name, &CGM.getModule());
158 return C;
159}
160
161
162
163
Mike Stump95e54802009-02-13 15:16:56 +0000164const llvm::Type *CodeGenModule::getBlockDescriptorType() {
165 if (BlockDescriptorType)
166 return BlockDescriptorType;
167
Mike Stumpc4ae9632009-02-13 15:32:32 +0000168 const llvm::Type *UnsignedLongTy =
Mike Stump95e54802009-02-13 15:16:56 +0000169 getTypes().ConvertType(getContext().UnsignedLongTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000170
Mike Stump95e54802009-02-13 15:16:56 +0000171 // struct __block_descriptor {
172 // unsigned long reserved;
173 // unsigned long block_size;
174 // };
Mike Stumpc4ae9632009-02-13 15:32:32 +0000175 BlockDescriptorType = llvm::StructType::get(UnsignedLongTy,
176 UnsignedLongTy,
Mike Stump95e54802009-02-13 15:16:56 +0000177 NULL);
178
179 getModule().addTypeName("struct.__block_descriptor",
180 BlockDescriptorType);
181
182 return BlockDescriptorType;
Anders Carlssond2a889b2009-02-12 00:39:25 +0000183}
184
Mike Stump0dffa462009-02-13 15:25:34 +0000185const llvm::Type *
186CodeGenModule::getGenericBlockLiteralType() {
187 if (GenericBlockLiteralType)
188 return GenericBlockLiteralType;
189
Mike Stumpc4ae9632009-02-13 15:32:32 +0000190 const llvm::Type *Int8PtrTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000191 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000192
193 const llvm::Type *BlockDescPtrTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000194 llvm::PointerType::getUnqual(getBlockDescriptorType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000195
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000196 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
197 getTypes().ConvertType(getContext().IntTy));
198
Mike Stump0dffa462009-02-13 15:25:34 +0000199 // struct __block_literal_generic {
200 // void *isa;
201 // int flags;
202 // int reserved;
203 // void (*invoke)(void *);
204 // struct __block_descriptor *descriptor;
205 // };
206 GenericBlockLiteralType = llvm::StructType::get(Int8PtrTy,
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000207 IntTy,
208 IntTy,
Mike Stump0dffa462009-02-13 15:25:34 +0000209 Int8PtrTy,
210 BlockDescPtrTy,
211 NULL);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000212
Mike Stump0dffa462009-02-13 15:25:34 +0000213 getModule().addTypeName("struct.__block_literal_generic",
214 GenericBlockLiteralType);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000215
Mike Stump0dffa462009-02-13 15:25:34 +0000216 return GenericBlockLiteralType;
Anders Carlssond2a889b2009-02-12 00:39:25 +0000217}
218
Mike Stumpc4ae9632009-02-13 15:32:32 +0000219/// getBlockFunctionType - Given a BlockPointerType, will return the
Anders Carlssond2a889b2009-02-12 00:39:25 +0000220/// function type for the block, including the first block literal argument.
221static QualType getBlockFunctionType(ASTContext &Ctx,
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000222 const BlockPointerType *BPT) {
Anders Carlssond2a889b2009-02-12 00:39:25 +0000223 const FunctionTypeProto *FTy = cast<FunctionTypeProto>(BPT->getPointeeType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000224
Anders Carlssond2a889b2009-02-12 00:39:25 +0000225 llvm::SmallVector<QualType, 8> Types;
226 Types.push_back(Ctx.getPointerType(Ctx.VoidTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000227
Anders Carlssond2a889b2009-02-12 00:39:25 +0000228 for (FunctionTypeProto::arg_type_iterator i = FTy->arg_type_begin(),
229 e = FTy->arg_type_end(); i != e; ++i)
230 Types.push_back(*i);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000231
Anders Carlssond2a889b2009-02-12 00:39:25 +0000232 return Ctx.getFunctionType(FTy->getResultType(),
Mike Stumpc4ae9632009-02-13 15:32:32 +0000233 &Types[0], Types.size(),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000234 FTy->isVariadic(), 0);
235}
236
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000237RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
Mike Stumpc4ae9632009-02-13 15:32:32 +0000238 const BlockPointerType *BPT =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000239 E->getCallee()->getType()->getAsBlockPointerType();
Mike Stumpc4ae9632009-02-13 15:32:32 +0000240
Anders Carlssond2a889b2009-02-12 00:39:25 +0000241 llvm::Value *Callee = EmitScalarExpr(E->getCallee());
242
243 // Get a pointer to the generic block literal.
244 const llvm::Type *BlockLiteralTy =
Mike Stump0dffa462009-02-13 15:25:34 +0000245 llvm::PointerType::getUnqual(CGM.getGenericBlockLiteralType());
Anders Carlssond2a889b2009-02-12 00:39:25 +0000246
247 // Bitcast the callee to a block literal.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000248 llvm::Value *BlockLiteral =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000249 Builder.CreateBitCast(Callee, BlockLiteralTy, "block.literal");
250
251 // Get the function pointer from the literal.
252 llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp");
253 llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp");
254
255 // Cast the function pointer to the right type.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000256 const llvm::Type *BlockFTy =
Anders Carlssond2a889b2009-02-12 00:39:25 +0000257 ConvertType(getBlockFunctionType(getContext(), BPT));
258 const llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
259 Func = Builder.CreateBitCast(Func, BlockFTyPtr);
260
Mike Stumpc4ae9632009-02-13 15:32:32 +0000261 BlockLiteral =
262 Builder.CreateBitCast(BlockLiteral,
Anders Carlssond2a889b2009-02-12 00:39:25 +0000263 llvm::PointerType::getUnqual(llvm::Type::Int8Ty),
264 "tmp");
Mike Stumpc4ae9632009-02-13 15:32:32 +0000265
Anders Carlssond2a889b2009-02-12 00:39:25 +0000266 // Add the block literal.
267 QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy);
268 CallArgList Args;
269 Args.push_back(std::make_pair(RValue::get(BlockLiteral), VoidPtrTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000270
Anders Carlssond2a889b2009-02-12 00:39:25 +0000271 // And the rest of the arguments.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000272 for (CallExpr::const_arg_iterator i = E->arg_begin(), e = E->arg_end();
Anders Carlssond2a889b2009-02-12 00:39:25 +0000273 i != e; ++i)
Mike Stumpc4ae9632009-02-13 15:32:32 +0000274 Args.push_back(std::make_pair(EmitAnyExprToTemp(*i),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000275 i->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000276
Anders Carlssond2a889b2009-02-12 00:39:25 +0000277 // And call the block.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000278 return EmitCall(CGM.getTypes().getFunctionInfo(E->getType(), Args),
Anders Carlssond2a889b2009-02-12 00:39:25 +0000279 Func, Args);
280}
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000281
282llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000283 // Generate the block descriptor.
284 const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000285 const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
286 getTypes().ConvertType(getContext().IntTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000287
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000288 llvm::Constant *DescriptorFields[2];
Mike Stumpc4ae9632009-02-13 15:32:32 +0000289
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000290 // Reserved
291 DescriptorFields[0] = llvm::Constant::getNullValue(UnsignedLongTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000292
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000293 // Block literal size. For global blocks we just use the size of the generic
294 // block literal struct.
Mike Stumpc4ae9632009-02-13 15:32:32 +0000295 uint64_t BlockLiteralSize =
Mike Stump0dffa462009-02-13 15:25:34 +0000296 TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8;
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000297 DescriptorFields[1] = llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000298
299 llvm::Constant *DescriptorStruct =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000300 llvm::ConstantStruct::get(&DescriptorFields[0], 2);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000301
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000302 llvm::GlobalVariable *Descriptor =
303 new llvm::GlobalVariable(DescriptorStruct->getType(), true,
Mike Stumpc4ae9632009-02-13 15:32:32 +0000304 llvm::GlobalVariable::InternalLinkage,
305 DescriptorStruct, "__block_descriptor_global",
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000306 &getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000307
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000308 // Generate the constants for the block literal.
309 llvm::Constant *LiteralFields[5];
Mike Stumpc4ae9632009-02-13 15:32:32 +0000310
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000311 CodeGenFunction::BlockInfo Info(0, "global");
312 llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000313
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000314 // isa
Mike Stump5f87e9d2009-02-13 17:23:42 +0000315 LiteralFields[0] = getNSConcreteGlobalBlock();
Mike Stumpc4ae9632009-02-13 15:32:32 +0000316
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000317 // Flags
Mike Stumpb95bc002009-02-13 16:19:19 +0000318 LiteralFields[1] = llvm::ConstantInt::get(IntTy, BLOCK_IS_GLOBAL);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000319
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000320 // Reserved
Mike Stump7b7cd8b2009-02-13 16:01:35 +0000321 LiteralFields[2] = llvm::Constant::getNullValue(IntTy);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000322
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000323 // Function
324 LiteralFields[3] = Fn;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000325
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000326 // Descriptor
327 LiteralFields[4] = Descriptor;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000328
329 llvm::Constant *BlockLiteralStruct =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000330 llvm::ConstantStruct::get(&LiteralFields[0], 5);
Mike Stumpc4ae9632009-02-13 15:32:32 +0000331
332 llvm::GlobalVariable *BlockLiteral =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000333 new llvm::GlobalVariable(BlockLiteralStruct->getType(), true,
Mike Stumpc4ae9632009-02-13 15:32:32 +0000334 llvm::GlobalVariable::InternalLinkage,
335 BlockLiteralStruct, "__block_literal_global",
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000336 &getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000337
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000338 return BlockLiteral;
339}
340
341llvm::Function *CodeGenFunction::GenerateBlockFunction(const BlockExpr *Expr,
342 const BlockInfo& Info)
343{
Mike Stumpc4ae9632009-02-13 15:32:32 +0000344 const FunctionTypeProto *FTy =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000345 cast<FunctionTypeProto>(Expr->getFunctionType());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000346
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000347 FunctionArgList Args;
Mike Stumpc4ae9632009-02-13 15:32:32 +0000348
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000349 const BlockDecl *BD = Expr->getBlockDecl();
350
351 // FIXME: This leaks
Mike Stumpc4ae9632009-02-13 15:32:32 +0000352 ImplicitParamDecl *SelfDecl =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000353 ImplicitParamDecl::Create(getContext(), 0,
354 SourceLocation(), 0,
355 getContext().getPointerType(getContext().VoidTy));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000356
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000357 Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000358
359 for (BlockDecl::param_iterator i = BD->param_begin(),
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000360 e = BD->param_end(); i != e; ++i)
361 Args.push_back(std::make_pair(*e, (*e)->getType()));
Mike Stumpc4ae9632009-02-13 15:32:32 +0000362
363 const CGFunctionInfo &FI =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000364 CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
365
366 std::string Name = std::string("__block_function_") + Info.NameSuffix;
367
368 CodeGenTypes &Types = CGM.getTypes();
369 const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000370
371 llvm::Function *Fn =
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000372 llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
373 Name,
374 &CGM.getModule());
Mike Stumpc4ae9632009-02-13 15:32:32 +0000375
376 StartFunction(BD, FTy->getResultType(), Fn, Args,
Anders Carlsson1f1cd392009-02-12 17:55:02 +0000377 Expr->getBody()->getLocEnd());
378 EmitStmt(Expr->getBody());
379 FinishFunction(cast<CompoundStmt>(Expr->getBody())->getRBracLoc());
380
381 return Fn;
382}