[llvm-branch-commits] [clang] [LifetimeSafety] Don't treat assignment to a temporary as a use of its pointee (PR #240175)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 8 10:46:45 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Zhijie Wang (aeft)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/240175.diff


2 Files Affected:

- (modified) clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp (+1-1) 
- (modified) clang/test/Sema/LifetimeSafety/safety.cpp (+10) 


``````````diff
diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
index 589082a0dcd9d..6f963b1114031 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 e3e228233f798..c244fd07c16b7 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;
   {

``````````

</details>


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


More information about the llvm-branch-commits mailing list