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

Haojian Wu via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 14:27:28 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));
----------------
hokein wrote:

I agree that `checkExprLifetimeImpl` is quite complex, especially with the 300-line lambda. However, this change doesn't significantly worsen the situation, as it only adds a few lines of code to handle the new case. Considering the minimal impact, I’d prefer not to block this patch.

That said, I understand the importance of reducing overall complexity. I think we can  refactor it in a follow-up.

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


More information about the llvm-commits mailing list