[clang] [Clang] Prevent Null Pointer Dereference in in sema::​isNormalAssignmentOperator() (PR #115880)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 07:07:53 PST 2024


https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/115880

This patch replaces dyn_cast<> with cast<> for CXXMethodDecl in isNormalAssignmentOperator() function, assuming FD is always a CXXMethodDecl. This change simplifies the code by removing the null check and relying on cast to assert the type.

>From bfebe2102dc20b71bce09b4bc7e2bb028454c239 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Tue, 12 Nov 2024 07:05:16 -0800
Subject: [PATCH] =?UTF-8?q?[Clang]=20Prevent=20Null=20Pointer=20Dereferenc?=
 =?UTF-8?q?e=20in=20sema::=E2=80=8BisNormalAssignmentOperator()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 clang/lib/Sema/CheckExprLifetime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp
index a1a402b4a2b530..e5ed9012fede51 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -482,8 +482,8 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
     if (RetT->isLValueReferenceType()) {
       ASTContext &Ctx = FD->getASTContext();
       QualType LHST;
-      auto *MD = dyn_cast<CXXMethodDecl>(FD);
-      if (MD && MD->isCXXInstanceMember())
+      auto *MD = cast<CXXMethodDecl>(FD);
+      if (MD->isCXXInstanceMember())
         LHST = Ctx.getLValueReferenceType(MD->getFunctionObjectParameterType());
       else
         LHST = MD->getParamDecl(0)->getType();



More information about the cfe-commits mailing list