[clang] [LifetimeSafety] Add suggestion and inference for implicit this (PR #176703)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 23 08:56:43 PST 2026


================
@@ -172,6 +183,7 @@ class OriginManager {
   llvm::BumpPtrAllocator ListAllocator;
   llvm::DenseMap<const clang::ValueDecl *, OriginList *> DeclToList;
   llvm::DenseMap<const clang::Expr *, OriginList *> ExprToList;
+  const Decl *CurrentDecl;
----------------
usx95 wrote:

I don't see a use of having this as a field except `const auto *MD = dyn_cast<CXXMethodDecl>(CurrentDecl)`

I would suggest to instead have a `llvm::Optional<OriginList*> ThisOrigins`; and create this in the `OriginManager` ctor if `D` is a `CXXMethodDecl.`

You can then remove `OriginList *getOrCreateList(const CXXMethodDecl *MD);` and move parts of its docs to document `ThisOrigins`

Origins.cpp could do:

```cpp
 if (isa<CXXThisExpr>(E) && ThisOrigins)
   return *ThisOrigins;
```



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


More information about the cfe-commits mailing list