[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

Boaz Brickner via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 06:09:41 PST 2024


================
@@ -1110,13 +1117,14 @@ static bool shouldRunGSLAssignmentAnalysis(const Sema &SemaRef,
            isAssignmentOperatorLifetimeBound(Entity.AssignmentOperator)));
 }
 
-static void checkExprLifetimeImpl(Sema &SemaRef,
-                                  const InitializedEntity *InitEntity,
-                                  const InitializedEntity *ExtendingEntity,
-                                  LifetimeKind LK,
-                                  const AssignedEntity *AEntity, Expr *Init) {
-  assert((AEntity && LK == LK_Assignment) ||
-         (InitEntity && LK != LK_Assignment));
+static void
+checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
+                      const InitializedEntity *ExtendingEntity, LifetimeKind LK,
+                      const AssignedEntity *AEntity,
+                      const CapturingEntity *CapEntity, Expr *Init) {
+  assert(!AEntity || LK == LK_Assignment);
+  assert(!CapEntity || LK == LK_LifetimeCapture);
+  assert(!InitEntity || (LK != LK_Assignment && LK != LK_LifetimeCapture));
----------------
bricknerb wrote:

I feel that trying to handle all use cases in this method makes the logic much more complex.
The fact you have to keep in mind the different cases when following the logic here makes it harder to verify correctness and harder to change in the future.
Could we split this, while reusing the shared parts?

https://github.com/llvm/llvm-project/pull/115921


More information about the cfe-commits mailing list