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

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 19:01:45 PDT 2026


================
@@ -372,6 +372,21 @@ void FactsGenerator::VisitUnaryOperator(const UnaryOperator *UO) {
     killAndFlowOrigin(*UO, *SubExpr);
     return;
   }
+  case UO_PreInc:
+  case UO_PostInc:
+  case UO_PreDec:
+  case UO_PostDec: {
+    // Incrementing/decrementing a pointer keeps it in the same allocation, so
+    // the result carries the operand's loans. The operand is always an lvalue;
+    // peel its storage origin when the result is a prvalue (post-inc/dec, or
+    // any form in C).
+    if (!UO->getType()->isPointerType())
+      return;
+    OriginList *SubList = getOriginsList(*UO->getSubExpr());
+    flow(getOriginsList(*UO),
+         UO->isGLValue() ? SubList : SubList->peelOuterOrigin(), /*Kill=*/true);
----------------
usx95 wrote:

Got it. Thanks.

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


More information about the cfe-commits mailing list