]> granicus.if.org Git - clang/commitdiff
If a method is virtual and the class key function is in another file, emit the method...
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 19 Apr 2010 00:44:22 +0000 (00:44 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 19 Apr 2010 00:44:22 +0000 (00:44 +0000)
Fixes PR6747

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101757 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVTables.h
lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/PR6747.cpp [new file with mode: 0644]

index b4262fe224caa7957241f7880a1fee6e4d0b5fd9..bc113ec42fae5bbb4f0638e768568faedd33f322 100644 (file)
@@ -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.
index ab2f1c7aa2eca1453547fbea5d239da93edbcb35..035e57fd0b29be1cc2b10f23ac366104c5468b6d 100644 (file)
@@ -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<CXXMethodDecl>(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 (file)
index 0000000..5a07ce6
--- /dev/null
@@ -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();
+}