|
@@ -650,7 +650,8 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
|
|
|
|
|
|
llvm::Constant *Aliasee;
|
|
llvm::Constant *Aliasee;
|
|
if (isa<llvm::FunctionType>(DeclTy))
|
|
if (isa<llvm::FunctionType>(DeclTy))
|
|
- Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl());
|
|
|
|
|
|
+ Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(),
|
|
|
|
+ /*ForVTable=*/false);
|
|
else
|
|
else
|
|
Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
|
|
Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
|
|
llvm::PointerType::getUnqual(DeclTy), 0);
|
|
llvm::PointerType::getUnqual(DeclTy), 0);
|
|
@@ -782,7 +783,7 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
|
|
llvm::Constant *
|
|
llvm::Constant *
|
|
CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
|
|
CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
|
|
const llvm::Type *Ty,
|
|
const llvm::Type *Ty,
|
|
- GlobalDecl D) {
|
|
|
|
|
|
+ GlobalDecl D, bool ForVTable) {
|
|
// Lookup the entry, lazily creating it if necessary.
|
|
// Lookup the entry, lazily creating it if necessary.
|
|
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
|
|
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
|
|
if (Entry) {
|
|
if (Entry) {
|
|
@@ -840,7 +841,11 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
|
|
// - special member functions with implicit definitions
|
|
// - special member functions with implicit definitions
|
|
// If we ever change our AST traversal to walk into class methods,
|
|
// If we ever change our AST traversal to walk into class methods,
|
|
// this will be unnecessary.
|
|
// this will be unnecessary.
|
|
- } else if (getLangOptions().CPlusPlus && D.getDecl()) {
|
|
|
|
|
|
+ //
|
|
|
|
+ // We also don't emit a definition for a function if it's going to be an entry
|
|
|
|
+ // in a vtable, unless it's already marked as used.
|
|
|
|
+ } else if (getLangOptions().CPlusPlus && D.getDecl() &&
|
|
|
|
+ !(ForVTable && !D.getDecl()->isUsed())) {
|
|
// Look for a declaration that's lexically in a record.
|
|
// Look for a declaration that's lexically in a record.
|
|
const FunctionDecl *FD = cast<FunctionDecl>(D.getDecl());
|
|
const FunctionDecl *FD = cast<FunctionDecl>(D.getDecl());
|
|
do {
|
|
do {
|
|
@@ -872,13 +877,14 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
|
|
/// non-null, then this function will use the specified type if it has to
|
|
/// non-null, then this function will use the specified type if it has to
|
|
/// create it (this occurs when we see a definition of the function).
|
|
/// create it (this occurs when we see a definition of the function).
|
|
llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
|
|
llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
|
|
- const llvm::Type *Ty) {
|
|
|
|
|
|
+ const llvm::Type *Ty,
|
|
|
|
+ bool ForVTable) {
|
|
// If there was no specific requested type, just convert it now.
|
|
// If there was no specific requested type, just convert it now.
|
|
if (!Ty)
|
|
if (!Ty)
|
|
Ty = getTypes().ConvertType(cast<ValueDecl>(GD.getDecl())->getType());
|
|
Ty = getTypes().ConvertType(cast<ValueDecl>(GD.getDecl())->getType());
|
|
|
|
|
|
llvm::StringRef MangledName = getMangledName(GD);
|
|
llvm::StringRef MangledName = getMangledName(GD);
|
|
- return GetOrCreateLLVMFunction(MangledName, Ty, GD);
|
|
|
|
|
|
+ return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable);
|
|
}
|
|
}
|
|
|
|
|
|
/// CreateRuntimeFunction - Create a new runtime function with the specified
|
|
/// CreateRuntimeFunction - Create a new runtime function with the specified
|
|
@@ -886,7 +892,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
|
|
llvm::Constant *
|
|
llvm::Constant *
|
|
CodeGenModule::CreateRuntimeFunction(const llvm::FunctionType *FTy,
|
|
CodeGenModule::CreateRuntimeFunction(const llvm::FunctionType *FTy,
|
|
llvm::StringRef Name) {
|
|
llvm::StringRef Name) {
|
|
- return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl());
|
|
|
|
|
|
+ return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false);
|
|
}
|
|
}
|
|
|
|
|
|
static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) {
|
|
static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) {
|
|
@@ -1445,7 +1451,8 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
|
|
// if a deferred decl.
|
|
// if a deferred decl.
|
|
llvm::Constant *Aliasee;
|
|
llvm::Constant *Aliasee;
|
|
if (isa<llvm::FunctionType>(DeclTy))
|
|
if (isa<llvm::FunctionType>(DeclTy))
|
|
- Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl());
|
|
|
|
|
|
+ Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(),
|
|
|
|
+ /*ForVTable=*/false);
|
|
else
|
|
else
|
|
Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
|
|
Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
|
|
llvm::PointerType::getUnqual(DeclTy), 0);
|
|
llvm::PointerType::getUnqual(DeclTy), 0);
|
|
@@ -1511,7 +1518,7 @@ llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
|
|
const llvm::FunctionType *Ty =
|
|
const llvm::FunctionType *Ty =
|
|
cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType()));
|
|
cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType()));
|
|
|
|
|
|
- return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD));
|
|
|
|
|
|
+ return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD), /*ForVTable=*/false);
|
|
}
|
|
}
|
|
|
|
|
|
llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,
|
|
llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,
|