[PATCH] D55698: [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 14 02:25:39 PST 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, majnemer.

This matches what GCC does in these situations.

This fixes compiling Qt in debug mode. In release mode, references to the vtable of this particular class ends up optimized away, but in debug mode, the compiler creates references to the vtable, which is expected to be dllexported from a different DLL. Make sure the dllexported version actually ends up emitted.


Repository:
  rC Clang

https://reviews.llvm.org/D55698

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/dllexport-missing-key.cpp


Index: test/CodeGenCXX/dllexport-missing-key.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/dllexport-missing-key.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -std=c++11 -o - %s |
+// FileCheck --check-prefix=GNU %s
+
+class __declspec(dllexport) QAbstractLayoutStyleInfo {
+public:
+  QAbstractLayoutStyleInfo() : m_isWindow(false) {}
+  virtual ~QAbstractLayoutStyleInfo() {}
+
+  virtual bool hasChangedCore() const { return false; }
+
+  virtual void invalidate() {}
+
+  virtual double windowMargin(bool orientation) const = 0;
+
+  bool isWindow() const { return m_isWindow; }
+
+protected:
+  bool m_isWindow;
+};
+
+// GNU-DAG: @_ZTV24QAbstractLayoutStyleInfo = weak_odr dso_local dllexport
+// GNU-DAG: @_ZTS24QAbstractLayoutStyleInfo = linkonce_odr
+// GNU-DAG: @_ZTI24QAbstractLayoutStyleInfo = linkonce_odr
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5750,6 +5750,10 @@
 
   if (ClassExported)
     DelayedDllExportClasses.push_back(Class);
+
+  if (ClassExported &&
+      Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+    MarkVTableUsed(Class->getLocation(), Class, true);
 }
 
 /// Perform propagation of DLL attributes from a derived class to a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55698.178207.patch
Type: text/x-patch
Size: 1390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181214/ec40e76e/attachment-0001.bin>


More information about the cfe-commits mailing list