================
@@ -19804,3 +19803,36 @@ void 
Sema::ActOnFinishFunctionDeclarationDeclarator(Declarator &Declarator) {
   }
   InventedParameterInfos.pop_back();
 }
+
+bool Sema::BuildCtorClosureDefaultArgs(SourceLocation Loc,
+                                       CXXConstructorDecl *Ctor, bool IsCopy) {
+  assert(Context.getTargetInfo().getCXXABI().isMicrosoft());
+
+  if (!Ctor->getCtorClosureDefaultArgs().empty()) {
+    // If we build args for default constructor closures, those will have
+    // been generated *before* building args for any copy constructor closures.
+    assert(IsCopy || Ctor->getCtorClosureDefaultArgs()[0] != nullptr);
+    return false;
+  }
+
+  unsigned NumParams = Ctor->getNumParams();
+  if (NumParams == 0)
+    return false;
+
+  CXXDefaultArgExpr **Args =
+      new (getASTContext()) CXXDefaultArgExpr *[NumParams];
+
+  if (IsCopy)
+    Args[0] = nullptr; // Copy ctor closure will provide the first argument.
+
+  for (unsigned I = IsCopy ? 1 : 0; I != NumParams; ++I) {
+    ExprResult R = BuildCXXDefaultArgExpr(Loc, Ctor, Ctor->getParamDecl(I));
+    CleanupVarDeclMarking();
----------------
zmodem wrote:

Setting `RebuildDefaultArgOrDefaultInit` doesn't help.

IIUC the root of the problem is that when the default argument is a constexpr 
variable, and we go to mark it as ODR-used:

https://github.com/llvm/llvm-project/blob/5c57289bf017f7aa216f242080b7244e4cea88b7/clang/lib/Sema/SemaExpr.cpp#L20748-L20755

we take the "delay the marking" path and put it in `MaybeODRUseExprs`.

The only code I see picking up the var from that list is 
`CleanupVarDeclMarking()`, so that needs to get called somehow. There are only 
a few places that do this:

- `Sema::PopExpressionEvaluationContext()` for unevaluated or constevaluated 
contexts: but as you point out, that's conceptually wrong for us.
- `Sema::MaybeCreateExprWithCleanups`: this is not appropriate for the 
arguments since any cleanups should run after the full function call.
- `Sema::MaybeCreateStmtWithCleanups`: not applicable
- `SemaOpenMP::EndOpenMPClause`: not applicable
- `Sema::ActOnGCCAsmStmt`: not applicable.

So I think it makes sense to call `CleanupVarDeclMarking()` ourselves here.

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

Reply via email to