]> granicus.if.org Git - clang/commitdiff
[MinGW] Produce a vtable and RTTI for dllexported classes without a key function
authorMartin Storsjo <martin@martin.st>
Sat, 15 Dec 2018 08:08:11 +0000 (08:08 +0000)
committerMartin Storsjo <martin@martin.st>
Sat, 15 Dec 2018 08:08:11 +0000 (08:08 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349256 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/dllexport-missing-key.cpp [new file with mode: 0644]

index 4a7ab11c7159e3a1b0ed325dd8e873d77f2b8dbb..d56c880311393ccfa62318fbdfc3452059c8e83c 100644 (file)
@@ -5528,6 +5528,9 @@ static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
     // 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.
diff --git a/test/CodeGenCXX/dllexport-missing-key.cpp b/test/CodeGenCXX/dllexport-missing-key.cpp
new file mode 100644 (file)
index 0000000..90e736f
--- /dev/null
@@ -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