[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:08:42 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (smanna12)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/115880.diff
1 Files Affected:
- (modified) clang/lib/Sema/CheckExprLifetime.cpp (+2-2)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/115880
More information about the cfe-commits
mailing list