[analyzer] MisusedMovedObject: Fix state-resetting a base-class sub-object.

If a method is resetting the state of an object that was moved from, it should
be safe to use this object again. However if the method was defined in a parent
class, but used in a child class, the reset didn't happen from the checker's
perspective.

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

llvm-svn: 315301
This commit is contained in:
Artem Dergachev 2017-10-10 11:55:56 +00:00
parent c06bb16f1c
commit 0f22a06b4d
2 changed files with 16 additions and 1 deletions

View File

@ -416,7 +416,14 @@ void MisusedMovedObjectChecker::checkPreCall(const CallEvent &Call,
return;
if (isStateResetMethod(MethodDecl)) {
State = State->remove<TrackedRegionMap>(ThisRegion);
// A state reset method resets the whole object, not only sub-object
// of a parent class in which it is defined.
const MemRegion *WholeObjectRegion = ThisRegion;
while (const CXXBaseObjectRegion *BR =
dyn_cast<CXXBaseObjectRegion>(WholeObjectRegion))
WholeObjectRegion = BR->getSuperRegion();
State = State->remove<TrackedRegionMap>(WholeObjectRegion);
C.addTransition(State);
return;
}

View File

@ -617,3 +617,11 @@ void subRegionMoveTest() {
a.b.foo(); // no-warning
}
}
class C: public A {};
void resetSuperClass() {
C c;
C c1 = std::move(c);
c.clear();
C c2 = c; // no-warning
}