[analyzer] MisusedMovedObject: Add printState() method for self-debugging.

This method injects additional information into program state dumps,
describing which objects have been moved from.

Differential Revision: https://reviews.llvm.org/D31541

llvm-svn: 315300
This commit is contained in:
Artem Dergachev 2017-10-10 11:50:45 +00:00
parent 5b0f885691
commit c06bb16f1c
1 changed files with 21 additions and 0 deletions

View File

@ -56,6 +56,8 @@ public:
ArrayRef<const MemRegion *> ExplicitRegions,
ArrayRef<const MemRegion *> Regions,
const LocationContext *LCtx, const CallEvent *Call) const;
void printState(raw_ostream &Out, ProgramStateRef State,
const char *NL, const char *Sep) const override;
private:
class MovedBugVisitor : public BugReporterVisitorImpl<MovedBugVisitor> {
@ -476,6 +478,25 @@ ProgramStateRef MisusedMovedObjectChecker::checkRegionChanges(
return State;
}
void MisusedMovedObjectChecker::printState(raw_ostream &Out,
ProgramStateRef State,
const char *NL,
const char *Sep) const {
TrackedRegionMapTy RS = State->get<TrackedRegionMap>();
if (!RS.isEmpty()) {
Out << Sep << "Moved-from objects :" << NL;
for (auto I: RS) {
I.first->dumpToStream(Out);
if (I.second.isMoved())
Out << ": moved";
else
Out << ": moved and reported";
Out << NL;
}
}
}
void ento::registerMisusedMovedObjectChecker(CheckerManager &mgr) {
mgr.registerChecker<MisusedMovedObjectChecker>();
}