blob: 9c400e75a60fa56a5fb3e3cd4010eb1c06ddd6e2 [file] [log] [blame]
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +00001//===--- CGDeclCXX.cpp - Emit LLVM Code for C++ 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 dealing with code generation of C++ declarations
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenFunction.h"
Fariborz Jahanianec805122011-01-13 20:00:54 +000015#include "CGObjCRuntime.h"
John McCall4c40d982010-08-31 07:33:07 +000016#include "CGCXXABI.h"
Chandler Carruth06057ce2010-06-15 23:19:56 +000017#include "clang/Frontend/CodeGenOptions.h"
Douglas Gregor86a3a032010-05-16 01:24:12 +000018#include "llvm/Intrinsics.h"
19
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000020using namespace clang;
21using namespace CodeGen;
22
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000023static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
24 llvm::Constant *DeclPtr) {
25 assert(D.hasGlobalStorage() && "VarDecl must have global storage!");
26 assert(!D.getType()->isReferenceType() &&
27 "Should not call EmitDeclInit on a reference!");
28
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000029 ASTContext &Context = CGF.getContext();
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000030
John McCalla07398e2011-06-16 04:16:24 +000031 unsigned alignment = Context.getDeclAlign(&D).getQuantity();
32 QualType type = D.getType();
33 LValue lv = CGF.MakeAddrLValue(DeclPtr, type, alignment);
34
35 const Expr *Init = D.getInit();
36 if (!CGF.hasAggregateLLVMType(type)) {
Fariborz Jahanianec805122011-01-13 20:00:54 +000037 CodeGenModule &CGM = CGF.CGM;
John McCalla07398e2011-06-16 04:16:24 +000038 if (lv.isObjCStrong())
John McCallf85e1932011-06-15 23:02:42 +000039 CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init),
40 DeclPtr, D.isThreadSpecified());
John McCalla07398e2011-06-16 04:16:24 +000041 else if (lv.isObjCWeak())
42 CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init),
43 DeclPtr);
Fariborz Jahanianec805122011-01-13 20:00:54 +000044 else
John McCalla07398e2011-06-16 04:16:24 +000045 CGF.EmitScalarInit(Init, &D, lv, false);
46 } else if (type->isAnyComplexType()) {
47 CGF.EmitComplexExprIntoAddr(Init, DeclPtr, lv.isVolatile());
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000048 } else {
John McCalla07398e2011-06-16 04:16:24 +000049 CGF.EmitAggExpr(Init, AggValueSlot::forLValue(lv, true));
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000050 }
51}
52
John McCall5cd91b52010-09-08 01:44:27 +000053/// Emit code to cause the destruction of the given variable with
54/// static storage duration.
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000055static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
56 llvm::Constant *DeclPtr) {
57 CodeGenModule &CGM = CGF.CGM;
58 ASTContext &Context = CGF.getContext();
59
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000060 QualType T = D.getType();
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000061
John McCall85aca0f2010-07-30 04:56:58 +000062 // Drill down past array types.
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000063 const ConstantArrayType *Array = Context.getAsConstantArrayType(T);
64 if (Array)
65 T = Context.getBaseElementType(Array);
66
John McCall85aca0f2010-07-30 04:56:58 +000067 /// If that's not a record, we're done.
68 /// FIXME: __attribute__((cleanup)) ?
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000069 const RecordType *RT = T->getAs<RecordType>();
70 if (!RT)
71 return;
72
73 CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
74 if (RD->hasTrivialDestructor())
75 return;
76
Douglas Gregor1d110e02010-07-01 14:13:13 +000077 CXXDestructorDecl *Dtor = RD->getDestructor();
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000078
79 llvm::Constant *DtorFn;
80 if (Array) {
81 DtorFn =
Anders Carlsson02e370a2010-06-08 22:14:59 +000082 CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(Dtor, Array,
83 DeclPtr);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000084 const llvm::Type *Int8PtrTy =
Anders Carlsson02e370a2010-06-08 22:14:59 +000085 llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000086 DeclPtr = llvm::Constant::getNullValue(Int8PtrTy);
87 } else
88 DtorFn = CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete);
89
90 CGF.EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
91}
92
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000093void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
94 llvm::Constant *DeclPtr) {
95
96 const Expr *Init = D.getInit();
97 QualType T = D.getType();
98
99 if (!T->isReferenceType()) {
100 EmitDeclInit(*this, D, DeclPtr);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +0000101 EmitDeclDestroy(*this, D, DeclPtr);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000102 return;
103 }
Anders Carlsson045a6d82010-06-27 17:52:15 +0000104
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000105 unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
Anders Carlsson045a6d82010-06-27 17:52:15 +0000106 RValue RV = EmitReferenceBindingToExpr(Init, &D);
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000107 EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000108}
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000109
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000110void
111CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
112 llvm::Constant *DeclPtr) {
113 // Generate a global destructor entry if not using __cxa_atexit.
114 if (!CGM.getCodeGenOpts().CXAAtExit) {
115 CGM.AddCXXDtorEntry(DtorFn, DeclPtr);
116 return;
117 }
118
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000119 // Get the destructor function type
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000120 llvm::Type *ArgTys[] = { Int8PtrTy };
121 llvm::Type *DtorFnTy =
John McCalld16c2cf2011-02-08 08:22:06 +0000122 llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()),
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000123 ArgTys, false);
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000124 DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
125
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000126 llvm::Type *Params[] = { DtorFnTy, Int8PtrTy, Int8PtrTy };
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000127
128 // Get the __cxa_atexit function type
129 // extern "C" int __cxa_atexit ( void (*f)(void *), void *p, void *d );
130 const llvm::FunctionType *AtExitFnTy =
131 llvm::FunctionType::get(ConvertType(getContext().IntTy), Params, false);
132
133 llvm::Constant *AtExitFn = CGM.CreateRuntimeFunction(AtExitFnTy,
134 "__cxa_atexit");
Anders Carlssonbd4a0732011-03-20 20:52:32 +0000135 if (llvm::Function *Fn = dyn_cast<llvm::Function>(AtExitFn))
136 Fn->setDoesNotThrow();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000137
138 llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy,
139 "__dso_handle");
140 llvm::Value *Args[3] = { llvm::ConstantExpr::getBitCast(DtorFn, DtorFnTy),
141 llvm::ConstantExpr::getBitCast(DeclPtr, Int8PtrTy),
142 llvm::ConstantExpr::getBitCast(Handle, Int8PtrTy) };
143 Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
144}
145
John McCall3030eb82010-11-06 09:44:32 +0000146void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
147 llvm::GlobalVariable *DeclPtr) {
John McCall32096692011-03-18 02:56:14 +0000148 // If we've been asked to forbid guard variables, emit an error now.
149 // This diagnostic is hard-coded for Darwin's use case; we can find
150 // better phrasing if someone else needs it.
151 if (CGM.getCodeGenOpts().ForbidGuardVariables)
152 CGM.Error(D.getLocation(),
153 "this initialization requires a guard variable, which "
154 "the kernel does not support");
155
John McCall3030eb82010-11-06 09:44:32 +0000156 CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr);
John McCall5cd91b52010-09-08 01:44:27 +0000157}
158
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000159static llvm::Function *
160CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
161 const llvm::FunctionType *FTy,
162 llvm::StringRef Name) {
163 llvm::Function *Fn =
164 llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
165 Name, &CGM.getModule());
Fariborz Jahaniand6c9a0f2011-02-15 18:54:46 +0000166 if (!CGM.getContext().getLangOptions().AppleKext) {
167 // Set the section if needed.
168 if (const char *Section =
169 CGM.getContext().Target.getStaticInitSectionSpecifier())
170 Fn->setSection(Section);
171 }
Anders Carlsson18af3682010-06-08 22:47:50 +0000172
Anders Carlsson7a178512011-02-28 00:33:03 +0000173 if (!CGM.getLangOptions().Exceptions)
John McCall044cc542010-07-06 04:38:10 +0000174 Fn->setDoesNotThrow();
175
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000176 return Fn;
177}
178
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000179void
John McCall3030eb82010-11-06 09:44:32 +0000180CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
181 llvm::GlobalVariable *Addr) {
Eli Friedman6c6bda32010-01-08 00:50:11 +0000182 const llvm::FunctionType *FTy
183 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
184 false);
185
186 // Create a variable initialization function.
187 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000188 CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
Eli Friedman6c6bda32010-01-08 00:50:11 +0000189
John McCall3030eb82010-11-06 09:44:32 +0000190 CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr);
Eli Friedman6c6bda32010-01-08 00:50:11 +0000191
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000192 if (D->hasAttr<InitPriorityAttr>()) {
193 unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
Chris Lattnerec2830d2010-06-27 06:32:58 +0000194 OrderGlobalInits Key(order, PrioritizedCXXGlobalInits.size());
Fariborz Jahaniane0b691a2010-06-21 21:27:42 +0000195 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
John McCallbf40cb52010-07-15 23:40:35 +0000196 DelayedCXXInitPosition.erase(D);
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000197 }
John McCallbf40cb52010-07-15 23:40:35 +0000198 else {
199 llvm::DenseMap<const Decl *, unsigned>::iterator I =
200 DelayedCXXInitPosition.find(D);
201 if (I == DelayedCXXInitPosition.end()) {
202 CXXGlobalInits.push_back(Fn);
203 } else {
204 assert(CXXGlobalInits[I->second] == 0);
205 CXXGlobalInits[I->second] = Fn;
206 DelayedCXXInitPosition.erase(I);
207 }
208 }
Eli Friedman6c6bda32010-01-08 00:50:11 +0000209}
210
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000211void
212CodeGenModule::EmitCXXGlobalInitFunc() {
John McCallbf40cb52010-07-15 23:40:35 +0000213 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
214 CXXGlobalInits.pop_back();
215
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000216 if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000217 return;
218
219 const llvm::FunctionType *FTy
220 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
221 false);
222
223 // Create our global initialization function.
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000224 llvm::Function *Fn =
225 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000226
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000227 if (!PrioritizedCXXGlobalInits.empty()) {
Fariborz Jahanian027d7ed2010-06-21 19:49:38 +0000228 llvm::SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
229 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
Fariborz Jahanianf4896882010-06-22 00:23:08 +0000230 PrioritizedCXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000231 for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
232 llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
233 LocalCXXGlobalInits.push_back(Fn);
234 }
John McCallbf40cb52010-07-15 23:40:35 +0000235 LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000236 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
237 &LocalCXXGlobalInits[0],
238 LocalCXXGlobalInits.size());
239 }
240 else
241 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
242 &CXXGlobalInits[0],
243 CXXGlobalInits.size());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000244 AddGlobalCtor(Fn);
Axel Naumann54ec6c52011-05-06 15:24:04 +0000245 CXXGlobalInits.clear();
246 PrioritizedCXXGlobalInits.clear();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000247}
248
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000249void CodeGenModule::EmitCXXGlobalDtorFunc() {
250 if (CXXGlobalDtors.empty())
251 return;
252
253 const llvm::FunctionType *FTy
254 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
255 false);
256
257 // Create our global destructor function.
258 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000259 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000260
261 CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
262 AddGlobalDtor(Fn);
263}
264
John McCall3030eb82010-11-06 09:44:32 +0000265/// Emit the code necessary to initialize the given global variable.
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000266void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
John McCall3030eb82010-11-06 09:44:32 +0000267 const VarDecl *D,
268 llvm::GlobalVariable *Addr) {
John McCalld26bc762011-03-09 04:27:21 +0000269 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
270 getTypes().getNullaryFunctionInfo(),
271 FunctionArgList(), SourceLocation());
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000272
Douglas Gregore67d1512011-07-01 21:54:36 +0000273 // Use guarded initialization if the global variable is weak. This
274 // occurs for, e.g., instantiated static data members and
275 // definitions explicitly marked weak.
276 if (Addr->getLinkage() == llvm::GlobalValue::WeakODRLinkage ||
277 Addr->getLinkage() == llvm::GlobalValue::WeakAnyLinkage) {
John McCall3030eb82010-11-06 09:44:32 +0000278 EmitCXXGuardedInit(*D, Addr);
279 } else {
280 EmitCXXGlobalVarDeclInit(*D, Addr);
Fariborz Jahanian92d835a2010-10-26 22:47:47 +0000281 }
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000282
283 FinishFunction();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000284}
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000285
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000286void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
287 llvm::Constant **Decls,
288 unsigned NumDecls) {
John McCalld26bc762011-03-09 04:27:21 +0000289 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
290 getTypes().getNullaryFunctionInfo(),
291 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000292
John McCallf85e1932011-06-15 23:02:42 +0000293 RunCleanupsScope Scope(*this);
294
295 // When building in Objective-C++ ARC mode, create an autorelease pool
296 // around the global initializers.
297 if (getLangOptions().ObjCAutoRefCount && getLangOptions().CPlusPlus) {
298 llvm::Value *token = EmitObjCAutoreleasePoolPush();
299 EmitObjCAutoreleasePoolCleanup(token);
300 }
301
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000302 for (unsigned i = 0; i != NumDecls; ++i)
John McCallbf40cb52010-07-15 23:40:35 +0000303 if (Decls[i])
John McCallf85e1932011-06-15 23:02:42 +0000304 Builder.CreateCall(Decls[i]);
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000305
John McCallf85e1932011-06-15 23:02:42 +0000306 Scope.ForceCleanup();
307
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000308 FinishFunction();
309}
310
311void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
Chris Lattner810112e2010-06-19 05:52:45 +0000312 const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000313 &DtorsAndObjects) {
John McCalld26bc762011-03-09 04:27:21 +0000314 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
315 getTypes().getNullaryFunctionInfo(),
316 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000317
318 // Emit the dtors, in reverse order from construction.
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000319 for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
Chris Lattner810112e2010-06-19 05:52:45 +0000320 llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000321 llvm::CallInst *CI = Builder.CreateCall(Callee,
322 DtorsAndObjects[e - i - 1].second);
323 // Make sure the call and the callee agree on calling convention.
324 if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
325 CI->setCallingConv(F->getCallingConv());
326 }
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000327
328 FinishFunction();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000329}
330
Anders Carlsson77291362010-06-08 22:17:27 +0000331/// GenerateCXXAggrDestructorHelper - Generates a helper function which when
332/// invoked, calls the default destructor on array elements in reverse order of
333/// construction.
334llvm::Function *
335CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
336 const ArrayType *Array,
337 llvm::Value *This) {
John McCalld26bc762011-03-09 04:27:21 +0000338 FunctionArgList args;
339 ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
340 args.push_back(&dst);
Anders Carlsson77291362010-06-08 22:17:27 +0000341
Anders Carlsson77291362010-06-08 22:17:27 +0000342 const CGFunctionInfo &FI =
John McCalld26bc762011-03-09 04:27:21 +0000343 CGM.getTypes().getFunctionInfo(getContext().VoidTy, args,
Anders Carlsson77291362010-06-08 22:17:27 +0000344 FunctionType::ExtInfo());
345 const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000346 llvm::Function *Fn =
347 CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
Anders Carlsson77291362010-06-08 22:17:27 +0000348
John McCalld26bc762011-03-09 04:27:21 +0000349 StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FI, args,
350 SourceLocation());
Anders Carlsson77291362010-06-08 22:17:27 +0000351
352 QualType BaseElementTy = getContext().getBaseElementType(Array);
353 const llvm::Type *BasePtr = ConvertType(BaseElementTy)->getPointerTo();
354 llvm::Value *BaseAddrPtr = Builder.CreateBitCast(This, BasePtr);
355
356 EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
357
358 FinishFunction();
359
360 return Fn;
361}