-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[clang] Fix nullptr dereference when checking friend default comparison #132320
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
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang Author: Chongzhi Deng (BruceAko) ChangesFix a crash in The fix ensures we check that Full diff: https://github.com/llvm/llvm-project/pull/132320.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a1551e8027cd3..eae2bbf65db31 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9039,8 +9039,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
return true;
if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
- return FD->getCanonicalDecl() ==
- F->getFriendDecl()->getCanonicalDecl();
+ NamedDecl *ND = F->getFriendDecl();
+ return ND && FD->getCanonicalDecl() == ND->getCanonicalDecl();
})) {
Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
<< int(DCK) << int(0) << RD;
|
mizvekov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should add test and release note.
clang/lib/Sema/SemaDeclCXX.cpp
Outdated
| NamedDecl *ND = F->getFriendDecl(); | ||
| return ND && FD->getCanonicalDecl() == ND->getCanonicalDecl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| NamedDecl *ND = F->getFriendDecl(); | |
| return ND && FD->getCanonicalDecl() == ND->getCanonicalDecl(); | |
| NamedDecl *ND = F->getFriendDecl(); | |
| return declaresSameEntity(F->getFriendDecl(), FD); |
Fix comparison check for explicitly defaulted functions by using declaresSameEntity for friend declarations.
shafik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BruceAko why did you close the PR?
Fix a crash in
SemaDeclCXX.cppwhen defaulting a comparison operator that has been declared as a friend function alongside class friend declarations. When checking if a defaulted operator is a friend, the code would dereference the result ofFriendDecl::getFriendDecl()without checking for nullptr, which occurs for class friend declarations.The fix ensures we check that
getFriendDecl()returns a non-null pointer before attempting to access its canonical declaration.Fixes #132249