[cfe-commits] r124780 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/vtable-available-externally.cpp
Rafael Espindola
rafael.espindola at gmail.com
Wed Feb 2 22:30:58 PST 2011
Author: rafael
Date: Thu Feb 3 00:30:58 2011
New Revision: 124780
URL: http://llvm.org/viewvc/llvm-project?rev=124780&view=rev
Log:
Revert 124768.
This reopens PR99114, but that one at least can be avoided with an #include.
PR9130 cannot.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Feb 3 00:30:58 2011
@@ -227,8 +227,7 @@
const llvm::FunctionType *FTy =
getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type),
FPT->isVariadic());
- return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD,
- /*ForVTable=*/false));
+ return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD));
}
void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
@@ -285,8 +284,7 @@
const llvm::FunctionType *FTy =
getTypes().GetFunctionType(getTypes().getFunctionInfo(D, Type), false);
- return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD,
- /*ForVTable=*/false));
+ return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, GD));
}
static llvm::Value *BuildVirtualCall(CodeGenFunction &CGF, uint64_t VTableIndex,
Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Thu Feb 3 00:30:58 2011
@@ -2463,7 +2463,7 @@
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 @@
} 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);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Feb 3 00:30:58 2011
@@ -650,8 +650,7 @@
llvm::Constant *Aliasee;
if (isa<llvm::FunctionType>(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 @@
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 @@
// - 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<FunctionDecl>(D.getDecl());
do {
@@ -877,14 +872,13 @@
/// 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<ValueDecl>(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::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 @@
// if a deferred decl.
llvm::Constant *Aliasee;
if (isa<llvm::FunctionType>(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 @@
const llvm::FunctionType *Ty =
cast<llvm::FunctionType>(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,
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Feb 3 00:30:58 2011
@@ -317,8 +317,7 @@
/// 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 @@
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,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Feb 3 00:30:58 2011
@@ -7118,6 +7118,13 @@
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;
Modified: cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp?rev=124780&r1=124779&r2=124780&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp Thu Feb 3 00:30:58 2011
@@ -53,51 +53,3 @@
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 <class T> struct RefPtr {
- T* p;
- ~RefPtr() {
- p->deref();
- }
-};
-
-struct A {
- virtual ~A();
-};
-
-struct Node;
-
-struct B : A {
- virtual void deref();
- RefPtr<Node> m;
-};
-
-void f() {
- RefPtr<B> b;
-}
-
-}
More information about the cfe-commits
mailing list