2010-10-05 05:15:33 +08:00
|
|
|
//===--- CGCXX.cpp - Emit LLVM Code for declarations ----------------------===//
|
2008-08-23 00:00:37 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// We might split this into multiple files if it gets too unwieldy
|
2008-08-23 00:00:37 +08:00
|
|
|
|
2010-05-26 03:52:27 +08:00
|
|
|
#include "CGCXXABI.h"
|
2008-08-23 00:00:37 +08:00
|
|
|
#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"
|
2009-09-28 02:58:34 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
2010-06-16 07:19:56 +08:00
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
2008-08-23 00:00:37 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
/// Determines whether the given function has a trivial body that does
|
|
|
|
/// not require any specific codegen.
|
|
|
|
static bool HasTrivialBody(const FunctionDecl *FD) {
|
|
|
|
Stmt *S = FD->getBody();
|
|
|
|
if (!S)
|
|
|
|
return true;
|
|
|
|
if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Try to emit a base destructor as an alias to its primary
|
|
|
|
/// base-class destructor.
|
|
|
|
bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
|
2010-02-19 09:32:20 +08:00
|
|
|
if (!getCodeGenOpts().CXXCtorDtorAliases)
|
|
|
|
return true;
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
// If the destructor doesn't have a trivial body, we have to emit it
|
|
|
|
// separately.
|
|
|
|
if (!HasTrivialBody(D))
|
|
|
|
return true;
|
2010-02-19 09:32:20 +08:00
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
const CXXRecordDecl *Class = D->getParent();
|
|
|
|
|
|
|
|
// If we need to manipulate a VTT parameter, give up.
|
|
|
|
if (Class->getNumVBases()) {
|
|
|
|
// Extra Credit: passing extra parameters is perfectly safe
|
|
|
|
// in many calling conventions, so only bail out if the ctor's
|
|
|
|
// calling convention is nonstandard.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any fields have a non-trivial destructor, we have to emit it
|
|
|
|
// separately.
|
|
|
|
for (CXXRecordDecl::field_iterator I = Class->field_begin(),
|
|
|
|
E = Class->field_end(); I != E; ++I)
|
|
|
|
if (const RecordType *RT = (*I)->getType()->getAs<RecordType>())
|
|
|
|
if (!cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Try to find a unique base class with a non-trivial destructor.
|
|
|
|
const CXXRecordDecl *UniqueBase = 0;
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator I = Class->bases_begin(),
|
|
|
|
E = Class->bases_end(); I != E; ++I) {
|
|
|
|
|
|
|
|
// We're in the base destructor, so skip virtual bases.
|
|
|
|
if (I->isVirtual()) continue;
|
|
|
|
|
|
|
|
// Skip base classes with trivial destructors.
|
|
|
|
const CXXRecordDecl *Base
|
|
|
|
= cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
if (Base->hasTrivialDestructor()) continue;
|
|
|
|
|
|
|
|
// If we've already found a base class with a non-trivial
|
|
|
|
// destructor, give up.
|
|
|
|
if (UniqueBase) return true;
|
|
|
|
UniqueBase = Base;
|
2010-02-19 09:32:20 +08:00
|
|
|
}
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
// If we didn't find any bases with a non-trivial destructor, then
|
|
|
|
// the base destructor is actually effectively trivial, which can
|
|
|
|
// happen if it was needlessly user-defined or if there are virtual
|
|
|
|
// bases with non-trivial destructors.
|
|
|
|
if (!UniqueBase)
|
|
|
|
return true;
|
|
|
|
|
2010-03-03 11:40:11 +08:00
|
|
|
/// If we don't have a definition for the destructor yet, don't
|
|
|
|
/// emit. We can't emit aliases to declarations; that's just not
|
|
|
|
/// how aliases work.
|
2010-07-01 22:13:13 +08:00
|
|
|
const CXXDestructorDecl *BaseD = UniqueBase->getDestructor();
|
2010-07-07 19:31:19 +08:00
|
|
|
if (!BaseD->isImplicit() && !BaseD->hasBody())
|
2010-03-03 11:40:11 +08:00
|
|
|
return true;
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
// If the base is at a non-zero offset, give up.
|
|
|
|
const ASTRecordLayout &ClassLayout = Context.getASTRecordLayout(Class);
|
|
|
|
if (ClassLayout.getBaseClassOffset(UniqueBase) != 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
|
|
|
|
GlobalDecl(BaseD, Dtor_Base));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Try to emit a definition as a global alias for another definition.
|
|
|
|
bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
|
|
|
|
GlobalDecl TargetDecl) {
|
|
|
|
if (!getCodeGenOpts().CXXCtorDtorAliases)
|
|
|
|
return true;
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
// The alias will use the linkage of the referrent. If we can't
|
|
|
|
// support aliases with that linkage, fail.
|
|
|
|
llvm::GlobalValue::LinkageTypes Linkage
|
|
|
|
= getFunctionLinkage(cast<FunctionDecl>(AliasDecl.getDecl()));
|
|
|
|
|
|
|
|
switch (Linkage) {
|
|
|
|
// We can definitely emit aliases to definitions with external linkage.
|
|
|
|
case llvm::GlobalValue::ExternalLinkage:
|
|
|
|
case llvm::GlobalValue::ExternalWeakLinkage:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Same with local linkage.
|
|
|
|
case llvm::GlobalValue::InternalLinkage:
|
|
|
|
case llvm::GlobalValue::PrivateLinkage:
|
|
|
|
case llvm::GlobalValue::LinkerPrivateLinkage:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// We should try to support linkonce linkages.
|
|
|
|
case llvm::GlobalValue::LinkOnceAnyLinkage:
|
|
|
|
case llvm::GlobalValue::LinkOnceODRLinkage:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Other linkages will probably never be supported.
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-05 09:21:10 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes TargetLinkage
|
|
|
|
= getFunctionLinkage(cast<FunctionDecl>(TargetDecl.getDecl()));
|
|
|
|
|
2010-03-06 15:35:18 +08:00
|
|
|
if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
|
2010-03-05 09:21:10 +08:00
|
|
|
return true;
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
// Derive the type for the alias.
|
|
|
|
const llvm::PointerType *AliasType
|
|
|
|
= getTypes().GetFunctionType(AliasDecl)->getPointerTo();
|
|
|
|
|
|
|
|
// Find the referrent. Some aliases might require a bitcast, in
|
|
|
|
// which case the caller is responsible for ensuring the soundness
|
|
|
|
// of these semantics.
|
|
|
|
llvm::GlobalValue *Ref = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl));
|
|
|
|
llvm::Constant *Aliasee = Ref;
|
|
|
|
if (Ref->getType() != AliasType)
|
|
|
|
Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
// Create the alias with no name.
|
|
|
|
llvm::GlobalAlias *Alias =
|
2010-02-23 08:48:20 +08:00
|
|
|
new llvm::GlobalAlias(AliasType, Linkage, "", Aliasee, &getModule());
|
2010-02-19 09:32:20 +08:00
|
|
|
|
2010-02-25 04:32:01 +08:00
|
|
|
// Switch any previous uses to the alias.
|
2010-06-23 00:16:50 +08:00
|
|
|
llvm::StringRef MangledName = getMangledName(AliasDecl);
|
2010-03-20 07:29:14 +08:00
|
|
|
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
|
2010-02-19 09:32:20 +08:00
|
|
|
if (Entry) {
|
2010-02-25 04:32:01 +08:00
|
|
|
assert(Entry->isDeclaration() && "definition already exists for alias");
|
|
|
|
assert(Entry->getType() == AliasType &&
|
|
|
|
"declaration exists with different type");
|
2010-03-20 07:29:14 +08:00
|
|
|
Alias->takeName(Entry);
|
2010-02-19 09:32:20 +08:00
|
|
|
Entry->replaceAllUsesWith(Alias);
|
|
|
|
Entry->eraseFromParent();
|
2010-03-20 07:29:14 +08:00
|
|
|
} else {
|
2010-06-23 00:16:50 +08:00
|
|
|
Alias->setName(MangledName);
|
2010-02-19 09:32:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, set up the alias with its proper name and attributes.
|
|
|
|
SetCommonAttributes(AliasDecl.getDecl(), Alias);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-12 07:37:08 +08:00
|
|
|
|
2009-04-15 23:55:24 +08:00
|
|
|
void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
|
2010-02-19 09:32:20 +08:00
|
|
|
// The constructor used for constructing this as a complete class;
|
|
|
|
// constucts the virtual bases, then calls the base constructor.
|
2010-02-17 11:52:49 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Ctor_Complete));
|
2010-02-19 09:32:20 +08:00
|
|
|
|
|
|
|
// The constructor used for constructing this as a base class;
|
|
|
|
// ignores virtual bases.
|
2010-02-19 05:31:48 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Ctor_Base));
|
2009-04-15 23:55:24 +08:00
|
|
|
}
|
2009-04-17 07:57:24 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
|
2009-04-17 09:58:57 +08:00
|
|
|
CXXCtorType Type) {
|
2010-02-19 09:32:20 +08:00
|
|
|
// The complete constructor is equivalent to the base constructor
|
|
|
|
// for classes with no virtual bases. Try to emit it as an alias.
|
|
|
|
if (Type == Ctor_Complete &&
|
|
|
|
!D->getParent()->getNumVBases() &&
|
|
|
|
!TryEmitDefinitionAsAlias(GlobalDecl(D, Ctor_Complete),
|
|
|
|
GlobalDecl(D, Ctor_Base)))
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXConstructor(D, Type));
|
2010-05-25 12:30:21 +08:00
|
|
|
setFunctionLinkage(D, Fn);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-11 08:07:24 +08:00
|
|
|
CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
SetFunctionDefinitionAttributes(D, Fn);
|
|
|
|
SetLLVMFunctionAttributesForDefinition(D, Fn);
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
llvm::GlobalValue *
|
2009-09-09 23:08:12 +08:00
|
|
|
CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
|
2009-04-17 07:57:24 +08:00
|
|
|
CXXCtorType Type) {
|
2010-06-09 10:30:12 +08:00
|
|
|
GlobalDecl GD(D, Type);
|
|
|
|
|
2010-06-23 00:16:50 +08:00
|
|
|
llvm::StringRef Name = getMangledName(GD);
|
2010-03-20 07:29:14 +08:00
|
|
|
if (llvm::GlobalValue *V = GetGlobalValue(Name))
|
2010-02-19 09:32:20 +08:00
|
|
|
return V;
|
|
|
|
|
2009-11-07 02:47:57 +08:00
|
|
|
const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>();
|
2009-04-17 07:57:24 +08:00
|
|
|
const llvm::FunctionType *FTy =
|
2009-11-25 11:15:49 +08:00
|
|
|
getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type),
|
2009-11-07 02:47:57 +08:00
|
|
|
FPT->isVariadic());
|
2010-06-09 10:30:12 +08:00
|
|
|
return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD));
|
2009-04-17 07:57:24 +08:00
|
|
|
}
|
2009-04-17 09:58:57 +08:00
|
|
|
|
|
|
|
void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
|
2010-02-19 09:32:20 +08:00
|
|
|
// The destructor in a virtual table is always a 'deleting'
|
|
|
|
// destructor, which calls the complete destructor and then uses the
|
|
|
|
// appropriate operator delete.
|
2009-11-14 12:19:37 +08:00
|
|
|
if (D->isVirtual())
|
2009-12-15 10:06:15 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Dtor_Deleting));
|
2010-02-19 09:32:20 +08:00
|
|
|
|
|
|
|
// The destructor used for destructing this as a most-derived class;
|
|
|
|
// call the base destructor and then destructs any virtual bases.
|
2010-02-19 05:31:48 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Dtor_Complete));
|
2010-02-19 09:32:20 +08:00
|
|
|
|
|
|
|
// The destructor used for destructing this as a base class; ignores
|
|
|
|
// virtual bases.
|
2010-02-19 05:31:48 +08:00
|
|
|
EmitGlobal(GlobalDecl(D, Dtor_Base));
|
2009-04-17 09:58:57 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *D,
|
2009-04-17 09:58:57 +08:00
|
|
|
CXXDtorType Type) {
|
2010-02-19 09:32:20 +08:00
|
|
|
// The complete destructor is equivalent to the base destructor for
|
|
|
|
// classes with no virtual bases, so try to emit it as an alias.
|
|
|
|
if (Type == Dtor_Complete &&
|
|
|
|
!D->getParent()->getNumVBases() &&
|
|
|
|
!TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Complete),
|
|
|
|
GlobalDecl(D, Dtor_Base)))
|
|
|
|
return;
|
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
// The base destructor is equivalent to the base destructor of its
|
|
|
|
// base class if there is exactly one non-virtual base class with a
|
|
|
|
// non-trivial destructor, there are no fields with a non-trivial
|
|
|
|
// destructor, and the body of the destructor is trivial.
|
|
|
|
if (Type == Dtor_Base && !TryEmitBaseDestructorAsAlias(D))
|
|
|
|
return;
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXDestructor(D, Type));
|
2010-05-25 12:30:21 +08:00
|
|
|
setFunctionLinkage(D, Fn);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-11 08:07:24 +08:00
|
|
|
CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
SetFunctionDefinitionAttributes(D, Fn);
|
|
|
|
SetLLVMFunctionAttributesForDefinition(D, Fn);
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
llvm::GlobalValue *
|
2009-09-09 23:08:12 +08:00
|
|
|
CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
|
2009-04-17 09:58:57 +08:00
|
|
|
CXXDtorType Type) {
|
2010-06-09 10:30:12 +08:00
|
|
|
GlobalDecl GD(D, Type);
|
|
|
|
|
2010-06-23 00:16:50 +08:00
|
|
|
llvm::StringRef Name = getMangledName(GD);
|
2010-03-20 07:29:14 +08:00
|
|
|
if (llvm::GlobalValue *V = GetGlobalValue(Name))
|
2010-02-19 09:32:20 +08:00
|
|
|
return V;
|
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
const llvm::FunctionType *FTy =
|
2009-11-25 11:15:49 +08:00
|
|
|
getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type), false);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-06-09 10:30:12 +08:00
|
|
|
return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD));
|
2009-04-17 09:58:57 +08:00
|
|
|
}
|
|
|
|
|
2010-04-18 04:15:18 +08:00
|
|
|
static llvm::Value *BuildVirtualCall(CodeGenFunction &CGF, uint64_t VTableIndex,
|
2009-11-13 12:45:41 +08:00
|
|
|
llvm::Value *This, const llvm::Type *Ty) {
|
|
|
|
Ty = Ty->getPointerTo()->getPointerTo()->getPointerTo();
|
|
|
|
|
2010-04-18 04:15:18 +08:00
|
|
|
llvm::Value *VTable = CGF.Builder.CreateBitCast(This, Ty);
|
|
|
|
VTable = CGF.Builder.CreateLoad(VTable);
|
2009-11-13 12:45:41 +08:00
|
|
|
|
|
|
|
llvm::Value *VFuncPtr =
|
2010-04-18 04:15:18 +08:00
|
|
|
CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
|
2009-11-13 12:45:41 +08:00
|
|
|
return CGF.Builder.CreateLoad(VFuncPtr);
|
|
|
|
}
|
|
|
|
|
2009-08-27 04:46:33 +08:00
|
|
|
llvm::Value *
|
2009-11-13 12:45:41 +08:00
|
|
|
CodeGenFunction::BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
|
2009-08-27 04:46:33 +08:00
|
|
|
const llvm::Type *Ty) {
|
2009-11-13 12:45:41 +08:00
|
|
|
MD = MD->getCanonicalDecl();
|
2010-04-18 04:15:18 +08:00
|
|
|
uint64_t VTableIndex = CGM.getVTables().getMethodVTableIndex(MD);
|
2009-10-03 22:56:57 +08:00
|
|
|
|
2010-03-23 12:11:45 +08:00
|
|
|
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
|
2009-11-13 12:45:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *
|
|
|
|
CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
llvm::Value *&This, const llvm::Type *Ty) {
|
|
|
|
DD = cast<CXXDestructorDecl>(DD->getCanonicalDecl());
|
2010-03-23 12:11:45 +08:00
|
|
|
uint64_t VTableIndex =
|
2010-04-18 04:15:18 +08:00
|
|
|
CGM.getVTables().getMethodVTableIndex(GlobalDecl(DD, Type));
|
2009-11-13 12:45:41 +08:00
|
|
|
|
2010-03-23 12:11:45 +08:00
|
|
|
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
|
2009-08-27 04:46:33 +08:00
|
|
|
}
|
2010-05-26 03:52:27 +08:00
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Implementation for CGCXXABI. Possibly this should be moved into
|
|
|
|
/// the incomplete ABI implementations?
|
|
|
|
|
2010-09-08 09:44:27 +08:00
|
|
|
void CGCXXABI::_anchor() {}
|
2010-08-22 08:05:51 +08:00
|
|
|
|
2010-08-22 11:04:22 +08:00
|
|
|
static void ErrorUnsupportedABI(CodeGenFunction &CGF,
|
|
|
|
llvm::StringRef S) {
|
|
|
|
Diagnostic &Diags = CGF.CGM.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
|
2010-09-02 17:58:18 +08:00
|
|
|
"cannot yet compile %1 in this ABI");
|
2010-08-22 11:04:22 +08:00
|
|
|
Diags.Report(CGF.getContext().getFullLoc(CGF.CurCodeDecl->getLocation()),
|
|
|
|
DiagID)
|
|
|
|
<< S;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
static llvm::Constant *GetBogusMemberPointer(CodeGenModule &CGM,
|
|
|
|
QualType T) {
|
|
|
|
return llvm::Constant::getNullValue(CGM.getTypes().ConvertType(T));
|
|
|
|
}
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
const llvm::Type *
|
|
|
|
CGCXXABI::ConvertMemberPointerType(const MemberPointerType *MPT) {
|
|
|
|
return CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:05:51 +08:00
|
|
|
llvm::Value *CGCXXABI::EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *&This,
|
|
|
|
llvm::Value *MemPtr,
|
|
|
|
const MemberPointerType *MPT) {
|
2010-08-22 11:04:22 +08:00
|
|
|
ErrorUnsupportedABI(CGF, "calls through member pointers");
|
2010-08-22 08:05:51 +08:00
|
|
|
|
|
|
|
const FunctionProtoType *FPT =
|
|
|
|
MPT->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
const CXXRecordDecl *RD =
|
|
|
|
cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
|
|
|
|
const llvm::FunctionType *FTy =
|
2010-08-22 18:59:02 +08:00
|
|
|
CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(RD, FPT),
|
|
|
|
FPT->isVariadic());
|
2010-08-22 08:05:51 +08:00
|
|
|
return llvm::Constant::getNullValue(FTy->getPointerTo());
|
|
|
|
}
|
2010-08-22 11:04:22 +08:00
|
|
|
|
2010-09-01 05:07:20 +08:00
|
|
|
llvm::Value *CGCXXABI::EmitMemberDataPointerAddress(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Base,
|
|
|
|
llvm::Value *MemPtr,
|
|
|
|
const MemberPointerType *MPT) {
|
|
|
|
ErrorUnsupportedABI(CGF, "loads of member pointers");
|
|
|
|
const llvm::Type *Ty = CGF.ConvertType(MPT->getPointeeType())->getPointerTo();
|
|
|
|
return llvm::Constant::getNullValue(Ty);
|
|
|
|
}
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
llvm::Value *CGCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
|
|
|
|
const CastExpr *E,
|
|
|
|
llvm::Value *Src) {
|
2010-08-22 12:16:24 +08:00
|
|
|
ErrorUnsupportedABI(CGF, "member function pointer conversions");
|
2010-08-22 18:59:02 +08:00
|
|
|
return GetBogusMemberPointer(CGM, E->getType());
|
2010-08-22 14:43:33 +08:00
|
|
|
}
|
|
|
|
|
2010-08-22 16:30:07 +08:00
|
|
|
llvm::Value *
|
2010-08-23 09:21:21 +08:00
|
|
|
CGCXXABI::EmitMemberPointerComparison(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *L,
|
|
|
|
llvm::Value *R,
|
|
|
|
const MemberPointerType *MPT,
|
|
|
|
bool Inequality) {
|
2010-08-22 16:30:07 +08:00
|
|
|
ErrorUnsupportedABI(CGF, "member function pointer comparison");
|
|
|
|
return CGF.Builder.getFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *
|
2010-08-23 09:21:21 +08:00
|
|
|
CGCXXABI::EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *MemPtr,
|
|
|
|
const MemberPointerType *MPT) {
|
2010-08-22 16:30:07 +08:00
|
|
|
ErrorUnsupportedABI(CGF, "member function pointer null testing");
|
|
|
|
return CGF.Builder.getFalse();
|
|
|
|
}
|
|
|
|
|
2010-08-22 12:16:24 +08:00
|
|
|
llvm::Constant *
|
2010-08-23 09:21:21 +08:00
|
|
|
CGCXXABI::EmitMemberPointerConversion(llvm::Constant *C, const CastExpr *E) {
|
2010-08-22 18:59:02 +08:00
|
|
|
return GetBogusMemberPointer(CGM, E->getType());
|
2010-08-22 12:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *
|
2010-08-23 09:21:21 +08:00
|
|
|
CGCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) {
|
2010-08-22 18:59:02 +08:00
|
|
|
return GetBogusMemberPointer(CGM, QualType(MPT, 0));
|
2010-08-22 12:16:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
|
2010-08-22 18:59:02 +08:00
|
|
|
return GetBogusMemberPointer(CGM,
|
|
|
|
CGM.getContext().getMemberPointerType(MD->getType(),
|
|
|
|
MD->getParent()->getTypeForDecl()));
|
2010-08-22 14:43:33 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
llvm::Constant *CGCXXABI::EmitMemberPointer(const FieldDecl *FD) {
|
|
|
|
return GetBogusMemberPointer(CGM,
|
|
|
|
CGM.getContext().getMemberPointerType(FD->getType(),
|
|
|
|
FD->getParent()->getTypeForDecl()));
|
|
|
|
}
|
|
|
|
|
2010-08-23 05:01:12 +08:00
|
|
|
bool CGCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
|
|
|
|
// Fake answer.
|
|
|
|
return true;
|
2010-08-22 11:04:22 +08:00
|
|
|
}
|
2010-08-31 15:33:07 +08:00
|
|
|
|
|
|
|
void CGCXXABI::BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params) {
|
|
|
|
const CXXMethodDecl *MD = cast<CXXMethodDecl>(CGF.CurGD.getDecl());
|
|
|
|
|
|
|
|
// FIXME: I'm not entirely sure I like using a fake decl just for code
|
|
|
|
// generation. Maybe we can come up with a better way?
|
|
|
|
ImplicitParamDecl *ThisDecl
|
|
|
|
= ImplicitParamDecl::Create(CGM.getContext(), 0, MD->getLocation(),
|
|
|
|
&CGM.getContext().Idents.get("this"),
|
|
|
|
MD->getThisType(CGM.getContext()));
|
|
|
|
Params.push_back(std::make_pair(ThisDecl, ThisDecl->getType()));
|
|
|
|
getThisDecl(CGF) = ThisDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGCXXABI::EmitThisParam(CodeGenFunction &CGF) {
|
|
|
|
/// Initialize the 'this' slot.
|
|
|
|
assert(getThisDecl(CGF) && "no 'this' variable for function");
|
|
|
|
getThisValue(CGF)
|
|
|
|
= CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(getThisDecl(CGF)),
|
|
|
|
"this");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGCXXABI::EmitReturnFromThunk(CodeGenFunction &CGF,
|
|
|
|
RValue RV, QualType ResultType) {
|
|
|
|
CGF.EmitReturnOfRValue(RV, ResultType);
|
|
|
|
}
|
2010-09-02 17:58:18 +08:00
|
|
|
|
|
|
|
CharUnits CGCXXABI::GetArrayCookieSize(QualType ElementType) {
|
|
|
|
return CharUnits::Zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *CGCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *NewPtr,
|
|
|
|
llvm::Value *NumElements,
|
|
|
|
QualType ElementType) {
|
|
|
|
// Should never be called.
|
|
|
|
ErrorUnsupportedABI(CGF, "array cookie initialization");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
|
|
|
|
QualType ElementType, llvm::Value *&NumElements,
|
|
|
|
llvm::Value *&AllocPtr, CharUnits &CookieSize) {
|
|
|
|
ErrorUnsupportedABI(CGF, "array cookie reading");
|
|
|
|
|
|
|
|
// This should be enough to avoid assertions.
|
|
|
|
NumElements = 0;
|
|
|
|
AllocPtr = llvm::Constant::getNullValue(CGF.Builder.getInt8PtrTy());
|
|
|
|
CookieSize = CharUnits::Zero();
|
|
|
|
}
|
2010-09-08 09:44:27 +08:00
|
|
|
|
|
|
|
void CGCXXABI::EmitStaticLocalInit(CodeGenFunction &CGF,
|
|
|
|
const VarDecl &D,
|
|
|
|
llvm::GlobalVariable *GV) {
|
|
|
|
ErrorUnsupportedABI(CGF, "static local variable initialization");
|
|
|
|
}
|