[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

Kristóf Umann via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 26 02:06:56 PDT 2024


https://github.com/Szelethus created https://github.com/llvm/llvm-project/pull/100719

Response to the catch in this comment: https://github.com/llvm/llvm-project/pull/94357/files/07f6daf2cf0f5d5bd4fc9950f2585a3f52b4ad2f#r1692084074

>From d176b03b211144dadaa1efb4b7da959110d7725c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= <dkszelethus at gmail.com>
Date: Fri, 26 Jul 2024 11:01:41 +0200
Subject: [PATCH] [analyzer][NFC] Eliminate a dyn_cast

---
 clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp          | 5 ++---
 clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h | 2 +-
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp          | 5 ++---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fe202c79ed620..39e5c7c014a2a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -796,14 +796,13 @@ class NoMemOwnershipChangeVisitor final : public NoOwnershipChangeVisitor {
   /// done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
                                      ASTContext &ACtx) final {
     using namespace clang::ast_matchers;
-    const FunctionDecl *FD = dyn_cast<FunctionDecl>(Callee);
 
     auto Matches = match(findAll(stmt(anyOf(cxxDeleteExpr().bind("delete"),
                                             callExpr().bind("call")))),
-                         *FD->getBody(), ACtx);
+                         Callee->getBody(), ACtx);
     for (BoundNodes Match : Matches) {
       if (Match.getNodeAs<CXXDeleteExpr>("delete"))
         return true;
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
index 027f1a156a7c0..7be74860d863b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
+++ b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
@@ -26,7 +26,7 @@ class NoOwnershipChangeVisitor : public NoStateChangeFuncVisitor {
   /// is done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  virtual bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  virtual bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
                                              ASTContext &ACtx) = 0;
 
   virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 9aee7f952ad2d..41187ee9b5cdf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -746,13 +746,12 @@ class NoStreamStateChangeVisitor final : public NoOwnershipChangeVisitor {
     return StreamChk->FCloseDesc.matchesAsWritten(Call);
   }
 
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
                                      ASTContext &ACtx) final {
     using namespace clang::ast_matchers;
-    const FunctionDecl *FD = dyn_cast<FunctionDecl>(Callee);
 
     auto Matches =
-        match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+        match(findAll(callExpr().bind("call")), Callee->getBody(), ACtx);
     for (BoundNodes Match : Matches) {
       if (const auto *Call = Match.getNodeAs<CallExpr>("call"))
         if (isClosingCallAsWritten(*Call))



More information about the cfe-commits mailing list