diff options
author | Kristóf Umann <dkszelethus@gmail.com> | 2024-08-05 13:25:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-05 13:25:31 +0200 |
commit | 8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0 (patch) | |
tree | 4918a9d09c5c086a7ff45fe52c513173e57c02a5 /clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | |
parent | 6f8ef5ad2f35321257adbe353f86027bf5209023 (diff) | |
download | llvm-8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0.zip llvm-8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0.tar.gz llvm-8370ba4d15c6726ed82bcd0d42a3ea9c94cc56b0.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 95ec28b..3ddcb7e 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -832,9 +832,18 @@ protected: /// 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); |