r315301 - [analyzer] MisusedMovedObject: Fix state-resetting a base-class sub-object.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 04:55:56 PDT 2017
Author: dergachev
Date: Tue Oct 10 04:55:56 2017
New Revision: 315301
URL: http://llvm.org/viewvc/llvm-project?rev=315301&view=rev
Log:
[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
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
cfe/trunk/test/Analysis/MisusedMovedObject.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp?rev=315301&r1=315300&r2=315301&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp Tue Oct 10 04:55:56 2017
@@ -416,7 +416,14 @@ void MisusedMovedObjectChecker::checkPre
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;
}
Modified: cfe/trunk/test/Analysis/MisusedMovedObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/MisusedMovedObject.cpp?rev=315301&r1=315300&r2=315301&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/MisusedMovedObject.cpp (original)
+++ cfe/trunk/test/Analysis/MisusedMovedObject.cpp Tue Oct 10 04:55:56 2017
@@ -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
+}
More information about the cfe-commits
mailing list