[cfe-commits] r103208 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/template-linkage.cpp

Douglas Gregor dgregor at apple.com
Thu May 6 16:13:35 PDT 2010


Author: dgregor
Date: Thu May  6 18:13:35 2010
New Revision: 103208

URL: http://llvm.org/viewvc/llvm-project?rev=103208&view=rev
Log:
Do not give implicitly-defined virtual members functions
available_externally linkage, since they may not have been given a
strong definition in another translation unit. Without this patch, the
following test case fails to link with a GCC-compiled libstdc++:

  #include <sstream>
  int main() { std::basic_stringbuf<char> bs; }

Fixes the last problem with the Boost.IO library.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/template-linkage.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=103208&r1=103207&r2=103208&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May  6 18:13:35 2010
@@ -322,8 +322,8 @@
   // only for inlining and analysis. This is the semantics of c99 inline.
   if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
     const CXXRecordDecl *RD = MD->getParent();
-    if (MD->isVirtual() &&
-	CodeGenVTables::isKeyFunctionInAnotherTU(Context, RD))
+    if (MD->isVirtual() && !MD->isImplicit() &&
+        CodeGenVTables::isKeyFunctionInAnotherTU(Context, RD))
       return CodeGenModule::GVA_C99Inline;
   }  
 

Modified: cfe/trunk/test/CodeGenCXX/template-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/template-linkage.cpp?rev=103208&r1=103207&r2=103208&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/template-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/template-linkage.cpp Thu May  6 18:13:35 2010
@@ -22,3 +22,23 @@
 template <typename T> inline void g(T) { }
 template void g<int>(int);
 
+template<typename T>
+struct X0 {
+  virtual ~X0() { }
+};
+
+template<typename T>
+struct X1 : X0<T> {
+  virtual void blarg();
+};
+
+template<typename T> void X1<T>::blarg() { }
+
+extern template struct X0<char>;
+extern template struct X1<char>;
+
+// CHECK: define linkonce_odr void @_ZN2X1IcED1Ev(
+void test_X1() {
+  X1<char> i1c;
+}
+





More information about the cfe-commits mailing list