r349256 - [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

Martin Storsjo via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 15 00:08:11 PST 2018


Author: mstorsjo
Date: Sat Dec 15 00:08:11 2018
New Revision: 349256

URL: http://llvm.org/viewvc/llvm-project?rev=349256&view=rev
Log:
[MinGW] Produce a vtable and RTTI for dllexported classes without a key function

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.

Differential Revision: https://reviews.llvm.org/D55698

Added:
    cfe/trunk/test/CodeGenCXX/dllexport-missing-key.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=349256&r1=349255&r2=349256&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Dec 15 00:08:11 2018
@@ -5528,6 +5528,9 @@ static void ReferenceDllExportedMembers(
     // declaration.
     return;
 
+  if (S.Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+    S.MarkVTableUsed(Class->getLocation(), Class, true);
+
   for (Decl *Member : Class->decls()) {
     // Defined static variables that are members of an exported base
     // class must be marked export too.

Added: cfe/trunk/test/CodeGenCXX/dllexport-missing-key.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport-missing-key.cpp?rev=349256&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllexport-missing-key.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/dllexport-missing-key.cpp Sat Dec 15 00:08:11 2018
@@ -0,0 +1,22 @@
+// 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




More information about the cfe-commits mailing list