]> granicus.if.org Git - clang/commitdiff
[dllimport] A non-imported class with an imported key can't have a key
authorReid Kleckner <rnk@google.com>
Mon, 10 Aug 2015 19:39:01 +0000 (19:39 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 10 Aug 2015 19:39:01 +0000 (19:39 +0000)
Summary:
The vtable takes its DLL storage class from the class, not the key
function. When they disagree, the vtable won't be exported by the DLL
that defines the key function. The easiest way to ensure that importers
of the class emit their own vtable is to say that the class has no key
function.

Reviewers: hans, majnemer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D11913

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

lib/AST/RecordLayoutBuilder.cpp
test/CodeGenCXX/dllimport-rtti.cpp

index ec6dac34c52dd1fe3ad95ed2ab1eba9a11d05219..d3aeb3e41adfe69260ea979394ba34e694d009e1 100644 (file)
@@ -2008,6 +2008,12 @@ static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
         continue;
     }
 
+    // If the key function is dllimport but the class isn't, then the class has
+    // no key function. The DLL that exports the key function won't export the
+    // vtable in this case.
+    if (MD->hasAttr<DLLImportAttr>() && !RD->hasAttr<DLLImportAttr>())
+      return nullptr;
+
     // We found it.
     return MD;
   }
index 609ad1637ca98a7532a4d4e300a7f28ebd251141..071ce278a5bbdf783c2e561b3042452e408cf545 100644 (file)
@@ -22,3 +22,11 @@ struct __declspec(dllimport) V {
 // GNU-DAG: @_ZTV1V = available_externally dllimport
 // GNU-DAG: @_ZTS1V = linkonce_odr
 // GNU-DAG: @_ZTI1V = linkonce_odr
+
+struct W {
+  __declspec(dllimport) virtual void f();
+  virtual void g();
+} w;
+// GNU-DAG: @_ZTV1W = linkonce_odr
+// GNU-DAG: @_ZTS1W = linkonce_odr
+// GNU-DAG: @_ZTI1W = linkonce_odr