summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-08-10 19:39:01 +0000
committerReid Kleckner <rnk@google.com>2015-08-10 19:39:01 +0000
commitc2e3ba48e315312560a2fb26cbb8e8045ab9991e (patch)
tree7435985e66350f922596d4891892e781872dc207
parent5dcf15744336f698e9a0573f9606522af8470a41 (diff)
downloadbcm5719-llvm-c2e3ba48e315312560a2fb26cbb8e8045ab9991e.tar.gz
bcm5719-llvm-c2e3ba48e315312560a2fb26cbb8e8045ab9991e.zip
[dllimport] A non-imported class with an imported key can't have a key
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 llvm-svn: 244488
-rw-r--r--clang/lib/AST/RecordLayoutBuilder.cpp6
-rw-r--r--clang/test/CodeGenCXX/dllimport-rtti.cpp8
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index ec6dac34c52..d3aeb3e41ad 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -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;
}
diff --git a/clang/test/CodeGenCXX/dllimport-rtti.cpp b/clang/test/CodeGenCXX/dllimport-rtti.cpp
index 609ad1637ca..071ce278a5b 100644
--- a/clang/test/CodeGenCXX/dllimport-rtti.cpp
+++ b/clang/test/CodeGenCXX/dllimport-rtti.cpp
@@ -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
OpenPOWER on IntegriCloud