[PATCH] D123405: [dllexport] odr-use constexpr default args for constructor closures

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 8 09:53:57 PDT 2022


hans created this revision.
hans added reviewers: rnk, mstorsjo, thakis.
Herald added a project: All.
hans requested review of this revision.
Herald added a project: clang.

InstantiateDefaultCtorDefaultArgs() is supposed to mark default constructor args as odr-used, since those args will be used when emitting the constructor closure.

However, constexpr vars were not getting odr-used since DoMarkVarDeclReferenced() defers them in MaybeODRUseExprs, and the code was calling CleanupVarDeclMarking() which discarded those uses instead of processing them.

(This came up in Chromium, crbug.com/1312086)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123405

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp


Index: clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
===================================================================
--- clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
+++ clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
@@ -88,3 +88,10 @@
 // CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor1@@QAE at XZ"
 // CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureOutOfLine@@QAEXXZ"
 // CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor2@@QAE at XZ"
+
+struct SomeStruct {};
+constexpr SomeStruct kConstexprStruct;
+struct __declspec(dllexport) ConstexprDefaultArg {
+  ConstexprDefaultArg(SomeStruct = kConstexprStruct) {}
+};
+// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FConstexprDefaultArg@@QAEXXZ"
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -821,7 +821,7 @@
   for (unsigned I = 0; I != NumParams; ++I) {
     (void)CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor,
                                    Ctor->getParamDecl(I));
-    DiscardCleanupsInEvaluationContext();
+    CleanupVarDeclMarking();
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123405.421561.patch
Type: text/x-patch
Size: 1335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220408/7d6f025a/attachment.bin>


More information about the cfe-commits mailing list