blob: 08e8e0c48e32a89847f951590d07d3000a47084e [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();
30
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000031 const Expr *Init = D.getInit();
32 QualType T = D.getType();
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000033 bool isVolatile = Context.getCanonicalType(T).isVolatileQualified();
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000034
Daniel Dunbar91a16fa2010-08-21 02:24:36 +000035 unsigned Alignment = Context.getDeclAlign(&D).getQuantity();
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000036 if (!CGF.hasAggregateLLVMType(T)) {
Fariborz Jahanianec805122011-01-13 20:00:54 +000037 CodeGenModule &CGM = CGF.CGM;
Fariborz Jahanian0990b002011-01-13 21:35:27 +000038 Qualifiers::GC GCAttr = CGM.getContext().getObjCGCAttrKind(T);
39 if (GCAttr == Qualifiers::Strong)
John McCallf85e1932011-06-15 23:02:42 +000040 CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init),
41 DeclPtr, D.isThreadSpecified());
Fariborz Jahanian0990b002011-01-13 21:35:27 +000042 else if (GCAttr == Qualifiers::Weak)
John McCallf85e1932011-06-15 23:02:42 +000043 CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init),
44 DeclPtr);
Fariborz Jahanianec805122011-01-13 20:00:54 +000045 else
John McCallf85e1932011-06-15 23:02:42 +000046 CGF.EmitScalarInit(Init, &D, DeclPtr, false, isVolatile, Alignment,
47 D.getType());
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000048 } else if (T->isAnyComplexType()) {
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000049 CGF.EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000050 } else {
John McCallf85e1932011-06-15 23:02:42 +000051 CGF.EmitAggExpr(Init, AggValueSlot::forAddr(DeclPtr, T.getQualifiers(),
52 true));
Anders Carlsson5ec2e7c2009-12-10 00:16:00 +000053 }
54}
55
John McCall5cd91b52010-09-08 01:44:27 +000056/// Emit code to cause the destruction of the given variable with
57/// static storage duration.
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000058static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
59 llvm::Constant *DeclPtr) {
60 CodeGenModule &CGM = CGF.CGM;
61 ASTContext &Context = CGF.getContext();
62
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000063 QualType T = D.getType();
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000064
John McCall85aca0f2010-07-30 04:56:58 +000065 // Drill down past array types.
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000066 const ConstantArrayType *Array = Context.getAsConstantArrayType(T);
67 if (Array)
68 T = Context.getBaseElementType(Array);
69
John McCall85aca0f2010-07-30 04:56:58 +000070 /// If that's not a record, we're done.
71 /// FIXME: __attribute__((cleanup)) ?
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000072 const RecordType *RT = T->getAs<RecordType>();
73 if (!RT)
74 return;
75
76 CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
77 if (RD->hasTrivialDestructor())
78 return;
79
Douglas Gregor1d110e02010-07-01 14:13:13 +000080 CXXDestructorDecl *Dtor = RD->getDestructor();
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000081
82 llvm::Constant *DtorFn;
83 if (Array) {
84 DtorFn =
Anders Carlsson02e370a2010-06-08 22:14:59 +000085 CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(Dtor, Array,
86 DeclPtr);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000087 const llvm::Type *Int8PtrTy =
Anders Carlsson02e370a2010-06-08 22:14:59 +000088 llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000089 DeclPtr = llvm::Constant::getNullValue(Int8PtrTy);
90 } else
91 DtorFn = CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete);
92
93 CGF.EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
94}
95
Anders Carlssonfcbfdc12009-12-10 00:57:45 +000096void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
97 llvm::Constant *DeclPtr) {
98
99 const Expr *Init = D.getInit();
100 QualType T = D.getType();
101
102 if (!T->isReferenceType()) {
103 EmitDeclInit(*this, D, DeclPtr);
Douglas Gregorcc6a44b2010-05-05 15:38:32 +0000104 EmitDeclDestroy(*this, D, DeclPtr);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000105 return;
106 }
Anders Carlsson045a6d82010-06-27 17:52:15 +0000107
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000108 unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
Anders Carlsson045a6d82010-06-27 17:52:15 +0000109 RValue RV = EmitReferenceBindingToExpr(Init, &D);
Daniel Dunbar91a16fa2010-08-21 02:24:36 +0000110 EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
Anders Carlssonfcbfdc12009-12-10 00:57:45 +0000111}
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000112
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000113void
114CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
115 llvm::Constant *DeclPtr) {
116 // Generate a global destructor entry if not using __cxa_atexit.
117 if (!CGM.getCodeGenOpts().CXAAtExit) {
118 CGM.AddCXXDtorEntry(DtorFn, DeclPtr);
119 return;
120 }
121
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000122 // Get the destructor function type
123 const llvm::Type *DtorFnTy =
John McCalld16c2cf2011-02-08 08:22:06 +0000124 llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()),
Benjamin Kramer95d318c2011-05-28 14:26:31 +0000125 Int8PtrTy, false);
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000126 DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
127
Benjamin Kramer95d318c2011-05-28 14:26:31 +0000128 const llvm::Type *Params[] = { DtorFnTy, Int8PtrTy, Int8PtrTy };
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000129
130 // Get the __cxa_atexit function type
131 // extern "C" int __cxa_atexit ( void (*f)(void *), void *p, void *d );
132 const llvm::FunctionType *AtExitFnTy =
133 llvm::FunctionType::get(ConvertType(getContext().IntTy), Params, false);
134
135 llvm::Constant *AtExitFn = CGM.CreateRuntimeFunction(AtExitFnTy,
136 "__cxa_atexit");
Anders Carlssonbd4a0732011-03-20 20:52:32 +0000137 if (llvm::Function *Fn = dyn_cast<llvm::Function>(AtExitFn))
138 Fn->setDoesNotThrow();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000139
140 llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy,
141 "__dso_handle");
142 llvm::Value *Args[3] = { llvm::ConstantExpr::getBitCast(DtorFn, DtorFnTy),
143 llvm::ConstantExpr::getBitCast(DeclPtr, Int8PtrTy),
144 llvm::ConstantExpr::getBitCast(Handle, Int8PtrTy) };
145 Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
146}
147
John McCall3030eb82010-11-06 09:44:32 +0000148void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
149 llvm::GlobalVariable *DeclPtr) {
John McCall32096692011-03-18 02:56:14 +0000150 // If we've been asked to forbid guard variables, emit an error now.
151 // This diagnostic is hard-coded for Darwin's use case; we can find
152 // better phrasing if someone else needs it.
153 if (CGM.getCodeGenOpts().ForbidGuardVariables)
154 CGM.Error(D.getLocation(),
155 "this initialization requires a guard variable, which "
156 "the kernel does not support");
157
John McCall3030eb82010-11-06 09:44:32 +0000158 CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr);
John McCall5cd91b52010-09-08 01:44:27 +0000159}
160
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000161static llvm::Function *
162CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
163 const llvm::FunctionType *FTy,
164 llvm::StringRef Name) {
165 llvm::Function *Fn =
166 llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
167 Name, &CGM.getModule());
Fariborz Jahaniand6c9a0f2011-02-15 18:54:46 +0000168 if (!CGM.getContext().getLangOptions().AppleKext) {
169 // Set the section if needed.
170 if (const char *Section =
171 CGM.getContext().Target.getStaticInitSectionSpecifier())
172 Fn->setSection(Section);
173 }
Anders Carlsson18af3682010-06-08 22:47:50 +0000174
Anders Carlsson7a178512011-02-28 00:33:03 +0000175 if (!CGM.getLangOptions().Exceptions)
John McCall044cc542010-07-06 04:38:10 +0000176 Fn->setDoesNotThrow();
177
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000178 return Fn;
179}
180
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000181void
John McCall3030eb82010-11-06 09:44:32 +0000182CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
183 llvm::GlobalVariable *Addr) {
Eli Friedman6c6bda32010-01-08 00:50:11 +0000184 const llvm::FunctionType *FTy
185 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
186 false);
187
188 // Create a variable initialization function.
189 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000190 CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
Eli Friedman6c6bda32010-01-08 00:50:11 +0000191
John McCall3030eb82010-11-06 09:44:32 +0000192 CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr);
Eli Friedman6c6bda32010-01-08 00:50:11 +0000193
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000194 if (D->hasAttr<InitPriorityAttr>()) {
195 unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
Chris Lattnerec2830d2010-06-27 06:32:58 +0000196 OrderGlobalInits Key(order, PrioritizedCXXGlobalInits.size());
Fariborz Jahaniane0b691a2010-06-21 21:27:42 +0000197 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
John McCallbf40cb52010-07-15 23:40:35 +0000198 DelayedCXXInitPosition.erase(D);
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000199 }
John McCallbf40cb52010-07-15 23:40:35 +0000200 else {
201 llvm::DenseMap<const Decl *, unsigned>::iterator I =
202 DelayedCXXInitPosition.find(D);
203 if (I == DelayedCXXInitPosition.end()) {
204 CXXGlobalInits.push_back(Fn);
205 } else {
206 assert(CXXGlobalInits[I->second] == 0);
207 CXXGlobalInits[I->second] = Fn;
208 DelayedCXXInitPosition.erase(I);
209 }
210 }
Eli Friedman6c6bda32010-01-08 00:50:11 +0000211}
212
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000213void
214CodeGenModule::EmitCXXGlobalInitFunc() {
John McCallbf40cb52010-07-15 23:40:35 +0000215 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
216 CXXGlobalInits.pop_back();
217
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000218 if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000219 return;
220
221 const llvm::FunctionType *FTy
222 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
223 false);
224
225 // Create our global initialization function.
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000226 llvm::Function *Fn =
227 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000228
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000229 if (!PrioritizedCXXGlobalInits.empty()) {
Fariborz Jahanian027d7ed2010-06-21 19:49:38 +0000230 llvm::SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
231 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
Fariborz Jahanianf4896882010-06-22 00:23:08 +0000232 PrioritizedCXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000233 for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
234 llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
235 LocalCXXGlobalInits.push_back(Fn);
236 }
John McCallbf40cb52010-07-15 23:40:35 +0000237 LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
Fariborz Jahanian9f967c52010-06-21 18:45:05 +0000238 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
239 &LocalCXXGlobalInits[0],
240 LocalCXXGlobalInits.size());
241 }
242 else
243 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
244 &CXXGlobalInits[0],
245 CXXGlobalInits.size());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000246 AddGlobalCtor(Fn);
Axel Naumann54ec6c52011-05-06 15:24:04 +0000247 CXXGlobalInits.clear();
248 PrioritizedCXXGlobalInits.clear();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000249}
250
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000251void CodeGenModule::EmitCXXGlobalDtorFunc() {
252 if (CXXGlobalDtors.empty())
253 return;
254
255 const llvm::FunctionType *FTy
256 = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
257 false);
258
259 // Create our global destructor function.
260 llvm::Function *Fn =
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000261 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000262
263 CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
264 AddGlobalDtor(Fn);
265}
266
John McCall3030eb82010-11-06 09:44:32 +0000267/// Emit the code necessary to initialize the given global variable.
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000268void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
John McCall3030eb82010-11-06 09:44:32 +0000269 const VarDecl *D,
270 llvm::GlobalVariable *Addr) {
John McCalld26bc762011-03-09 04:27:21 +0000271 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
272 getTypes().getNullaryFunctionInfo(),
273 FunctionArgList(), SourceLocation());
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000274
John McCall3030eb82010-11-06 09:44:32 +0000275 // Use guarded initialization if the global variable is weak due to
John McCall99ace162011-04-12 01:46:54 +0000276 // being a class template's static data member. These will always
277 // have weak_odr linkage.
278 if (Addr->getLinkage() == llvm::GlobalValue::WeakODRLinkage &&
279 D->isStaticDataMember() &&
280 D->getInstantiatedFromStaticDataMember()) {
John McCall3030eb82010-11-06 09:44:32 +0000281 EmitCXXGuardedInit(*D, Addr);
282 } else {
283 EmitCXXGlobalVarDeclInit(*D, Addr);
Fariborz Jahanian92d835a2010-10-26 22:47:47 +0000284 }
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000285
286 FinishFunction();
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000287}
Daniel Dunbar5c6846e2010-03-20 04:15:29 +0000288
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000289void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
290 llvm::Constant **Decls,
291 unsigned NumDecls) {
John McCalld26bc762011-03-09 04:27:21 +0000292 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
293 getTypes().getNullaryFunctionInfo(),
294 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000295
John McCallf85e1932011-06-15 23:02:42 +0000296 RunCleanupsScope Scope(*this);
297
298 // When building in Objective-C++ ARC mode, create an autorelease pool
299 // around the global initializers.
300 if (getLangOptions().ObjCAutoRefCount && getLangOptions().CPlusPlus) {
301 llvm::Value *token = EmitObjCAutoreleasePoolPush();
302 EmitObjCAutoreleasePoolCleanup(token);
303 }
304
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000305 for (unsigned i = 0; i != NumDecls; ++i)
John McCallbf40cb52010-07-15 23:40:35 +0000306 if (Decls[i])
John McCallf85e1932011-06-15 23:02:42 +0000307 Builder.CreateCall(Decls[i]);
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000308
John McCallf85e1932011-06-15 23:02:42 +0000309 Scope.ForceCleanup();
310
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000311 FinishFunction();
312}
313
314void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
Chris Lattner810112e2010-06-19 05:52:45 +0000315 const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000316 &DtorsAndObjects) {
John McCalld26bc762011-03-09 04:27:21 +0000317 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
318 getTypes().getNullaryFunctionInfo(),
319 FunctionArgList(), SourceLocation());
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000320
321 // Emit the dtors, in reverse order from construction.
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000322 for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
Chris Lattner810112e2010-06-19 05:52:45 +0000323 llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
Chris Lattnerc9a85f92010-04-26 20:35:54 +0000324 llvm::CallInst *CI = Builder.CreateCall(Callee,
325 DtorsAndObjects[e - i - 1].second);
326 // Make sure the call and the callee agree on calling convention.
327 if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
328 CI->setCallingConv(F->getCallingConv());
329 }
Daniel Dunbarefb0fa92010-03-20 04:15:41 +0000330
331 FinishFunction();
Anders Carlssoneb4072e2009-12-10 00:30:05 +0000332}
333
Anders Carlsson77291362010-06-08 22:17:27 +0000334/// GenerateCXXAggrDestructorHelper - Generates a helper function which when
335/// invoked, calls the default destructor on array elements in reverse order of
336/// construction.
337llvm::Function *
338CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
339 const ArrayType *Array,
340 llvm::Value *This) {
John McCalld26bc762011-03-09 04:27:21 +0000341 FunctionArgList args;
342 ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
343 args.push_back(&dst);
Anders Carlsson77291362010-06-08 22:17:27 +0000344
Anders Carlsson77291362010-06-08 22:17:27 +0000345 const CGFunctionInfo &FI =
John McCalld26bc762011-03-09 04:27:21 +0000346 CGM.getTypes().getFunctionInfo(getContext().VoidTy, args,
Anders Carlsson77291362010-06-08 22:17:27 +0000347 FunctionType::ExtInfo());
348 const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
Anders Carlsson9dc046e2010-06-08 22:40:05 +0000349 llvm::Function *Fn =
350 CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
Anders Carlsson77291362010-06-08 22:17:27 +0000351
John McCalld26bc762011-03-09 04:27:21 +0000352 StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FI, args,
353 SourceLocation());
Anders Carlsson77291362010-06-08 22:17:27 +0000354
355 QualType BaseElementTy = getContext().getBaseElementType(Array);
356 const llvm::Type *BasePtr = ConvertType(BaseElementTy)->getPointerTo();
357 llvm::Value *BaseAddrPtr = Builder.CreateBitCast(This, BasePtr);
358
359 EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
360
361 FinishFunction();
362
363 return Fn;
364}