clang 22.0.0git
clang::ento::NoOwnershipChangeVisitor Class Referenceabstract

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h"

Inheritance diagram for clang::ento::NoOwnershipChangeVisitor:
[legend]

Public Types

using OwnerSet = llvm::SmallPtrSet<const MemRegion *, 8>

Public Member Functions

 NoOwnershipChangeVisitor (SymbolRef Sym, const CheckerBackend *Checker)
void Profile (llvm::FoldingSetNodeID &ID) const override
Public Member Functions inherited from clang::ento::NoStateChangeFuncVisitor
 NoStateChangeFuncVisitor (bugreporter::TrackingKind TKind)
PathDiagnosticPieceRef VisitNode (const ExplodedNode *N, BugReporterContext &BR, PathSensitiveBugReport &R) final
 Return a diagnostic piece which should be associated with the given node.
Public Member Functions inherited from clang::ento::BugReporterVisitor
 BugReporterVisitor ()=default
 BugReporterVisitor (const BugReporterVisitor &)=default
 BugReporterVisitor (BugReporterVisitor &&)
BugReporterVisitoroperator= (const BugReporterVisitor &)=delete
BugReporterVisitoroperator= (BugReporterVisitor &&)=delete
virtual ~BugReporterVisitor ()
virtual void finalizeVisitor (BugReporterContext &BRC, const ExplodedNode *EndPathNode, PathSensitiveBugReport &BR)
 Last function called on the visitor, no further calls to VisitNode would follow.
virtual PathDiagnosticPieceRef getEndPath (BugReporterContext &BRC, const ExplodedNode *N, PathSensitiveBugReport &BR)
 Provide custom definition for the final diagnostic piece on the path - the piece, which is displayed before the path is expanded.

Protected Member Functions

virtual bool doesFnIntendToHandleOwnership (const Decl *Callee, ASTContext &ACtx)=0
 Heuristically guess whether the callee intended to free the resource.
virtual bool hasResourceStateChanged (ProgramStateRef CallEnterState, ProgramStateRef CallExitEndState)=0
bool wasModifiedInFunction (const ExplodedNode *CallEnterN, const ExplodedNode *CallExitEndN) final
virtual PathDiagnosticPieceRef emitNote (const ExplodedNode *N)=0
PathDiagnosticPieceRef maybeEmitNoteForObjCSelf (PathSensitiveBugReport &R, const ObjCMethodCall &Call, const ExplodedNode *N) final
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
PathDiagnosticPieceRef maybeEmitNoteForCXXThis (PathSensitiveBugReport &R, const CXXConstructorCall &Call, const ExplodedNode *N) final
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
PathDiagnosticPieceRef maybeEmitNoteForParameters (PathSensitiveBugReport &R, const CallEvent &Call, const ExplodedNode *N) final
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
Protected Member Functions inherited from clang::ento::NoStateChangeFuncVisitor
virtual bool wasModifiedBeforeCallExit (const ExplodedNode *CurrN, const ExplodedNode *CallExitBeginN)

Static Protected Member Functions

static LLVM_DUMP_METHOD std::string getFunctionName (const ExplodedNode *CallEnterN)

Protected Attributes

SymbolRef Sym
const CheckerBackendChecker
Protected Attributes inherited from clang::ento::NoStateChangeFuncVisitor
bugreporter::TrackingKind TKind

Additional Inherited Members

Static Public Member Functions inherited from clang::ento::BugReporterVisitor
static PathDiagnosticPieceRef getDefaultEndPath (const BugReporterContext &BRC, const ExplodedNode *N, const PathSensitiveBugReport &BR)
 Generates the default final diagnostic piece.

Detailed Description

Definition at line 16 of file NoOwnershipChangeVisitor.h.

Member Typedef Documentation

◆ OwnerSet

Constructor & Destructor Documentation

◆ NoOwnershipChangeVisitor()

clang::ento::NoOwnershipChangeVisitor::NoOwnershipChangeVisitor ( SymbolRef Sym,
const CheckerBackend * Checker )
inline

Member Function Documentation

◆ doesFnIntendToHandleOwnership()

virtual bool clang::ento::NoOwnershipChangeVisitor::doesFnIntendToHandleOwnership ( const Decl * Callee,
ASTContext & ACtx )
protectedpure virtual

Heuristically guess whether the callee intended to free the resource.

This is done syntactically, because we are trying to argue about alternative paths of execution, and as a consequence we don't have path-sensitive information.

Referenced by wasModifiedInFunction().

◆ emitNote()

virtual PathDiagnosticPieceRef clang::ento::NoOwnershipChangeVisitor::emitNote ( const ExplodedNode * N)
protectedpure virtual

◆ getFunctionName()

LLVM_DUMP_METHOD std::string NoOwnershipChangeVisitor::getFunctionName ( const ExplodedNode * CallEnterN)
staticprotected

◆ hasResourceStateChanged()

virtual bool clang::ento::NoOwnershipChangeVisitor::hasResourceStateChanged ( ProgramStateRef CallEnterState,
ProgramStateRef CallExitEndState )
protectedpure virtual

Referenced by wasModifiedInFunction().

◆ maybeEmitNoteForCXXThis()

PathDiagnosticPieceRef clang::ento::NoOwnershipChangeVisitor::maybeEmitNoteForCXXThis ( PathSensitiveBugReport & R,
const CXXConstructorCall & Call,
const ExplodedNode * N )
inlinefinalprotectedvirtual

Consume the information on the non-modifying stack frame in order to either emit a note or not.

May suppress the report entirely.

Returns
Diagnostics piece for the unmodified state in the current function, if it decides to emit one. A good description might start with "Returning without...".

Implements clang::ento::NoStateChangeFuncVisitor.

Definition at line 47 of file NoOwnershipChangeVisitor.h.

References clang::Call.

◆ maybeEmitNoteForObjCSelf()

PathDiagnosticPieceRef clang::ento::NoOwnershipChangeVisitor::maybeEmitNoteForObjCSelf ( PathSensitiveBugReport & R,
const ObjCMethodCall & Call,
const ExplodedNode * N )
inlinefinalprotectedvirtual

Consume the information on the non-modifying stack frame in order to either emit a note or not.

May suppress the report entirely.

Returns
Diagnostics piece for the unmodified state in the current function, if it decides to emit one. A good description might start with "Returning without...".

Implements clang::ento::NoStateChangeFuncVisitor.

Definition at line 40 of file NoOwnershipChangeVisitor.h.

References clang::Call.

◆ maybeEmitNoteForParameters()

PathDiagnosticPieceRef NoOwnershipChangeVisitor::maybeEmitNoteForParameters ( PathSensitiveBugReport & R,
const CallEvent & Call,
const ExplodedNode * N )
finalprotectedvirtual

Consume the information on the non-modifying stack frame in order to either emit a note or not.

May suppress the report entirely.

Returns
Diagnostics piece for the unmodified state in the current function, if it decides to emit one. A good description might start with "Returning without...".

Implements clang::ento::NoStateChangeFuncVisitor.

Definition at line 95 of file NoOwnershipChangeVisitor.cpp.

References clang::Call, emitNote(), Sym, and V.

◆ Profile()

void clang::ento::NoOwnershipChangeVisitor::Profile ( llvm::FoldingSetNodeID & ID) const
inlineoverridevirtual

Implements clang::ento::BugReporterVisitor.

Definition at line 70 of file NoOwnershipChangeVisitor.h.

References Sym.

◆ wasModifiedInFunction()

bool NoOwnershipChangeVisitor::wasModifiedInFunction ( const ExplodedNode * CallEnterN,
const ExplodedNode * CallExitEndN )
finalprotectedvirtual
Returns
Whether the state was modified in the inlined function call in between CallEnterN and CallExitEndN. Mind that the stack frame retrieved from a CallEnterN and CallExitEndN is the caller's stack frame! The inlined function's stack should be retrieved from either the immediate successor to CallEnterN or immediate predecessor to CallExitEndN. Clients should override this function if a state changes local to the inlined function are not interesting, only the change occuring as a result of it. Example: we want to leave a not about a leaked resource object not being deallocated / its ownership changed inside a function, and we don't care if it was assigned to a local variable (its change in ownership is inconsequential).

Reimplemented from clang::ento::NoStateChangeFuncVisitor.

Definition at line 71 of file NoOwnershipChangeVisitor.cpp.

References doesFnIntendToHandleOwnership(), clang::LocationContext::getDecl(), clang::ento::ExplodedNode::getFirstPred(), clang::ento::ExplodedNode::getLocationContext(), clang::ento::ExplodedNode::getState(), and hasResourceStateChanged().

Member Data Documentation

◆ Checker

const CheckerBackend& clang::ento::NoOwnershipChangeVisitor::Checker
protected

Definition at line 20 of file NoOwnershipChangeVisitor.h.

Referenced by NoOwnershipChangeVisitor().

◆ Sym

SymbolRef clang::ento::NoOwnershipChangeVisitor::Sym
protected

The documentation for this class was generated from the following files: