2009-12-10 08:16:00 +08:00
|
|
|
//===--- CGDeclCXX.cpp - Emit LLVM Code for C++ 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 code generation of C++ declarations
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
2011-01-14 04:00:54 +08:00
|
|
|
#include "CGObjCRuntime.h"
|
2010-08-31 15:33:07 +08:00
|
|
|
#include "CGCXXABI.h"
|
2010-06-16 07:19:56 +08:00
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
2010-05-16 09:24:12 +08:00
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
|
2009-12-10 08:16:00 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2009-12-10 08:57:45 +08:00
|
|
|
static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
assert(D.hasGlobalStorage() && "VarDecl must have global storage!");
|
|
|
|
assert(!D.getType()->isReferenceType() &&
|
|
|
|
"Should not call EmitDeclInit on a reference!");
|
|
|
|
|
|
|
|
ASTContext &Context = CGF.getContext();
|
2009-12-10 08:16:00 +08:00
|
|
|
|
2011-06-16 12:16:24 +08:00
|
|
|
unsigned alignment = Context.getDeclAlign(&D).getQuantity();
|
|
|
|
QualType type = D.getType();
|
|
|
|
LValue lv = CGF.MakeAddrLValue(DeclPtr, type, alignment);
|
|
|
|
|
|
|
|
const Expr *Init = D.getInit();
|
|
|
|
if (!CGF.hasAggregateLLVMType(type)) {
|
2011-01-14 04:00:54 +08:00
|
|
|
CodeGenModule &CGM = CGF.CGM;
|
2011-06-16 12:16:24 +08:00
|
|
|
if (lv.isObjCStrong())
|
2011-06-16 07:02:42 +08:00
|
|
|
CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init),
|
|
|
|
DeclPtr, D.isThreadSpecified());
|
2011-06-16 12:16:24 +08:00
|
|
|
else if (lv.isObjCWeak())
|
|
|
|
CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init),
|
|
|
|
DeclPtr);
|
2011-01-14 04:00:54 +08:00
|
|
|
else
|
2011-06-16 12:16:24 +08:00
|
|
|
CGF.EmitScalarInit(Init, &D, lv, false);
|
|
|
|
} else if (type->isAnyComplexType()) {
|
|
|
|
CGF.EmitComplexExprIntoAddr(Init, DeclPtr, lv.isVolatile());
|
2009-12-10 08:16:00 +08:00
|
|
|
} else {
|
2011-06-16 12:16:24 +08:00
|
|
|
CGF.EmitAggExpr(Init, AggValueSlot::forLValue(lv, true));
|
2009-12-10 08:16:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:44:27 +08:00
|
|
|
/// Emit code to cause the destruction of the given variable with
|
|
|
|
/// static storage duration.
|
2010-05-05 23:38:32 +08:00
|
|
|
static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
CodeGenModule &CGM = CGF.CGM;
|
|
|
|
ASTContext &Context = CGF.getContext();
|
|
|
|
|
|
|
|
QualType T = D.getType();
|
|
|
|
|
2010-07-30 12:56:58 +08:00
|
|
|
// Drill down past array types.
|
2010-05-05 23:38:32 +08:00
|
|
|
const ConstantArrayType *Array = Context.getAsConstantArrayType(T);
|
|
|
|
if (Array)
|
|
|
|
T = Context.getBaseElementType(Array);
|
|
|
|
|
2010-07-30 12:56:58 +08:00
|
|
|
/// If that's not a record, we're done.
|
|
|
|
/// FIXME: __attribute__((cleanup)) ?
|
2010-05-05 23:38:32 +08:00
|
|
|
const RecordType *RT = T->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (RD->hasTrivialDestructor())
|
|
|
|
return;
|
|
|
|
|
2010-07-01 22:13:13 +08:00
|
|
|
CXXDestructorDecl *Dtor = RD->getDestructor();
|
2010-05-05 23:38:32 +08:00
|
|
|
|
|
|
|
llvm::Constant *DtorFn;
|
|
|
|
if (Array) {
|
|
|
|
DtorFn =
|
2010-06-09 06:14:59 +08:00
|
|
|
CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(Dtor, Array,
|
|
|
|
DeclPtr);
|
2010-05-05 23:38:32 +08:00
|
|
|
const llvm::Type *Int8PtrTy =
|
2010-06-09 06:14:59 +08:00
|
|
|
llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
|
2010-05-05 23:38:32 +08:00
|
|
|
DeclPtr = llvm::Constant::getNullValue(Int8PtrTy);
|
|
|
|
} else
|
|
|
|
DtorFn = CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete);
|
|
|
|
|
|
|
|
CGF.EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
|
|
|
|
}
|
|
|
|
|
2009-12-10 08:57:45 +08:00
|
|
|
void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
|
|
|
|
const Expr *Init = D.getInit();
|
|
|
|
QualType T = D.getType();
|
|
|
|
|
|
|
|
if (!T->isReferenceType()) {
|
|
|
|
EmitDeclInit(*this, D, DeclPtr);
|
2010-05-05 23:38:32 +08:00
|
|
|
EmitDeclDestroy(*this, D, DeclPtr);
|
2009-12-10 08:57:45 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-06-28 01:52:15 +08:00
|
|
|
|
2010-08-21 10:24:36 +08:00
|
|
|
unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
|
2010-06-28 01:52:15 +08:00
|
|
|
RValue RV = EmitReferenceBindingToExpr(Init, &D);
|
2010-08-21 10:24:36 +08:00
|
|
|
EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
|
2009-12-10 08:57:45 +08:00
|
|
|
}
|
2009-12-10 08:30:05 +08:00
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
void
|
|
|
|
CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
|
|
|
|
llvm::Constant *DeclPtr) {
|
|
|
|
// Generate a global destructor entry if not using __cxa_atexit.
|
|
|
|
if (!CGM.getCodeGenOpts().CXAAtExit) {
|
|
|
|
CGM.AddCXXDtorEntry(DtorFn, DeclPtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-10 08:30:05 +08:00
|
|
|
// Get the destructor function type
|
|
|
|
const llvm::Type *DtorFnTy =
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()),
|
2011-05-28 22:26:31 +08:00
|
|
|
Int8PtrTy, false);
|
2009-12-10 08:30:05 +08:00
|
|
|
DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
|
|
|
|
|
2011-05-28 22:26:31 +08:00
|
|
|
const llvm::Type *Params[] = { DtorFnTy, Int8PtrTy, Int8PtrTy };
|
2009-12-10 08:30:05 +08:00
|
|
|
|
|
|
|
// 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");
|
2011-03-21 04:52:32 +08:00
|
|
|
if (llvm::Function *Fn = dyn_cast<llvm::Function>(AtExitFn))
|
|
|
|
Fn->setDoesNotThrow();
|
2009-12-10 08:30:05 +08:00
|
|
|
|
|
|
|
llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy,
|
|
|
|
"__dso_handle");
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
|
|
|
|
llvm::GlobalVariable *DeclPtr) {
|
2011-03-18 10:56:14 +08:00
|
|
|
// If we've been asked to forbid guard variables, emit an error now.
|
|
|
|
// This diagnostic is hard-coded for Darwin's use case; we can find
|
|
|
|
// better phrasing if someone else needs it.
|
|
|
|
if (CGM.getCodeGenOpts().ForbidGuardVariables)
|
|
|
|
CGM.Error(D.getLocation(),
|
|
|
|
"this initialization requires a guard variable, which "
|
|
|
|
"the kernel does not support");
|
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr);
|
2010-09-08 09:44:27 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 06:40:05 +08:00
|
|
|
static llvm::Function *
|
|
|
|
CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
|
|
|
|
const llvm::FunctionType *FTy,
|
|
|
|
llvm::StringRef Name) {
|
|
|
|
llvm::Function *Fn =
|
|
|
|
llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
|
|
|
|
Name, &CGM.getModule());
|
2011-02-16 02:54:46 +08:00
|
|
|
if (!CGM.getContext().getLangOptions().AppleKext) {
|
|
|
|
// Set the section if needed.
|
|
|
|
if (const char *Section =
|
|
|
|
CGM.getContext().Target.getStaticInitSectionSpecifier())
|
|
|
|
Fn->setSection(Section);
|
|
|
|
}
|
2010-06-09 06:47:50 +08:00
|
|
|
|
2011-02-28 08:33:03 +08:00
|
|
|
if (!CGM.getLangOptions().Exceptions)
|
2010-07-06 12:38:10 +08:00
|
|
|
Fn->setDoesNotThrow();
|
|
|
|
|
2010-06-09 06:40:05 +08:00
|
|
|
return Fn;
|
|
|
|
}
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
void
|
2010-11-06 17:44:32 +08:00
|
|
|
CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
|
|
|
|
llvm::GlobalVariable *Addr) {
|
2010-01-08 08:50:11 +08:00
|
|
|
const llvm::FunctionType *FTy
|
|
|
|
= llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Create a variable initialization function.
|
|
|
|
llvm::Function *Fn =
|
2010-06-09 06:40:05 +08:00
|
|
|
CreateGlobalInitOrDestructFunction(*this, FTy, "__cxx_global_var_init");
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr);
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2010-06-22 02:45:05 +08:00
|
|
|
if (D->hasAttr<InitPriorityAttr>()) {
|
|
|
|
unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
|
2010-06-27 14:32:58 +08:00
|
|
|
OrderGlobalInits Key(order, PrioritizedCXXGlobalInits.size());
|
2010-06-22 05:27:42 +08:00
|
|
|
PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
|
2010-07-16 07:40:35 +08:00
|
|
|
DelayedCXXInitPosition.erase(D);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
llvm::DenseMap<const Decl *, unsigned>::iterator I =
|
|
|
|
DelayedCXXInitPosition.find(D);
|
|
|
|
if (I == DelayedCXXInitPosition.end()) {
|
|
|
|
CXXGlobalInits.push_back(Fn);
|
|
|
|
} else {
|
|
|
|
assert(CXXGlobalInits[I->second] == 0);
|
|
|
|
CXXGlobalInits[I->second] = Fn;
|
|
|
|
DelayedCXXInitPosition.erase(I);
|
|
|
|
}
|
2010-06-22 02:45:05 +08:00
|
|
|
}
|
2010-01-08 08:50:11 +08:00
|
|
|
}
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
void
|
|
|
|
CodeGenModule::EmitCXXGlobalInitFunc() {
|
2010-07-16 07:40:35 +08:00
|
|
|
while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
|
|
|
|
CXXGlobalInits.pop_back();
|
|
|
|
|
2010-06-22 02:45:05 +08:00
|
|
|
if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
|
2009-12-10 08:30:05 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const llvm::FunctionType *FTy
|
|
|
|
= llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Create our global initialization function.
|
2010-06-09 06:40:05 +08:00
|
|
|
llvm::Function *Fn =
|
|
|
|
CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2010-06-22 02:45:05 +08:00
|
|
|
if (!PrioritizedCXXGlobalInits.empty()) {
|
2010-06-22 03:49:38 +08:00
|
|
|
llvm::SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
|
|
|
|
llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
|
2010-06-22 08:23:08 +08:00
|
|
|
PrioritizedCXXGlobalInits.end());
|
2010-06-22 02:45:05 +08:00
|
|
|
for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
|
|
|
|
llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
|
|
|
|
LocalCXXGlobalInits.push_back(Fn);
|
|
|
|
}
|
2010-07-16 07:40:35 +08:00
|
|
|
LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
|
2010-06-22 02:45:05 +08:00
|
|
|
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
|
|
|
|
&LocalCXXGlobalInits[0],
|
|
|
|
LocalCXXGlobalInits.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
|
|
|
|
&CXXGlobalInits[0],
|
|
|
|
CXXGlobalInits.size());
|
2010-03-20 12:15:41 +08:00
|
|
|
AddGlobalCtor(Fn);
|
2011-05-06 23:24:04 +08:00
|
|
|
CXXGlobalInits.clear();
|
|
|
|
PrioritizedCXXGlobalInits.clear();
|
2010-03-20 12:15:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenModule::EmitCXXGlobalDtorFunc() {
|
|
|
|
if (CXXGlobalDtors.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const llvm::FunctionType *FTy
|
|
|
|
= llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
|
|
|
|
false);
|
2009-12-10 08:30:05 +08:00
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
// Create our global destructor function.
|
|
|
|
llvm::Function *Fn =
|
2010-06-09 06:40:05 +08:00
|
|
|
CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__D_a");
|
2010-03-20 12:15:41 +08:00
|
|
|
|
|
|
|
CodeGenFunction(*this).GenerateCXXGlobalDtorFunc(Fn, CXXGlobalDtors);
|
|
|
|
AddGlobalDtor(Fn);
|
|
|
|
}
|
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
/// Emit the code necessary to initialize the given global variable.
|
2010-03-20 12:15:41 +08:00
|
|
|
void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
|
2010-11-06 17:44:32 +08:00
|
|
|
const VarDecl *D,
|
|
|
|
llvm::GlobalVariable *Addr) {
|
2011-03-09 12:27:21 +08:00
|
|
|
StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
|
|
|
|
getTypes().getNullaryFunctionInfo(),
|
|
|
|
FunctionArgList(), SourceLocation());
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
// Use guarded initialization if the global variable is weak due to
|
2011-04-12 09:46:54 +08:00
|
|
|
// being a class template's static data member. These will always
|
|
|
|
// have weak_odr linkage.
|
|
|
|
if (Addr->getLinkage() == llvm::GlobalValue::WeakODRLinkage &&
|
|
|
|
D->isStaticDataMember() &&
|
|
|
|
D->getInstantiatedFromStaticDataMember()) {
|
2010-11-06 17:44:32 +08:00
|
|
|
EmitCXXGuardedInit(*D, Addr);
|
|
|
|
} else {
|
|
|
|
EmitCXXGlobalVarDeclInit(*D, Addr);
|
2010-10-27 06:47:47 +08:00
|
|
|
}
|
2010-01-08 08:50:11 +08:00
|
|
|
|
|
|
|
FinishFunction();
|
2010-03-20 12:15:41 +08:00
|
|
|
}
|
2009-12-10 08:30:05 +08:00
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
|
|
|
|
llvm::Constant **Decls,
|
|
|
|
unsigned NumDecls) {
|
2011-03-09 12:27:21 +08:00
|
|
|
StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
|
|
|
|
getTypes().getNullaryFunctionInfo(),
|
|
|
|
FunctionArgList(), SourceLocation());
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
RunCleanupsScope Scope(*this);
|
|
|
|
|
|
|
|
// When building in Objective-C++ ARC mode, create an autorelease pool
|
|
|
|
// around the global initializers.
|
|
|
|
if (getLangOptions().ObjCAutoRefCount && getLangOptions().CPlusPlus) {
|
|
|
|
llvm::Value *token = EmitObjCAutoreleasePoolPush();
|
|
|
|
EmitObjCAutoreleasePoolCleanup(token);
|
|
|
|
}
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
for (unsigned i = 0; i != NumDecls; ++i)
|
2010-07-16 07:40:35 +08:00
|
|
|
if (Decls[i])
|
2011-06-16 07:02:42 +08:00
|
|
|
Builder.CreateCall(Decls[i]);
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
Scope.ForceCleanup();
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
FinishFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
|
2010-06-19 13:52:45 +08:00
|
|
|
const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
|
2010-03-20 12:15:41 +08:00
|
|
|
&DtorsAndObjects) {
|
2011-03-09 12:27:21 +08:00
|
|
|
StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
|
|
|
|
getTypes().getNullaryFunctionInfo(),
|
|
|
|
FunctionArgList(), SourceLocation());
|
2010-03-20 12:15:41 +08:00
|
|
|
|
|
|
|
// Emit the dtors, in reverse order from construction.
|
2010-04-27 04:35:54 +08:00
|
|
|
for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
|
2010-06-19 13:52:45 +08:00
|
|
|
llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
|
2010-04-27 04:35:54 +08:00
|
|
|
llvm::CallInst *CI = Builder.CreateCall(Callee,
|
|
|
|
DtorsAndObjects[e - i - 1].second);
|
|
|
|
// Make sure the call and the callee agree on calling convention.
|
|
|
|
if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
|
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
}
|
2010-03-20 12:15:41 +08:00
|
|
|
|
|
|
|
FinishFunction();
|
2009-12-10 08:30:05 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 06:17:27 +08:00
|
|
|
/// GenerateCXXAggrDestructorHelper - Generates a helper function which when
|
|
|
|
/// invoked, calls the default destructor on array elements in reverse order of
|
|
|
|
/// construction.
|
|
|
|
llvm::Function *
|
|
|
|
CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
|
|
|
|
const ArrayType *Array,
|
|
|
|
llvm::Value *This) {
|
2011-03-09 12:27:21 +08:00
|
|
|
FunctionArgList args;
|
|
|
|
ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
|
|
|
|
args.push_back(&dst);
|
2010-06-09 06:17:27 +08:00
|
|
|
|
|
|
|
const CGFunctionInfo &FI =
|
2011-03-09 12:27:21 +08:00
|
|
|
CGM.getTypes().getFunctionInfo(getContext().VoidTy, args,
|
2010-06-09 06:17:27 +08:00
|
|
|
FunctionType::ExtInfo());
|
|
|
|
const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
|
2010-06-09 06:40:05 +08:00
|
|
|
llvm::Function *Fn =
|
|
|
|
CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
|
2010-06-09 06:17:27 +08:00
|
|
|
|
2011-03-09 12:27:21 +08:00
|
|
|
StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FI, args,
|
|
|
|
SourceLocation());
|
2010-06-09 06:17:27 +08:00
|
|
|
|
|
|
|
QualType BaseElementTy = getContext().getBaseElementType(Array);
|
|
|
|
const llvm::Type *BasePtr = ConvertType(BaseElementTy)->getPointerTo();
|
|
|
|
llvm::Value *BaseAddrPtr = Builder.CreateBitCast(This, BasePtr);
|
|
|
|
|
|
|
|
EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
|
|
|
|
|
|
|
|
FinishFunction();
|
|
|
|
|
|
|
|
return Fn;
|
|
|
|
}
|