[clang] [LifetimeSafety] Propagate loans through pointer inc/dec and compound assignment (PR #204477)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 03:59:11 PDT 2026


================
@@ -472,8 +489,19 @@ void FactsGenerator::VisitBinaryOperator(const BinaryOperator *BO) {
     killAndFlowOrigin(*BO, *BO->getRHS());
     return;
   }
-  if (BO->isCompoundAssignmentOp())
+  if (BO->isCompoundAssignmentOp()) {
+    // A pointer compound additive assignment (`p += n`) keeps the pointer in
+    // the same allocation, so its result carries the LHS pointer's loans. The
+    // LHS is always an lvalue; peel when the result is a prvalue (in C).
+    if (BO->getType()->isPointerType()) {
+      OriginList *LHSList = getOriginsList(*BO->getLHS());
+      OriginList *Src = LHSList && !BO->isGLValue() ? LHSList->peelOuterOrigin()
+                                                    : LHSList;
----------------
Xazax-hun wrote:

Done.

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


More information about the cfe-commits mailing list