[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)

Pasquale Riello via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 02:01:33 PDT 2024


https://github.com/Pask00 created https://github.com/llvm/llvm-project/pull/101640

`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`.

>From 7d1263ad9c72b638d4624173b128d24b1a4317a1 Mon Sep 17 00:00:00 2001
From: Pasquale Riello <pas.riello at gmail.com>
Date: Fri, 2 Aug 2024 08:59:07 +0000
Subject: [PATCH] [clang][dataflow] Fix casting in `ChromiumCheckModel`.

`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`.
---
 clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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));



More information about the cfe-commits mailing list