clang 19.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::ento::NoStateChangeFuncVisitor Class Referenceabstract

Put a diagnostic on return statement (or on } in its absence) of all inlined functions for which some property remained unchanged. More...

#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"

Inheritance diagram for clang::ento::NoStateChangeFuncVisitor:
Inheritance graph
[legend]

Public Member Functions

 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 PathDiagnosticPieceRef VisitNode (const ExplodedNode *Succ, BugReporterContext &BRC, PathSensitiveBugReport &BR)=0
 Return a diagnostic piece which should be associated with the given node.
 
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.
 
virtual void Profile (llvm::FoldingSetNodeID &ID) const =0
 

Protected Member Functions

virtual bool wasModifiedBeforeCallExit (const ExplodedNode *CurrN, const ExplodedNode *CallExitBeginN)
 
virtual bool wasModifiedInFunction (const ExplodedNode *CallEnterN, const ExplodedNode *CallExitEndN)
 
virtual PathDiagnosticPieceRef maybeEmitNoteForObjCSelf (PathSensitiveBugReport &R, const ObjCMethodCall &Call, const ExplodedNode *N)=0
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
 
virtual PathDiagnosticPieceRef maybeEmitNoteForCXXThis (PathSensitiveBugReport &R, const CXXConstructorCall &Call, const ExplodedNode *N)=0
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
 
virtual PathDiagnosticPieceRef maybeEmitNoteForParameters (PathSensitiveBugReport &R, const CallEvent &Call, const ExplodedNode *N)=0
 Consume the information on the non-modifying stack frame in order to either emit a note or not.
 

Protected Attributes

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

Put a diagnostic on return statement (or on } in its absence) of all inlined functions for which some property remained unchanged.

Resulting diagnostics may read such as "Returning without writing to X".

Descendants can define what a "state change is", like a change of value to a memory region, liveness, etc. For function calls where the state did not change as defined, a custom note may be constructed.

For a minimal example, check out clang/unittests/StaticAnalyzer/NoStateChangeFuncVisitorTest.cpp.

Definition at line 646 of file BugReporterVisitors.h.

Constructor & Destructor Documentation

◆ NoStateChangeFuncVisitor()

clang::ento::NoStateChangeFuncVisitor::NoStateChangeFuncVisitor ( bugreporter::TrackingKind  TKind)
inline

Definition at line 737 of file BugReporterVisitors.h.

Member Function Documentation

◆ maybeEmitNoteForCXXThis()

virtual PathDiagnosticPieceRef clang::ento::NoStateChangeFuncVisitor::maybeEmitNoteForCXXThis ( PathSensitiveBugReport R,
const CXXConstructorCall Call,
const ExplodedNode N 
)
protectedpure virtual

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...".

Referenced by VisitNode().

◆ maybeEmitNoteForObjCSelf()

virtual PathDiagnosticPieceRef clang::ento::NoStateChangeFuncVisitor::maybeEmitNoteForObjCSelf ( PathSensitiveBugReport R,
const ObjCMethodCall Call,
const ExplodedNode N 
)
protectedpure virtual

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...".

Referenced by VisitNode().

◆ maybeEmitNoteForParameters()

virtual PathDiagnosticPieceRef clang::ento::NoStateChangeFuncVisitor::maybeEmitNoteForParameters ( PathSensitiveBugReport R,
const CallEvent Call,
const ExplodedNode N 
)
protectedpure virtual

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...".

Referenced by VisitNode().

◆ VisitNode()

PathDiagnosticPieceRef NoStateChangeFuncVisitor::VisitNode ( const ExplodedNode Succ,
BugReporterContext BRC,
PathSensitiveBugReport BR 
)
finalvirtual

Return a diagnostic piece which should be associated with the given node.

Note that this function does not get run on the very last node of the report, as the PathDiagnosticPiece associated with the last node should be unique. Use getEndPath to customize the note associated with the report end instead.

The last parameter can be used to register a new visitor with the given BugReport while processing a node.

Implements clang::ento::BugReporterVisitor.

Definition at line 466 of file BugReporterVisitors.cpp.

References clang::Call, clang::ento::CallEventManager::getCaller(), clang::ento::ProgramStateManager::getCallEventManager(), clang::LocationContext::getCFG(), clang::ento::ExplodedNode::getLocationAs(), clang::ento::ExplodedNode::getLocationContext(), clang::LocationContext::getStackFrame(), clang::ento::ExplodedNode::getStackFrame(), clang::ento::ExplodedNode::getState(), clang::ento::BugReporterContext::getStateManager(), clang::CFG::isLinear(), clang::ento::PathSensitiveBugReport::markInvalid(), maybeEmitNoteForCXXThis(), maybeEmitNoteForObjCSelf(), and maybeEmitNoteForParameters().

◆ wasModifiedBeforeCallExit()

virtual bool clang::ento::NoStateChangeFuncVisitor::wasModifiedBeforeCallExit ( const ExplodedNode CurrN,
const ExplodedNode CallExitBeginN 
)
inlineprotectedvirtual
Returns
Whether the state was modified from the current node, CurrN, to the end of the stack frame, at CallExitBeginN. CurrN and CallExitBeginN are always in the same stack frame. Clients should override this callback when a state change is important not only on the entire function call, but inside of it as well. Example: we may want to leave a note about the lack of locking/unlocking on a particular mutex, but not if inside the function its state was changed, but also restored. wasModifiedInFunction() wouldn't know of this change.

Definition at line 684 of file BugReporterVisitors.h.

◆ wasModifiedInFunction()

virtual bool clang::ento::NoStateChangeFuncVisitor::wasModifiedInFunction ( const ExplodedNode CallEnterN,
const ExplodedNode CallExitEndN 
)
inlineprotectedvirtual
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).

Definition at line 702 of file BugReporterVisitors.h.

Member Data Documentation

◆ TKind

bugreporter::TrackingKind clang::ento::NoStateChangeFuncVisitor::TKind
protected

Definition at line 673 of file BugReporterVisitors.h.


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