<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 10, 2015 at 12:39 PM, Reid Kleckner via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Mon Aug 10 14:39:01 2015<br>
New Revision: 244488<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=244488&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=244488&view=rev</a><br>
Log:<br>
[dllimport] A non-imported class with an imported key can't have a key<br>
<br>
Summary:<br>
The vtable takes its DLL storage class from the class, not the key<br>
function. When they disagree, the vtable won't be exported by the DLL<br>
that defines the key function. The easiest way to ensure that importers<br>
of the class emit their own vtable is to say that the class has no key<br>
function.<br>
<br>
Reviewers: hans, majnemer<br>
<br>
Subscribers: cfe-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D11913" rel="noreferrer" target="_blank">http://reviews.llvm.org/D11913</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp<br>
    cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=244488&r1=244487&r2=244488&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=244488&r1=244487&r2=244488&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)<br>
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Aug 10 14:39:01 2015<br>
@@ -2008,6 +2008,12 @@ static const CXXMethodDecl *computeKeyFu<br>
         continue;<br>
     }<br>
<br>
+    // If the key function is dllimport but the class isn't, then the class has<br>
+    // no key function. The DLL that exports the key function won't export the<br>
+    // vtable in this case.<br>
+    if (MD->hasAttr<DLLImportAttr>() && !RD->hasAttr<DLLImportAttr>())<br>
+      return nullptr;<br></blockquote><div><br></div><div>Does the same apply if the key function is DLLExport and the class is not? (Presumably this would just lead us to export a vtable that we don't need to, which is presumably harmless?)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
     // We found it.<br>
     return MD;<br>
   }<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp?rev=244488&r1=244487&r2=244488&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp?rev=244488&r1=244487&r2=244488&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp Mon Aug 10 14:39:01 2015<br>
@@ -22,3 +22,11 @@ struct __declspec(dllimport) V {<br>
 // GNU-DAG: @_ZTV1V = available_externally dllimport<br>
 // GNU-DAG: @_ZTS1V = linkonce_odr<br>
 // GNU-DAG: @_ZTI1V = linkonce_odr<br>
+<br>
+struct W {<br>
+  __declspec(dllimport) virtual void f();<br>
+  virtual void g();<br>
+} w;<br>
+// GNU-DAG: @_ZTV1W = linkonce_odr<br>
+// GNU-DAG: @_ZTS1W = linkonce_odr<br>
+// GNU-DAG: @_ZTI1W = linkonce_odr<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>