[clang] e42ce42 - [dllexport] Instantiate default ctor default args

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 23 16:02:37 PDT 2021


Author: Reid Kleckner
Date: 2021-08-23T15:56:29-07:00
New Revision: e42ce422a97876e5ecd1c845b12ec65f96f8a293

URL: https://github.com/llvm/llvm-project/commit/e42ce422a97876e5ecd1c845b12ec65f96f8a293
DIFF: https://github.com/llvm/llvm-project/commit/e42ce422a97876e5ecd1c845b12ec65f96f8a293.diff

LOG: [dllexport] Instantiate default ctor default args

Fixes https://bugs.llvm.org/show_bug.cgi?id=51414.

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

Added: 
    clang/test/CodeGenCXX/dllexport-ctor-closure-nested.cpp

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4827f6b3bb345..d980869a3b067 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6005,6 +6005,15 @@ static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
       if (TSK == TSK_ImplicitInstantiation && !ClassAttr->isInherited())
         continue;
 
+      // If this is an MS ABI dllexport default constructor, instantiate any
+      // default arguments.
+      if (S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+        auto *CD = dyn_cast<CXXConstructorDecl>(MD);
+        if (CD && CD->isDefaultConstructor() && TSK == TSK_Undeclared) {
+          S.InstantiateDefaultCtorDefaultArgs(CD);
+        }
+      }
+
       S.MarkFunctionReferenced(Class->getLocation(), MD);
 
       // The function will be passed to the consumer when its definition is

diff  --git a/clang/test/CodeGenCXX/dllexport-ctor-closure-nested.cpp b/clang/test/CodeGenCXX/dllexport-ctor-closure-nested.cpp
new file mode 100644
index 0000000000000..36dab8600e21b
--- /dev/null
+++ b/clang/test/CodeGenCXX/dllexport-ctor-closure-nested.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++14 \
+// RUN:    -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases \
+// RUN:    -disable-llvm-passes -o - %s -w -fms-compatibility-version=19.00 | \
+// RUN:    FileCheck %s
+
+struct HasDtor {
+  ~HasDtor();
+  int o;
+};
+struct HasImplicitDtor1 {
+  HasDtor o;
+};
+struct __declspec(dllexport) CtorClosureOuter {
+  struct __declspec(dllexport) CtorClosureInner {
+    CtorClosureInner(const HasImplicitDtor1 &v = {}) {}
+  };
+};
+
+// CHECK-LABEL: $"??1HasImplicitDtor1@@QAE at XZ" = comdat any
+// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureInner at CtorClosureOuter@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat


        


More information about the cfe-commits mailing list