-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[analyzer] Assert Callee is FunctionDecl in doesFnIntendToHandleOwnership() #101066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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.
@llvm/pr-subscribers-clang-static-analyzer-1 Author: None (smanna12) ChangesThis 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:
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);
|
@llvm/pr-subscribers-clang Author: None (smanna12) ChangesThis 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:
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);
|
If this function only cares about FunctionDecls, why does it accept a generic Decl? I'd prefer a clear interface instead. BTW, what does prevent a BlockDecl from taking ownership? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already under fix in #100719, I'm just a lazy bum and haven't fixed the buildbots. I'll try to speed things up!
Thanks for reviews. Closing this JIRA |
@Szelethus, would it possible to speed up the PR#100719? Thanks |
Why? |
It impacts our scan with static analyzer tool. |
I see. In that case I think it makes sense to mark that report in your tool as a true-positive, and it will be eventually fixed. Probably pretty soon, but I don't want to speak for Husi, as he might be on vacation. If it's urgent, a downstream patch should be always an option, but I don't think this issue would justify one - at least it wouldn't for me. |
Just landed the patch, sorry for the slack! |
This patch replaces dyn_cast<> with cast<> for converting Callee to FunctionDecl, asserting non-null assumption to prevent undefined behavior due to null dereferences, reported by static analyzer tool and enforces the invariant that Callee must be a valid FunctionDecl.