[clang] [LifetimeSafety] Fix handling of reference-type DeclRefExpr (PR #176728)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 19 04:45:04 PST 2026


================
@@ -589,9 +589,10 @@ void FactsGenerator::handleUse(const DeclRefExpr *DRE) {
   OriginList *List = getOriginsList(*DRE);
   if (!List)
     return;
-  // Remove the outer layer of origin which borrows from the decl directly. This
-  // is a use of the underlying decl.
-  List = getRValueOrigins(DRE, List);
+  // Remove the outer layer of origin which borrows from the decl directly
+  // (e.g., when this is not a reference). This is a use of the underlying decl.
+  if (!DRE->getDecl()->getType()->isReferenceType())
----------------
Xazax-hun wrote:

I think my intuition here is whether we want to do `getRValueOrigins` might be context dependent.
So in case of `&var` we do not want to peel but in case of `T* copy = var` we do. So I'd expect that we do the peeling later, when we process an lvalue to rvalue conversion or something similar. Admittedly, I'd expect that most DeclRefExprs are used in a context where we need the rvalue. 

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


More information about the cfe-commits mailing list