26#include "llvm/ADT/StringRef.h"
33static const BugType *NullDereferenceBugTypePtr;
35class SmartPtrChecker :
public Checker<check::PreCall> {
38 BugType NullDereferenceBugType{
this,
"Null SmartPtr dereference",
44 void explainDereference(llvm::raw_ostream &OS,
const MemRegion *DerefRegion,
65 const auto *OC = dyn_cast<CXXMemberOperatorCall>(&
Call);
68 const MemRegion *ThisRegion = OC->getCXXThisVal().getAsRegion();
73 if (OOK == OO_Star || OOK == OO_Arrow) {
75 reportBug(
C, ThisRegion,
Call);
85 llvm::raw_svector_ostream OS(Str);
86 explainDereference(OS, DerefRegion,
Call);
87 auto R = std::make_unique<PathSensitiveBugReport>(NullDereferenceBugType,
89 R->markInteresting(DerefRegion);
90 C.emitReport(std::move(R));
93void SmartPtrChecker::explainDereference(llvm::raw_ostream &OS,
96 OS <<
"Dereference of null smart pointer ";
102 NullDereferenceBugTypePtr = &
Checker->NullDereferenceBugType;
105bool ento::shouldRegisterSmartPtrChecker(
const CheckerManager &mgr) {
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
C Language Family Type Representation.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
const LangOptions & getLangOpts() const
MemRegion - The root abstract class for all memory regions.
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.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.