[clang] [analyzer] Implemented the DanglingPtrDeref checker to detect use-after-scope lifetime errors (PR #209278)
Benedek Kaibas via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 14 04:15:25 PDT 2026
================
@@ -0,0 +1,95 @@
+#include "LifetimeModeling.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class ReportDanglingPtrDeref : public Checker<check::Location> {
+public:
+ void checkLocation(SVal Loc, bool IsLoad, const Stmt *S,
+ CheckerContext &C) const;
+ void reportUseAfterScope(const MemRegion *Region, ExplodedNode *N,
+ CheckerContext &C) const;
+ const BugType BugMsg{this, "ReportDanglingPtrDeref", "LifetimeBound"};
+};
+
+class ReportDanglingPtrDerefBRVisitor : public BugReporterVisitor {
+ const MemRegion *SourceRegion;
+
+public:
+ ReportDanglingPtrDerefBRVisitor(const MemRegion *Source)
----------------
benedekaibas wrote:
I see why it is needed, thank you! Applied change here: [099746f](https://github.com/llvm/llvm-project/pull/209278/commits/099746f9d0b2d968e42b0400d51e20e032bbf812)
https://github.com/llvm/llvm-project/pull/209278
More information about the cfe-commits
mailing list