#include "Move.h"
#include "SmartPtr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Type.h"
#include "clang/Basic/LLVM.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ErrorHandling.h"
#include <optional>
#include <string>
usingnamespaceclang;
usingnamespaceento;
namespace {
class SmartPtrModeling
: public Checker<eval::Call, check::DeadSymbols, check::RegionChanges,
check::LiveSymbols> { … };
}
REGISTER_MAP_WITH_PROGRAMSTATE(…) …
static bool hasStdClassWithName(const CXXRecordDecl *RD,
ArrayRef<llvm::StringLiteral> Names) { … }
constexpr llvm::StringLiteral STD_PTR_NAMES[] = …;
static bool isStdSmartPtr(const CXXRecordDecl *RD) { … }
static bool isStdSmartPtr(const Expr *E) { … }
namespace clang {
namespace ento {
namespace smartptr {
bool isStdSmartPtrCall(const CallEvent &Call) { … }
bool isStdSmartPtr(const CXXRecordDecl *RD) { … }
bool isStdSmartPtr(const Expr *E) { … }
bool isNullSmartPtr(const ProgramStateRef State, const MemRegion *ThisRegion) { … }
}
}
}
static TrackedRegionMapTy
removeTrackedSubregions(TrackedRegionMapTy RegionMap,
TrackedRegionMapTy::Factory &RegionMapFactory,
const MemRegion *Region) { … }
static ProgramStateRef updateSwappedRegion(ProgramStateRef State,
const MemRegion *Region,
const SVal *RegionInnerPointerVal) { … }
static QualType getInnerPointerType(CheckerContext C, const CXXRecordDecl *RD) { … }
static QualType getPointerTypeFromTemplateArg(const CallEvent &Call,
CheckerContext &C) { … }
static QualType getInnerPointerType(const CallEvent &Call, CheckerContext &C) { … }
static void checkAndPrettyPrintRegion(llvm::raw_ostream &OS,
const MemRegion *Region) { … }
bool SmartPtrModeling::isBoolConversionMethod(const CallEvent &Call) const { … }
constexpr llvm::StringLiteral BASIC_OSTREAM_NAMES[] = …;
static bool isStdBasicOstream(const Expr *E) { … }
static bool isStdFunctionCall(const CallEvent &Call) { … }
static bool isStdOstreamOperatorCall(const CallEvent &Call) { … }
static bool isPotentiallyComparisionOpCall(const CallEvent &Call) { … }
bool SmartPtrModeling::evalCall(const CallEvent &Call,
CheckerContext &C) const { … }
std::pair<SVal, ProgramStateRef> SmartPtrModeling::retrieveOrConjureInnerPtrVal(
ProgramStateRef State, const MemRegion *ThisRegion, const Expr *E,
QualType Type, CheckerContext &C) const { … }
bool SmartPtrModeling::handleComparisionOp(const CallEvent &Call,
CheckerContext &C) const { … }
bool SmartPtrModeling::handleOstreamOperator(const CallEvent &Call,
CheckerContext &C) const { … }
void SmartPtrModeling::checkDeadSymbols(SymbolReaper &SymReaper,
CheckerContext &C) const { … }
void SmartPtrModeling::printState(raw_ostream &Out, ProgramStateRef State,
const char *NL, const char *Sep) const { … }
ProgramStateRef SmartPtrModeling::checkRegionChanges(
ProgramStateRef State, const InvalidatedSymbols *Invalidated,
ArrayRef<const MemRegion *> ExplicitRegions,
ArrayRef<const MemRegion *> Regions, const LocationContext *LCtx,
const CallEvent *Call) const { … }
void SmartPtrModeling::checkLiveSymbols(ProgramStateRef State,
SymbolReaper &SR) const { … }
void SmartPtrModeling::handleReset(const CallEvent &Call,
CheckerContext &C) const { … }
void SmartPtrModeling::handleRelease(const CallEvent &Call,
CheckerContext &C) const { … }
void SmartPtrModeling::handleSwapMethod(const CallEvent &Call,
CheckerContext &C) const { … }
bool SmartPtrModeling::handleSwap(ProgramStateRef State, SVal First,
SVal Second, CheckerContext &C) const { … }
void SmartPtrModeling::handleGet(const CallEvent &Call,
CheckerContext &C) const { … }
bool SmartPtrModeling::handleAssignOp(const CallEvent &Call,
CheckerContext &C) const { … }
bool SmartPtrModeling::handleMoveCtr(const CallEvent &Call, CheckerContext &C,
const MemRegion *ThisRegion) const { … }
bool SmartPtrModeling::updateMovedSmartPointers(
CheckerContext &C, const MemRegion *ThisRegion,
const MemRegion *OtherSmartPtrRegion, const CallEvent &Call) const { … }
void SmartPtrModeling::handleBoolConversion(const CallEvent &Call,
CheckerContext &C) const { … }
void ento::registerSmartPtrModeling(CheckerManager &Mgr) { … }
bool ento::shouldRegisterSmartPtrModeling(const CheckerManager &mgr) { … }