Skip to content

Commit 90e2df6

Browse files
Merge pull request #5120 from apple/malavikasamak/analyzer-fp-ix
[analyzer] Fix false positive in use-after-move checker
2 parents 238133f + 8bce046 commit 90e2df6

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,6 @@ void MoveChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const {
619619
if (!IC)
620620
return;
621621

622-
// Calling a destructor on a moved object is fine.
623-
if (isa<CXXDestructorCall>(IC))
624-
return;
625-
626622
const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion();
627623
if (!ThisRegion)
628624
return;
@@ -632,6 +628,10 @@ void MoveChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const {
632628
if (!MethodDecl)
633629
return;
634630

631+
// Calling a destructor on a moved object is fine.
632+
if (isa<CXXDestructorDecl>(MethodDecl))
633+
return;
634+
635635
// We want to investigate the whole object, not only sub-object of a parent
636636
// class in which the encountered method defined.
637637
ThisRegion = ThisRegion->getMostDerivedObjectRegion();

clang/test/Analysis/use-after-move.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,28 @@ void checkMoreLoopZombies4(bool flag) {
900900
}
901901
}
902902

903+
void checkExplicitDestructorCalls() {
904+
// The below code segments invoke the destructor twice (explicit and
905+
// implicit). While this is not a desired code behavior, it is
906+
// not the use-after-move checker's responsibility to issue such a warning.
907+
{
908+
B* b = new B;
909+
B a = std::move(*b);
910+
b->~B(); // no-warning
911+
delete b;
912+
}
913+
{
914+
B a, b;
915+
new (&a) B(reinterpret_cast<B &&>(b));
916+
(&b)->~B(); // no-warning
917+
}
918+
{
919+
B b;
920+
B a = std::move(b);
921+
b.~B(); // no-warning
922+
}
923+
}
924+
903925
struct MoveOnlyWithDestructor {
904926
MoveOnlyWithDestructor();
905927
~MoveOnlyWithDestructor();

0 commit comments

Comments
 (0)