Skip to content

Commit 3e206a5

Browse files
committed
[analyzer] NFC: Introduce reusable bug category for "C++ move semantics".
Currently only used by MoveChecker but ideally all checkers should have reusable categories.
1 parent a5d85cb commit 3e206a5

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern const char *const MemoryRefCount;
1919
extern const char *const MemoryError;
2020
extern const char *const UnixAPI;
2121
extern const char *const CXXObjectLifecycle;
22+
extern const char *const CXXMoveSemantics;
2223
extern const char *const SecurityError;
2324
} // namespace categories
2425
} // namespace ento

clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class MoveChecker
202202
};
203203

204204
private:
205-
mutable std::unique_ptr<BugType> BT;
205+
BugType BT{this, "Use-after-move", categories::CXXMoveSemantics};
206206

207207
// Check if the given form of potential misuse of a given object
208208
// should be reported. If so, get it reported. The callback from which
@@ -393,11 +393,6 @@ ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
393393
MisuseKind MK) const {
394394
if (ExplodedNode *N = misuseCausesCrash(MK) ? C.generateErrorNode()
395395
: C.generateNonFatalErrorNode()) {
396-
397-
if (!BT)
398-
BT.reset(new BugType(this, "Use-after-move",
399-
"C++ move semantics"));
400-
401396
// Uniqueing report to the same object.
402397
PathDiagnosticLocation LocUsedForUniqueing;
403398
const ExplodedNode *MoveNode = getMoveLocation(N, Region, C);
@@ -431,7 +426,7 @@ ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
431426
}
432427

433428
auto R = std::make_unique<PathSensitiveBugReport>(
434-
*BT, OS.str(), N, LocUsedForUniqueing,
429+
BT, OS.str(), N, LocUsedForUniqueing,
435430
MoveNode->getLocationContext()->getDecl());
436431
R->addVisitor(std::make_unique<MovedBugVisitor>(*this, Region, RD, MK));
437432
C.emitReport(std::move(R));

clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const char *const MemoryRefCount =
2020
const char *const MemoryError = "Memory error";
2121
const char *const UnixAPI = "Unix API";
2222
const char *const CXXObjectLifecycle = "C++ object lifecycle";
23+
const char *const CXXMoveSemantics = "C++ move semantics";
2324
const char *const SecurityError = "Security error";
2425
} // namespace categories
2526
} // namespace ento

0 commit comments

Comments
 (0)