[clang] [analyzer] Assert Callee is FunctionDecl in doesFnIntendToHandleOwnership() (PR #101066)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 12:01:06 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-static-analyzer-1
Author: None (smanna12)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/101066.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+1-1)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/101066
More information about the cfe-commits
mailing list