[clang] 8370ba4 - [analyzer][NFC] Eliminate a dyn_cast (#100719)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 5 04:25:36 PDT 2024
Author: Kristóf Umann
Date: 2024-08-05T13:25:31+02:00
New Revision: 8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0
URL: https://github.com/llvm/llvm-project/commit/8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0
DIFF: https://github.com/llvm/llvm-project/commit/8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0.diff
LOG: [analyzer][NFC] Eliminate a dyn_cast (#100719)
Response to the catch in this comment:
https://github.com/llvm/llvm-project/pull/94357/files/07f6daf2cf0f5d5bd4fc9950f2585a3f52b4ad2f#r1692084074
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.cpp
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 95ec28bfd20da..3ddcb7e94ae5d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -832,9 +832,18 @@ class NoMemOwnershipChangeVisitor final : public NoOwnershipChangeVisitor {
/// information.
bool doesFnIntendToHandleOwnership(const Decl *Callee,
ASTContext &ACtx) final {
- using namespace clang::ast_matchers;
const FunctionDecl *FD = dyn_cast<FunctionDecl>(Callee);
+ // Given that the stack frame was entered, the body should always be
+ // theoretically obtainable. In case of body farms, the synthesized body
+ // is not attached to declaration, thus triggering the '!FD->hasBody()'
+ // branch. That said, would a synthesized body ever intend to handle
+ // ownership? As of today they don't. And if they did, how would we
+ // put notes inside it, given that it doesn't match any source locations?
+ if (!FD || !FD->hasBody())
+ return false;
+ using namespace clang::ast_matchers;
+
auto Matches = match(findAll(stmt(anyOf(cxxDeleteExpr().bind("delete"),
callExpr().bind("call")))),
*FD->getBody(), ACtx);
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.cpp b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.cpp
index 22b5ebfd6fab0..91f4ca371aa98 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.cpp
@@ -72,16 +72,6 @@ bool NoOwnershipChangeVisitor::wasModifiedInFunction(
const ExplodedNode *CallEnterN, const ExplodedNode *CallExitEndN) {
const Decl *Callee =
CallExitEndN->getFirstPred()->getLocationContext()->getDecl();
- const FunctionDecl *FD = dyn_cast<FunctionDecl>(Callee);
-
- // Given that the stack frame was entered, the body should always be
- // theoretically obtainable. In case of body farms, the synthesized body
- // is not attached to declaration, thus triggering the '!FD->hasBody()'
- // branch. That said, would a synthesized body ever intend to handle
- // ownership? As of today they don't. And if they did, how would we
- // put notes inside it, given that it doesn't match any source locations?
- if (!FD || !FD->hasBody())
- return false;
if (!doesFnIntendToHandleOwnership(
Callee,
CallExitEndN->getState()->getAnalysisManager().getASTContext()))
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 4454f30630e27..22061373c4b39 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -755,9 +755,18 @@ class NoStreamStateChangeVisitor final : public NoOwnershipChangeVisitor {
bool doesFnIntendToHandleOwnership(const Decl *Callee,
ASTContext &ACtx) final {
- using namespace clang::ast_matchers;
const FunctionDecl *FD = dyn_cast<FunctionDecl>(Callee);
+ // Given that the stack frame was entered, the body should always be
+ // theoretically obtainable. In case of body farms, the synthesized body
+ // is not attached to declaration, thus triggering the '!FD->hasBody()'
+ // branch. That said, would a synthesized body ever intend to handle
+ // ownership? As of today they don't. And if they did, how would we
+ // put notes inside it, given that it doesn't match any source locations?
+ if (!FD || !FD->hasBody())
+ return false;
+ using namespace clang::ast_matchers;
+
auto Matches =
match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
for (BoundNodes Match : Matches) {
More information about the cfe-commits
mailing list