[analyzer] NFC: Introduce reusable bug category for "C++ move semantics".
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 19 Jan 2021 21:31:14 +0000 (13:31 -0800)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 27 Jan 2021 11:39:18 +0000 (03:39 -0800)
Currently only used by MoveChecker but ideally all checkers
should have reusable categories.

clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp

index 637b89f..062a604 100644 (file)
@@ -19,6 +19,7 @@ extern const char *const MemoryRefCount;
 extern const char *const MemoryError;
 extern const char *const UnixAPI;
 extern const char *const CXXObjectLifecycle;
+extern const char *const CXXMoveSemantics;
 extern const char *const SecurityError;
 } // namespace categories
 } // namespace ento
index a38298a..aaab2f1 100644 (file)
@@ -202,7 +202,7 @@ public:
   };
 
 private:
-  mutable std::unique_ptr<BugType> BT;
+  BugType BT{this, "Use-after-move", categories::CXXMoveSemantics};
 
   // Check if the given form of potential misuse of a given object
   // should be reported. If so, get it reported. The callback from which
@@ -393,11 +393,6 @@ ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
                                      MisuseKind MK) const {
   if (ExplodedNode *N = misuseCausesCrash(MK) ? C.generateErrorNode()
                                               : C.generateNonFatalErrorNode()) {
-
-    if (!BT)
-      BT.reset(new BugType(this, "Use-after-move",
-                           "C++ move semantics"));
-
     // Uniqueing report to the same object.
     PathDiagnosticLocation LocUsedForUniqueing;
     const ExplodedNode *MoveNode = getMoveLocation(N, Region, C);
@@ -431,7 +426,7 @@ ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
     }
 
     auto R = std::make_unique<PathSensitiveBugReport>(
-        *BT, OS.str(), N, LocUsedForUniqueing,
+        BT, OS.str(), N, LocUsedForUniqueing,
         MoveNode->getLocationContext()->getDecl());
     R->addVisitor(std::make_unique<MovedBugVisitor>(*this, Region, RD, MK));
     C.emitReport(std::move(R));
index a601370..b61e307 100644 (file)
@@ -20,6 +20,7 @@ const char *const MemoryRefCount =
 const char *const MemoryError = "Memory error";
 const char *const UnixAPI = "Unix API";
 const char *const CXXObjectLifecycle = "C++ object lifecycle";
+const char *const CXXMoveSemantics = "C++ move semantics";
 const char *const SecurityError = "Security error";
 } // namespace categories
 } // namespace ento