Skip to content

[clang][dataflow] Fix casting in ChromiumCheckModel. #101640

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

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

Pask00
Copy link
Contributor

@Pask00 Pask00 commented Aug 2, 2024

getDirectCallee() may return a null pointer if the callee is not a FunctionDecl (for example when using function pointers), this requires to use dyn_cast_or_null instead of dyn_cast.

`getDirectCallee()` may return a null pointer if the callee is not a `FunctionDecl` (for example when using function pointers), this requires to use `dyn_cast_or_null` instead of `dyn_cast`.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang:analysis labels Aug 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 2, 2024

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Pasquale Riello (Pask00)

Changes

getDirectCallee() may return a null pointer if the callee is not a FunctionDecl (for example when using function pointers), this requires to use dyn_cast_or_null instead of dyn_cast.


Full diff: https://github.com/llvm/llvm-project/pull/101640.diff

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp (+1-1)
diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
index 5ac71e1d6bf64..27a624c61c7f2 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -56,7 +56,7 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) {
     return false;
   auto Stmt = CS->getStmt();
   if (const auto *Call = dyn_cast<CallExpr>(Stmt)) {
-    if (const auto *M = dyn_cast<CXXMethodDecl>(Call->getDirectCallee())) {
+    if (const auto *M = dyn_cast_or_null<CXXMethodDecl>(Call->getDirectCallee())) {
       if (isCheckLikeMethod(CheckDecls, *M)) {
         // Mark this branch as unreachable.
         Env.assume(Env.arena().makeLiteral(false));

Copy link

github-actions bot commented Aug 2, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@paulsemel paulsemel merged commit 28d4149 into llvm:main Aug 2, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants