blob: 85f0e35dc79ee2f0848ebc367c78998ad413a17a [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,
John McCalla91f6662011-07-13 03:01:35 +000056 llvm::Constant *addr) {
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000057 CodeGenModule &CGM = CGF.CGM;
John McCalla91f6662011-07-13 03:01:35 +000058
59 // FIXME: __attribute__((cleanup)) ?
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000060
John McCalla91f6662011-07-13 03:01:35 +000061 QualType type = D.getType();
62 QualType::DestructionKind dtorKind = type.isDestructedType();
63
64 switch (dtorKind) {
65 case QualType::DK_none:
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000066 return;
John McCalla91f6662011-07-13 03:01:35 +000067
68 case QualType::DK_cxx_destructor:
69 break;
70
71 case QualType::DK_objc_strong_lifetime:
72 case QualType::DK_objc_weak_lifetime:
73 // We don't care about releasing objects during process teardown.
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000074 return;
John McCalla91f6662011-07-13 03:01:35 +000075 }
76
77 llvm::Constant *function;
78 llvm::Constant *argument;
79
80 // Special-case non-array C++ destructors, where there's a function
81 // with the right signature that we can just call.
82 const CXXRecordDecl *record = 0;
83 if (dtorKind == QualType::DK_cxx_destructor &&
84 (record = type->getAsCXXRecordDecl())) {
85 assert(!record->hasTrivialDestructor());
86 CXXDestructorDecl *dtor = record->getDestructor();
87
88 function = CGM.GetAddrOfCXXDestructor(dtor, Dtor_Complete);
89 argument = addr;
90
91 // Otherwise, the standard logic requires a helper function.
92 } else {
93 function = CodeGenFunction(CGM).generateDestroyHelper(addr, type,
94 CGF.getDestroyer(dtorKind),
95 CGF.needsEHCleanup(dtorKind));
96 argument = llvm::Constant::getNullValue(CGF.Int8PtrTy);
97 }
98
99 CGF.EmitCXXGlobalDtorRegistration(function, argument);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +0000100}
101
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000102void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
103 llvm::Constant *DeclPtr) {
104
105 const Expr *Init = D.getInit();
106 QualType T = D.getType();
107
108 if (!T->isReferenceType()) {
109 EmitDeclInit(*this, D, DeclPtr);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +0000110 EmitDeclDestroy(*this, D, DeclPtr);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000111 return;
112 }
Anders Carlsson045a6d82010-06-27 17:52:15 +0000113
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000114 unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
Anders Carlsson045a6d82010-06-27 17:52:15 +0000115 RValue RV = EmitReferenceBindingToExpr(Init, &D);
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000116 EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000117}
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000118
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000119void
120CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
121 llvm::Constant *DeclPtr) {
122 // Generate a global destructor entry if not using __cxa_atexit.
123 if (!CGM.getCodeGenOpts().CXAAtExit) {
124 CGM.AddCXXDtorEntry(DtorFn, DeclPtr);
125 return;
126 }
127
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000128 // Get the destructor function type
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000129 llvm::Type *DtorFnTy =
John McCalld16c2cf2011-02-08 08:22:06 +0000130 llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()),
Jay Foadda549e82011-07-29 13:56:53 +0000131 Int8PtrTy, false);
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000132 DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
133
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000134 llvm::Type *Params[] = { DtorFnTy, Int8PtrTy, Int8PtrTy };
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000135
136 // Get the __cxa_atexit function type
137 // extern "C" int __cxa_atexit ( void (*f)(void *), void *p, void *d );
Chris Lattner2acc6e32011-07-18 04:24:23 +0000138 llvm::FunctionType *AtExitFnTy =
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000139 llvm::FunctionType::get(ConvertType(getContext().IntTy), Params, false);
140
141 llvm::Constant *AtExitFn = CGM.CreateRuntimeFunction(AtExitFnTy,
142 "__cxa_atexit");
Anders Carlssonbd4a0732011-03-20 20:52:32 +0000143 if (llvm::Function *Fn = dyn_cast<llvm::Function>(AtExitFn))
144 Fn->setDoesNotThrow();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000145
146 llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy,
147 "__dso_handle");
148 llvm::Value *Args[3] = { llvm::ConstantExpr::getBitCast(DtorFn, DtorFnTy),
149 llvm::ConstantExpr::getBitCast(DeclPtr, Int8PtrTy),
150 llvm::ConstantExpr::getBitCast(Handle, Int8PtrTy) };
Jay Foad4c7d9f12011-07-15 08:37:34 +0000151 Builder.CreateCall(AtExitFn, Args);
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000152}
153
John McCall3030eb82010-11-06 09:44:32 +0000154void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
155 llvm::GlobalVariable *DeclPtr) {
John McCall32096692011-03-18 02:56:14 +0000156 // If we've been asked to forbid guard variables, emit an error now.
157 // This diagnostic is hard-coded for Darwin's use case; we can find
158 // better phrasing if someone else needs it.
159 if (CGM.getCodeGenOpts().ForbidGuardVariables)
160 CGM.Error(D.getLocation(),
161 "this initialization requires a guard variable, which "
162 "the kernel does not support");
163
John McCall3030eb82010-11-06 09:44:32 +0000164 CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr);
John McCall5cd91b52010-09-08 01:44:27 +0000165}
166
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000167static llvm::Function *
168CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
Chris Lattner2acc6e32011-07-18 04:24:23 +0000169 llvm::FunctionType *FTy,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000170 StringRef Name) {
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000171 llvm::Function *Fn =
172 llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
173 Name, &CGM.getModule());
Fariborz Jahaniand6c9a0f2011-02-15 18:54:46 +0000174 if (!CGM.getContext().getLangOptions().AppleKext) {
175 // Set the section if needed.
176 if (const char *Section =
177 CGM.getContext().Target.getStaticInitSectionSpecifier())
178 Fn->setSection(Section);
179 }
Anders Carlsson18af3682010-06-08 22:47:50 +0000180
Anders Carlsson7a178512011-02-28 00:33:03 +0000181 if (!CGM.getLangOptions().Exceptions)
John McCall044cc542010-07-06 04:38:10 +0000182 Fn->setDoesNotThrow();
183
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000184 return Fn;
185}
186
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000187void
John McCall3030eb82010-11-06 09:44:32 +0000188CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
189 llvm::GlobalVariable *Addr) {
Chris Lattner2acc6e32011-07-18 04:24:23 +0000190 llvm::FunctionType *FTy
Eli Friedman6c6bda32010-01-08 00:50:11 +0000191 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
192 false);
193
194 // Create a variable initialization function.
195 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000196 CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
Eli Friedman6c6bda32010-01-08 00:50:11 +0000197
John McCall3030eb82010-11-06 09:44:32 +0000198 CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr);
Eli Friedman6c6bda32010-01-08 00:50:11 +0000199
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000200 if (D->hasAttr<InitPriorityAttr>()) {
201 unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
Chris Lattnerec2830d2010-06-27 06:32:58 +0000202 OrderGlobalInits Key(order, PrioritizedCXXGlobalInits.size());
Fariborz Jahaniane0b691a2010-06-21 21:27:42 +0000203 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
John McCallbf40cb52010-07-15 23:40:35 +0000204 DelayedCXXInitPosition.erase(D);
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000205 }
John McCallbf40cb52010-07-15 23:40:35 +0000206 else {
207 llvm::DenseMap<const Decl *, unsigned>::iterator I =
208 DelayedCXXInitPosition.find(D);
209 if (I == DelayedCXXInitPosition.end()) {
210 CXXGlobalInits.push_back(Fn);
211 } else {
212 assert(CXXGlobalInits[I->second] == 0);
213 CXXGlobalInits[I->second] = Fn;
214 DelayedCXXInitPosition.erase(I);
215 }
216 }
Eli Friedman6c6bda32010-01-08 00:50:11 +0000217}
218
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000219void
220CodeGenModule::EmitCXXGlobalInitFunc() {
John McCallbf40cb52010-07-15 23:40:35 +0000221 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
222 CXXGlobalInits.pop_back();
223
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000224 if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000225 return;
226
Chris Lattner2acc6e32011-07-18 04:24:23 +0000227 llvm::FunctionType *FTy
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000228 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
229 false);
230
231 // Create our global initialization function.
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000232 llvm::Function *Fn =
233 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000234
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000235 if (!PrioritizedCXXGlobalInits.empty()) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000236 SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
Fariborz Jahanian027d7ed2010-06-21 19:49:38 +0000237 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
Fariborz Jahanianf4896882010-06-22 00:23:08 +0000238 PrioritizedCXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000239 for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
240 llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
241 LocalCXXGlobalInits.push_back(Fn);
242 }
John McCallbf40cb52010-07-15 23:40:35 +0000243 LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000244 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
245 &LocalCXXGlobalInits[0],
246 LocalCXXGlobalInits.size());
247 }
248 else
249 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
250 &CXXGlobalInits[0],
251 CXXGlobalInits.size());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000252 AddGlobalCtor(Fn);
Axel Naumann54ec6c52011-05-06 15:24:04 +0000253 CXXGlobalInits.clear();
254 PrioritizedCXXGlobalInits.clear();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000255}
256
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000257void CodeGenModule::EmitCXXGlobalDtorFunc() {
258 if (CXXGlobalDtors.empty())
259 return;
260
Chris Lattner2acc6e32011-07-18 04:24:23 +0000261 llvm::FunctionType *FTy
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000262 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
263 false);
264
265 // Create our global destructor function.
266 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000267 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000268
269 CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
270 AddGlobalDtor(Fn);
271}
272
John McCall3030eb82010-11-06 09:44:32 +0000273/// Emit the code necessary to initialize the given global variable.
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000274void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
John McCall3030eb82010-11-06 09:44:32 +0000275 const VarDecl *D,
276 llvm::GlobalVariable *Addr) {
John McCalld26bc762011-03-09 04:27:21 +0000277 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
278 getTypes().getNullaryFunctionInfo(),
279 FunctionArgList(), SourceLocation());
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000280
Douglas Gregore67d1512011-07-01 21:54:36 +0000281 // Use guarded initialization if the global variable is weak. This
282 // occurs for, e.g., instantiated static data members and
283 // definitions explicitly marked weak.
284 if (Addr->getLinkage() == llvm::GlobalValue::WeakODRLinkage ||
285 Addr->getLinkage() == llvm::GlobalValue::WeakAnyLinkage) {
John McCall3030eb82010-11-06 09:44:32 +0000286 EmitCXXGuardedInit(*D, Addr);
287 } else {
288 EmitCXXGlobalVarDeclInit(*D, Addr);
Fariborz Jahanian92d835a2010-10-26 22:47:47 +0000289 }
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000290
291 FinishFunction();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000292}
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000293
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000294void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
295 llvm::Constant **Decls,
296 unsigned NumDecls) {
John McCalld26bc762011-03-09 04:27:21 +0000297 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
298 getTypes().getNullaryFunctionInfo(),
299 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000300
John McCallf85e1932011-06-15 23:02:42 +0000301 RunCleanupsScope Scope(*this);
302
303 // When building in Objective-C++ ARC mode, create an autorelease pool
304 // around the global initializers.
305 if (getLangOptions().ObjCAutoRefCount && getLangOptions().CPlusPlus) {
306 llvm::Value *token = EmitObjCAutoreleasePoolPush();
307 EmitObjCAutoreleasePoolCleanup(token);
308 }
309
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000310 for (unsigned i = 0; i != NumDecls; ++i)
John McCallbf40cb52010-07-15 23:40:35 +0000311 if (Decls[i])
John McCallf85e1932011-06-15 23:02:42 +0000312 Builder.CreateCall(Decls[i]);
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000313
John McCallf85e1932011-06-15 23:02:42 +0000314 Scope.ForceCleanup();
315
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000316 FinishFunction();
317}
318
319void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
Chris Lattner810112e2010-06-19 05:52:45 +0000320 const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000321 &DtorsAndObjects) {
John McCalld26bc762011-03-09 04:27:21 +0000322 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
323 getTypes().getNullaryFunctionInfo(),
324 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000325
326 // Emit the dtors, in reverse order from construction.
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000327 for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
Chris Lattner810112e2010-06-19 05:52:45 +0000328 llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000329 llvm::CallInst *CI = Builder.CreateCall(Callee,
330 DtorsAndObjects[e - i - 1].second);
331 // Make sure the call and the callee agree on calling convention.
332 if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
333 CI->setCallingConv(F->getCallingConv());
334 }
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000335
336 FinishFunction();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000337}
338
John McCalla91f6662011-07-13 03:01:35 +0000339/// generateDestroyHelper - Generates a helper function which, when
340/// invoked, destroys the given object.
Anders Carlsson77291362010-06-08 22:17:27 +0000341llvm::Function *
John McCalla91f6662011-07-13 03:01:35 +0000342CodeGenFunction::generateDestroyHelper(llvm::Constant *addr,
343 QualType type,
344 Destroyer &destroyer,
345 bool useEHCleanupForArray) {
John McCalld26bc762011-03-09 04:27:21 +0000346 FunctionArgList args;
347 ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
348 args.push_back(&dst);
Anders Carlsson77291362010-06-08 22:17:27 +0000349
Anders Carlsson77291362010-06-08 22:17:27 +0000350 const CGFunctionInfo &FI =
John McCalld26bc762011-03-09 04:27:21 +0000351 CGM.getTypes().getFunctionInfo(getContext().VoidTy, args,
Anders Carlsson77291362010-06-08 22:17:27 +0000352 FunctionType::ExtInfo());
Chris Lattner2acc6e32011-07-18 04:24:23 +0000353 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
John McCalla91f6662011-07-13 03:01:35 +0000354 llvm::Function *fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000355 CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
Anders Carlsson77291362010-06-08 22:17:27 +0000356
John McCalla91f6662011-07-13 03:01:35 +0000357 StartFunction(GlobalDecl(), getContext().VoidTy, fn, FI, args,
John McCalld26bc762011-03-09 04:27:21 +0000358 SourceLocation());
Anders Carlsson77291362010-06-08 22:17:27 +0000359
John McCalla91f6662011-07-13 03:01:35 +0000360 emitDestroy(addr, type, destroyer, useEHCleanupForArray);
Anders Carlsson77291362010-06-08 22:17:27 +0000361
362 FinishFunction();
363
John McCalla91f6662011-07-13 03:01:35 +0000364 return fn;
Anders Carlsson77291362010-06-08 22:17:27 +0000365}
John McCalla91f6662011-07-13 03:01:35 +0000366