Skip to content

[Clang] fixed clang frontend crash with friend class declaration and overload == #133878

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

Merged
merged 10 commits into from
Apr 3, 2025

Conversation

Ankur-0429
Copy link
Contributor

Fixes #132249

Copy link

github-actions bot commented Apr 1, 2025

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 @ followed by their GitHub username.

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.

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

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-clang

Author: Ankur Ahir (Ankur-0429)

Changes

Fixes #132249


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-2)
  • (modified) clang/test/CXX/class/class.compare/class.compare.default/p1.cpp (+11)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 43bf9b7cd0f95..36015a93c9728 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9037,8 +9037,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();
+          return F->getFriendDecl() &&
+                 FD->getCanonicalDecl() ==
+                     F->getFriendDecl()->getCanonicalDecl();
         })) {
       Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
           << int(DCK) << int(0) << RD;
diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index a195e0548152d..37bf98be889d5 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -285,3 +285,14 @@ struct j {
 };
 bool j::operator==(const j &) const = default;
 }
+
+namespace evil2 {
+  struct k {};
+  
+  struct l {
+    friend bool operator==(const l& a, const l& b);
+    friend class k;
+  };
+  
+  bool operator==(const l& a, const l& b) = default;
+}

Copy link
Contributor

@zyn0217 zyn0217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this should come with a release entry. Please make sure you add a note to the Bug Fixes to C++ Support section in clang/docs/ReleaseNotes.rst.

@zyn0217
Copy link
Contributor

zyn0217 commented Apr 2, 2025

And I think this should follow the same approach in #132320

@cor3ntin
Copy link
Contributor

cor3ntin commented Apr 2, 2025

Thanks! This makes sense to me, but I'm adding a couple more reviewers.

@cor3ntin
Copy link
Contributor

cor3ntin commented Apr 2, 2025

Congratulations on your first PR. Let me know if/when you want me to merge that for you. Cheers

@Ankur-0429
Copy link
Contributor Author

@cor3ntin feel free to merge the PR when it's ready. Happy to help!

@zyn0217 zyn0217 changed the title fixed clang frontend crash with friend class declaration and overload == [Clang] fixed clang frontend crash with friend class declaration and overload == Apr 3, 2025
Copy link
Contributor

@zyn0217 zyn0217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@zyn0217 zyn0217 merged commit fb7135e into llvm:main Apr 3, 2025
12 checks passed
Copy link

github-actions bot commented Apr 3, 2025

@Ankur-0429 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@Ankur-0429 Ankur-0429 deleted the ankurahir/clang-frontend-crash branch April 3, 2025 01:17
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 3, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building clang at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/15365

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: lang/c/cpp_keyword_identifiers/TestCppKeywordsAsCIdentifiers.py (715 of 2115)
PASS: lldb-api :: lang/c/const_variables/TestConstVariables.py (716 of 2115)
PASS: lldb-api :: lang/c/find_struct_type/TestFindStructTypes.py (717 of 2115)
PASS: lldb-api :: lang/c/conflicting-symbol/TestConflictingSymbol.py (718 of 2115)
PASS: lldb-api :: lang/c/flexible-array-members/TestCFlexibleArrayMembers.py (719 of 2115)
UNSUPPORTED: lldb-api :: lang/c/full_lto_stepping/TestFullLtoStepping.py (720 of 2115)
PASS: lldb-api :: lang/c/enum_types/TestEnumTypes.py (721 of 2115)
XFAIL: lldb-api :: lang/c/local_types/TestUseClosestType.py (722 of 2115)
PASS: lldb-api :: lang/c/forward/TestForwardDeclaration.py (723 of 2115)
PASS: lldb-api :: lang/c/anonymous/TestAnonymous.py (724 of 2115)
FAIL: lldb-api :: lang/c/fpeval/TestFPEval.py (725 of 2115)
******************** TEST 'lldb-api :: lang/c/fpeval/TestFPEval.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/lang/c/fpeval -p TestFPEval.py
--
Exit Code: -11

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision fb7135ec5239a45b43fae6206f7409fd77c50b9f)
  clang revision fb7135ec5239a45b43fae6206f7409fd77c50b9f
  llvm revision fb7135ec5239a45b43fae6206f7409fd77c50b9f
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_dsym (TestFPEval.FPEvalTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_dwarf (TestFPEval.FPEvalTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_dwo (TestFPEval.FPEvalTestCase)
----------------------------------------------------------------------
Ran 3 tests in 1.012s

OK (skipped=1)

--

********************
PASS: lldb-api :: lang/c/inlines/TestRedefinitionsInInlines.py (726 of 2115)
PASS: lldb-api :: lang/c/function_types/TestFunctionTypes.py (727 of 2115)
PASS: lldb-api :: lang/c/local_variables/TestLocalVariables.py (728 of 2115)
PASS: lldb-api :: lang/c/global_variables/TestGlobalVariables.py (729 of 2115)
PASS: lldb-api :: lang/c/offsetof/TestOffsetof.py (730 of 2115)
PASS: lldb-api :: lang/c/non-mangled/TestCNonMangled.py (731 of 2115)
XFAIL: lldb-api :: lang/c/modules/TestCModules.py (732 of 2115)
PASS: lldb-api :: lang/c/parray_vrs_char_array/TestParrayVrsCharArrayChild.py (733 of 2115)
PASS: lldb-api :: lang/c/record_decl_in_expr/TestRecordDeclInExpr.py (734 of 2115)
PASS: lldb-api :: lang/c/sizeof/TestCSizeof.py (735 of 2115)

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] clang frontend crash with friend class declaration and overloaded operator ==
6 participants