blob: 08e8e0c48e32a89847f951590d07d3000a47084e [file] [log] [blame]
Anders Carlssonbc49cfe2009-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 Jahaniand1339792011-01-13 20:00:54 +000015#include "CGObjCRuntime.h"
John McCall5d865c322010-08-31 07:33:07 +000016#include "CGCXXABI.h"
Chandler Carruth85098242010-06-15 23:19:56 +000017#include "clang/Frontend/CodeGenOptions.h"
Douglas Gregor51150ab2010-05-16 01:24:12 +000018#include "llvm/Intrinsics.h"
19
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000020using namespace clang;
21using namespace CodeGen;
22
Anders Carlsson364051c2009-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 Carlsson364051c2009-12-10 00:57:45 +000029 ASTContext &Context = CGF.getContext();
30
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000031 const Expr *Init = D.getInit();
32 QualType T = D.getType();
Anders Carlsson364051c2009-12-10 00:57:45 +000033 bool isVolatile = Context.getCanonicalType(T).isVolatileQualified();
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000034
Daniel Dunbar03816342010-08-21 02:24:36 +000035 unsigned Alignment = Context.getDeclAlign(&D).getQuantity();
Anders Carlsson364051c2009-12-10 00:57:45 +000036 if (!CGF.hasAggregateLLVMType(T)) {
Fariborz Jahaniand1339792011-01-13 20:00:54 +000037 CodeGenModule &CGM = CGF.CGM;
Fariborz Jahanianf59e80e2011-01-13 21:35:27 +000038 Qualifiers::GC GCAttr = CGM.getContext().getObjCGCAttrKind(T);
39 if (GCAttr == Qualifiers::Strong)
John McCall31168b02011-06-15 23:02:42 +000040 CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init),
41 DeclPtr, D.isThreadSpecified());
Fariborz Jahanianf59e80e2011-01-13 21:35:27 +000042 else if (GCAttr == Qualifiers::Weak)
John McCall31168b02011-06-15 23:02:42 +000043 CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init),
44 DeclPtr);
Fariborz Jahaniand1339792011-01-13 20:00:54 +000045 else
John McCall31168b02011-06-15 23:02:42 +000046 CGF.EmitScalarInit(Init, &D, DeclPtr, false, isVolatile, Alignment,
47 D.getType());
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000048 } else if (T->isAnyComplexType()) {
Anders Carlsson364051c2009-12-10 00:57:45 +000049 CGF.EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000050 } else {
John McCall31168b02011-06-15 23:02:42 +000051 CGF.EmitAggExpr(Init, AggValueSlot::forAddr(DeclPtr, T.getQualifiers(),
52 true));
Anders Carlssonbc49cfe2009-12-10 00:16:00 +000053 }
54}
55
John McCall68ff0372010-09-08 01:44:27 +000056/// Emit code to cause the destruction of the given variable with
57/// static storage duration.
Douglas Gregor370eadf2010-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 Gregor370eadf2010-05-05 15:38:32 +000063 QualType T = D.getType();
Douglas Gregor370eadf2010-05-05 15:38:32 +000064
John McCall45d49472010-07-30 04:56:58 +000065 // Drill down past array types.
Douglas Gregor370eadf2010-05-05 15:38:32 +000066 const ConstantArrayType *Array = Context.getAsConstantArrayType(T);
67 if (Array)
68 T = Context.getBaseElementType(Array);
69
John McCall45d49472010-07-30 04:56:58 +000070 /// If that's not a record, we're done.
71 /// FIXME: __attribute__((cleanup)) ?
Douglas Gregor370eadf2010-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 Gregorbac74902010-07-01 14:13:13 +000080 CXXDestructorDecl *Dtor = RD->getDestructor();
Douglas Gregor370eadf2010-05-05 15:38:32 +000081
82 llvm::Constant *DtorFn;
83 if (Array) {
84 DtorFn =
Anders Carlsson165ec0a2010-06-08 22:14:59 +000085 CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(Dtor, Array,
86 DeclPtr);
Douglas Gregor370eadf2010-05-05 15:38:32 +000087 const llvm::Type *Int8PtrTy =
Anders Carlsson165ec0a2010-06-08 22:14:59 +000088 llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
Douglas Gregor370eadf2010-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 Carlsson364051c2009-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 Gregor370eadf2010-05-05 15:38:32 +0000104 EmitDeclDestroy(*this, D, DeclPtr);
Anders Carlsson364051c2009-12-10 00:57:45 +0000105 return;
106 }
Anders Carlsson3f48c602010-06-27 17:52:15 +0000107
Daniel Dunbar03816342010-08-21 02:24:36 +0000108 unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
Anders Carlsson3f48c602010-06-27 17:52:15 +0000109 RValue RV = EmitReferenceBindingToExpr(Init, &D);
Daniel Dunbar03816342010-08-21 02:24:36 +0000110 EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
Anders Carlsson364051c2009-12-10 00:57:45 +0000111}
Anders Carlsson633c6f62009-12-10 00:30:05 +0000112
Daniel Dunbarfe06df42010-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 Carlsson633c6f62009-12-10 00:30:05 +0000122 // Get the destructor function type
123 const llvm::Type *DtorFnTy =
John McCallad7c5c12011-02-08 08:22:06 +0000124 llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()),
Benjamin Kramerdf1fb132011-05-28 14:26:31 +0000125 Int8PtrTy, false);
Anders Carlsson633c6f62009-12-10 00:30:05 +0000126 DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
127
Benjamin Kramerdf1fb132011-05-28 14:26:31 +0000128 const llvm::Type *Params[] = { DtorFnTy, Int8PtrTy, Int8PtrTy };
Anders Carlsson633c6f62009-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 Carlsson6dc204d2011-03-20 20:52:32 +0000137 if (llvm::Function *Fn = dyn_cast<llvm::Function>(AtExitFn))
138 Fn->setDoesNotThrow();
Anders Carlsson633c6f62009-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 McCallcdf7ef52010-11-06 09:44:32 +0000148void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
149 llvm::GlobalVariable *DeclPtr) {
John McCall7ef5cb32011-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 McCallcdf7ef52010-11-06 09:44:32 +0000158 CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr);
John McCall68ff0372010-09-08 01:44:27 +0000159}
160
Anders Carlssonb2839e42010-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 Jahanian09948f12011-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 Carlsson851318a2010-06-08 22:47:50 +0000174
Anders Carlsson6dc07d42011-02-28 00:33:03 +0000175 if (!CGM.getLangOptions().Exceptions)
John McCall466e2212010-07-06 04:38:10 +0000176 Fn->setDoesNotThrow();
177
Anders Carlssonb2839e42010-06-08 22:40:05 +0000178 return Fn;
179}
180
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000181void
John McCallcdf7ef52010-11-06 09:44:32 +0000182CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
183 llvm::GlobalVariable *Addr) {
Eli Friedman5866fe32010-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 Carlssonb2839e42010-06-08 22:40:05 +0000190 CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
Eli Friedman5866fe32010-01-08 00:50:11 +0000191
John McCallcdf7ef52010-11-06 09:44:32 +0000192 CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr);
Eli Friedman5866fe32010-01-08 00:50:11 +0000193
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000194 if (D->hasAttr<InitPriorityAttr>()) {
195 unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
Chris Lattnere0009072010-06-27 06:32:58 +0000196 OrderGlobalInits Key(order, PrioritizedCXXGlobalInits.size());
Fariborz Jahanian89bdd142010-06-21 21:27:42 +0000197 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
John McCall70013b62010-07-15 23:40:35 +0000198 DelayedCXXInitPosition.erase(D);
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000199 }
John McCall70013b62010-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 Friedman5866fe32010-01-08 00:50:11 +0000211}
212
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000213void
214CodeGenModule::EmitCXXGlobalInitFunc() {
John McCall70013b62010-07-15 23:40:35 +0000215 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
216 CXXGlobalInits.pop_back();
217
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000218 if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
Anders Carlsson633c6f62009-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 Carlssonb2839e42010-06-08 22:40:05 +0000226 llvm::Function *Fn =
227 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
Anders Carlsson633c6f62009-12-10 00:30:05 +0000228
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000229 if (!PrioritizedCXXGlobalInits.empty()) {
Fariborz Jahanian090e4e52010-06-21 19:49:38 +0000230 llvm::SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
231 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
Fariborz Jahanian469b2002010-06-22 00:23:08 +0000232 PrioritizedCXXGlobalInits.end());
Fariborz Jahanian9f2a4ee2010-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 McCall70013b62010-07-15 23:40:35 +0000237 LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
Fariborz Jahanian9f2a4ee2010-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 Dunbarfe06df42010-03-20 04:15:41 +0000246 AddGlobalCtor(Fn);
Axel Naumannbd26a582011-05-06 15:24:04 +0000247 CXXGlobalInits.clear();
248 PrioritizedCXXGlobalInits.clear();
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000249}
250
Daniel Dunbarfe06df42010-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 Carlssonb2839e42010-06-08 22:40:05 +0000261 CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000262
263 CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
264 AddGlobalDtor(Fn);
265}
266
John McCallcdf7ef52010-11-06 09:44:32 +0000267/// Emit the code necessary to initialize the given global variable.
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000268void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
John McCallcdf7ef52010-11-06 09:44:32 +0000269 const VarDecl *D,
270 llvm::GlobalVariable *Addr) {
John McCalla738c252011-03-09 04:27:21 +0000271 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
272 getTypes().getNullaryFunctionInfo(),
273 FunctionArgList(), SourceLocation());
Daniel Dunbar75722842010-03-20 04:15:29 +0000274
John McCallcdf7ef52010-11-06 09:44:32 +0000275 // Use guarded initialization if the global variable is weak due to
John McCalla97f3292011-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 McCallcdf7ef52010-11-06 09:44:32 +0000281 EmitCXXGuardedInit(*D, Addr);
282 } else {
283 EmitCXXGlobalVarDeclInit(*D, Addr);
Fariborz Jahanian67ca8c42010-10-26 22:47:47 +0000284 }
Daniel Dunbar75722842010-03-20 04:15:29 +0000285
286 FinishFunction();
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000287}
Daniel Dunbar75722842010-03-20 04:15:29 +0000288
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000289void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
290 llvm::Constant **Decls,
291 unsigned NumDecls) {
John McCalla738c252011-03-09 04:27:21 +0000292 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
293 getTypes().getNullaryFunctionInfo(),
294 FunctionArgList(), SourceLocation());
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000295
John McCall31168b02011-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 Dunbarfe06df42010-03-20 04:15:41 +0000305 for (unsigned i = 0; i != NumDecls; ++i)
John McCall70013b62010-07-15 23:40:35 +0000306 if (Decls[i])
John McCall31168b02011-06-15 23:02:42 +0000307 Builder.CreateCall(Decls[i]);
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000308
John McCall31168b02011-06-15 23:02:42 +0000309 Scope.ForceCleanup();
310
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000311 FinishFunction();
312}
313
314void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
Chris Lattner87233f72010-06-19 05:52:45 +0000315 const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000316 &DtorsAndObjects) {
John McCalla738c252011-03-09 04:27:21 +0000317 StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
318 getTypes().getNullaryFunctionInfo(),
319 FunctionArgList(), SourceLocation());
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000320
321 // Emit the dtors, in reverse order from construction.
Chris Lattner5e8416a2010-04-26 20:35:54 +0000322 for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
Chris Lattner87233f72010-06-19 05:52:45 +0000323 llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
Chris Lattner5e8416a2010-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 Dunbarfe06df42010-03-20 04:15:41 +0000330
331 FinishFunction();
Anders Carlsson633c6f62009-12-10 00:30:05 +0000332}
333
Anders Carlsson282bc102010-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 McCalla738c252011-03-09 04:27:21 +0000341 FunctionArgList args;
342 ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
343 args.push_back(&dst);
Anders Carlsson282bc102010-06-08 22:17:27 +0000344
Anders Carlsson282bc102010-06-08 22:17:27 +0000345 const CGFunctionInfo &FI =
John McCalla738c252011-03-09 04:27:21 +0000346 CGM.getTypes().getFunctionInfo(getContext().VoidTy, args,
Anders Carlsson282bc102010-06-08 22:17:27 +0000347 FunctionType::ExtInfo());
348 const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
Anders Carlssonb2839e42010-06-08 22:40:05 +0000349 llvm::Function *Fn =
350 CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
Anders Carlsson282bc102010-06-08 22:17:27 +0000351
John McCalla738c252011-03-09 04:27:21 +0000352 StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FI, args,
353 SourceLocation());
Anders Carlsson282bc102010-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}