29static const BugType *NullDereferenceBugTypePtr;
31class SmartPtrChecker :
public Checker<check::PreCall> {
33 void checkPreCall(
const CallEvent &
Call, CheckerContext &
C)
const;
34 BugType NullDereferenceBugType{
this,
"Null SmartPtr dereference",
38 void reportBug(CheckerContext &
C,
const MemRegion *DerefRegion,
39 const CallEvent &
Call)
const;
40 void explainDereference(llvm::raw_ostream &
OS,
const MemRegion *DerefRegion,
41 const CallEvent &
Call)
const;
61 const auto *OC = dyn_cast<CXXMemberOperatorCall>(&
Call);
64 const MemRegion *ThisRegion = OC->getCXXThisVal().getAsRegion();
69 if (OOK == OO_Star || OOK == OO_Arrow) {
71 reportBug(
C, ThisRegion,
Call);
75void SmartPtrChecker::reportBug(CheckerContext &
C,
const MemRegion *DerefRegion,
76 const CallEvent &
Call)
const {
77 ExplodedNode *ErrNode =
C.generateErrorNode();
80 llvm::SmallString<128> Str;
81 llvm::raw_svector_ostream
OS(Str);
82 explainDereference(
OS, DerefRegion,
Call);
83 auto R = std::make_unique<PathSensitiveBugReport>(NullDereferenceBugType,
85 R->markInteresting(DerefRegion);
86 C.emitReport(std::move(R));
89void SmartPtrChecker::explainDereference(llvm::raw_ostream &
OS,
90 const MemRegion *DerefRegion,
91 const CallEvent &
Call)
const {
92 OS <<
"Dereference of null smart pointer ";
96void ento::registerSmartPtrChecker(CheckerManager &Mgr) {
98 NullDereferenceBugTypePtr = &Checker->NullDereferenceBugType;
101bool ento::shouldRegisterSmartPtrChecker(
const CheckerManager &mgr) {
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
const LangOptions & getLangOpts() const
Simple checker classes that implement one frontend (i.e.
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
const BugType * getNullDereferenceBugType()
bool isNullSmartPtr(const ProgramStateRef State, const MemRegion *ThisRegion)
Returns whether the smart pointer is null or not.
bool isStdSmartPtrCall(const CallEvent &Call)
Returns true if the event call is on smart pointer.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.