Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Added nullptr check to getFriendDecl access #121056

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GrumpyPigSkin
Copy link
Contributor

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

@shafik please can you review.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 24, 2024

@llvm/pr-subscribers-clang

Author: None (GrumpyPigSkin)

Changes

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

@shafik please can you review.


Full diff: https://github.com/llvm/llvm-project/pull/121056.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-2)
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;

@cor3ntin
Copy link
Contributor

Can you add a test? (and a release note) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Clang] parser error
3 participants