diff options
author | Anders Carlsson <andersca@mac.com> | 2011-02-03 02:08:44 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-02-03 02:08:44 +0000 |
commit | aedd9d5ad3cc776fd61457050bcd54cac4c5ea66 (patch) | |
tree | e87d32a8c47c8825b7774c82088568999cb01285 /lib/CodeGen/CodeGenModule.cpp | |
parent | b51eee43676c2f4b7c4e1fa1648b438051b2b098 (diff) |
Don't try to mark virtual members referenced for classes where the key function
is not defined in the current translation unit. Doing so lead to compile errors
such as PR9114.
Instead, when CodeGen is building the vtable, don't try to emit a definition
for functions that aren't marked used in the current translation unit.
Fixes PR9114.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124768 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b8f91b464d..0c541b9670 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -650,7 +650,8 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { llvm::Constant *Aliasee; if (isa<llvm::FunctionType>(DeclTy)) - Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl()); + Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(), + /*ForVTable=*/false); else Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); @@ -782,7 +783,7 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { llvm::Constant * CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName, const llvm::Type *Ty, - GlobalDecl D) { + GlobalDecl D, bool ForVTable) { // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (Entry) { @@ -840,7 +841,11 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName, // - special member functions with implicit definitions // If we ever change our AST traversal to walk into class methods, // 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. const FunctionDecl *FD = cast<FunctionDecl>(D.getDecl()); do { @@ -872,13 +877,14 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName, /// 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). 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 (!Ty) Ty = getTypes().ConvertType(cast<ValueDecl>(GD.getDecl())->getType()); 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 @@ -886,7 +892,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Constant * CodeGenModule::CreateRuntimeFunction(const llvm::FunctionType *FTy, llvm::StringRef Name) { - return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl()); + return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false); } static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) { @@ -1445,7 +1451,8 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { // if a deferred decl. llvm::Constant *Aliasee; if (isa<llvm::FunctionType>(DeclTy)) - Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl()); + Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(), + /*ForVTable=*/false); else Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); @@ -1511,7 +1518,7 @@ llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, const llvm::FunctionType *Ty = 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, |