[clang] [analyzer] Assert Callee is FunctionDecl in doesFnIntendToHandleOwner… (PR #101066)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 29 11:59:58 PDT 2024


https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/101066

…ship()

This patch replaces dyn_cast<> with cast<> for converting Callee to FunctionDecl, asserting non-null assumption to prevent undefined behavior due to null dereferences and enforces the invariant that Callee must be a valid FunctionDecl.

>From 99948fa56e0a0604256184d3f7143ee21c5de76b Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Mon, 29 Jul 2024 11:56:09 -0700
Subject: [PATCH] [analyzer] Assert Callee is FunctionDecl in
 doesFnIntendToHandleOwnership()

This patch replaces dyn_cast<> with cast<> for converting Callee to FunctionDecl, asserting non-null assumption to prevent undefined behavior due to null dereferences and enforces the invariant that Callee must be a valid FunctionDecl.
---
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 4454f30630e27..534aa147aefb0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -756,7 +756,7 @@ 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);
+    const FunctionDecl *FD = cast<FunctionDecl>(Callee);
 
     auto Matches =
         match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);



More information about the cfe-commits mailing list