From 2c5945ca20ae3edf098e146e9901074f4dd97168 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Mon, 3 Dec 2018 22:32:32 +0000 Subject: [PATCH] [analyzer] Rename MisusedMovedObjectChecker to MoveChecker This follows the Static Analyzer's tradition to name checkers after things in which they find bugs, not after bugs they find. Differential Revision: https://reviews.llvm.org/D54556 llvm-svn: 348201 --- .../clang/StaticAnalyzer/Checkers/Checkers.td | 5 +- clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt | 2 +- ...susedMovedObjectChecker.cpp => MoveChecker.cpp} | 57 ++++++++++------------ .../{MisusedMovedObject.cpp => use-after-move.cpp} | 8 ++- 4 files changed, 34 insertions(+), 38 deletions(-) rename clang/lib/StaticAnalyzer/Checkers/{MisusedMovedObjectChecker.cpp => MoveChecker.cpp} (89%) rename clang/test/Analysis/{MisusedMovedObject.cpp => use-after-move.cpp} (97%) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 950a243..2933c3e 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -303,9 +303,8 @@ def MismatchedIteratorChecker : Checker<"MismatchedIterator">, HelpText<"Check for use of iterators of different containers where iterators " "of the same container are expected">; -def MisusedMovedObjectChecker: Checker<"MisusedMovedObject">, - HelpText<"Method calls on a moved-from object and copying a moved-from " - "object will be reported">; +def MoveChecker: Checker<"Move">, + HelpText<"Find use-after-move bugs in C++">; def UninitializedObjectChecker: Checker<"UninitializedObject">, HelpText<"Reports uninitialized fields after object construction">; diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt index 5e08a74..47dbac6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -52,7 +52,7 @@ add_clang_library(clangStaticAnalyzerCheckers MallocOverflowSecurityChecker.cpp MallocSizeofChecker.cpp MmapWriteExecChecker.cpp - MisusedMovedObjectChecker.cpp + MoveChecker.cpp MPI-Checker/MPIBugReporter.cpp MPI-Checker/MPIChecker.cpp MPI-Checker/MPIFunctionClassifier.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp similarity index 89% rename from clang/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp rename to clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp index ab5f3a1..33a89f9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp @@ -1,4 +1,4 @@ -// MisusedMovedObjectChecker.cpp - Check use of moved-from objects. - C++ -===// +// MoveChecker.cpp - Check use of moved-from objects. - C++ ---------------===// // // The LLVM Compiler Infrastructure // @@ -42,7 +42,7 @@ public: void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); } }; -class MisusedMovedObjectChecker +class MoveChecker : public Checker { public: @@ -117,9 +117,8 @@ static bool isAnyBaseRegionReported(ProgramStateRef State, } std::shared_ptr -MisusedMovedObjectChecker::MovedBugVisitor::VisitNode(const ExplodedNode *N, - BugReporterContext &BRC, - BugReport &) { +MoveChecker::MovedBugVisitor::VisitNode(const ExplodedNode *N, + BugReporterContext &BRC, BugReport &) { // We need only the last move of the reported object's region. // The visitor walks the ExplodedGraph backwards. if (Found) @@ -157,8 +156,9 @@ MisusedMovedObjectChecker::MovedBugVisitor::VisitNode(const ExplodedNode *N, return std::make_shared(Pos, InfoText, true); } -const ExplodedNode *MisusedMovedObjectChecker::getMoveLocation( - const ExplodedNode *N, const MemRegion *Region, CheckerContext &C) const { +const ExplodedNode *MoveChecker::getMoveLocation(const ExplodedNode *N, + const MemRegion *Region, + CheckerContext &C) const { // Walk the ExplodedGraph backwards and find the first node that referred to // the tracked region. const ExplodedNode *MoveNode = N; @@ -173,10 +173,9 @@ const ExplodedNode *MisusedMovedObjectChecker::getMoveLocation( return MoveNode; } -ExplodedNode *MisusedMovedObjectChecker::reportBug(const MemRegion *Region, - const CallEvent &Call, - CheckerContext &C, - MisuseKind MK) const { +ExplodedNode *MoveChecker::reportBug(const MemRegion *Region, + const CallEvent &Call, CheckerContext &C, + MisuseKind MK) const { if (ExplodedNode *N = C.generateNonFatalErrorNode()) { if (!BT) BT.reset(new BugType(this, "Usage of a 'moved-from' object", @@ -220,8 +219,8 @@ ExplodedNode *MisusedMovedObjectChecker::reportBug(const MemRegion *Region, // Removing the function parameters' MemRegion from the state. This is needed // for PODs where the trivial destructor does not even created nor executed. -void MisusedMovedObjectChecker::checkEndFunction(const ReturnStmt *RS, - CheckerContext &C) const { +void MoveChecker::checkEndFunction(const ReturnStmt *RS, + CheckerContext &C) const { auto State = C.getState(); TrackedRegionMapTy Objects = State->get(); if (Objects.isEmpty()) @@ -254,8 +253,8 @@ void MisusedMovedObjectChecker::checkEndFunction(const ReturnStmt *RS, C.addTransition(State); } -void MisusedMovedObjectChecker::checkPostCall(const CallEvent &Call, - CheckerContext &C) const { +void MoveChecker::checkPostCall(const CallEvent &Call, + CheckerContext &C) const { const auto *AFC = dyn_cast(&Call); if (!AFC) return; @@ -302,8 +301,7 @@ void MisusedMovedObjectChecker::checkPostCall(const CallEvent &Call, C.addTransition(State); } -bool MisusedMovedObjectChecker::isMoveSafeMethod( - const CXXMethodDecl *MethodDec) const { +bool MoveChecker::isMoveSafeMethod(const CXXMethodDecl *MethodDec) const { // We abandon the cases where bool/void/void* conversion happens. if (const auto *ConversionDec = dyn_cast_or_null(MethodDec)) { @@ -319,8 +317,7 @@ bool MisusedMovedObjectChecker::isMoveSafeMethod( MethodDec->getName().lower() == "isempty")); } -bool MisusedMovedObjectChecker::isStateResetMethod( - const CXXMethodDecl *MethodDec) const { +bool MoveChecker::isStateResetMethod(const CXXMethodDecl *MethodDec) const { if (!MethodDec) return false; if (MethodDec->hasAttr()) @@ -336,8 +333,7 @@ bool MisusedMovedObjectChecker::isStateResetMethod( // Don't report an error inside a move related operation. // We assume that the programmer knows what she does. -bool MisusedMovedObjectChecker::isInMoveSafeContext( - const LocationContext *LC) const { +bool MoveChecker::isInMoveSafeContext(const LocationContext *LC) const { do { const auto *CtxDec = LC->getDecl(); auto *CtorDec = dyn_cast_or_null(CtxDec); @@ -352,8 +348,7 @@ bool MisusedMovedObjectChecker::isInMoveSafeContext( return false; } -void MisusedMovedObjectChecker::checkPreCall(const CallEvent &Call, - CheckerContext &C) const { +void MoveChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const { ProgramStateRef State = C.getState(); const LocationContext *LC = C.getLocationContext(); ExplodedNode *N = nullptr; @@ -459,8 +454,8 @@ void MisusedMovedObjectChecker::checkPreCall(const CallEvent &Call, C.addTransition(State, N); } -void MisusedMovedObjectChecker::checkDeadSymbols(SymbolReaper &SymReaper, - CheckerContext &C) const { +void MoveChecker::checkDeadSymbols(SymbolReaper &SymReaper, + CheckerContext &C) const { ProgramStateRef State = C.getState(); TrackedRegionMapTy TrackedRegions = State->get(); for (TrackedRegionMapTy::value_type E : TrackedRegions) { @@ -475,7 +470,7 @@ void MisusedMovedObjectChecker::checkDeadSymbols(SymbolReaper &SymReaper, C.addTransition(State); } -ProgramStateRef MisusedMovedObjectChecker::checkRegionChanges( +ProgramStateRef MoveChecker::checkRegionChanges( ProgramStateRef State, const InvalidatedSymbols *Invalidated, ArrayRef ExplicitRegions, ArrayRef Regions, const LocationContext *LCtx, @@ -495,10 +490,8 @@ ProgramStateRef MisusedMovedObjectChecker::checkRegionChanges( return State; } -void MisusedMovedObjectChecker::printState(raw_ostream &Out, - ProgramStateRef State, - const char *NL, - const char *Sep) const { +void MoveChecker::printState(raw_ostream &Out, ProgramStateRef State, + const char *NL, const char *Sep) const { TrackedRegionMapTy RS = State->get(); @@ -514,6 +507,6 @@ void MisusedMovedObjectChecker::printState(raw_ostream &Out, } } } -void ento::registerMisusedMovedObjectChecker(CheckerManager &mgr) { - mgr.registerChecker(); +void ento::registerMoveChecker(CheckerManager &mgr) { + mgr.registerChecker(); } diff --git a/clang/test/Analysis/MisusedMovedObject.cpp b/clang/test/Analysis/use-after-move.cpp similarity index 97% rename from clang/test/Analysis/MisusedMovedObject.cpp rename to clang/test/Analysis/use-after-move.cpp index f7ad266..f39a5ec 100644 --- a/clang/test/Analysis/MisusedMovedObject.cpp +++ b/clang/test/Analysis/use-after-move.cpp @@ -1,5 +1,9 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.MisusedMovedObject -std=c++11 -verify -analyzer-output=text -analyzer-config exploration_strategy=unexplored_first_queue,eagerly-assume=false %s -// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.MisusedMovedObject -std=c++11 -analyzer-config exploration_strategy=dfs,eagerly-assume=false -verify -analyzer-output=text -DDFS=1 %s +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\ +// RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\ +// RUN: -analyzer-config exploration_strategy=unexplored_first_queue +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\ +// RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\ +// RUN: -analyzer-config exploration_strategy=dfs -DDFS=1 namespace std { -- 2.7.4