https://github.com/aeft created https://github.com/llvm/llvm-project/pull/240175
None >From 9b560c74d35e0cedb08f9b416031108612ee1daa Mon Sep 17 00:00:00 2001 From: Zhijie Wang <[email protected]> Date: Sun, 8 Nov 2026 09:46:32 -0800 Subject: [PATCH] [LifetimeSafety] Don't treat assignment to a temporary as a use of its pointee --- clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp | 2 +- clang/test/Sema/LifetimeSafety/safety.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp index 589082a0dcd9d1..6f963b11140317 100644 --- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp +++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp @@ -460,7 +460,7 @@ void FactsGenerator::VisitReturnStmt(const ReturnStmt *RS) { void FactsGenerator::handleAssignment(const Expr *TargetExpr, const Expr *LHSExpr, const Expr *RHSExpr) { - LHSExpr = LHSExpr->IgnoreParenImpCasts(); + LHSExpr = ignoreParensAndImpCasts(LHSExpr); handleAccess(LHSExpr); OriginList *RHSList = readValue(RHSExpr); OriginList *LHSList = nullptr; diff --git a/clang/test/Sema/LifetimeSafety/safety.cpp b/clang/test/Sema/LifetimeSafety/safety.cpp index e3e228233f7988..c244fd07c16b7c 100644 --- a/clang/test/Sema/LifetimeSafety/safety.cpp +++ b/clang/test/Sema/LifetimeSafety/safety.cpp @@ -106,6 +106,16 @@ void propagation_gsl() { v2.use(); // expected-note {{later used here}} } +void assign_to_temporary_copy_of_dangling_view() { + View v; + { + MyObj s; + v = s; + } + // Writes to the temporary's storage, not to 's'. + View{v} = View(); +} + void multiple_uses_one_warning() { MyObj* p; { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
