[clang] [LifetimeSafety] Detect use of a reference type as a use of underlying origin (PR #184295)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 29 12:47:16 PDT 2026


================
@@ -248,7 +249,9 @@ class UseFact : public Fact {
   const OriginList *getUsedOrigins() const { return OList; }
   const Expr *getUseExpr() const { return UseExpr; }
   void markAsWritten() { IsWritten = true; }
+  void markAsReferenceWrite() { IsReferenceWrite = true; }
----------------
usx95 wrote:

I would prefer to not have `IsReferenceWrite`and similar C++ language semantics introduced to liveness/dataflow.

Instead of adding `IsReferenceWrite`, we could generate two separate `UseFact`s for reference writes.

For `ref = 10` where `ref` is `int&`:

1. Read `UseFact` for the outer origin (reference binding) - keeps it live
2. Write `UseFact` for the full origin list - kills inner origins

We would need to change the `UseFact` to have single origin or a `OriginList`. Maybe using a variant here.

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


More information about the cfe-commits mailing list