[PATCH] D153294: [clang] Do not create ExprWithCleanups while checking immediate invocation

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 13:01:48 PDT 2023


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



More information about the cfe-commits mailing list