29class CXXSelfAssignmentChecker :
public Checker<check::BeginFunction> {
31 CXXSelfAssignmentChecker();
36CXXSelfAssignmentChecker::CXXSelfAssignmentChecker() {}
38void CXXSelfAssignmentChecker::checkBeginFunction(
CheckerContext &
C)
const {
41 const auto *LCtx =
C.getLocationContext();
42 const auto *MD = dyn_cast<CXXMethodDecl>(LCtx->getDecl());
45 if (!MD->isCopyAssignmentOperator() && !MD->isMoveAssignmentOperator())
47 auto &State =
C.getState();
48 auto &SVB =
C.getSValBuilder();
50 State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
51 auto Param = SVB.makeLoc(State->getRegion(MD->getParamDecl(0), LCtx));
52 auto ParamVal = State->getSVal(Param);
58 llvm::raw_svector_ostream Out(Msg);
59 Out <<
"Assuming " << MD->getParamDecl(0)->getName() <<
" == *this";
60 return std::string(Out.str());
62 C.addTransition(SelfAssignState, SelfAssignTag);
64 ProgramStateRef NonSelfAssignState = State->bindLoc(Param, ParamVal, LCtx);
65 const NoteTag *NonSelfAssignTag =
68 llvm::raw_svector_ostream Out(Msg);
69 Out <<
"Assuming " << MD->getParamDecl(0)->getName() <<
" != *this";
70 return std::string(Out.str());
72 C.addTransition(NonSelfAssignState, NonSelfAssignTag);
79bool ento::shouldRegisterCXXSelfAssignmentChecker(
const CheckerManager &mgr) {
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
The tag upon which the TagVisitor reacts.
The JSON file list parser is used to communicate input to InstallAPI.