Deleted Added
full compact
CXXSelfAssignmentChecker.cpp (344779) CXXSelfAssignmentChecker.cpp (353358)
1//=== CXXSelfAssignmentChecker.cpp -----------------------------*- C++ -*--===//
2//
1//=== CXXSelfAssignmentChecker.cpp -----------------------------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4//
6//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines CXXSelfAssignmentChecker, which tests all custom defined
11// copy and move assignment operators for the case of self assignment, thus
12// where the parameter refers to the same location where the this pointer
13// points to. The checker itself does not do any checks at all, but it
14// causes the analyzer to check every copy and move assignment operator twice:
15// once for when 'this' aliases with the parameter and once for when it may not.

--- 30 unchanged lines hidden (view full) ---

46 if (!MD->isCopyAssignmentOperator() && !MD->isMoveAssignmentOperator())
47 return;
48 auto &State = C.getState();
49 auto &SVB = C.getSValBuilder();
50 auto ThisVal =
51 State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
52 auto Param = SVB.makeLoc(State->getRegion(MD->getParamDecl(0), LCtx));
53 auto ParamVal = State->getSVal(Param);
7//===----------------------------------------------------------------------===//
8//
9// This file defines CXXSelfAssignmentChecker, which tests all custom defined
10// copy and move assignment operators for the case of self assignment, thus
11// where the parameter refers to the same location where the this pointer
12// points to. The checker itself does not do any checks at all, but it
13// causes the analyzer to check every copy and move assignment operator twice:
14// once for when 'this' aliases with the parameter and once for when it may not.

--- 30 unchanged lines hidden (view full) ---

45 if (!MD->isCopyAssignmentOperator() && !MD->isMoveAssignmentOperator())
46 return;
47 auto &State = C.getState();
48 auto &SVB = C.getSValBuilder();
49 auto ThisVal =
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);
53
54 ProgramStateRef SelfAssignState = State->bindLoc(Param, ThisVal, LCtx);
54 ProgramStateRef SelfAssignState = State->bindLoc(Param, ThisVal, LCtx);
55 C.addTransition(SelfAssignState);
55 const NoteTag *SelfAssignTag =
56 C.getNoteTag([MD](BugReport &BR) -> std::string {
57 SmallString<256> Msg;
58 llvm::raw_svector_ostream Out(Msg);
59 Out << "Assuming " << MD->getParamDecl(0)->getName() << " == *this";
60 return Out.str();
61 });
62 C.addTransition(SelfAssignState, SelfAssignTag);
63
56 ProgramStateRef NonSelfAssignState = State->bindLoc(Param, ParamVal, LCtx);
64 ProgramStateRef NonSelfAssignState = State->bindLoc(Param, ParamVal, LCtx);
57 C.addTransition(NonSelfAssignState);
65 const NoteTag *NonSelfAssignTag =
66 C.getNoteTag([MD](BugReport &BR) -> std::string {
67 SmallString<256> Msg;
68 llvm::raw_svector_ostream Out(Msg);
69 Out << "Assuming " << MD->getParamDecl(0)->getName() << " != *this";
70 return Out.str();
71 });
72 C.addTransition(NonSelfAssignState, NonSelfAssignTag);
58}
59
60void ento::registerCXXSelfAssignmentChecker(CheckerManager &Mgr) {
61 Mgr.registerChecker<CXXSelfAssignmentChecker>();
62}
73}
74
75void ento::registerCXXSelfAssignmentChecker(CheckerManager &Mgr) {
76 Mgr.registerChecker<CXXSelfAssignmentChecker>();
77}
78
79bool ento::shouldRegisterCXXSelfAssignmentChecker(const LangOptions &LO) {
80 return true;
81}