[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 15:49:06 PDT 2024


================
@@ -1053,16 +1072,23 @@ void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity,
         if (pathContainsInit(Path))
           return false;
 
-        SemaRef.Diag(DiagLoc, diag::warn_dangling_variable)
-            << RK << !Entity.getParent()
-            << ExtendingEntity->getDecl()->isImplicit()
-            << ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;
+        if (InitEntity) {
+          SemaRef.Diag(DiagLoc, diag::warn_dangling_variable)
+              << RK << !InitEntity->getParent()
+              << ExtendingEntity->getDecl()->isImplicit()
+              << ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;
+        } else {
+          SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
+              << AEntity->LHS << DiagRange;
+        }
         break;
       }
       break;
     }
 
     case LK_MemInitializer: {
+      assert(InitEntity && "Expect only on initializing the entity");
+
----------------
usx95 wrote:

nit: Replace uses of `isa<MaterializeTemporaryExpr>(L)` with already computed `MTE`.
Feel free to do this in a separate patch since this is not related.

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


More information about the cfe-commits mailing list