[clang] [analyzer] Only report the first dereference of the same variable in DanglingPtrDeref (PR #215409)

Benedek Kaibas via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 11 04:36:34 PDT 2026


================
@@ -181,6 +190,11 @@ void LifetimeModeling::checkDeadSymbols(SymbolReaper &SymReaper,
     if (!SymReaper.isLiveRegion(Region))
       State = State->remove<DeallocatedSourceSet>(Region);
   }
+
+  for (const MemRegion *Region : Reported) {
+    if (!SymReaper.isLiveRegion(Region))
+      State = State->remove<ReportedDeadRegions>(Region);
+  }
----------------
benedekaibas wrote:

I think, yes we should. Currently if there are multiple dereferences the checker emits warning for the first one which makes sense, but what if the user want to check if there are multiple dereferences of the same object afterwards? I think this is where `printState` can "shine" and help the user figure out if there are any more dereferences of the same object.

Applied changes here: [a44befc](https://github.com/llvm/llvm-project/pull/215409/commits/a44befc77019d7a6fa68bd071a0a9e0deb05d70d)

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


More information about the cfe-commits mailing list