From: Rafael Espindola Date: Mon, 19 Apr 2010 00:44:22 +0000 (+0000) Subject: If a method is virtual and the class key function is in another file, emit the method... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8cab18e8562994b87f8d7c06f8c122beb712677;p=clang If a method is virtual and the class key function is in another file, emit the method as available_externally. Fixes PR6747 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101757 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGVTables.h b/lib/CodeGen/CGVTables.h index b4262fe224..bc113ec42f 100644 --- a/lib/CodeGen/CGVTables.h +++ b/lib/CodeGen/CGVTables.h @@ -295,6 +295,15 @@ public: CodeGenVTables(CodeGenModule &CGM) : CGM(CGM) { } + // isKeyFunctionInAnotherTU - True if this record has a key function and it is + // in another translation unit. + static bool isKeyFunctionInAnotherTU(ASTContext &Context, + const CXXRecordDecl *RD) { + assert (RD->isDynamicClass() && "Non dynamic classes have no key."); + const CXXMethodDecl *KeyFunction = Context.getKeyFunction(RD); + return KeyFunction && !KeyFunction->getBody(); + } + /// needsVTTParameter - Return whether the given global decl needs a VTT /// parameter, which it does if it's a base constructor or destructor with /// virtual bases. diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ab2f1c7aa2..035e57fd0b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -314,7 +314,14 @@ GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD, if (FD->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDeclaration) return CodeGenModule::GVA_C99Inline; - + + if (const CXXMethodDecl *MD = dyn_cast(FD)) { + const CXXRecordDecl *RD = MD->getParent(); + if (MD->isVirtual() && + CodeGenVTables::isKeyFunctionInAnotherTU(Context, RD)) + return CodeGenModule::GVA_C99Inline; + } + return CodeGenModule::GVA_CXXInline; } diff --git a/test/CodeGenCXX/PR6747.cpp b/test/CodeGenCXX/PR6747.cpp new file mode 100644 index 0000000000..5a07ce6220 --- /dev/null +++ b/test/CodeGenCXX/PR6747.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +struct foo { + virtual void bar(); +// CHECK: define available_externally void @_ZN3foo3bazEv + virtual void baz() {} +}; +void zed() { + foo b; + b.baz(); +}