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

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


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

>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 1/2] [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));

>From d12bfaa9a9e217ada43f5e6f74a20c2dce5b77e7 Mon Sep 17 00:00:00 2001
From: Pasquale Riello <pas.riello at gmail.com>
Date: Fri, 2 Aug 2024 09:13:23 +0000
Subject: [PATCH 2/2] Apply clang-format.

---
 clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
index 27a624c61c7f2..77d817dafe837 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -56,7 +56,8 @@ 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_or_null<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