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

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 06:19:43 PDT 2026


================
@@ -472,8 +487,18 @@ 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. In C
+    // the result is a prvalue, so peel the LHS's storage origin.
+    if (BO->getType()->isPointerType()) {
+      OriginList *LHSList = getOriginsList(*BO->getLHS());
+      flow(getOriginsList(*BO),
+           IsCMode ? getRValueOrigins(BO->getLHS(), LHSList) : LHSList,
----------------
NeKon69 wrote:

Since in C it's always a glvalue:

```suggestion
           IsCMode ? LHSList->peelOuterOrigin() : LHSList,
```

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


More information about the cfe-commits mailing list