2008-08-23 00:00:37 +08:00
|
|
|
//===--- CGDecl.cpp - Emit LLVM Code for declarations ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code dealing with C++ code generation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// We might split this into multiple files if it gets too unwieldy
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
2009-04-14 02:03:33 +08:00
|
|
|
#include "Mangle.h"
|
2008-08-23 00:00:37 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2009-07-26 05:12:28 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2008-08-23 00:00:37 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2009-04-04 06:50:24 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2008-08-24 03:42:54 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2008-08-23 00:00:37 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2009-02-26 03:24:29 +08:00
|
|
|
void
|
2009-08-09 05:45:14 +08:00
|
|
|
CodeGenFunction::EmitCXXGlobalDtorRegistration(const CXXDestructorDecl *Dtor,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
// FIXME: This is ABI dependent and we use the Itanium ABI.
|
|
|
|
|
|
|
|
const llvm::Type *Int8PtrTy =
|
|
|
|
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
|
|
|
|
|
|
|
std::vector<const llvm::Type *> Params;
|
|
|
|
Params.push_back(Int8PtrTy);
|
|
|
|
|
|
|
|
// Get the destructor function type
|
|
|
|
const llvm::Type *DtorFnTy =
|
|
|
|
llvm::FunctionType::get(llvm::Type::VoidTy, Params, false);
|
|
|
|
DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
|
|
|
|
|
|
|
|
Params.clear();
|
|
|
|
Params.push_back(DtorFnTy);
|
|
|
|
Params.push_back(Int8PtrTy);
|
|
|
|
Params.push_back(Int8PtrTy);
|
|
|
|
|
|
|
|
// Get the __cxa_atexit function type
|
|
|
|
// extern "C" int __cxa_atexit ( void (*f)(void *), void *p, void *d );
|
|
|
|
const llvm::FunctionType *AtExitFnTy =
|
|
|
|
llvm::FunctionType::get(ConvertType(getContext().IntTy), Params, false);
|
|
|
|
|
|
|
|
llvm::Constant *AtExitFn = CGM.CreateRuntimeFunction(AtExitFnTy,
|
|
|
|
"__cxa_atexit");
|
|
|
|
|
|
|
|
llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy,
|
|
|
|
"__dso_handle");
|
|
|
|
|
|
|
|
llvm::Constant *DtorFn = CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete);
|
|
|
|
|
|
|
|
llvm::Value *Args[3] = { llvm::ConstantExpr::getBitCast(DtorFn, DtorFnTy),
|
|
|
|
llvm::ConstantExpr::getBitCast(DeclPtr, Int8PtrTy),
|
|
|
|
llvm::ConstantExpr::getBitCast(Handle, Int8PtrTy) };
|
|
|
|
Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
assert(D.hasGlobalStorage() &&
|
|
|
|
"VarDecl must have global storage!");
|
|
|
|
|
|
|
|
const Expr *Init = D.getInit();
|
|
|
|
QualType T = D.getType();
|
|
|
|
|
|
|
|
if (T->isReferenceType()) {
|
|
|
|
ErrorUnsupported(Init, "Global variable that binds to a reference");
|
|
|
|
} else if (!hasAggregateLLVMType(T)) {
|
|
|
|
llvm::Value *V = EmitScalarExpr(Init);
|
|
|
|
EmitStoreOfScalar(V, DeclPtr, T.isVolatileQualified(), T);
|
|
|
|
} else if (T->isAnyComplexType()) {
|
|
|
|
EmitComplexExprIntoAddr(Init, DeclPtr, T.isVolatileQualified());
|
|
|
|
} else {
|
|
|
|
EmitAggExpr(Init, DeclPtr, T.isVolatileQualified());
|
|
|
|
|
|
|
|
if (const RecordType *RT = T->getAs<RecordType>()) {
|
|
|
|
CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (!RD->hasTrivialDestructor())
|
|
|
|
EmitCXXGlobalDtorRegistration(RD->getDestructor(getContext()), DeclPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-09 07:24:23 +08:00
|
|
|
void
|
|
|
|
CodeGenModule::EmitCXXGlobalInitFunc() {
|
|
|
|
if (CXXGlobalInits.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const llvm::FunctionType *FTy = llvm::FunctionType::get(llvm::Type::VoidTy,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Create our global initialization function.
|
|
|
|
// FIXME: Should this be tweakable by targets?
|
|
|
|
llvm::Function *Fn =
|
|
|
|
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
|
|
|
|
"__cxx_global_initialization", &TheModule);
|
|
|
|
|
|
|
|
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
|
2009-08-09 07:43:26 +08:00
|
|
|
&CXXGlobalInits[0],
|
2009-08-09 07:24:23 +08:00
|
|
|
CXXGlobalInits.size());
|
|
|
|
AddGlobalCtor(Fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
|
|
|
|
const VarDecl **Decls,
|
|
|
|
unsigned NumDecls) {
|
|
|
|
StartFunction(0, getContext().VoidTy, Fn, FunctionArgList(),
|
|
|
|
SourceLocation());
|
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumDecls; ++i) {
|
|
|
|
const VarDecl *D = Decls[i];
|
|
|
|
|
|
|
|
llvm::Constant *DeclPtr = CGM.GetAddrOfGlobalVar(D);
|
|
|
|
EmitCXXGlobalVarDeclInit(*D, DeclPtr);
|
|
|
|
}
|
|
|
|
FinishFunction();
|
|
|
|
}
|
|
|
|
|
2009-08-09 05:45:14 +08:00
|
|
|
void
|
|
|
|
CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
|
|
|
|
llvm::GlobalVariable *GV) {
|
2009-02-26 03:24:29 +08:00
|
|
|
// FIXME: This should use __cxa_guard_{acquire,release}?
|
|
|
|
|
2008-08-23 00:00:37 +08:00
|
|
|
assert(!getContext().getLangOptions().ThreadsafeStatics &&
|
|
|
|
"thread safe statics are currently not supported!");
|
|
|
|
|
2009-04-14 02:03:33 +08:00
|
|
|
llvm::SmallString<256> GuardVName;
|
|
|
|
llvm::raw_svector_ostream GuardVOut(GuardVName);
|
|
|
|
mangleGuardVariable(&D, getContext(), GuardVOut);
|
|
|
|
|
2008-08-23 00:00:37 +08:00
|
|
|
// Create the guard variable.
|
|
|
|
llvm::GlobalValue *GuardV =
|
2009-07-09 03:05:04 +08:00
|
|
|
new llvm::GlobalVariable(CGM.getModule(), llvm::Type::Int64Ty, false,
|
2009-02-26 03:24:29 +08:00
|
|
|
GV->getLinkage(),
|
2009-08-01 04:28:54 +08:00
|
|
|
llvm::Constant::getNullValue(llvm::Type::Int64Ty),
|
2009-07-09 03:05:04 +08:00
|
|
|
GuardVName.c_str());
|
2008-08-23 00:00:37 +08:00
|
|
|
|
|
|
|
// Load the first byte of the guard variable.
|
2009-07-30 06:16:19 +08:00
|
|
|
const llvm::Type *PtrTy = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
|
2008-08-23 00:00:37 +08:00
|
|
|
llvm::Value *V = Builder.CreateLoad(Builder.CreateBitCast(GuardV, PtrTy),
|
|
|
|
"tmp");
|
|
|
|
|
|
|
|
// Compare it against 0.
|
2009-08-01 04:28:54 +08:00
|
|
|
llvm::Value *nullValue = llvm::Constant::getNullValue(llvm::Type::Int8Ty);
|
2008-08-23 00:00:37 +08:00
|
|
|
llvm::Value *ICmp = Builder.CreateICmpEQ(V, nullValue , "tobool");
|
|
|
|
|
2008-11-11 10:29:29 +08:00
|
|
|
llvm::BasicBlock *InitBlock = createBasicBlock("init");
|
2008-11-13 09:38:36 +08:00
|
|
|
llvm::BasicBlock *EndBlock = createBasicBlock("init.end");
|
2008-08-23 00:00:37 +08:00
|
|
|
|
|
|
|
// If the guard variable is 0, jump to the initializer code.
|
|
|
|
Builder.CreateCondBr(ICmp, InitBlock, EndBlock);
|
|
|
|
|
|
|
|
EmitBlock(InitBlock);
|
|
|
|
|
2009-08-09 05:45:14 +08:00
|
|
|
EmitCXXGlobalVarDeclInit(D, GV);
|
|
|
|
|
2009-07-25 07:12:58 +08:00
|
|
|
Builder.CreateStore(llvm::ConstantInt::get(llvm::Type::Int8Ty, 1),
|
2008-08-23 00:00:37 +08:00
|
|
|
Builder.CreateBitCast(GuardV, PtrTy));
|
|
|
|
|
|
|
|
EmitBlock(EndBlock);
|
|
|
|
}
|
|
|
|
|
2009-05-12 07:37:08 +08:00
|
|
|
RValue CodeGenFunction::EmitCXXMemberCall(const CXXMethodDecl *MD,
|
|
|
|
llvm::Value *Callee,
|
|
|
|
llvm::Value *This,
|
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd) {
|
2009-04-04 06:50:24 +08:00
|
|
|
assert(MD->isInstance() &&
|
|
|
|
"Trying to emit a member call expr on a static method!");
|
2009-05-12 07:37:08 +08:00
|
|
|
|
|
|
|
const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType();
|
|
|
|
|
|
|
|
CallArgList Args;
|
|
|
|
|
|
|
|
// Push the this ptr.
|
|
|
|
Args.push_back(std::make_pair(RValue::get(This),
|
|
|
|
MD->getThisType(getContext())));
|
|
|
|
|
|
|
|
// And the rest of the call args
|
|
|
|
EmitCallArgs(Args, FPT, ArgBeg, ArgEnd);
|
2009-04-04 06:50:24 +08:00
|
|
|
|
2009-05-12 07:37:08 +08:00
|
|
|
QualType ResultType = MD->getType()->getAsFunctionType()->getResultType();
|
|
|
|
return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args),
|
|
|
|
Callee, Args, MD);
|
|
|
|
}
|
|
|
|
|
|
|
|
RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE) {
|
|
|
|
const MemberExpr *ME = cast<MemberExpr>(CE->getCallee());
|
|
|
|
const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl());
|
|
|
|
|
2009-04-09 04:31:57 +08:00
|
|
|
const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType();
|
2009-07-31 05:47:44 +08:00
|
|
|
|
2009-08-01 02:25:34 +08:00
|
|
|
if (MD->isVirtual()) {
|
2009-07-31 05:47:44 +08:00
|
|
|
ErrorUnsupported(CE, "virtual dispatch");
|
|
|
|
}
|
|
|
|
|
2009-04-04 06:50:24 +08:00
|
|
|
const llvm::Type *Ty =
|
2009-04-09 04:31:57 +08:00
|
|
|
CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
|
|
|
|
FPT->isVariadic());
|
2009-05-13 05:21:08 +08:00
|
|
|
llvm::Constant *Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty);
|
2009-04-04 06:50:24 +08:00
|
|
|
|
2009-05-12 07:37:08 +08:00
|
|
|
llvm::Value *This;
|
2009-04-04 06:50:24 +08:00
|
|
|
|
|
|
|
if (ME->isArrow())
|
2009-05-12 07:37:08 +08:00
|
|
|
This = EmitScalarExpr(ME->getBase());
|
2009-04-04 06:50:24 +08:00
|
|
|
else {
|
|
|
|
LValue BaseLV = EmitLValue(ME->getBase());
|
2009-05-12 07:37:08 +08:00
|
|
|
This = BaseLV.getAddress();
|
2009-04-04 06:50:24 +08:00
|
|
|
}
|
|
|
|
|
2009-05-12 07:37:08 +08:00
|
|
|
return EmitCXXMemberCall(MD, Callee, This,
|
|
|
|
CE->arg_begin(), CE->arg_end());
|
2009-04-04 06:50:24 +08:00
|
|
|
}
|
2009-04-15 00:58:56 +08:00
|
|
|
|
2009-05-27 12:18:27 +08:00
|
|
|
RValue
|
|
|
|
CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
|
|
|
|
const CXXMethodDecl *MD) {
|
|
|
|
assert(MD->isInstance() &&
|
|
|
|
"Trying to emit a member call expr on a static method!");
|
|
|
|
|
|
|
|
|
|
|
|
const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType();
|
|
|
|
const llvm::Type *Ty =
|
|
|
|
CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
|
|
|
|
FPT->isVariadic());
|
|
|
|
llvm::Constant *Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty);
|
|
|
|
|
|
|
|
llvm::Value *This = EmitLValue(E->getArg(0)).getAddress();
|
|
|
|
|
|
|
|
return EmitCXXMemberCall(MD, Callee, This,
|
|
|
|
E->arg_begin() + 1, E->arg_end());
|
|
|
|
}
|
|
|
|
|
2009-04-15 00:58:56 +08:00
|
|
|
llvm::Value *CodeGenFunction::LoadCXXThis() {
|
|
|
|
assert(isa<CXXMethodDecl>(CurFuncDecl) &&
|
|
|
|
"Must be in a C++ member function decl to load 'this'");
|
|
|
|
assert(cast<CXXMethodDecl>(CurFuncDecl)->isInstance() &&
|
|
|
|
"Must be in a C++ member function decl to load 'this'");
|
|
|
|
|
|
|
|
// FIXME: What if we're inside a block?
|
2009-05-16 15:57:57 +08:00
|
|
|
// ans: See how CodeGenFunction::LoadObjCSelf() uses
|
|
|
|
// CodeGenFunction::BlockForwardSelf() for how to do this.
|
2009-04-15 00:58:56 +08:00
|
|
|
return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
|
|
|
|
}
|
2009-04-15 23:55:24 +08:00
|
|
|
|
2009-07-30 08:10:25 +08:00
|
|
|
static bool
|
|
|
|
GetNestedPaths(llvm::SmallVectorImpl<const CXXRecordDecl *> &NestedBasePaths,
|
|
|
|
const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl) {
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(),
|
|
|
|
e = ClassDecl->bases_end(); i != e; ++i) {
|
|
|
|
if (i->isVirtual())
|
|
|
|
continue;
|
|
|
|
const CXXRecordDecl *Base =
|
2009-08-05 05:58:42 +08:00
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
2009-07-30 08:10:25 +08:00
|
|
|
if (Base == BaseClassDecl) {
|
|
|
|
NestedBasePaths.push_back(BaseClassDecl);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// BaseClassDecl not an immediate base of ClassDecl.
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(),
|
|
|
|
e = ClassDecl->bases_end(); i != e; ++i) {
|
|
|
|
if (i->isVirtual())
|
|
|
|
continue;
|
|
|
|
const CXXRecordDecl *Base =
|
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
if (GetNestedPaths(NestedBasePaths, Base, BaseClassDecl)) {
|
|
|
|
NestedBasePaths.push_back(Base);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-29 01:38:28 +08:00
|
|
|
llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
|
2009-07-29 02:09:28 +08:00
|
|
|
const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl) {
|
2009-07-29 01:38:28 +08:00
|
|
|
if (ClassDecl == BaseClassDecl)
|
|
|
|
return BaseValue;
|
|
|
|
|
2009-07-30 08:10:25 +08:00
|
|
|
llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
|
|
|
llvm::SmallVector<const CXXRecordDecl *, 16> NestedBasePaths;
|
|
|
|
GetNestedPaths(NestedBasePaths, ClassDecl, BaseClassDecl);
|
|
|
|
assert(NestedBasePaths.size() > 0 &&
|
|
|
|
"AddressCXXOfBaseClass - inheritence path failed");
|
|
|
|
NestedBasePaths.push_back(ClassDecl);
|
|
|
|
uint64_t Offset = 0;
|
|
|
|
|
2009-07-29 01:38:28 +08:00
|
|
|
// Accessing a member of the base class. Must add delata to
|
|
|
|
// the load of 'this'.
|
2009-07-30 08:10:25 +08:00
|
|
|
for (unsigned i = NestedBasePaths.size()-1; i > 0; i--) {
|
|
|
|
const CXXRecordDecl *DerivedClass = NestedBasePaths[i];
|
|
|
|
const CXXRecordDecl *BaseClass = NestedBasePaths[i-1];
|
|
|
|
const ASTRecordLayout &Layout =
|
|
|
|
getContext().getASTRecordLayout(DerivedClass);
|
|
|
|
Offset += Layout.getBaseClassOffset(BaseClass) / 8;
|
|
|
|
}
|
2009-07-29 23:54:56 +08:00
|
|
|
llvm::Value *OffsetVal =
|
|
|
|
llvm::ConstantInt::get(
|
|
|
|
CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset);
|
2009-07-29 01:38:28 +08:00
|
|
|
BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr);
|
|
|
|
BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr");
|
|
|
|
QualType BTy =
|
|
|
|
getContext().getCanonicalType(
|
2009-07-29 02:09:28 +08:00
|
|
|
getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(BaseClassDecl)));
|
2009-07-29 01:38:28 +08:00
|
|
|
const llvm::Type *BasePtr = ConvertType(BTy);
|
2009-07-30 06:16:19 +08:00
|
|
|
BasePtr = llvm::PointerType::getUnqual(BasePtr);
|
2009-07-29 01:38:28 +08:00
|
|
|
BaseValue = Builder.CreateBitCast(BaseValue, BasePtr);
|
|
|
|
return BaseValue;
|
|
|
|
}
|
|
|
|
|
2009-04-17 08:06:03 +08:00
|
|
|
void
|
|
|
|
CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type,
|
|
|
|
llvm::Value *This,
|
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd) {
|
2009-05-12 07:37:08 +08:00
|
|
|
llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(D, Type);
|
|
|
|
|
|
|
|
EmitCXXMemberCall(D, Callee, This, ArgBeg, ArgEnd);
|
2009-04-17 08:06:03 +08:00
|
|
|
}
|
|
|
|
|
2009-05-30 05:03:38 +08:00
|
|
|
void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type,
|
|
|
|
llvm::Value *This) {
|
|
|
|
llvm::Value *Callee = CGM.GetAddrOfCXXDestructor(D, Type);
|
|
|
|
|
|
|
|
EmitCXXMemberCall(D, Callee, This, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-04-17 08:06:03 +08:00
|
|
|
void
|
2009-05-04 01:47:16 +08:00
|
|
|
CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest,
|
|
|
|
const CXXConstructExpr *E) {
|
2009-04-17 08:06:03 +08:00
|
|
|
assert(Dest && "Must have a destination!");
|
|
|
|
|
|
|
|
const CXXRecordDecl *RD =
|
2009-07-30 05:53:49 +08:00
|
|
|
cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl());
|
2009-04-17 08:06:03 +08:00
|
|
|
if (RD->hasTrivialConstructor())
|
|
|
|
return;
|
2009-08-06 09:02:49 +08:00
|
|
|
|
|
|
|
// Code gen optimization to eliminate copy constructor and return
|
|
|
|
// its first argument instead.
|
2009-08-07 03:12:38 +08:00
|
|
|
if (E->isElidable()) {
|
2009-08-06 09:02:49 +08:00
|
|
|
CXXConstructExpr::const_arg_iterator i = E->arg_begin();
|
2009-08-07 03:12:38 +08:00
|
|
|
EmitAggExpr((*i), Dest, false);
|
|
|
|
return;
|
2009-08-06 09:02:49 +08:00
|
|
|
}
|
2009-04-17 08:06:03 +08:00
|
|
|
// Call the constructor.
|
|
|
|
EmitCXXConstructorCall(E->getConstructor(), Ctor_Complete, Dest,
|
|
|
|
E->arg_begin(), E->arg_end());
|
|
|
|
}
|
|
|
|
|
2009-05-31 09:40:14 +08:00
|
|
|
llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
|
2009-06-01 04:21:44 +08:00
|
|
|
if (E->isArray()) {
|
|
|
|
ErrorUnsupported(E, "new[] expression");
|
2009-07-31 07:11:26 +08:00
|
|
|
return llvm::UndefValue::get(ConvertType(E->getType()));
|
2009-06-01 04:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QualType AllocType = E->getAllocatedType();
|
|
|
|
FunctionDecl *NewFD = E->getOperatorNew();
|
|
|
|
const FunctionProtoType *NewFTy = NewFD->getType()->getAsFunctionProtoType();
|
|
|
|
|
|
|
|
CallArgList NewArgs;
|
|
|
|
|
|
|
|
// The allocation size is the first argument.
|
|
|
|
QualType SizeTy = getContext().getSizeType();
|
|
|
|
llvm::Value *AllocSize =
|
2009-07-25 07:12:58 +08:00
|
|
|
llvm::ConstantInt::get(ConvertType(SizeTy),
|
2009-06-01 04:21:44 +08:00
|
|
|
getContext().getTypeSize(AllocType) / 8);
|
|
|
|
|
|
|
|
NewArgs.push_back(std::make_pair(RValue::get(AllocSize), SizeTy));
|
|
|
|
|
|
|
|
// Emit the rest of the arguments.
|
|
|
|
// FIXME: Ideally, this should just use EmitCallArgs.
|
|
|
|
CXXNewExpr::const_arg_iterator NewArg = E->placement_arg_begin();
|
|
|
|
|
|
|
|
// First, use the types from the function type.
|
|
|
|
// We start at 1 here because the first argument (the allocation size)
|
|
|
|
// has already been emitted.
|
|
|
|
for (unsigned i = 1, e = NewFTy->getNumArgs(); i != e; ++i, ++NewArg) {
|
|
|
|
QualType ArgType = NewFTy->getArgType(i);
|
|
|
|
|
|
|
|
assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
|
|
|
|
getTypePtr() ==
|
|
|
|
getContext().getCanonicalType(NewArg->getType()).getTypePtr() &&
|
|
|
|
"type mismatch in call argument!");
|
|
|
|
|
|
|
|
NewArgs.push_back(std::make_pair(EmitCallArg(*NewArg, ArgType),
|
|
|
|
ArgType));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either we've emitted all the call args, or we have a call to a
|
|
|
|
// variadic function.
|
|
|
|
assert((NewArg == E->placement_arg_end() || NewFTy->isVariadic()) &&
|
|
|
|
"Extra arguments in non-variadic function!");
|
|
|
|
|
|
|
|
// If we still have any arguments, emit them using the type of the argument.
|
|
|
|
for (CXXNewExpr::const_arg_iterator NewArgEnd = E->placement_arg_end();
|
|
|
|
NewArg != NewArgEnd; ++NewArg) {
|
|
|
|
QualType ArgType = NewArg->getType();
|
|
|
|
NewArgs.push_back(std::make_pair(EmitCallArg(*NewArg, ArgType),
|
|
|
|
ArgType));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the call to new.
|
|
|
|
RValue RV =
|
|
|
|
EmitCall(CGM.getTypes().getFunctionInfo(NewFTy->getResultType(), NewArgs),
|
|
|
|
CGM.GetAddrOfFunction(GlobalDecl(NewFD)),
|
|
|
|
NewArgs, NewFD);
|
|
|
|
|
2009-06-01 05:53:59 +08:00
|
|
|
// If an allocation function is declared with an empty exception specification
|
|
|
|
// it returns null to indicate failure to allocate storage. [expr.new]p13.
|
|
|
|
// (We don't need to check for null when there's no new initializer and
|
|
|
|
// we're allocating a POD type).
|
|
|
|
bool NullCheckResult = NewFTy->hasEmptyExceptionSpec() &&
|
|
|
|
!(AllocType->isPODType() && !E->hasInitializer());
|
2009-06-01 04:21:44 +08:00
|
|
|
|
2009-06-01 08:05:16 +08:00
|
|
|
llvm::BasicBlock *NewNull = 0;
|
|
|
|
llvm::BasicBlock *NewNotNull = 0;
|
|
|
|
llvm::BasicBlock *NewEnd = 0;
|
|
|
|
|
|
|
|
llvm::Value *NewPtr = RV.getScalarVal();
|
|
|
|
|
2009-06-01 05:53:59 +08:00
|
|
|
if (NullCheckResult) {
|
2009-06-01 08:05:16 +08:00
|
|
|
NewNull = createBasicBlock("new.null");
|
|
|
|
NewNotNull = createBasicBlock("new.notnull");
|
|
|
|
NewEnd = createBasicBlock("new.end");
|
|
|
|
|
|
|
|
llvm::Value *IsNull =
|
|
|
|
Builder.CreateICmpEQ(NewPtr,
|
2009-08-01 04:28:54 +08:00
|
|
|
llvm::Constant::getNullValue(NewPtr->getType()),
|
2009-06-01 08:05:16 +08:00
|
|
|
"isnull");
|
|
|
|
|
|
|
|
Builder.CreateCondBr(IsNull, NewNull, NewNotNull);
|
|
|
|
EmitBlock(NewNotNull);
|
2009-06-01 05:53:59 +08:00
|
|
|
}
|
|
|
|
|
2009-06-01 08:05:16 +08:00
|
|
|
NewPtr = Builder.CreateBitCast(NewPtr, ConvertType(E->getType()));
|
2009-06-01 05:53:59 +08:00
|
|
|
|
2009-06-01 04:56:36 +08:00
|
|
|
if (AllocType->isPODType()) {
|
2009-06-01 08:26:14 +08:00
|
|
|
if (E->getNumConstructorArgs() > 0) {
|
2009-06-01 04:56:36 +08:00
|
|
|
assert(E->getNumConstructorArgs() == 1 &&
|
|
|
|
"Can only have one argument to initializer of POD type.");
|
|
|
|
|
|
|
|
const Expr *Init = E->getConstructorArg(0);
|
|
|
|
|
2009-06-01 05:07:58 +08:00
|
|
|
if (!hasAggregateLLVMType(AllocType))
|
2009-06-01 04:56:36 +08:00
|
|
|
Builder.CreateStore(EmitScalarExpr(Init), NewPtr);
|
2009-06-01 05:07:58 +08:00
|
|
|
else if (AllocType->isAnyComplexType())
|
|
|
|
EmitComplexExprIntoAddr(Init, NewPtr, AllocType.isVolatileQualified());
|
2009-06-01 05:12:26 +08:00
|
|
|
else
|
|
|
|
EmitAggExpr(Init, NewPtr, AllocType.isVolatileQualified());
|
2009-06-01 04:56:36 +08:00
|
|
|
}
|
2009-06-01 05:53:59 +08:00
|
|
|
} else {
|
|
|
|
// Call the constructor.
|
|
|
|
CXXConstructorDecl *Ctor = E->getConstructor();
|
2009-06-01 04:56:36 +08:00
|
|
|
|
2009-06-01 05:53:59 +08:00
|
|
|
EmitCXXConstructorCall(Ctor, Ctor_Complete, NewPtr,
|
|
|
|
E->constructor_arg_begin(),
|
|
|
|
E->constructor_arg_end());
|
2009-06-01 04:21:44 +08:00
|
|
|
}
|
2009-06-01 05:53:59 +08:00
|
|
|
|
2009-06-01 08:05:16 +08:00
|
|
|
if (NullCheckResult) {
|
|
|
|
Builder.CreateBr(NewEnd);
|
|
|
|
EmitBlock(NewNull);
|
|
|
|
Builder.CreateBr(NewEnd);
|
|
|
|
EmitBlock(NewEnd);
|
|
|
|
|
|
|
|
llvm::PHINode *PHI = Builder.CreatePHI(NewPtr->getType());
|
|
|
|
PHI->reserveOperandSpace(2);
|
|
|
|
PHI->addIncoming(NewPtr, NewNotNull);
|
2009-08-01 04:28:54 +08:00
|
|
|
PHI->addIncoming(llvm::Constant::getNullValue(NewPtr->getType()), NewNull);
|
2009-06-01 08:05:16 +08:00
|
|
|
|
|
|
|
NewPtr = PHI;
|
|
|
|
}
|
|
|
|
|
2009-06-01 05:53:59 +08:00
|
|
|
return NewPtr;
|
2009-05-31 09:40:14 +08:00
|
|
|
}
|
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
|
|
|
|
ASTContext &Context) {
|
2009-04-16 05:02:13 +08:00
|
|
|
// The class has base classes - we don't support that right now.
|
|
|
|
if (RD->getNumBases() > 0)
|
|
|
|
return false;
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
|
|
|
|
I != E; ++I) {
|
2009-04-16 05:02:13 +08:00
|
|
|
// We don't support ctors for fields that aren't POD.
|
|
|
|
if (!I->getType()->isPODType())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-15 23:55:24 +08:00
|
|
|
void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
|
2009-04-17 09:58:57 +08:00
|
|
|
if (!canGenerateCXXstructor(D->getParent(), getContext())) {
|
2009-04-16 05:02:13 +08:00
|
|
|
ErrorUnsupported(D, "C++ constructor", true);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-15 23:55:24 +08:00
|
|
|
|
2009-05-05 12:44:02 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Ctor_Complete));
|
|
|
|
EmitGlobal(GlobalDecl(D, Ctor_Base));
|
2009-04-15 23:55:24 +08:00
|
|
|
}
|
2009-04-17 07:57:24 +08:00
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type) {
|
|
|
|
|
|
|
|
llvm::Function *Fn = GetAddrOfCXXConstructor(D, Type);
|
|
|
|
|
|
|
|
CodeGenFunction(*this).GenerateCode(D, Fn);
|
|
|
|
|
|
|
|
SetFunctionDefinitionAttributes(D, Fn);
|
|
|
|
SetLLVMFunctionAttributesForDefinition(D, Fn);
|
|
|
|
}
|
|
|
|
|
2009-04-17 07:57:24 +08:00
|
|
|
llvm::Function *
|
|
|
|
CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type) {
|
|
|
|
const llvm::FunctionType *FTy =
|
|
|
|
getTypes().GetFunctionType(getTypes().getFunctionInfo(D), false);
|
|
|
|
|
|
|
|
const char *Name = getMangledCXXCtorName(D, Type);
|
2009-05-13 05:21:08 +08:00
|
|
|
return cast<llvm::Function>(
|
|
|
|
GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(D, Type)));
|
2009-04-17 07:57:24 +08:00
|
|
|
}
|
2009-04-17 09:58:57 +08:00
|
|
|
|
|
|
|
const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type) {
|
|
|
|
llvm::SmallString<256> Name;
|
|
|
|
llvm::raw_svector_ostream Out(Name);
|
|
|
|
mangleCXXCtor(D, Type, Context, Out);
|
|
|
|
|
|
|
|
Name += '\0';
|
|
|
|
return UniqueMangledName(Name.begin(), Name.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
|
|
|
|
if (!canGenerateCXXstructor(D->getParent(), getContext())) {
|
|
|
|
ErrorUnsupported(D, "C++ destructor", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitCXXDestructor(D, Dtor_Complete);
|
|
|
|
EmitCXXDestructor(D, Dtor_Base);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type) {
|
|
|
|
llvm::Function *Fn = GetAddrOfCXXDestructor(D, Type);
|
|
|
|
|
|
|
|
CodeGenFunction(*this).GenerateCode(D, Fn);
|
|
|
|
|
|
|
|
SetFunctionDefinitionAttributes(D, Fn);
|
|
|
|
SetLLVMFunctionAttributesForDefinition(D, Fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *
|
|
|
|
CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type) {
|
|
|
|
const llvm::FunctionType *FTy =
|
|
|
|
getTypes().GetFunctionType(getTypes().getFunctionInfo(D), false);
|
|
|
|
|
|
|
|
const char *Name = getMangledCXXDtorName(D, Type);
|
2009-05-13 05:21:08 +08:00
|
|
|
return cast<llvm::Function>(
|
|
|
|
GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(D, Type)));
|
2009-04-17 09:58:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type) {
|
|
|
|
llvm::SmallString<256> Name;
|
|
|
|
llvm::raw_svector_ostream Out(Name);
|
|
|
|
mangleCXXDtor(D, Type, Context, Out);
|
|
|
|
|
|
|
|
Name += '\0';
|
|
|
|
return UniqueMangledName(Name.begin(), Name.end());
|
|
|
|
}
|
2009-07-21 07:18:55 +08:00
|
|
|
|
2009-08-01 07:15:31 +08:00
|
|
|
llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
|
|
|
|
llvm::Type *Ptr8Ty;
|
|
|
|
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
|
2009-08-05 04:06:48 +08:00
|
|
|
llvm::Constant *Rtti = llvm::Constant::getNullValue(Ptr8Ty);
|
2009-08-01 07:15:31 +08:00
|
|
|
|
|
|
|
if (!getContext().getLangOptions().Rtti)
|
2009-08-05 04:06:48 +08:00
|
|
|
return Rtti;
|
2009-08-01 07:15:31 +08:00
|
|
|
|
|
|
|
llvm::SmallString<256> OutName;
|
|
|
|
llvm::raw_svector_ostream Out(OutName);
|
|
|
|
QualType ClassTy;
|
2009-08-08 02:05:12 +08:00
|
|
|
ClassTy = getContext().getTagDeclType(RD);
|
2009-08-01 07:15:31 +08:00
|
|
|
mangleCXXRtti(ClassTy, getContext(), Out);
|
|
|
|
const char *Name = OutName.c_str();
|
|
|
|
llvm::GlobalVariable::LinkageTypes linktype;
|
|
|
|
linktype = llvm::GlobalValue::WeakAnyLinkage;
|
|
|
|
std::vector<llvm::Constant *> info;
|
2009-08-07 05:49:36 +08:00
|
|
|
// assert (0 && "FIXME: implement rtti descriptor");
|
2009-08-01 07:15:31 +08:00
|
|
|
// FIXME: descriptor
|
|
|
|
info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
|
2009-08-07 05:49:36 +08:00
|
|
|
// assert (0 && "FIXME: implement rtti ts");
|
2009-08-01 07:15:31 +08:00
|
|
|
// FIXME: TS
|
|
|
|
info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
|
|
|
|
|
|
|
|
llvm::Constant *C;
|
|
|
|
llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, info.size());
|
|
|
|
C = llvm::ConstantArray::get(type, info);
|
2009-08-05 04:06:48 +08:00
|
|
|
Rtti = new llvm::GlobalVariable(CGM.getModule(), type, true, linktype, C,
|
2009-08-01 07:15:31 +08:00
|
|
|
Name);
|
2009-08-05 04:06:48 +08:00
|
|
|
Rtti = llvm::ConstantExpr::getBitCast(Rtti, Ptr8Ty);
|
|
|
|
return Rtti;
|
2009-08-01 07:15:31 +08:00
|
|
|
}
|
|
|
|
|
2009-08-13 07:14:12 +08:00
|
|
|
void CodeGenFunction::GenerateVcalls(std::vector<llvm::Constant *> &methods,
|
|
|
|
const CXXRecordDecl *RD,
|
|
|
|
llvm::Type *Ptr8Ty) {
|
|
|
|
typedef CXXRecordDecl::method_iterator meth_iter;
|
|
|
|
llvm::Constant *m;
|
2009-08-13 07:25:18 +08:00
|
|
|
|
|
|
|
for (meth_iter mi = RD->method_begin(),
|
|
|
|
me = RD->method_end(); mi != me; ++mi) {
|
|
|
|
if (mi->isVirtual()) {
|
|
|
|
// FIXME: vcall: offset for virtual base for this function
|
|
|
|
m = llvm::Constant::getNullValue(Ptr8Ty);
|
|
|
|
methods.push_back(m);
|
2009-08-13 07:14:12 +08:00
|
|
|
}
|
2009-08-13 07:25:18 +08:00
|
|
|
}
|
2009-08-13 07:14:12 +08:00
|
|
|
}
|
|
|
|
|
2009-08-13 07:00:59 +08:00
|
|
|
void CodeGenFunction::GenerateMethods(std::vector<llvm::Constant *> &methods,
|
|
|
|
const CXXRecordDecl *RD,
|
|
|
|
llvm::Type *Ptr8Ty) {
|
|
|
|
typedef CXXRecordDecl::method_iterator meth_iter;
|
|
|
|
llvm::Constant *m;
|
|
|
|
|
|
|
|
for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
|
|
|
|
++mi) {
|
|
|
|
if (mi->isVirtual()) {
|
|
|
|
m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
|
|
|
|
m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
|
|
|
|
methods.push_back(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-06 23:50:11 +08:00
|
|
|
void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
|
2009-08-07 05:49:36 +08:00
|
|
|
const CXXRecordDecl *Class,
|
|
|
|
llvm::Constant *rtti,
|
|
|
|
std::vector<llvm::Constant *> &methods,
|
2009-08-07 07:48:32 +08:00
|
|
|
bool isPrimary,
|
2009-08-13 01:42:21 +08:00
|
|
|
bool ForVirtualBase,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) {
|
2009-08-06 23:50:11 +08:00
|
|
|
llvm::Type *Ptr8Ty;
|
|
|
|
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
|
2009-08-07 05:49:36 +08:00
|
|
|
llvm::Constant *m = llvm::Constant::getNullValue(Ptr8Ty);
|
|
|
|
|
|
|
|
if (RD && !RD->isDynamicClass())
|
|
|
|
return;
|
2009-08-07 07:48:32 +08:00
|
|
|
|
2009-08-11 12:03:59 +08:00
|
|
|
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Class);
|
|
|
|
|
2009-08-13 02:50:26 +08:00
|
|
|
if (isPrimary) {
|
|
|
|
// The virtual base offsets come first...
|
|
|
|
for (CXXRecordDecl::reverse_base_class_const_iterator i
|
|
|
|
= Class->bases_rbegin(),
|
|
|
|
e = Class->bases_rend(); i != e; ++i) {
|
|
|
|
if (!i->isVirtual())
|
|
|
|
continue;
|
|
|
|
const CXXRecordDecl *Base =
|
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
int64_t BaseOffset = Layout.getBaseClassOffset(Base) / 8;
|
|
|
|
llvm::Constant *m;
|
|
|
|
m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
|
|
|
|
m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
|
|
|
|
methods.push_back(m);
|
|
|
|
}
|
2009-08-11 12:03:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// then comes the the vcall offsets for all our functions...
|
|
|
|
if (isPrimary && ForVirtualBase)
|
2009-08-13 07:14:12 +08:00
|
|
|
GenerateVcalls(methods, Class, Ptr8Ty);
|
|
|
|
|
2009-08-11 12:03:59 +08:00
|
|
|
bool TopPrimary = true;
|
|
|
|
// Primary tables are composed from the chain of primaries.
|
|
|
|
if (isPrimary) {
|
|
|
|
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
|
|
|
|
const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual();
|
|
|
|
if (PrimaryBase) {
|
2009-08-13 01:42:21 +08:00
|
|
|
if (PrimaryBaseWasVirtual)
|
|
|
|
IndirectPrimary.insert(PrimaryBase);
|
2009-08-11 12:03:59 +08:00
|
|
|
TopPrimary = false;
|
|
|
|
GenerateVtableForBase(0, PrimaryBase, rtti, methods, true,
|
2009-08-13 01:42:21 +08:00
|
|
|
PrimaryBaseWasVirtual, IndirectPrimary);
|
2009-08-11 12:03:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// then come the vcall offsets for all our virtual bases.
|
|
|
|
if (!isPrimary && RD && ForVirtualBase)
|
2009-08-13 07:14:12 +08:00
|
|
|
GenerateVcalls(methods, RD, Ptr8Ty);
|
2009-08-07 07:48:32 +08:00
|
|
|
|
2009-08-11 12:03:59 +08:00
|
|
|
if (TopPrimary) {
|
|
|
|
if (RD) {
|
|
|
|
int64_t BaseOffset = -(Layout.getBaseClassOffset(RD) / 8);
|
|
|
|
m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
|
|
|
|
m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
|
|
|
|
}
|
|
|
|
methods.push_back(m);
|
|
|
|
methods.push_back(rtti);
|
2009-08-07 05:49:36 +08:00
|
|
|
}
|
|
|
|
|
2009-08-13 06:34:12 +08:00
|
|
|
if (!isPrimary) {
|
2009-08-13 07:00:59 +08:00
|
|
|
if (RD)
|
|
|
|
GenerateMethods(methods, RD, Ptr8Ty);
|
2009-08-07 05:49:36 +08:00
|
|
|
return;
|
2009-08-13 06:34:12 +08:00
|
|
|
}
|
2009-08-07 05:49:36 +08:00
|
|
|
|
|
|
|
// And add the virtuals for the class to the primary vtable.
|
2009-08-13 07:00:59 +08:00
|
|
|
GenerateMethods(methods, Class, Ptr8Ty);
|
2009-08-06 23:50:11 +08:00
|
|
|
}
|
|
|
|
|
2009-08-01 02:25:34 +08:00
|
|
|
llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
|
|
|
|
llvm::SmallString<256> OutName;
|
|
|
|
llvm::raw_svector_ostream Out(OutName);
|
|
|
|
QualType ClassTy;
|
2009-08-08 02:05:12 +08:00
|
|
|
ClassTy = getContext().getTagDeclType(RD);
|
2009-08-01 02:25:34 +08:00
|
|
|
mangleCXXVtable(ClassTy, getContext(), Out);
|
|
|
|
const char *Name = OutName.c_str();
|
2009-08-01 05:43:43 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes linktype;
|
|
|
|
linktype = llvm::GlobalValue::WeakAnyLinkage;
|
|
|
|
std::vector<llvm::Constant *> methods;
|
2009-08-13 07:03:28 +08:00
|
|
|
llvm::Type *Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
|
2009-08-06 06:37:18 +08:00
|
|
|
int64_t Offset = 0;
|
2009-08-07 05:49:36 +08:00
|
|
|
llvm::Constant *rtti = GenerateRtti(RD);
|
|
|
|
|
|
|
|
Offset += LLVMPointerWidth;
|
|
|
|
Offset += LLVMPointerWidth;
|
2009-08-06 06:37:18 +08:00
|
|
|
|
|
|
|
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
|
|
|
|
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
|
2009-08-08 04:14:05 +08:00
|
|
|
const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual();
|
2009-08-13 01:42:21 +08:00
|
|
|
llvm::SmallSet<const CXXRecordDecl *, 32> IndirectPrimary;
|
2009-08-05 05:58:42 +08:00
|
|
|
|
2009-08-07 02:05:22 +08:00
|
|
|
// The primary base comes first.
|
2009-08-08 03:00:50 +08:00
|
|
|
GenerateVtableForBase(PrimaryBase, RD, rtti, methods, true,
|
2009-08-13 01:42:21 +08:00
|
|
|
PrimaryBaseWasVirtual, IndirectPrimary);
|
2009-08-05 05:58:42 +08:00
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
|
|
|
|
e = RD->bases_end(); i != e; ++i) {
|
|
|
|
if (i->isVirtual())
|
|
|
|
continue;
|
|
|
|
const CXXRecordDecl *Base =
|
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
2009-08-06 06:37:18 +08:00
|
|
|
if (PrimaryBase != Base) {
|
2009-08-13 01:42:21 +08:00
|
|
|
GenerateVtableForBase(Base, RD, rtti, methods, false, false,
|
|
|
|
IndirectPrimary);
|
2009-08-01 05:43:43 +08:00
|
|
|
}
|
2009-08-01 02:25:34 +08:00
|
|
|
}
|
2009-08-07 02:05:22 +08:00
|
|
|
|
2009-08-06 23:50:11 +08:00
|
|
|
// FIXME: finish layout for virtual bases
|
|
|
|
// FIXME: audit indirect virtual bases
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
|
|
|
|
e = RD->vbases_end(); i != e; ++i) {
|
|
|
|
const CXXRecordDecl *Base =
|
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
2009-08-13 01:42:21 +08:00
|
|
|
if (!IndirectPrimary.count(Base))
|
|
|
|
GenerateVtableForBase(Base, RD, rtti, methods, false, true,
|
|
|
|
IndirectPrimary);
|
2009-08-06 23:50:11 +08:00
|
|
|
}
|
2009-08-06 06:37:18 +08:00
|
|
|
|
2009-08-01 05:43:43 +08:00
|
|
|
llvm::Constant *C;
|
|
|
|
llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
|
|
|
|
C = llvm::ConstantArray::get(type, methods);
|
|
|
|
llvm::Value *vtable = new llvm::GlobalVariable(CGM.getModule(), type, true,
|
|
|
|
linktype, C, Name);
|
2009-08-01 02:25:34 +08:00
|
|
|
vtable = Builder.CreateBitCast(vtable, Ptr8Ty);
|
|
|
|
vtable = Builder.CreateGEP(vtable,
|
|
|
|
llvm::ConstantInt::get(llvm::Type::Int64Ty,
|
2009-08-06 06:37:18 +08:00
|
|
|
Offset/8));
|
2009-08-01 02:25:34 +08:00
|
|
|
return vtable;
|
|
|
|
}
|
|
|
|
|
2009-08-08 07:51:33 +08:00
|
|
|
/// EmitClassMemberwiseCopy - This routine generates code to copy a class
|
|
|
|
/// object from SrcValue to DestValue. Copying can be either a bitwise copy
|
|
|
|
/// of via a copy constructor call.
|
|
|
|
void CodeGenFunction::EmitClassMemberwiseCopy(
|
2009-08-09 07:32:22 +08:00
|
|
|
llvm::Value *Dest, llvm::Value *Src,
|
2009-08-08 07:51:33 +08:00
|
|
|
const CXXRecordDecl *ClassDecl,
|
2009-08-09 07:32:22 +08:00
|
|
|
const CXXRecordDecl *BaseClassDecl, QualType Ty) {
|
|
|
|
if (ClassDecl) {
|
|
|
|
Dest = AddressCXXOfBaseClass(Dest, ClassDecl, BaseClassDecl);
|
|
|
|
Src = AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl) ;
|
|
|
|
}
|
|
|
|
if (BaseClassDecl->hasTrivialCopyConstructor()) {
|
|
|
|
EmitAggregateCopy(Dest, Src, Ty);
|
2009-08-08 07:51:33 +08:00
|
|
|
return;
|
2009-08-09 07:32:22 +08:00
|
|
|
}
|
|
|
|
|
2009-08-08 07:51:33 +08:00
|
|
|
if (CXXConstructorDecl *BaseCopyCtor =
|
2009-08-08 08:59:58 +08:00
|
|
|
BaseClassDecl->getCopyConstructor(getContext(), 0)) {
|
2009-08-08 07:51:33 +08:00
|
|
|
llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(BaseCopyCtor,
|
|
|
|
Ctor_Complete);
|
|
|
|
CallArgList CallArgs;
|
|
|
|
// Push the this (Dest) ptr.
|
|
|
|
CallArgs.push_back(std::make_pair(RValue::get(Dest),
|
|
|
|
BaseCopyCtor->getThisType(getContext())));
|
|
|
|
|
|
|
|
// Push the Src ptr.
|
|
|
|
CallArgs.push_back(std::make_pair(RValue::get(Src),
|
2009-08-11 01:20:45 +08:00
|
|
|
BaseCopyCtor->getParamDecl(0)->getType()));
|
2009-08-08 07:51:33 +08:00
|
|
|
QualType ResultType =
|
|
|
|
BaseCopyCtor->getType()->getAsFunctionType()->getResultType();
|
|
|
|
EmitCall(CGM.getTypes().getFunctionInfo(ResultType, CallArgs),
|
|
|
|
Callee, CallArgs, BaseCopyCtor);
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 02:46:38 +08:00
|
|
|
|
|
|
|
/// SynthesizeDefaultConstructor - synthesize a default constructor
|
|
|
|
void
|
|
|
|
CodeGenFunction::SynthesizeDefaultConstructor(const CXXConstructorDecl *CD,
|
|
|
|
const FunctionDecl *FD,
|
|
|
|
llvm::Function *Fn,
|
|
|
|
const FunctionArgList &Args) {
|
|
|
|
StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
|
|
|
|
EmitCtorPrologue(CD);
|
|
|
|
FinishFunction();
|
|
|
|
}
|
|
|
|
|
2009-08-09 03:31:03 +08:00
|
|
|
/// SynthesizeCXXCopyConstructor - This routine implicitly defines body of a copy
|
2009-08-08 04:22:40 +08:00
|
|
|
/// constructor, in accordance with section 12.8 (p7 and p8) of C++03
|
|
|
|
/// The implicitly-defined copy constructor for class X performs a memberwise
|
|
|
|
/// copy of its subobjects. The order of copying is the same as the order
|
|
|
|
/// of initialization of bases and members in a user-defined constructor
|
|
|
|
/// Each subobject is copied in the manner appropriate to its type:
|
|
|
|
/// if the subobject is of class type, the copy constructor for the class is
|
|
|
|
/// used;
|
|
|
|
/// if the subobject is an array, each element is copied, in the manner
|
|
|
|
/// appropriate to the element type;
|
|
|
|
/// if the subobject is of scalar type, the built-in assignment operator is
|
|
|
|
/// used.
|
|
|
|
/// Virtual base class subobjects shall be copied only once by the
|
|
|
|
/// implicitly-defined copy constructor
|
|
|
|
|
2009-08-09 03:31:03 +08:00
|
|
|
void CodeGenFunction::SynthesizeCXXCopyConstructor(const CXXConstructorDecl *CD,
|
|
|
|
const FunctionDecl *FD,
|
|
|
|
llvm::Function *Fn,
|
2009-08-08 07:51:33 +08:00
|
|
|
const FunctionArgList &Args) {
|
2009-08-08 04:22:40 +08:00
|
|
|
const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext());
|
|
|
|
assert(!ClassDecl->hasUserDeclaredCopyConstructor() &&
|
2009-08-09 03:31:03 +08:00
|
|
|
"SynthesizeCXXCopyConstructor - copy constructor has definition already");
|
|
|
|
StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
|
2009-08-08 04:22:40 +08:00
|
|
|
|
2009-08-08 08:15:41 +08:00
|
|
|
FunctionArgList::const_iterator i = Args.begin();
|
|
|
|
const VarDecl *ThisArg = i->first;
|
|
|
|
llvm::Value *ThisObj = GetAddrOfLocalVar(ThisArg);
|
|
|
|
llvm::Value *LoadOfThis = Builder.CreateLoad(ThisObj, "this");
|
|
|
|
const VarDecl *SrcArg = (i+1)->first;
|
|
|
|
llvm::Value *SrcObj = GetAddrOfLocalVar(SrcArg);
|
|
|
|
llvm::Value *LoadOfSrc = Builder.CreateLoad(SrcObj);
|
|
|
|
|
2009-08-08 04:22:40 +08:00
|
|
|
for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin();
|
|
|
|
Base != ClassDecl->bases_end(); ++Base) {
|
|
|
|
// FIXME. copy constrution of virtual base NYI
|
|
|
|
if (Base->isVirtual())
|
|
|
|
continue;
|
2009-08-08 07:51:33 +08:00
|
|
|
|
2009-08-08 04:22:40 +08:00
|
|
|
CXXRecordDecl *BaseClassDecl
|
|
|
|
= cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
|
2009-08-09 07:32:22 +08:00
|
|
|
EmitClassMemberwiseCopy(LoadOfThis, LoadOfSrc, ClassDecl, BaseClassDecl,
|
|
|
|
Base->getType());
|
2009-08-08 04:22:40 +08:00
|
|
|
}
|
|
|
|
|
2009-08-08 08:15:41 +08:00
|
|
|
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
|
|
|
|
FieldEnd = ClassDecl->field_end();
|
|
|
|
Field != FieldEnd; ++Field) {
|
|
|
|
QualType FieldType = getContext().getCanonicalType((*Field)->getType());
|
|
|
|
|
|
|
|
// FIXME. How about copying arrays!
|
|
|
|
assert(!getContext().getAsArrayType(FieldType) &&
|
|
|
|
"FIXME. Copying arrays NYI");
|
2009-08-12 02:49:54 +08:00
|
|
|
|
2009-08-08 08:15:41 +08:00
|
|
|
if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
|
|
|
|
CXXRecordDecl *FieldClassDecl
|
|
|
|
= cast<CXXRecordDecl>(FieldClassType->getDecl());
|
|
|
|
LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
|
|
|
|
LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
|
2009-08-09 07:32:22 +08:00
|
|
|
|
2009-08-08 08:15:41 +08:00
|
|
|
EmitClassMemberwiseCopy(LHS.getAddress(), RHS.getAddress(),
|
2009-08-09 07:32:22 +08:00
|
|
|
0 /*ClassDecl*/, FieldClassDecl, FieldType);
|
2009-08-08 08:15:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-08-11 02:34:26 +08:00
|
|
|
// Do a built-in assignment of scalar data members.
|
|
|
|
LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
|
|
|
|
LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
|
|
|
|
RValue RVRHS = EmitLoadOfLValue(RHS, FieldType);
|
|
|
|
EmitStoreThroughLValue(RVRHS, LHS, FieldType);
|
2009-08-08 08:15:41 +08:00
|
|
|
}
|
2009-08-09 03:31:03 +08:00
|
|
|
FinishFunction();
|
2009-08-08 04:22:40 +08:00
|
|
|
}
|
|
|
|
|
2009-08-13 05:14:35 +08:00
|
|
|
/// SynthesizeCXXCopyAssignment - Implicitly define copy assignment operator.
|
|
|
|
/// Before the implicitly-declared copy assignment operator for a class is
|
|
|
|
/// implicitly defined, all implicitly- declared copy assignment operators for
|
|
|
|
/// its direct base classes and its nonstatic data members shall have been
|
|
|
|
/// implicitly defined. [12.8-p12]
|
|
|
|
/// The implicitly-defined copy assignment operator for class X performs
|
|
|
|
/// memberwise assignment of its subob- jects. The direct base classes of X are
|
|
|
|
/// assigned first, in the order of their declaration in
|
|
|
|
/// the base-specifier-list, and then the immediate nonstatic data members of X
|
|
|
|
/// are assigned, in the order in which they were declared in the class
|
|
|
|
/// definition.Each subobject is assigned in the manner appropriate to its type:
|
|
|
|
/// — if the subobject is of class type, the copy assignment operator for the
|
|
|
|
/// class is used (as if by explicit qual- ification; that is, ignoring any
|
|
|
|
/// possible virtual overriding functions in more derived classes);
|
|
|
|
/// — if the subobject is an array, each element is assigned, in the manner
|
|
|
|
/// appropriate to the element type;
|
|
|
|
/// — if the subobject is of scalar type, the built-in assignment operator is
|
|
|
|
/// used.
|
|
|
|
void CodeGenFunction::SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD,
|
|
|
|
const FunctionDecl *FD,
|
|
|
|
llvm::Function *Fn,
|
|
|
|
const FunctionArgList &Args) {
|
|
|
|
StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
|
|
|
|
|
|
|
|
FinishFunction();
|
|
|
|
}
|
2009-08-08 04:22:40 +08:00
|
|
|
|
2009-07-21 07:18:55 +08:00
|
|
|
/// EmitCtorPrologue - This routine generates necessary code to initialize
|
|
|
|
/// base classes and non-static data members belonging to this constructor.
|
|
|
|
void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
|
2009-07-26 05:12:28 +08:00
|
|
|
const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext());
|
2009-08-06 21:41:24 +08:00
|
|
|
// FIXME: Add vbase initialization
|
2009-08-01 02:25:34 +08:00
|
|
|
llvm::Value *LoadOfThis = 0;
|
2009-07-29 02:09:28 +08:00
|
|
|
|
2009-07-26 05:12:28 +08:00
|
|
|
for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(),
|
2009-07-21 07:18:55 +08:00
|
|
|
E = CD->init_end();
|
|
|
|
B != E; ++B) {
|
|
|
|
CXXBaseOrMemberInitializer *Member = (*B);
|
|
|
|
if (Member->isBaseInitializer()) {
|
2009-08-01 02:25:34 +08:00
|
|
|
LoadOfThis = LoadCXXThis();
|
2009-07-29 02:09:28 +08:00
|
|
|
Type *BaseType = Member->getBaseClass();
|
|
|
|
CXXRecordDecl *BaseClassDecl =
|
2009-07-30 05:53:49 +08:00
|
|
|
cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
|
2009-07-29 02:09:28 +08:00
|
|
|
llvm::Value *V = AddressCXXOfBaseClass(LoadOfThis, ClassDecl,
|
|
|
|
BaseClassDecl);
|
2009-07-26 05:12:28 +08:00
|
|
|
EmitCXXConstructorCall(Member->getConstructor(),
|
|
|
|
Ctor_Complete, V,
|
|
|
|
Member->const_arg_begin(),
|
|
|
|
Member->const_arg_end());
|
2009-07-31 06:28:39 +08:00
|
|
|
} else {
|
2009-07-21 07:18:55 +08:00
|
|
|
// non-static data member initilaizers.
|
|
|
|
FieldDecl *Field = Member->getMember();
|
|
|
|
QualType FieldType = getContext().getCanonicalType((Field)->getType());
|
|
|
|
assert(!getContext().getAsArrayType(FieldType)
|
|
|
|
&& "FIXME. Field arrays initialization unsupported");
|
2009-08-11 07:56:17 +08:00
|
|
|
|
2009-08-01 02:25:34 +08:00
|
|
|
LoadOfThis = LoadCXXThis();
|
2009-07-21 07:18:55 +08:00
|
|
|
LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
|
2009-07-30 05:53:49 +08:00
|
|
|
if (FieldType->getAs<RecordType>()) {
|
2009-08-12 02:49:54 +08:00
|
|
|
if (!Field->isAnonymousStructOrUnion()) {
|
2009-07-25 01:57:02 +08:00
|
|
|
assert(Member->getConstructor() &&
|
|
|
|
"EmitCtorPrologue - no constructor to initialize member");
|
|
|
|
EmitCXXConstructorCall(Member->getConstructor(),
|
|
|
|
Ctor_Complete, LHS.getAddress(),
|
|
|
|
Member->const_arg_begin(),
|
|
|
|
Member->const_arg_end());
|
2009-08-12 02:49:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Initializing an anonymous union data member.
|
|
|
|
FieldDecl *anonMember = Member->getAnonUnionMember();
|
|
|
|
LHS = EmitLValueForField(LHS.getAddress(), anonMember, false, 0);
|
|
|
|
FieldType = anonMember->getType();
|
|
|
|
}
|
2009-07-25 01:57:02 +08:00
|
|
|
}
|
2009-07-21 07:18:55 +08:00
|
|
|
|
|
|
|
assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only");
|
2009-07-25 01:57:02 +08:00
|
|
|
Expr *RhsExpr = *Member->arg_begin();
|
2009-07-21 07:18:55 +08:00
|
|
|
llvm::Value *RHS = EmitScalarExpr(RhsExpr, true);
|
2009-08-11 07:56:17 +08:00
|
|
|
EmitStoreThroughLValue(RValue::get(RHS), LHS, FieldType);
|
2009-07-21 07:18:55 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-01 02:25:34 +08:00
|
|
|
|
|
|
|
// Initialize the vtable pointer
|
2009-08-06 06:59:44 +08:00
|
|
|
if (ClassDecl->isDynamicClass()) {
|
2009-08-01 02:25:34 +08:00
|
|
|
if (!LoadOfThis)
|
|
|
|
LoadOfThis = LoadCXXThis();
|
|
|
|
llvm::Value *VtableField;
|
|
|
|
llvm::Type *Ptr8Ty, *PtrPtr8Ty;
|
|
|
|
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
|
|
|
|
PtrPtr8Ty = llvm::PointerType::get(Ptr8Ty, 0);
|
|
|
|
VtableField = Builder.CreateBitCast(LoadOfThis, PtrPtr8Ty);
|
|
|
|
llvm::Value *vtable = GenerateVtable(ClassDecl);
|
|
|
|
Builder.CreateStore(vtable, VtableField);
|
|
|
|
}
|
2009-07-21 07:18:55 +08:00
|
|
|
}
|
2009-07-31 01:49:11 +08:00
|
|
|
|
|
|
|
/// EmitDtorEpilogue - Emit all code that comes at the end of class's
|
|
|
|
/// destructor. This is to call destructors on members and base classes
|
|
|
|
/// in reverse order of their construction.
|
|
|
|
void CodeGenFunction::EmitDtorEpilogue(const CXXDestructorDecl *DD) {
|
|
|
|
const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(DD->getDeclContext());
|
|
|
|
assert(!ClassDecl->isPolymorphic() &&
|
|
|
|
"FIXME. polymorphic destruction not supported");
|
|
|
|
(void)ClassDecl; // prevent warning.
|
|
|
|
|
|
|
|
for (CXXDestructorDecl::destr_const_iterator *B = DD->destr_begin(),
|
|
|
|
*E = DD->destr_end(); B != E; ++B) {
|
|
|
|
uintptr_t BaseOrMember = (*B);
|
|
|
|
if (DD->isMemberToDestroy(BaseOrMember)) {
|
|
|
|
FieldDecl *FD = DD->getMemberToDestroy(BaseOrMember);
|
|
|
|
QualType FieldType = getContext().getCanonicalType((FD)->getType());
|
|
|
|
assert(!getContext().getAsArrayType(FieldType)
|
|
|
|
&& "FIXME. Field arrays destruction unsupported");
|
|
|
|
const RecordType *RT = FieldType->getAs<RecordType>();
|
|
|
|
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (FieldClassDecl->hasTrivialDestructor())
|
|
|
|
continue;
|
|
|
|
llvm::Value *LoadOfThis = LoadCXXThis();
|
|
|
|
LValue LHS = EmitLValueForField(LoadOfThis, FD, false, 0);
|
|
|
|
EmitCXXDestructorCall(FieldClassDecl->getDestructor(getContext()),
|
|
|
|
Dtor_Complete, LHS.getAddress());
|
2009-07-31 06:28:39 +08:00
|
|
|
} else {
|
2009-07-31 01:49:11 +08:00
|
|
|
const RecordType *RT =
|
|
|
|
DD->getAnyBaseClassToDestroy(BaseOrMember)->getAs<RecordType>();
|
|
|
|
CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (BaseClassDecl->hasTrivialDestructor())
|
|
|
|
continue;
|
|
|
|
llvm::Value *V = AddressCXXOfBaseClass(LoadCXXThis(),
|
|
|
|
ClassDecl,BaseClassDecl);
|
|
|
|
EmitCXXDestructorCall(BaseClassDecl->getDestructor(getContext()),
|
|
|
|
Dtor_Complete, V);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|