rnk created this revision. rnk added reviewers: majnemer, hans. rnk added a subscriber: cfe-commits.
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. http://reviews.llvm.org/D11913 Files: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/dllimport-rtti.cpp Index: test/CodeGenCXX/dllimport-rtti.cpp =================================================================== --- test/CodeGenCXX/dllimport-rtti.cpp +++ test/CodeGenCXX/dllimport-rtti.cpp @@ -22,3 +22,11 @@ // 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 Index: lib/AST/RecordLayoutBuilder.cpp =================================================================== --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -2008,6 +2008,12 @@ 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: test/CodeGenCXX/dllimport-rtti.cpp =================================================================== --- test/CodeGenCXX/dllimport-rtti.cpp +++ test/CodeGenCXX/dllimport-rtti.cpp @@ -22,3 +22,11 @@ // 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 Index: lib/AST/RecordLayoutBuilder.cpp =================================================================== --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -2008,6 +2008,12 @@ 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits