[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/Sirraide approved this pull request. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/139767 >From 7249f9c5d4307aa3eb302bdd689fbf45ef7b9cc9 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 13 May 2025 13:02:13 -0400 Subject: [PATCH 1/2] [C++20] Fix a crash with spaceship and vector types Vector types cannot be directly compared, you get an error when you try to do so. This patch causes the explicitly defaulted spaceship operator to be implicitly deleted. Fixes #137452 --- clang/docs/ReleaseNotes.rst | 3 +++ clang/lib/Sema/SemaDeclCXX.cpp| 5 + clang/test/SemaCXX/cxx2a-three-way-comparison.cpp | 8 3 files changed, 16 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bc13d02e2d20b..3941eb51b00d7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -118,6 +118,9 @@ C++23 Feature Support C++20 Feature Support ^ +- Fixed a crash with a defaulted spaceship (``<=>``) operator when the class + contains a member declaration of vector type. Vector types cannot yet be + compared directly, so this causes the operator to be deleted. (#GH137452) C++17 Feature Support ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index cbccb567e2adf..2f2ff2d471c71 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8651,6 +8651,11 @@ class DefaultedComparisonAnalyzer assert(Best->BuiltinParamTypes[2].isNull() && "invalid builtin comparison"); +// FIXME: If the type we deduced is a vector type, we mark the +// comparison as deleted because we don't yet support this. +if (isa(T)) + return Result::deleted(); + if (NeedsDeducing) { std::optional Cat = getComparisonCategoryForBuiltinCmp(T); diff --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp index b94225274fffb..36b603e4f7660 100644 --- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp +++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp @@ -58,3 +58,11 @@ namespace PR44325 { // implicit rewrite rules, not for explicit use by programs. bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}} } + +namespace GH137452 { +struct comparable_t { +__attribute__((vector_size(32))) double numbers; +auto operator<=>(const comparable_t& rhs) const = default; // expected-warning {{explicitly defaulted three-way comparison operator is implicitly deleted}} \ + expected-note {{replace 'default' with 'delete'}} +}; +} // namespace GH137452 >From f40a2d14d7e2983e897156e4faeb135c01913cf6 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 13 May 2025 13:26:43 -0400 Subject: [PATCH 2/2] Report why it's deleted --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ clang/lib/Sema/SemaDeclCXX.cpp| 9 - clang/test/SemaCXX/cxx2a-three-way-comparison.cpp | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3efe9593b8633..17c292412d18b 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10176,6 +10176,9 @@ def note_defaulted_comparison_no_viable_function_synthesized : Note< def note_defaulted_comparison_not_rewritten_callee : Note< "defaulted %0 is implicitly deleted because this non-rewritten comparison " "function would be the best match for the comparison">; +def note_defaulted_comparison_vector_types : Note< + "defaulted %0 is implicitly deleted because defaulted comparison of vector " + "types is not supported">; def note_defaulted_comparison_not_rewritten_conversion : Note< "defaulted %0 is implicitly deleted because a builtin comparison function " "using this conversion would be the best match for the comparison">; diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 2f2ff2d471c71..91bdaad242e6b 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8653,8 +8653,15 @@ class DefaultedComparisonAnalyzer // FIXME: If the type we deduced is a vector type, we mark the // comparison as deleted because we don't yet support this. -if (isa(T)) +if (isa(T)) { + if (Diagnose == ExplainDeleted) { +S.Diag(FD->getLocation(), + diag::note_defaulted_comparison_vector_types) +<< FD; +S.Diag(Subobj.Decl->getLocation(), diag::note_declared_at); + } return Result::deleted(); +} if (NeedsDeducing) { std::optional Cat = diff --git a/clang/test/SemaCXX/cxx2a-thr
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
AaronBallman wrote: > Do we want to issue a diagnostic for this? I would imagine that users could > get confused about this if they don’t know _why_ the operator is marked as > deleted. Yeah, I missed that part of the patch. More changes coming. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
Sirraide wrote: GCC does print a note explaining that this is not implemented apparently. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
@@ -8651,6 +8651,11 @@ class DefaultedComparisonAnalyzer assert(Best->BuiltinParamTypes[2].isNull() && "invalid builtin comparison"); +// FIXME: If the type we deduced is a vector type, we mark the +// comparison as deleted because we don't yet support this. +if (isa(T)) + return Result::deleted(); AaronBallman wrote: Oh, I missed the "explain deleted" code paths entirely. I'll address that. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/Sirraide approved this pull request. Do we want to issue a diagnostic for this? I would imagine that users could get confused about this if they don’t know *why* the operator is marked as deleted. https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
@@ -8651,6 +8651,11 @@ class DefaultedComparisonAnalyzer assert(Best->BuiltinParamTypes[2].isNull() && "invalid builtin comparison"); +// FIXME: If the type we deduced is a vector type, we mark the +// comparison as deleted because we don't yet support this. +if (isa(T)) + return Result::deleted(); erichkeane wrote: The other versions of 'deleted' all seem to diagnose first, is there a reason to not do so here? https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changes Vector types cannot be directly compared, you get an error when you try to do so. This patch causes the explicitly defaulted spaceship operator to be implicitly deleted. Fixes #137452 --- Full diff: https://github.com/llvm/llvm-project/pull/139767.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+3) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+5) - (modified) clang/test/SemaCXX/cxx2a-three-way-comparison.cpp (+8) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bc13d02e2d20b..3941eb51b00d7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -118,6 +118,9 @@ C++23 Feature Support C++20 Feature Support ^ +- Fixed a crash with a defaulted spaceship (``<=>``) operator when the class + contains a member declaration of vector type. Vector types cannot yet be + compared directly, so this causes the operator to be deleted. (#GH137452) C++17 Feature Support ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index cbccb567e2adf..2f2ff2d471c71 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8651,6 +8651,11 @@ class DefaultedComparisonAnalyzer assert(Best->BuiltinParamTypes[2].isNull() && "invalid builtin comparison"); +// FIXME: If the type we deduced is a vector type, we mark the +// comparison as deleted because we don't yet support this. +if (isa(T)) + return Result::deleted(); + if (NeedsDeducing) { std::optional Cat = getComparisonCategoryForBuiltinCmp(T); diff --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp index b94225274fffb..36b603e4f7660 100644 --- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp +++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp @@ -58,3 +58,11 @@ namespace PR44325 { // implicit rewrite rules, not for explicit use by programs. bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}} } + +namespace GH137452 { +struct comparable_t { +__attribute__((vector_size(32))) double numbers; +auto operator<=>(const comparable_t& rhs) const = default; // expected-warning {{explicitly defaulted three-way comparison operator is implicitly deleted}} \ + expected-note {{replace 'default' with 'delete'}} +}; +} // namespace GH137452 `` https://github.com/llvm/llvm-project/pull/139767 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] Fix a crash with spaceship and vector types (PR #139767)
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/139767 Vector types cannot be directly compared, you get an error when you try to do so. This patch causes the explicitly defaulted spaceship operator to be implicitly deleted. Fixes #137452 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 14px; line-height: 1.5; margin: 0; } .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; } a { color: #0366d6; text-decoration: none; } a:hover { text-decoration: underline; } h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #66; font-weight: 200; font-size: 14px; margin: 0 10px; } Whoa there! You have exceeded a secondary rate limit. Please wait a few minutes before you try again; in some cases this may take up to an hour. https://support.github.com/contact";>Contact Support — https://githubstatus.com";>GitHub Status — https://twitter.com/githubstatus";>@githubstatus ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits