From 01de7a44cea9f77cbcda65faad8edc8b48a3b617 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Feb 2011 06:30:58 +0000 Subject: [PATCH] Revert 124768. This reopens PR99114, but that one at least can be avoided with an #include. PR9130 cannot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124780 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCXX.cpp | 6 +-- lib/CodeGen/CGVTables.cpp | 4 +- lib/CodeGen/CodeGenModule.cpp | 23 ++++----- lib/CodeGen/CodeGenModule.h | 6 +-- lib/Sema/SemaDeclCXX.cpp | 7 +++ .../vtable-available-externally.cpp | 48 ------------------- 6 files changed, 21 insertions(+), 73 deletions(-) diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index f2128792f8..a4145675b3 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -227,8 +227,7 @@ CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D, const llvm::FunctionType *FTy = getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type), FPT->isVariadic()); - return cast(GetOrCreateLLVMFunction(Name, FTy, GD, - /*ForVTable=*/false)); + return cast(GetOrCreateLLVMFunction(Name, FTy, GD)); } void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) { @@ -285,8 +284,7 @@ CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D, const llvm::FunctionType *FTy = getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type), false); - return cast(GetOrCreateLLVMFunction(Name, FTy, GD, - /*ForVTable=*/false)); + return cast(GetOrCreateLLVMFunction(Name, FTy, GD)); } static llvm::Value *BuildVirtualCall(CodeGenFunction &CGF, uint64_t VTableIndex, diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index eadfe9f146..de6cbf52f3 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -2463,7 +2463,7 @@ llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD, getCXXABI().getMangleContext().mangleThunk(MD, Thunk, Name); const llvm::Type *Ty = getTypes().GetFunctionTypeForVTable(GD); - return GetOrCreateLLVMFunction(Name, Ty, GD, /*ForVTable=*/false); + return GetOrCreateLLVMFunction(Name, Ty, GD); } static llvm::Value *PerformTypeAdjustment(CodeGenFunction &CGF, @@ -2918,7 +2918,7 @@ CodeGenVTables::CreateVTableInitializer(const CXXRecordDecl *RD, } else { const llvm::Type *Ty = CGM.getTypes().GetFunctionTypeForVTable(GD); - Init = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); + Init = CGM.GetAddrOfFunction(GD, Ty); } Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0c541b9670..b8f91b464d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -650,8 +650,7 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { llvm::Constant *Aliasee; if (isa(DeclTy)) - Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(), - /*ForVTable=*/false); + Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl()); else Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); @@ -783,7 +782,7 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { llvm::Constant * CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName, const llvm::Type *Ty, - GlobalDecl D, bool ForVTable) { + GlobalDecl D) { // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (Entry) { @@ -841,11 +840,7 @@ 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. - // - // 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())) { + } else if (getLangOptions().CPlusPlus && D.getDecl()) { // Look for a declaration that's lexically in a record. const FunctionDecl *FD = cast(D.getDecl()); do { @@ -877,14 +872,13 @@ 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, - bool ForVTable) { + const llvm::Type *Ty) { // If there was no specific requested type, just convert it now. if (!Ty) Ty = getTypes().ConvertType(cast(GD.getDecl())->getType()); llvm::StringRef MangledName = getMangledName(GD); - return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable); + return GetOrCreateLLVMFunction(MangledName, Ty, GD); } /// CreateRuntimeFunction - Create a new runtime function with the specified @@ -892,7 +886,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Constant * CodeGenModule::CreateRuntimeFunction(const llvm::FunctionType *FTy, llvm::StringRef Name) { - return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false); + return GetOrCreateLLVMFunction(Name, FTy, GlobalDecl()); } static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) { @@ -1451,8 +1445,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { // if a deferred decl. llvm::Constant *Aliasee; if (isa(DeclTy)) - Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl(), - /*ForVTable=*/false); + Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GlobalDecl()); else Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); @@ -1518,7 +1511,7 @@ llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, const llvm::FunctionType *Ty = cast(getTypes().ConvertType(FD->getType())); - return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD), /*ForVTable=*/false); + return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD)); } llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys, diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 00f88f6f5a..7652b88fdc 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -317,8 +317,7 @@ public: /// non-null, then this function will use the specified type if it has to /// create it. llvm::Constant *GetAddrOfFunction(GlobalDecl GD, - const llvm::Type *Ty = 0, - bool ForVTable = false); + const llvm::Type *Ty = 0); /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor /// for the given type. @@ -542,8 +541,7 @@ private: llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName, const llvm::Type *Ty, - GlobalDecl D, - bool ForVTable); + GlobalDecl D); llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName, const llvm::PointerType *PTy, const VarDecl *D, diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0565a7fef9..b4c375d638 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -7118,6 +7118,13 @@ bool Sema::DefineUsedVTables() { switch (KeyFunction->getTemplateSpecializationKind()) { case TSK_Undeclared: case TSK_ExplicitSpecialization: + // The key function is in another translation unit. Mark all of the + // virtual members of this class as referenced so that we can build a + // vtable anyway (in order to do devirtualization when optimizations + // are turned on for example. + MarkVirtualMembersReferenced(Loc, Class); + continue; + case TSK_ExplicitInstantiationDeclaration: // The key function is in another translation unit. continue; diff --git a/test/CodeGenCXX/vtable-available-externally.cpp b/test/CodeGenCXX/vtable-available-externally.cpp index 11c1abda4b..b6e48c8f8c 100644 --- a/test/CodeGenCXX/vtable-available-externally.cpp +++ b/test/CodeGenCXX/vtable-available-externally.cpp @@ -53,51 +53,3 @@ namespace Test2 { void A::f() { } } - -// Test that we don't assert on this test. -namespace Test3 { - -struct A { - virtual void f(); - virtual ~A() { } -}; - -struct B : A { - B(); - virtual void f(); -}; - -B::B() { } - -void g(A* a) { - a->f(); -}; - -} - -// PR9114, test that we don't try to emit a definition of -namespace Test4 { - -template struct RefPtr { - T* p; - ~RefPtr() { - p->deref(); - } -}; - -struct A { - virtual ~A(); -}; - -struct Node; - -struct B : A { - virtual void deref(); - RefPtr m; -}; - -void f() { - RefPtr b; -} - -} -- 2.40.0