14#ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTERVISITORS_H
15#define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTERVISITORS_H
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/ADT/IntrusiveRefCntPtr.h"
23#include "llvm/ADT/STLExtras.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/ADT/StringRef.h"
92 virtual void Profile(llvm::FoldingSetNodeID &ID)
const = 0;
176 using ExpressionHandlerPtr = std::unique_ptr<ExpressionHandler>;
177 using StoreHandlerPtr = std::unique_ptr<StoreHandler>;
180 std::list<ExpressionHandlerPtr> ExpressionHandlers;
181 std::list<StoreHandlerPtr> StoreHandlers;
246 TrackingOptions Opts);
253 ExpressionHandlers.push_front(std::move(SH));
261 ExpressionHandlers.push_back(std::move(SH));
269 StoreHandlers.push_front(std::move(SH));
277 StoreHandlers.push_back(std::move(SH));
283 template <
class HandlerType,
class... Args>
286 *
this, std::forward<Args>(ConstructorArgs)...));
292 template <
class HandlerType,
class... Args>
295 *
this, std::forward<Args>(ConstructorArgs)...));
355 : ParentTracker(ParentTracker) {}
389 PathSensitiveBugReport &
Report, TrackingOptions Opts = {},
390 const StackFrame *Origin =
nullptr);
399 const bool Assumption;
400 bool IsSatisfied =
false;
404 bool IsTrackingTurnedOn =
false;
409 : Message(Message), Constraint(constraint), Assumption(assumption) {}
411 void Profile(llvm::FoldingSetNodeID &ID)
const override;
415 static const char *
getTag();
423 bool isZeroCheck()
const;
433 void Profile(llvm::FoldingSetNodeID &ID)
const override {
450 constexpr static llvm::StringLiteral GenericTrueMessage =
451 "Assuming the condition is true";
452 constexpr static llvm::StringLiteral GenericFalseMessage =
453 "Assuming the condition is false";
456 void Profile(llvm::FoldingSetNodeID &ID)
const override {
463 static const char *
getTag();
520 std::optional<bool> &prunable,
bool IsSameFieldName);
533 return static_cast<void *
>(&Tag);
536 void Profile(llvm::FoldingSetNodeID &ID)
const override {
561 void Profile(llvm::FoldingSetNodeID &ID)
const override {
578 bool IsSatisfied =
false;
585 bool IsTrackingTurnedOn =
false;
590 void Profile(llvm::FoldingSetNodeID &ID)
const override;
594 static const char *
getTag();
604 void Profile(llvm::FoldingSetNodeID &ID)
const override;
642 bool isModifiedInFrame(
const ExplodedNode *CallExitBeginN);
644 void markFrameAsModifying(
const StackFrame *SF);
648 void findModifyingFrames(
const ExplodedNode *
const CallExitBeginN);
735 static const unsigned DEREFERENCE_LIMIT = 2;
744 MmrMgr(R->getMemRegionManager()),
745 SM(MmrMgr.getContext().getSourceManager()),
746 PP(MmrMgr.getContext().getPrintingPolicy()) {}
748 void Profile(llvm::FoldingSetNodeID &ID)
const override {
751 ID.AddPointer(RegionOfInterest);
757 bool wasModifiedBeforeCallExit(
const ExplodedNode *CurrN,
766 const std::optional<RegionVector>
768 const MemRegion *R,
const RegionVector &Vec = {},
774 const ObjCMethodCall &
Call,
775 const ExplodedNode *N)
final;
778 const CXXConstructorCall &
Call,
779 const ExplodedNode *N)
final;
782 maybeEmitNoteForParameters(PathSensitiveBugReport &R,
const CallEvent &
Call,
783 const ExplodedNode *N)
final;
790 maybeEmitNote(PathSensitiveBugReport &R,
const CallEvent &
Call,
791 const ExplodedNode *N,
const RegionVector &FieldChain,
792 const MemRegion *MatchedRegion, StringRef FirstElement,
793 bool FirstIsReferenceType,
unsigned IndirectionLevel);
795 bool prettyPrintRegionName(
const RegionVector &FieldChain,
796 const MemRegion *MatchedRegion,
797 StringRef FirstElement,
bool FirstIsReferenceType,
798 unsigned IndirectionLevel,
799 llvm::raw_svector_ostream &os);
801 StringRef prettyPrintFirstElement(StringRef FirstElement,
802 bool MoreItemsExpected,
803 int IndirectionLevel,
804 llvm::raw_svector_ostream &os);
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
A builtin binary operation expression such as "x + y" or "x <= y".
Represents a single basic block in a source-level CFG.
A reference to a declared variable, function, enum, etc.
This represents one expression.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Represents a struct/union/class.
This class handles loading and caching of source files into memory.
It represents a stack frame of the call stack.
Stmt - This represents one statement.
virtual void Profile(llvm::FoldingSetNodeID &ID) const =0
BugReporterVisitor(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 PathDiagnosticPieceRef getEndPath(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR)
Provide custom definition for the final diagnostic piece on the path - the piece, which is displayed ...
BugReporterVisitor & operator=(BugReporterVisitor &&)=delete
BugReporterVisitor(const BugReporterVisitor &)=default
BugReporterVisitor()=default
static PathDiagnosticPieceRef getDefaultEndPath(const BugReporterContext &BRC, const ExplodedNode *N, const PathSensitiveBugReport &BR)
Generates the default final diagnostic piece.
virtual ~BugReporterVisitor()
BugReporterVisitor & operator=(const BugReporterVisitor &)=delete
virtual void finalizeVisitor(const ExplodedNode *EndPathNode, BugReporterContext &BRC, PathSensitiveBugReport &BR)
Last function called on the visitor, no further calls to VisitNode would follow.
Represents a call to a C++ constructor.
Represents an abstract call to a function or method along a particular path.
Visitor that tries to report interesting diagnostics from conditions.
PathDiagnosticPieceRef VisitTerminator(const Stmt *Term, const ExplodedNode *N, const CFGBlock *SrcBlk, const CFGBlock *DstBlk, PathSensitiveBugReport &R, BugReporterContext &BRC)
bool printValue(const Expr *CondVarExpr, raw_ostream &Out, const ExplodedNode *N, bool TookTrue, bool IsAssuming)
Tries to print the value of the given expression.
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Return a diagnostic piece which should be associated with the given node.
static bool isPieceMessageGeneric(const PathDiagnosticPiece *Piece)
PathDiagnosticPieceRef VisitConditionVariable(StringRef LhsString, const Expr *CondVarExpr, BugReporterContext &BRC, PathSensitiveBugReport &R, const ExplodedNode *N, bool TookTrue)
bool patternMatch(const Expr *Ex, const Expr *ParentEx, const Expr *OtherEx, raw_ostream &Out, BugReporterContext &BRC, PathSensitiveBugReport &R, const ExplodedNode *N, std::optional< bool > &prunable, bool IsSameFieldName)
PathDiagnosticPieceRef VisitTrueTest(const Expr *Cond, BugReporterContext &BRC, PathSensitiveBugReport &R, const ExplodedNode *N, bool TookTrue)
static const char * getTag()
Return the tag associated with this visitor.
PathDiagnosticPieceRef VisitNodeImpl(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR)
void Profile(llvm::FoldingSetNodeID &ID) const override
Suppress reports that might lead to known false positives.
void Profile(llvm::FoldingSetNodeID &ID) const override
void finalizeVisitor(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Last function called on the visitor, no further calls to VisitNode would follow.
PathDiagnosticPieceRef VisitNode(const ExplodedNode *, BugReporterContext &, PathSensitiveBugReport &) override
Return a diagnostic piece which should be associated with the given node.
MemRegion - The root abstract class for all memory regions.
Prints path notes when a message is sent to a nil receiver.
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Return a diagnostic piece which should be associated with the given node.
void Profile(llvm::FoldingSetNodeID &ID) const override
static const Expr * getNilReceiver(const Stmt *S, const ExplodedNode *N)
If the statement is a message send expression with nil receiver, returns the receiver expression.
virtual bool wasModifiedBeforeCallExit(const ExplodedNode *CurrN, const ExplodedNode *CallExitBeginN)
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.
bugreporter::TrackingKind TKind
NoStateChangeFuncVisitor(bugreporter::TrackingKind TKind)
virtual bool wasModifiedInFunction(const ExplodedNode *CallEnterN, const ExplodedNode *CallExitEndN)
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BR, PathSensitiveBugReport &R) final
Return a diagnostic piece which should be associated with the given node.
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.
void Profile(llvm::FoldingSetNodeID &ID) const override
NoStoreFuncVisitor(const SubRegion *R, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough)
Represents any expression that calls an Objective-C method.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
SubRegion - A region that subsets another larger region.
PathDiagnosticPieceRef VisitNode(const ExplodedNode *Succ, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Return a diagnostic piece which should be associated with the given node.
SuppressInlineDefensiveChecksVisitor(DefinedSVal Val, const ExplodedNode *N)
static const char * getTag()
Return the tag associated with this visitor.
void Profile(llvm::FoldingSetNodeID &ID) const override
The visitor detects NoteTags and displays the event notes they contain.
void Profile(llvm::FoldingSetNodeID &ID) const override
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &R) override
Return a diagnostic piece which should be associated with the given node.
void Profile(llvm::FoldingSetNodeID &ID) const override
static const char * getTag()
Return the tag associated with this visitor.
TrackConstraintBRVisitor(DefinedSVal constraint, bool assumption, StringRef Message)
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Return a diagnostic piece which should be associated with the given node.
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &BR) override
Return a diagnostic piece which should be associated with the given node.
void Profile(llvm::FoldingSetNodeID &ID) const override
UndefOrNullArgVisitor(const MemRegion *InR)
Handles expressions during the tracking.
virtual Tracker::Result handle(const Expr *E, const ExplodedNode *Original, const ExplodedNode *ExprNode, TrackingOptions Opts)=0
Handle the given expression from the given node.
virtual ~ExpressionHandler()
Tracker & getParentTracker()
\Return the tracker that initiated the process.
ExpressionHandler(Tracker &ParentTracker)
Handles stores during the tracking.
virtual PathDiagnosticPieceRef handle(StoreInfo SI, BugReporterContext &BRC, TrackingOptions Opts)=0
Handle the given store and produce the node.
Tracker & getParentTracker()
StoreHandler(Tracker &ParentTracker)
PathDiagnosticPieceRef constructNote(StoreInfo SI, BugReporterContext &BRC, StringRef NodeText)
A generalized component for tracking expressions, values, and stores.
void addLowPriorityHandler(ExpressionHandlerPtr SH)
Add custom expression handler with the lowest priority.
static TrackerRef create(PathSensitiveBugReport &Report)
PathSensitiveBugReport & getReport()
void addHighPriorityHandler(Args &&... ConstructorArgs)
Add custom expression/store handler with the highest priority.
virtual PathDiagnosticPieceRef handle(StoreInfo SI, BugReporterContext &BRC, TrackingOptions Opts)
Handle the store operation and produce the note.
void addHighPriorityHandler(StoreHandlerPtr SH)
Add custom store handler with the highest priority.
void addHighPriorityHandler(ExpressionHandlerPtr SH)
Add custom expression handler with the highest priority.
void addLowPriorityHandler(Args &&... ConstructorArgs)
Add custom expression/store handler with the lowest priority.
void addLowPriorityHandler(StoreHandlerPtr SH)
Add custom store handler with the lowest priority.
Tracker(PathSensitiveBugReport &Report)
virtual ~Tracker()=default
virtual Result track(const Expr *E, const ExplodedNode *N, TrackingOptions Opts={})
Track expression value back to its point of origin.
Tracker & getParentTracker()
TrackingBugReporterVisitor(TrackerRef ParentTracker)
llvm::IntrusiveRefCntPtr< Tracker > TrackerRef
const Expr * getDerefExpr(const Stmt *S)
Given that expression S represents a pointer that would be dereferenced, try to find a sub-expression...
void trackStoredValue(SVal V, const MemRegion *R, PathSensitiveBugReport &Report, TrackingOptions Opts={}, const StackFrame *Origin=nullptr)
Track how the value got stored into the given region and where it came from.
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.
TrackingKind
Specifies the type of tracking for an expression.
@ Thorough
Default tracking kind – specifies that as much information should be gathered about the tracked expre...
@ Condition
Specifies that a more moderate tracking should be used for the expression value.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
std::shared_ptr< PathDiagnosticPiece > PathDiagnosticPieceRef
Top level wrappers for InstallAPI frontend operations.
@ Result
The result type of a method or function.
Describes how types, statements, expressions, and declarations should be printed.
Describes an event when the value got stored into a memory region.
@ Assignment
The value got stored into the region during assignment: int x; x = 42;.
@ CallArgument
The value got stored into the parameter region as the result of a call.
@ BlockCapture
The value got stored into the region as block capture.
@ Initialization
The value got stored into the region during initialization: int x = 42;.
const Expr * SourceOfTheValue
The expression where the value comes from.
const ExplodedNode * StoreSite
The node where the store happened.
Kind StoreKind
The type of store operation.
SVal Value
Symbolic value that is being stored.
const MemRegion * Dest
Memory regions involved in the store operation.
Describes a tracking result with the most basic information of what was actually done (or not done).
bool FoundSomethingToTrack
Usually it means that the tracker added visitors.
void combineWith(const Result &Other)
Combines the current result with the given result.
bool WasInterrupted
Signifies that the tracking was interrupted at some point.
Defines a set of options altering tracking behavior.
bool EnableNullFPSuppression
Specifies whether we should employ false positive suppression (inlined defensive checks,...
TrackingKind Kind
Specifies the kind of tracking.