[cfe-commits] r101757 - in /cfe/trunk: lib/CodeGen/CGVTables.h lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/PR6747.cpp

Rafael Espindola rafael.espindola at gmail.com
Sun Apr 18 17:44:23 PDT 2010


Author: rafael
Date: Sun Apr 18 19:44:22 2010
New Revision: 101757

URL: http://llvm.org/viewvc/llvm-project?rev=101757&view=rev
Log:
If a method is virtual and the class key function is in another file, emit the method as available_externally.
Fixes PR6747

Added:
    cfe/trunk/test/CodeGenCXX/PR6747.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGVTables.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.h?rev=101757&r1=101756&r2=101757&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.h (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.h Sun Apr 18 19:44:22 2010
@@ -295,6 +295,15 @@
   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.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=101757&r1=101756&r2=101757&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Apr 18 19:44:22 2010
@@ -314,7 +314,14 @@
   if (FD->getTemplateSpecializationKind() 
                                        == TSK_ExplicitInstantiationDeclaration)
     return CodeGenModule::GVA_C99Inline;
-  
+
+  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
+    const CXXRecordDecl *RD = MD->getParent();
+    if (MD->isVirtual() &&
+	CodeGenVTables::isKeyFunctionInAnotherTU(Context, RD))
+      return CodeGenModule::GVA_C99Inline;
+  }  
+
   return CodeGenModule::GVA_CXXInline;
 }
 

Added: cfe/trunk/test/CodeGenCXX/PR6747.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR6747.cpp?rev=101757&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/PR6747.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/PR6747.cpp Sun Apr 18 19:44:22 2010
@@ -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();
+}





More information about the cfe-commits mailing list