[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 00:57:06 PDT 2026


================
@@ -372,6 +372,23 @@ 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());
+    OriginList *Src = SubList && !UO->isGLValue() ? SubList->peelOuterOrigin()
+                                                  : SubList;
+    if (Src)
----------------
Xazax-hun wrote:

Hmm, you might be right, this could be an assert.

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


More information about the cfe-commits mailing list