blob: d4bd9cbc9ab01c92748072b757b84168b9dfb102 [file] [log] [blame]
Devang Pateldaaf1de2010-10-04 21:15:33 +00001//===--- CGCXX.cpp - Emit LLVM Code for declarations ----------------------===//
Anders Carlssone1b29ef2008-08-22 16:00:37 +00002//
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 C++ code generation.
11//
12//===----------------------------------------------------------------------===//
13
Mike Stump1eb44332009-09-09 15:08:12 +000014// We might split this into multiple files if it gets too unwieldy
Anders Carlssone1b29ef2008-08-22 16:00:37 +000015
Charles Davis3a811f12010-05-25 19:52:27 +000016#include "CGCXXABI.h"
Anders Carlssone1b29ef2008-08-22 16:00:37 +000017#include "CodeGenFunction.h"
18#include "CodeGenModule.h"
19#include "clang/AST/ASTContext.h"
Fariborz Jahanian742cd1b2009-07-25 21:12:28 +000020#include "clang/AST/RecordLayout.h"
Anders Carlssone1b29ef2008-08-22 16:00:37 +000021#include "clang/AST/Decl.h"
Anders Carlsson774e7c62009-04-03 22:50:24 +000022#include "clang/AST/DeclCXX.h"
Anders Carlsson86e96442008-08-23 19:42:54 +000023#include "clang/AST/DeclObjC.h"
Peter Collingbourne14110472011-01-13 18:57:25 +000024#include "clang/AST/Mangle.h"
Anders Carlsson6815e942009-09-27 18:58:34 +000025#include "clang/AST/StmtCXX.h"
Chandler Carruth06057ce2010-06-15 23:19:56 +000026#include "clang/Frontend/CodeGenOptions.h"
Anders Carlssone1b29ef2008-08-22 16:00:37 +000027#include "llvm/ADT/StringExtras.h"
Anders Carlssone1b29ef2008-08-22 16:00:37 +000028using namespace clang;
29using namespace CodeGen;
30
John McCallc0bf4622010-02-23 00:48:20 +000031/// Determines whether the given function has a trivial body that does
32/// not require any specific codegen.
33static bool HasTrivialBody(const FunctionDecl *FD) {
34 Stmt *S = FD->getBody();
35 if (!S)
36 return true;
37 if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
38 return true;
39 return false;
40}
41
42/// Try to emit a base destructor as an alias to its primary
43/// base-class destructor.
44bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
45 if (!getCodeGenOpts().CXXCtorDtorAliases)
46 return true;
47
48 // If the destructor doesn't have a trivial body, we have to emit it
49 // separately.
50 if (!HasTrivialBody(D))
51 return true;
52
53 const CXXRecordDecl *Class = D->getParent();
54
55 // If we need to manipulate a VTT parameter, give up.
56 if (Class->getNumVBases()) {
57 // Extra Credit: passing extra parameters is perfectly safe
58 // in many calling conventions, so only bail out if the ctor's
59 // calling convention is nonstandard.
60 return true;
61 }
62
63 // If any fields have a non-trivial destructor, we have to emit it
64 // separately.
65 for (CXXRecordDecl::field_iterator I = Class->field_begin(),
66 E = Class->field_end(); I != E; ++I)
67 if (const RecordType *RT = (*I)->getType()->getAs<RecordType>())
68 if (!cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor())
69 return true;
70
71 // Try to find a unique base class with a non-trivial destructor.
72 const CXXRecordDecl *UniqueBase = 0;
73 for (CXXRecordDecl::base_class_const_iterator I = Class->bases_begin(),
74 E = Class->bases_end(); I != E; ++I) {
75
76 // We're in the base destructor, so skip virtual bases.
77 if (I->isVirtual()) continue;
78
79 // Skip base classes with trivial destructors.
80 const CXXRecordDecl *Base
81 = cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
82 if (Base->hasTrivialDestructor()) continue;
83
84 // If we've already found a base class with a non-trivial
85 // destructor, give up.
86 if (UniqueBase) return true;
87 UniqueBase = Base;
88 }
89
90 // If we didn't find any bases with a non-trivial destructor, then
91 // the base destructor is actually effectively trivial, which can
92 // happen if it was needlessly user-defined or if there are virtual
93 // bases with non-trivial destructors.
94 if (!UniqueBase)
95 return true;
96
John McCall9a708462010-03-03 03:40:11 +000097 /// If we don't have a definition for the destructor yet, don't
98 /// emit. We can't emit aliases to declarations; that's just not
99 /// how aliases work.
Douglas Gregor1d110e02010-07-01 14:13:13 +0000100 const CXXDestructorDecl *BaseD = UniqueBase->getDestructor();
Argyrios Kyrtzidis06a54a32010-07-07 11:31:19 +0000101 if (!BaseD->isImplicit() && !BaseD->hasBody())
John McCall9a708462010-03-03 03:40:11 +0000102 return true;
103
John McCallc0bf4622010-02-23 00:48:20 +0000104 // If the base is at a non-zero offset, give up.
105 const ASTRecordLayout &ClassLayout = Context.getASTRecordLayout(Class);
Anders Carlssona14f5972010-10-31 23:22:37 +0000106 if (ClassLayout.getBaseClassOffsetInBits(UniqueBase) != 0)
John McCallc0bf4622010-02-23 00:48:20 +0000107 return true;
108
John McCallc0bf4622010-02-23 00:48:20 +0000109 return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
110 GlobalDecl(BaseD, Dtor_Base));
111}
112
John McCalld46f9852010-02-19 01:32:20 +0000113/// Try to emit a definition as a global alias for another definition.
114bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
115 GlobalDecl TargetDecl) {
116 if (!getCodeGenOpts().CXXCtorDtorAliases)
117 return true;
118
John McCalld46f9852010-02-19 01:32:20 +0000119 // The alias will use the linkage of the referrent. If we can't
120 // support aliases with that linkage, fail.
121 llvm::GlobalValue::LinkageTypes Linkage
122 = getFunctionLinkage(cast<FunctionDecl>(AliasDecl.getDecl()));
123
124 switch (Linkage) {
125 // We can definitely emit aliases to definitions with external linkage.
126 case llvm::GlobalValue::ExternalLinkage:
127 case llvm::GlobalValue::ExternalWeakLinkage:
128 break;
129
130 // Same with local linkage.
131 case llvm::GlobalValue::InternalLinkage:
132 case llvm::GlobalValue::PrivateLinkage:
133 case llvm::GlobalValue::LinkerPrivateLinkage:
134 break;
135
136 // We should try to support linkonce linkages.
137 case llvm::GlobalValue::LinkOnceAnyLinkage:
138 case llvm::GlobalValue::LinkOnceODRLinkage:
139 return true;
140
141 // Other linkages will probably never be supported.
142 default:
143 return true;
144 }
145
Rafael Espindolabc6afd12010-03-05 01:21:10 +0000146 llvm::GlobalValue::LinkageTypes TargetLinkage
147 = getFunctionLinkage(cast<FunctionDecl>(TargetDecl.getDecl()));
148
Rafael Espindola3c157452010-03-06 07:35:18 +0000149 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
Rafael Espindolabc6afd12010-03-05 01:21:10 +0000150 return true;
151
John McCallc0bf4622010-02-23 00:48:20 +0000152 // Derive the type for the alias.
153 const llvm::PointerType *AliasType
154 = getTypes().GetFunctionType(AliasDecl)->getPointerTo();
155
John McCallc0bf4622010-02-23 00:48:20 +0000156 // Find the referrent. Some aliases might require a bitcast, in
157 // which case the caller is responsible for ensuring the soundness
158 // of these semantics.
159 llvm::GlobalValue *Ref = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl));
160 llvm::Constant *Aliasee = Ref;
161 if (Ref->getType() != AliasType)
162 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
163
John McCalld46f9852010-02-19 01:32:20 +0000164 // Create the alias with no name.
165 llvm::GlobalAlias *Alias =
John McCallc0bf4622010-02-23 00:48:20 +0000166 new llvm::GlobalAlias(AliasType, Linkage, "", Aliasee, &getModule());
John McCalld46f9852010-02-19 01:32:20 +0000167
John McCall1962bee2010-02-24 20:32:01 +0000168 // Switch any previous uses to the alias.
Anders Carlsson9a20d552010-06-22 16:16:50 +0000169 llvm::StringRef MangledName = getMangledName(AliasDecl);
John McCallf746aa62010-03-19 23:29:14 +0000170 llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
John McCalld46f9852010-02-19 01:32:20 +0000171 if (Entry) {
John McCall1962bee2010-02-24 20:32:01 +0000172 assert(Entry->isDeclaration() && "definition already exists for alias");
173 assert(Entry->getType() == AliasType &&
174 "declaration exists with different type");
John McCallf746aa62010-03-19 23:29:14 +0000175 Alias->takeName(Entry);
John McCalld46f9852010-02-19 01:32:20 +0000176 Entry->replaceAllUsesWith(Alias);
177 Entry->eraseFromParent();
John McCallf746aa62010-03-19 23:29:14 +0000178 } else {
Anders Carlsson9a20d552010-06-22 16:16:50 +0000179 Alias->setName(MangledName);
John McCalld46f9852010-02-19 01:32:20 +0000180 }
John McCalld46f9852010-02-19 01:32:20 +0000181
182 // Finally, set up the alias with its proper name and attributes.
John McCall1fb0caa2010-10-22 21:05:15 +0000183 SetCommonAttributes(cast<NamedDecl>(AliasDecl.getDecl()), Alias);
John McCalld46f9852010-02-19 01:32:20 +0000184
185 return false;
186}
Anders Carlssonb9de2c52009-05-11 23:37:08 +0000187
Anders Carlsson95d4e5d2009-04-15 15:55:24 +0000188void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
John McCalld46f9852010-02-19 01:32:20 +0000189 // The constructor used for constructing this as a complete class;
190 // constucts the virtual bases, then calls the base constructor.
John McCall92ac9ff2010-02-17 03:52:49 +0000191 EmitGlobal(GlobalDecl(D, Ctor_Complete));
John McCalld46f9852010-02-19 01:32:20 +0000192
193 // The constructor used for constructing this as a base class;
194 // ignores virtual bases.
John McCall8e51a1f2010-02-18 21:31:48 +0000195 EmitGlobal(GlobalDecl(D, Ctor_Base));
Anders Carlsson95d4e5d2009-04-15 15:55:24 +0000196}
Anders Carlsson363c1842009-04-16 23:57:24 +0000197
Mike Stump1eb44332009-09-09 15:08:12 +0000198void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
Anders Carlsson27ae5362009-04-17 01:58:57 +0000199 CXXCtorType Type) {
John McCalld46f9852010-02-19 01:32:20 +0000200 // The complete constructor is equivalent to the base constructor
201 // for classes with no virtual bases. Try to emit it as an alias.
202 if (Type == Ctor_Complete &&
203 !D->getParent()->getNumVBases() &&
204 !TryEmitDefinitionAsAlias(GlobalDecl(D, Ctor_Complete),
205 GlobalDecl(D, Ctor_Base)))
206 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000207
John McCalld46f9852010-02-19 01:32:20 +0000208 llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXConstructor(D, Type));
John McCall8b242332010-05-25 04:30:21 +0000209 setFunctionLinkage(D, Fn);
Mike Stump1eb44332009-09-09 15:08:12 +0000210
Anders Carlsson0ff8baf2009-09-11 00:07:24 +0000211 CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
Mike Stump1eb44332009-09-09 15:08:12 +0000212
Anders Carlsson27ae5362009-04-17 01:58:57 +0000213 SetFunctionDefinitionAttributes(D, Fn);
214 SetLLVMFunctionAttributesForDefinition(D, Fn);
215}
216
John McCalld46f9852010-02-19 01:32:20 +0000217llvm::GlobalValue *
Mike Stump1eb44332009-09-09 15:08:12 +0000218CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
Anders Carlsson363c1842009-04-16 23:57:24 +0000219 CXXCtorType Type) {
Anders Carlssondc709a82010-06-09 02:30:12 +0000220 GlobalDecl GD(D, Type);
221
Anders Carlsson9a20d552010-06-22 16:16:50 +0000222 llvm::StringRef Name = getMangledName(GD);
John McCallf746aa62010-03-19 23:29:14 +0000223 if (llvm::GlobalValue *V = GetGlobalValue(Name))
John McCalld46f9852010-02-19 01:32:20 +0000224 return V;
225
Fariborz Jahanian30509a32009-11-06 18:47:57 +0000226 const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>();
Anders Carlsson363c1842009-04-16 23:57:24 +0000227 const llvm::FunctionType *FTy =
Anders Carlssonf6c56e22009-11-25 03:15:49 +0000228 getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type),
Fariborz Jahanian30509a32009-11-06 18:47:57 +0000229 FPT->isVariadic());
Anders Carlsson1faa89f2011-02-05 04:35:53 +0000230 return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD,
231 /*ForVTable=*/false));
Anders Carlsson363c1842009-04-16 23:57:24 +0000232}
Anders Carlsson27ae5362009-04-17 01:58:57 +0000233
Anders Carlsson27ae5362009-04-17 01:58:57 +0000234void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
John McCalld46f9852010-02-19 01:32:20 +0000235 // The destructor in a virtual table is always a 'deleting'
236 // destructor, which calls the complete destructor and then uses the
237 // appropriate operator delete.
Eli Friedmanea9a2082009-11-14 04:19:37 +0000238 if (D->isVirtual())
Eli Friedman624c7d72009-12-15 02:06:15 +0000239 EmitGlobal(GlobalDecl(D, Dtor_Deleting));
John McCalld46f9852010-02-19 01:32:20 +0000240
241 // The destructor used for destructing this as a most-derived class;
242 // call the base destructor and then destructs any virtual bases.
John McCall8e51a1f2010-02-18 21:31:48 +0000243 EmitGlobal(GlobalDecl(D, Dtor_Complete));
John McCalld46f9852010-02-19 01:32:20 +0000244
245 // The destructor used for destructing this as a base class; ignores
246 // virtual bases.
John McCall8e51a1f2010-02-18 21:31:48 +0000247 EmitGlobal(GlobalDecl(D, Dtor_Base));
Anders Carlsson27ae5362009-04-17 01:58:57 +0000248}
249
Mike Stump1eb44332009-09-09 15:08:12 +0000250void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *D,
Anders Carlsson27ae5362009-04-17 01:58:57 +0000251 CXXDtorType Type) {
John McCalld46f9852010-02-19 01:32:20 +0000252 // The complete destructor is equivalent to the base destructor for
253 // classes with no virtual bases, so try to emit it as an alias.
254 if (Type == Dtor_Complete &&
255 !D->getParent()->getNumVBases() &&
256 !TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Complete),
257 GlobalDecl(D, Dtor_Base)))
258 return;
259
John McCallc0bf4622010-02-23 00:48:20 +0000260 // The base destructor is equivalent to the base destructor of its
261 // base class if there is exactly one non-virtual base class with a
262 // non-trivial destructor, there are no fields with a non-trivial
263 // destructor, and the body of the destructor is trivial.
264 if (Type == Dtor_Base && !TryEmitBaseDestructorAsAlias(D))
265 return;
266
John McCalld46f9852010-02-19 01:32:20 +0000267 llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXDestructor(D, Type));
John McCall8b242332010-05-25 04:30:21 +0000268 setFunctionLinkage(D, Fn);
Mike Stump1eb44332009-09-09 15:08:12 +0000269
Anders Carlsson0ff8baf2009-09-11 00:07:24 +0000270 CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
Mike Stump1eb44332009-09-09 15:08:12 +0000271
Anders Carlsson27ae5362009-04-17 01:58:57 +0000272 SetFunctionDefinitionAttributes(D, Fn);
273 SetLLVMFunctionAttributesForDefinition(D, Fn);
274}
275
John McCalld46f9852010-02-19 01:32:20 +0000276llvm::GlobalValue *
Mike Stump1eb44332009-09-09 15:08:12 +0000277CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
Anders Carlsson27ae5362009-04-17 01:58:57 +0000278 CXXDtorType Type) {
Anders Carlssondc709a82010-06-09 02:30:12 +0000279 GlobalDecl GD(D, Type);
280
Anders Carlsson9a20d552010-06-22 16:16:50 +0000281 llvm::StringRef Name = getMangledName(GD);
John McCallf746aa62010-03-19 23:29:14 +0000282 if (llvm::GlobalValue *V = GetGlobalValue(Name))
John McCalld46f9852010-02-19 01:32:20 +0000283 return V;
284
Anders Carlsson27ae5362009-04-17 01:58:57 +0000285 const llvm::FunctionType *FTy =
Anders Carlssonf6c56e22009-11-25 03:15:49 +0000286 getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type), false);
Mike Stump1eb44332009-09-09 15:08:12 +0000287
Anders Carlsson1faa89f2011-02-05 04:35:53 +0000288 return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD,
289 /*ForVTable=*/false));
Anders Carlsson27ae5362009-04-17 01:58:57 +0000290}
291
Anders Carlsson046c2942010-04-17 20:15:18 +0000292static llvm::Value *BuildVirtualCall(CodeGenFunction &CGF, uint64_t VTableIndex,
Anders Carlsson566abee2009-11-13 04:45:41 +0000293 llvm::Value *This, const llvm::Type *Ty) {
Dan Gohman043fb9a2010-10-26 18:44:08 +0000294 Ty = Ty->getPointerTo()->getPointerTo();
Anders Carlsson2b358352009-10-03 14:56:57 +0000295
Dan Gohman043fb9a2010-10-26 18:44:08 +0000296 llvm::Value *VTable = CGF.GetVTablePtr(This, Ty);
Anders Carlsson566abee2009-11-13 04:45:41 +0000297 llvm::Value *VFuncPtr =
Anders Carlsson046c2942010-04-17 20:15:18 +0000298 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
Anders Carlsson566abee2009-11-13 04:45:41 +0000299 return CGF.Builder.CreateLoad(VFuncPtr);
300}
301
302llvm::Value *
303CodeGenFunction::BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
304 const llvm::Type *Ty) {
305 MD = MD->getCanonicalDecl();
Anders Carlsson046c2942010-04-17 20:15:18 +0000306 uint64_t VTableIndex = CGM.getVTables().getMethodVTableIndex(MD);
Anders Carlsson566abee2009-11-13 04:45:41 +0000307
Anders Carlssonaf440352010-03-23 04:11:45 +0000308 return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
Anders Carlsson566abee2009-11-13 04:45:41 +0000309}
310
Fariborz Jahanian27262672011-01-20 17:19:02 +0000311/// BuildVirtualCall - This routine is to support gcc's kext ABI making
312/// indirect call to virtual functions. It makes the call through indexing
313/// into the vtable.
314llvm::Value *
315CodeGenFunction::BuildAppleKextVirtualCall(const CXXMethodDecl *MD,
316 NestedNameSpecifier *Qual,
Fariborz Jahanian27262672011-01-20 17:19:02 +0000317 const llvm::Type *Ty) {
318 llvm::Value *VTable = 0;
319 assert((Qual->getKind() == NestedNameSpecifier::TypeSpec) &&
320 "BuildAppleKextVirtualCall - bad Qual kind");
321
322 const Type *QTy = Qual->getAsType();
323 QualType T = QualType(QTy, 0);
324 const RecordType *RT = T->getAs<RecordType>();
325 assert(RT && "BuildAppleKextVirtualCall - Qual type must be record");
326 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000327
328 if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD))
329 return BuildAppleKextVirtualDestructorCall(DD, Dtor_Complete, RD);
330
Fariborz Jahanian27262672011-01-20 17:19:02 +0000331 VTable = CGM.getVTables().GetAddrOfVTable(RD);
332 Ty = Ty->getPointerTo()->getPointerTo();
333 VTable = Builder.CreateBitCast(VTable, Ty);
334 assert(VTable && "BuildVirtualCall = kext vtbl pointer is null");
335 MD = MD->getCanonicalDecl();
336 uint64_t VTableIndex = CGM.getVTables().getMethodVTableIndex(MD);
Fariborz Jahaniana50e33e2011-01-28 23:42:29 +0000337 uint64_t AddressPoint =
338 CGM.getVTables().getAddressPoint(BaseSubobject(RD, 0), RD);
339 VTableIndex += AddressPoint;
Fariborz Jahanian27262672011-01-20 17:19:02 +0000340 llvm::Value *VFuncPtr =
John McCalld16c2cf2011-02-08 08:22:06 +0000341 Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfnkxt");
342 return Builder.CreateLoad(VFuncPtr);
Fariborz Jahanian27262672011-01-20 17:19:02 +0000343}
344
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000345/// BuildVirtualCall - This routine makes indirect vtable call for
346/// call to virtual destructors. It returns 0 if it could not do it.
347llvm::Value *
348CodeGenFunction::BuildAppleKextVirtualDestructorCall(
349 const CXXDestructorDecl *DD,
350 CXXDtorType Type,
351 const CXXRecordDecl *RD) {
352 llvm::Value * Callee = 0;
353 const CXXMethodDecl *MD = cast<CXXMethodDecl>(DD);
354 // FIXME. Dtor_Base dtor is always direct!!
355 // It need be somehow inline expanded into the caller.
356 // -O does that. But need to support -O0 as well.
357 if (MD->isVirtual() && Type != Dtor_Base) {
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000358 // Compute the function type we're calling.
359 const CGFunctionInfo *FInfo =
360 &CGM.getTypes().getFunctionInfo(cast<CXXDestructorDecl>(MD),
361 Dtor_Complete);
362 const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
363 const llvm::Type *Ty
364 = CGM.getTypes().GetFunctionType(*FInfo, FPT->isVariadic());
Fariborz Jahanian771c6782011-02-03 19:27:17 +0000365
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000366 llvm::Value *VTable = CGM.getVTables().GetAddrOfVTable(RD);
367 Ty = Ty->getPointerTo()->getPointerTo();
368 VTable = Builder.CreateBitCast(VTable, Ty);
Fariborz Jahanian771c6782011-02-03 19:27:17 +0000369 DD = cast<CXXDestructorDecl>(DD->getCanonicalDecl());
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000370 uint64_t VTableIndex =
Fariborz Jahanian771c6782011-02-03 19:27:17 +0000371 CGM.getVTables().getMethodVTableIndex(GlobalDecl(DD, Type));
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000372 uint64_t AddressPoint =
Fariborz Jahanian771c6782011-02-03 19:27:17 +0000373 CGM.getVTables().getAddressPoint(BaseSubobject(RD, 0), RD);
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000374 VTableIndex += AddressPoint;
375 llvm::Value *VFuncPtr =
John McCalld16c2cf2011-02-08 08:22:06 +0000376 Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfnkxt");
377 Callee = Builder.CreateLoad(VFuncPtr);
Fariborz Jahanianccd52592011-02-01 23:22:34 +0000378 }
379 return Callee;
380}
381
Anders Carlsson566abee2009-11-13 04:45:41 +0000382llvm::Value *
383CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
Anders Carlsson83eedd92010-11-28 17:53:32 +0000384 llvm::Value *This, const llvm::Type *Ty) {
Anders Carlsson566abee2009-11-13 04:45:41 +0000385 DD = cast<CXXDestructorDecl>(DD->getCanonicalDecl());
Anders Carlssonaf440352010-03-23 04:11:45 +0000386 uint64_t VTableIndex =
Anders Carlsson046c2942010-04-17 20:15:18 +0000387 CGM.getVTables().getMethodVTableIndex(GlobalDecl(DD, Type));
Anders Carlsson566abee2009-11-13 04:45:41 +0000388
Anders Carlssonaf440352010-03-23 04:11:45 +0000389 return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
Mike Stumpf0070db2009-08-26 20:46:33 +0000390}
Charles Davis3a811f12010-05-25 19:52:27 +0000391