[clang] [analyzer] Implement BugReporterVisitor for UseAfterLifetimeEnd to trace lifetime source binding (PR #207052)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 04:00:04 PDT 2026
================
@@ -8,12 +8,35 @@ using namespace ento;
namespace {
class UseAfterLifetimeEnd : public Checker<check::EndFunction> {
public:
- void reportDanglingSource(const MemRegion *Source, ExplodedNode *N,
+ void reportDanglingSource(const MemRegion *Source, SVal Val, ExplodedNode *N,
CheckerContext &C) const;
void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
const BugType BugMsg{this, "UseAfterLifetimeEnd", "LifetimeBound"};
};
+class UseAfterLifetimeEndBRVisitor : public BugReporterVisitor {
+ SVal BoundVal;
+ const MemRegion *SourceRegion;
+
+public:
+ explicit UseAfterLifetimeEndBRVisitor(SVal Val, const MemRegion *Source)
+ : BoundVal(Val), SourceRegion(Source) {}
+
+ void Profile(llvm::FoldingSetNodeID &ID) const override {
+ static int X = 0;
+ ID.AddPointer(&X);
----------------
isuckatcs wrote:
> Maybe we could use addresses of some functions unique to these checkers?
Won't that interfere with optimization? Said function cannot be inlined and omitted, as it needs an address, right?
I'm wondering if we should add the name of the class as a `const char *`, but that just makes it difficult to maintain, so this variable is probably the best option. Maybe rename it to `Tag` like it is in many other cases to make it more obvious what it does.
https://github.com/llvm/llvm-project/pull/207052
More information about the cfe-commits
mailing list