================
@@ -6604,13 +6617,42 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
*Class) {
       if (MD->isDeleted())
         continue;
 
+      // Don't export inherited constructors whose parameters prevent ABI-
+      // compatible forwarding thunk. When canEmitDelegateCallArgs (in
+      // CodeGen) returns false, Clang inlines the constructor body instead
+      // of emitting a forwarding thunk, producing code that is not ABI-
+      // compatible with MSVC. Suppress the export so the user gets a linker
+      // error rather than a silent runtime mismatch.
+      if (ClassExported) {
+        if (auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
+          if (CD->getInheritedConstructor()) {
+            if (CD->isVariadic())
+              continue;
+            if (Context.getTargetInfo()
+                    .getCXXABI()
+                    .areArgsDestroyedLeftToRightInCallee()) {
+              bool HasCalleeCleanupParam = false;
+              for (const auto *P : CD->parameters())
+                if (P->needsDestruction(Context))
+                  HasCalleeCleanupParam = true;
+              if (HasCalleeCleanupParam)
+                continue;
+            }
+          }
+        }
+      }
----------------
chinmaydd wrote:

> Maybe emit a "exporting this constructor is not yet supported" warning?

Added, thanks.

> Should we also exclude variadic constructors?

They are being excluded 
[already](https://github.com/llvm/llvm-project/pull/182706/changes#diff-9ced4fa47ee2b9c03b6996ce89a1d131c0f5b71013993bc582209f50d5e934daR6629)
 (was part of the previous commit). Added an explicit warning (and relevant 
tests) to disambiguate the reason of the dllexport exclusion.

https://github.com/llvm/llvm-project/pull/182706
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to