[clang] [Clang] Added nullptr check to getFriendDecl access (PR #121056)

via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 24 07:23:34 PST 2024


https://github.com/GrumpyPigSkin created https://github.com/llvm/llvm-project/pull/121056

fixes: #120857 where a `nullptr` access was causing a crash.

@shafik please can you review. 

>From a6c7f0dfd1da4b17118f25023cf2f5da70ee3dab Mon Sep 17 00:00:00 2001
From: GrumpyPigSkin <oliver61 at live.co.uk>
Date: Tue, 24 Dec 2024 15:18:29 +0000
Subject: [PATCH] Added nullptr check to getFriendDecl access

---
 clang/lib/Sema/SemaDeclCXX.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c5a72cf812ebc9..64b1fb28e2e184 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8871,8 +8871,9 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
       return true;
 
     if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
-          return FD->getCanonicalDecl() ==
-                 F->getFriendDecl()->getCanonicalDecl();
+          if (NamedDecl* Ffd = F->getFriendDecl())
+            return FD->getCanonicalDecl() == Ffd->getCanonicalDecl();
+          return false;
         })) {
       Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
           << int(DCK) << int(0) << RD;



More information about the cfe-commits mailing list