rsmith added a comment.

A constant expression (including the immediate invocations generated for 
`consteval` functions) is a full-expression, so destructors should be run at 
the end of evaluating it, not as part of the enclosing expression. That's 
presumably why the code is calling `MaybeCreateExprWithCleanups` -- to 
associate cleanups for the immediate invocation with that `ConstantExpr` rather 
than with the outer context. I think the problem is that we don't have an 
`ExpressionEvaluationContext` wrapping the immediate invocation, so we don't 
save and restore the enclosing cleanup state -- and we can't really wrap it, 
because we don't find out that we're building an immediate invocation until 
after we've already done so. Probably the best way to handle that is to create 
the inner `ExprWithCleanups` for the constant expression, but leave the 
cleanups flags alone so that we also create an outer `ExprWithCleanups`. 
That'll mean we sometimes create an `ExprWithCleanups` that doesn't actually 
run any cleanups, but that's OK, just redundant. One thing we will need to be 
careful about is assigning any block / compound literal cleanups to the right 
`ExprWithCleanups` node. We can figure out where to put them by doing a 
traversal of the `ConstantExpr`'s subexpression to see if it contains the 
`BlockDecl` / `CompoundLiteralExpr` being referenced by the cleanup.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153294/new/

https://reviews.llvm.org/D153294

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to