[clang] [LifetimeSafety] Fix handling of reference-type DeclRefExpr (PR #176728)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 19 04:39:32 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())
----------------
usx95 wrote:
`getRValueOrigins`look correct to me. The thing which was incorrect was that we always assumed that the outer origin of a DRE is not always useful and can be peeled when considering a use.
Added some more tests that references work as intended currently.
The more principled way would be to attach "use" of all origins of all layers without peeling any layer. I think I did not do this to avoid overflooding with "UseFacts" for all DRE we see. But in principle, it wouldn't be incorrect.
https://github.com/llvm/llvm-project/pull/176728
More information about the cfe-commits
mailing list