Skip to content

Commit 40ad667

Browse files
committed
[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
1 parent f018a5f commit 40ad667

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ void Sema::InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor) {
821821
for (unsigned I = 0; I != NumParams; ++I) {
822822
(void)CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor,
823823
Ctor->getParamDecl(I));
824-
DiscardCleanupsInEvaluationContext();
824+
CleanupVarDeclMarking();
825825
}
826826
}
827827

clang/test/CodeGenCXX/dllexport-ctor-closure.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ CtorClosureOutOfLine::CtorClosureOutOfLine(const HasImplicitDtor2 &v) {}
8888
// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor1@@QAE@XZ"
8989
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureOutOfLine@@QAEXXZ"
9090
// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor2@@QAE@XZ"
91+
92+
struct SomeStruct {};
93+
constexpr SomeStruct kConstexprStruct;
94+
struct __declspec(dllexport) ConstexprDefaultArg {
95+
ConstexprDefaultArg(SomeStruct = kConstexprStruct) {}
96+
};
97+
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FConstexprDefaultArg@@QAEXXZ"

0 commit comments

Comments
 (0)