This revision was automatically updated to reflect the committed changes.
Closed by commit rGc74a204826da: [analyzer] Fix false positive in
use-after-move checker (authored by malavikasamak).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131525/new/
https://reviews.llvm.org/D131525
Files:
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/test/Analysis/use-after-move.cpp
Index: clang/test/Analysis/use-after-move.cpp
===================================================================
--- clang/test/Analysis/use-after-move.cpp
+++ clang/test/Analysis/use-after-move.cpp
@@ -900,6 +900,28 @@
}
}
+void checkExplicitDestructorCalls() {
+ // The below code segments invoke the destructor twice (explicit and
+ // implicit). While this is not a desired code behavior, it is
+ // not the use-after-move checker's responsibility to issue such a warning.
+ {
+ B* b = new B;
+ B a = std::move(*b);
+ b->~B(); // no-warning
+ delete b;
+ }
+ {
+ B a, b;
+ new (&a) B(reinterpret_cast<B &&>(b));
+ (&b)->~B(); // no-warning
+ }
+ {
+ B b;
+ B a = std::move(b);
+ b.~B(); // no-warning
+ }
+}
+
struct MoveOnlyWithDestructor {
MoveOnlyWithDestructor();
~MoveOnlyWithDestructor();
Index: clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -618,10 +618,6 @@
if (!IC)
return;
- // Calling a destructor on a moved object is fine.
- if (isa<CXXDestructorCall>(IC))
- return;
-
const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion();
if (!ThisRegion)
return;
@@ -631,6 +627,10 @@
if (!MethodDecl)
return;
+ // Calling a destructor on a moved object is fine.
+ if (isa<CXXDestructorDecl>(MethodDecl))
+ return;
+
// We want to investigate the whole object, not only sub-object of a parent
// class in which the encountered method defined.
ThisRegion = ThisRegion->getMostDerivedObjectRegion();
Index: clang/test/Analysis/use-after-move.cpp
===================================================================
--- clang/test/Analysis/use-after-move.cpp
+++ clang/test/Analysis/use-after-move.cpp
@@ -900,6 +900,28 @@
}
}
+void checkExplicitDestructorCalls() {
+ // The below code segments invoke the destructor twice (explicit and
+ // implicit). While this is not a desired code behavior, it is
+ // not the use-after-move checker's responsibility to issue such a warning.
+ {
+ B* b = new B;
+ B a = std::move(*b);
+ b->~B(); // no-warning
+ delete b;
+ }
+ {
+ B a, b;
+ new (&a) B(reinterpret_cast<B &&>(b));
+ (&b)->~B(); // no-warning
+ }
+ {
+ B b;
+ B a = std::move(b);
+ b.~B(); // no-warning
+ }
+}
+
struct MoveOnlyWithDestructor {
MoveOnlyWithDestructor();
~MoveOnlyWithDestructor();
Index: clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -618,10 +618,6 @@
if (!IC)
return;
- // Calling a destructor on a moved object is fine.
- if (isa<CXXDestructorCall>(IC))
- return;
-
const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion();
if (!ThisRegion)
return;
@@ -631,6 +627,10 @@
if (!MethodDecl)
return;
+ // Calling a destructor on a moved object is fine.
+ if (isa<CXXDestructorDecl>(MethodDecl))
+ return;
+
// We want to investigate the whole object, not only sub-object of a parent
// class in which the encountered method defined.
ThisRegion = ThisRegion->getMostDerivedObjectRegion();
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits