From 40ad6670138ab8130a426432b0e94544b5e03642 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Fri, 8 Apr 2022 15:54:09 +0200 Subject: [PATCH] [dllexport] odr-use constexpr default args for constructor closures 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) Differential revision: https://reviews.llvm.org/D123405 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- clang/test/CodeGenCXX/dllexport-ctor-closure.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index a914ae2..925d6fa 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -821,7 +821,7 @@ void Sema::InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor) { for (unsigned I = 0; I != NumParams; ++I) { (void)CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor, Ctor->getParamDecl(I)); - DiscardCleanupsInEvaluationContext(); + CleanupVarDeclMarking(); } } diff --git a/clang/test/CodeGenCXX/dllexport-ctor-closure.cpp b/clang/test/CodeGenCXX/dllexport-ctor-closure.cpp index 4a639fc..50cc223 100644 --- a/clang/test/CodeGenCXX/dllexport-ctor-closure.cpp +++ b/clang/test/CodeGenCXX/dllexport-ctor-closure.cpp @@ -88,3 +88,10 @@ CtorClosureOutOfLine::CtorClosureOutOfLine(const HasImplicitDtor2 &v) {} // CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor1@@QAE@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@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" -- 2.7.4