[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-18 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

This patch is causing breakages downstream because it didn't have do the struct 
dance, so I've added D148677 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Hi folks!

We have a setup in which clang (more specifically clang-tools) is always built 
from a version close to HEAD and libcxx is fetched from user's checkout of the 
codebase (which can lag behind HEAD for ~a month).
So the 1 week gap between 
https://github.com/llvm/llvm-project/commit/380b6a13dad61e1d90e68fdd128af5dc177db3e1
 and this patch is not enough for us to prevent most of the breakages 
(clang-tools we have cannot work on checkouts that are not synced past this CL 
as they hit the name conflict).

Hence is it possible to revert this change and land it couple weeks later or 
add the token behind a PP-directive (looking at the way token is introduced 
having this optionally available seems to be hard though)?

also it would be nice to have general policies about changes that might break 
backward compat and how long to wait (i guess we would be more careful if the 
libcxx symbol was actually used in a released version). do we already have any 
guidance around that so that we can be prepared for those in the future?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-17 Thread Nikolas Klauser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe98776a180a7: [clang] Add __is_trivially_equality_comparable 
(authored by philnik).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
 
 #define T(b) (b) ? 1 : -1
 #define F(b) (b) ? -1 : 1
@@ -570,7 +571,11 @@
   static_assert(__is_aggregate(DerivesAr), "");
   static_assert(__is_aggregate(DerivesArNB), "");
   static_assert(!__is_aggregate(HasCons), "");
+#if __cplusplus >= 202002L
+  static_assert(!__is_aggregate(HasDefaultCons), "");
+#else
   static_assert(__is_aggregate(HasDefaultCons), "");
+#endif
   static_assert(!__is_aggregate(HasExplicitDefaultCons), "");
   static_assert(!__is_aggregate(HasInheritedCons), "");
   static_assert(__is_aggregate(HasNoInheritedCons) == TrueAfterCpp14, "");
@@ -3098,6 +3103,168 @@
 
 } // namespace is_trivially_relocatable
 
+namespace is_trivially_equality_comparable {
+struct ForwardDeclared; // expected-note {{forward declaration of 'is_trivially_equality_comparable::ForwardDeclared'}}
+static_assert(!__is_trivially_equality_comparable(ForwardDeclared), ""); // expected-error {{incomplete type 'ForwardDeclared' used in type trait expression}}
+
+static_assert(!__is_trivially_equality_comparable(void), "");
+static_assert(__is_trivially_equality_comparable(int), "");
+static_assert(!__is_trivially_equality_comparable(int[]), "");
+static_assert(__is_trivially_equality_comparable(int[3]), "");
+static_assert(!__is_trivially_equality_comparable(float), "");
+static_assert(!__is_trivially_equality_comparable(double), "");
+static_assert(!__is_trivially_equality_comparable(long double), "");
+
+struct TriviallyEqualityComparableNoDefaultedComparator {
+  int i;
+  int j;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator), "");
+
+#if __cplusplus >= 202002L
+
+struct TriviallyEqualityComparable {
+  int i;
+  int j;
+
+  void func();
+  bool operator==(int) const { return false; }
+
+  bool operator==(const TriviallyEqualityComparable&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), "");
+
+struct NotTriviallyEqualityComparableHasPadding {
+  short i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding), "");
+
+struct NotTriviallyEqualityComparableHasFloat {
+  float i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasFloat&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat), "");
+
+struct NotTriviallyEqualityComparableHasTailPadding {
+  int i;
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasTailPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding), "");
+
+struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding {
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableBase&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase), "");
+
+class TriviallyEqualityComparablePaddedOutBase {
+  int i;
+  char c;
+
+public:
+  bool operator==(const TriviallyEqualityComparablePaddedOutBase&) const = 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-16 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

ping @aaron.ballman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-10 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added inline comments.



Comment at: libcxx/include/__type_traits/is_equality_comparable.h:46
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant philnik wrote:
> > Mordante wrote:
> > > This does not magically use the builtin right? Does the patch miss that 
> > > parts that use the builtin or is that a followup? If it's a followup I 
> > > would prefer move the libc++ code changes of this patch to a separate 
> > > review.
> > No, it doesn't magically use the builtin. I plan to do that in a follow-up. 
> > These changes are required though, since clang grabs the name with this 
> > patch.
> But it would still be possible to have these libc++ changes in a separate 
> review and commit them separately. I would say the libc++ changes are quite 
> trivial and can be landed quite quickly.
See D147953


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-10 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 512201.
philnik marked 3 inline comments as done.
philnik added a comment.

- Moved libc++ changes into it's own PR
- Rebased
- Fixed `enum` false-positive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
 
 #define T(b) (b) ? 1 : -1
 #define F(b) (b) ? -1 : 1
@@ -570,7 +571,11 @@
   static_assert(__is_aggregate(DerivesAr), "");
   static_assert(__is_aggregate(DerivesArNB), "");
   static_assert(!__is_aggregate(HasCons), "");
+#if __cplusplus >= 202002L
+  static_assert(!__is_aggregate(HasDefaultCons), "");
+#else
   static_assert(__is_aggregate(HasDefaultCons), "");
+#endif
   static_assert(!__is_aggregate(HasExplicitDefaultCons), "");
   static_assert(!__is_aggregate(HasInheritedCons), "");
   static_assert(__is_aggregate(HasNoInheritedCons) == TrueAfterCpp14, "");
@@ -3092,6 +3097,168 @@
 
 } // namespace is_trivially_relocatable
 
+namespace is_trivially_equality_comparable {
+struct ForwardDeclared; // expected-note {{forward declaration of 'is_trivially_equality_comparable::ForwardDeclared'}}
+static_assert(!__is_trivially_equality_comparable(ForwardDeclared), ""); // expected-error {{incomplete type 'ForwardDeclared' used in type trait expression}}
+
+static_assert(!__is_trivially_equality_comparable(void), "");
+static_assert(__is_trivially_equality_comparable(int), "");
+static_assert(!__is_trivially_equality_comparable(int[]), "");
+static_assert(__is_trivially_equality_comparable(int[3]), "");
+static_assert(!__is_trivially_equality_comparable(float), "");
+static_assert(!__is_trivially_equality_comparable(double), "");
+static_assert(!__is_trivially_equality_comparable(long double), "");
+
+struct TriviallyEqualityComparableNoDefaultedComparator {
+  int i;
+  int j;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator), "");
+
+#if __cplusplus >= 202002L
+
+struct TriviallyEqualityComparable {
+  int i;
+  int j;
+
+  void func();
+  bool operator==(int) const { return false; }
+
+  bool operator==(const TriviallyEqualityComparable&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), "");
+
+struct NotTriviallyEqualityComparableHasPadding {
+  short i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding), "");
+
+struct NotTriviallyEqualityComparableHasFloat {
+  float i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasFloat&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat), "");
+
+struct NotTriviallyEqualityComparableHasTailPadding {
+  int i;
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasTailPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding), "");
+
+struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding {
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableBase&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase), "");
+
+class TriviallyEqualityComparablePaddedOutBase {
+  int i;
+  char c;
+
+public:
+  bool operator==(const 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D147175#4251852 , @philnik wrote:

> In D147175#4251076 , @aaron.ballman 
> wrote:
>
>> One thing I can't quite determine is whether we expect to call this type 
>> trait often or not. Are either of the uses in libc++ going to be 
>> instantiated frequently? I'm trying to figure out whether we want the 
>> current implementation of `HasNonDeletedDefaultedEqualityComparison()` or 
>> whether we should bite the bullet up front and add another bit to 
>> `CXXRecordDecl::DefinitionData` so we compute this property once as the 
>> class is being formed and don't have to loop over all of the methods and 
>> bases each time. We do this for other special member functions, as with: 
>> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/DeclCXX.h#L695
>
> We currently use `__is_trivially_equality_comparable` only for `std::equal` 
> (and I'm working on using it for `std::find`), and I don't think there are a 
> lot more places where we can use it. It's also only relevant for cases where 
> we have raw pointers. Would the `enable_if` be evaluated, even if the 
> arguments aren't raw pointers in the example below?
>
>   template , 
> remove_cvref_t> && __is_trivially_equality_comparable(T)>>
>   bool equal(T* first1, T* last1, U* first2);
>   
>   
>
> If not, then I don't think it makes sense to save the information, since it 
> will most likely not be evaluated more than once or twice per type.

I believe that we deduce the type of `T` before we can instantiate any of the 
deduced template parameters, so I think the `enable_if` is not evaluated unless 
`T` is known to have a raw pointer type. Based on that, I don't think we need 
to steal any bits anywhere right now -- we can use the current approach and if 
it turns up on the hot path at some point, we can address the concern then. The 
clang bits LGTM, but I'll hold off on signing off until someone from libc++ 
approves as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-08 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added inline comments.



Comment at: libcxx/include/__type_traits/is_equality_comparable.h:46
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant Mordante wrote:
> > This does not magically use the builtin right? Does the patch miss that 
> > parts that use the builtin or is that a followup? If it's a followup I 
> > would prefer move the libc++ code changes of this patch to a separate 
> > review.
> No, it doesn't magically use the builtin. I plan to do that in a follow-up. 
> These changes are required though, since clang grabs the name with this patch.
But it would still be possible to have these libc++ changes in a separate 
review and commit them separately. I would say the libc++ changes are quite 
trivial and can be landed quite quickly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-08 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik marked an inline comment as done.
philnik added inline comments.



Comment at: libcxx/include/__type_traits/is_equality_comparable.h:46
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant This does not magically use the builtin right? Does the patch miss that parts 
> that use the builtin or is that a followup? If it's a followup I would prefer 
> move the libc++ code changes of this patch to a separate review.
No, it doesn't magically use the builtin. I plan to do that in a follow-up. 
These changes are required though, since clang grabs the name with this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-08 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I mainly glossed over the patch and didn't do a real review.




Comment at: clang/lib/AST/ASTContext.cpp:2672
+const RecordDecl *RD,
+bool CheckIfTriviallyCOpyable) 
{
   assert(RD->isUnion() && "Must be union type");





Comment at: libcxx/include/__type_traits/is_equality_comparable.h:46
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constanthttps://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-07 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D147175#4251076 , @aaron.ballman 
wrote:

> One thing I can't quite determine is whether we expect to call this type 
> trait often or not. Are either of the uses in libc++ going to be instantiated 
> frequently? I'm trying to figure out whether we want the current 
> implementation of `HasNonDeletedDefaultedEqualityComparison()` or whether we 
> should bite the bullet up front and add another bit to 
> `CXXRecordDecl::DefinitionData` so we compute this property once as the class 
> is being formed and don't have to loop over all of the methods and bases each 
> time. We do this for other special member functions, as with: 
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/DeclCXX.h#L695

We currently use `__is_trivially_equality_comparable` only for `std::equal` 
(and I'm working on using it for `std::find`), and I don't think there are a 
lot more places where we can use it. It's also only relevant for cases where we 
have raw pointers. Would the `enable_if` be evaluated, even if the arguments 
aren't raw pointers in the example below?

  template , 
remove_cvref_t> && __is_trivially_equality_comparable(T)>>
  bool equal(T* first1, T* last1, U* first2);
  
  

If not, then I don't think it makes sense to save the information, since it 
will most likely not be evaluated more than once or twice per type.




Comment at: clang/lib/AST/Type.cpp:2618-2619
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return !FD->getType()->isReferenceType();
+   return HasNonDeletedDefaultedEqualityComparison(

aaron.ballman wrote:
> Why the check for !RecordType? If any field is a reference, we can bail out 
> early, so I think this is better as:
> ```
> if (FD->getType()->isReferenceType())
>   return false;
> if (const auto *RD = FD->getType()->getAsCXXRecordDecl())
>   return HasNonDeletedDefaultedEqualityComparison(RD);
> return true;
> ```
> WDYT?
I don't really have an opinion here. Your version seems reasonable, so I'm 
going to take it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-07 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 511762.
philnik marked 2 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant::value && 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D147175#4249212 , @philnik wrote:

> In D147175#4246513 , @aaron.ballman 
> wrote:
>
>> Ah, I like this approach -- it keeps things roughly in sync with checking 
>> for unique object representations, which is great. I spotted a few 
>> questions, but in general this is heading in the right direction. You should 
>> also add a release note to clang/docs/ReleaseNotes.rst so that users know 
>> there's a new builtin coming.
>>
>> I suppose one thing to double-check: do you know of any other STL 
>> implementations that might be using this identifier as part of their 
>> implementation details? (We've had issues in the past where we accidentally 
>> stole a reserved identifier that was being used by libstdc++ and it caused 
>> issues.)
>
> Neither libstdc++ nor the MSVC STL use the 
> `__is_trivially_equality_comparable` AFAICT. A sourcegraph search also 
> exclusively finds libc++: 
> https://sourcegraph.com/search?q=context%3Aglobal+__is_trivially_equality_comparable=standard=1=repo
>  (which only started using it in this release cycle, so it shouldn't be a 
> problem).

Perfect, thank you for double-checking!

One thing I can't quite determine is whether we expect to call this type trait 
often or not. Are either of the uses in libc++ going to be instantiated 
frequently? I'm trying to figure out whether we want the current implementation 
of `HasNonDeletedDefaultedEqualityComparison()` or whether we should bite the 
bullet up front and add another bit to `CXXRecordDecl::DefinitionData` so we 
compute this property once as the class is being formed and don't have to loop 
over all of the methods and bases each time. We do this for other special 
member functions, as with: 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/DeclCXX.h#L695




Comment at: clang/lib/AST/Type.cpp:2618-2619
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return !FD->getType()->isReferenceType();
+   return HasNonDeletedDefaultedEqualityComparison(

Why the check for !RecordType? If any field is a reference, we can bail out 
early, so I think this is better as:
```
if (FD->getType()->isReferenceType())
  return false;
if (const auto *RD = FD->getType()->getAsCXXRecordDecl())
  return HasNonDeletedDefaultedEqualityComparison(RD);
return true;
```
WDYT?



Comment at: clang/lib/AST/Type.cpp:2631-2632
+
+  if (const auto *RecordDecl = CanonicalType->getAsCXXRecordDecl()) {
+if 
(!HasNonDeletedDefaultedEqualityComparison(CanonicalType->getAsCXXRecordDecl()))
+  return false;

Avoids calling the same method twice and avoids using a type name as a 
declaration identifier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-06 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D147175#4246513 , @aaron.ballman 
wrote:

> Ah, I like this approach -- it keeps things roughly in sync with checking for 
> unique object representations, which is great. I spotted a few questions, but 
> in general this is heading in the right direction. You should also add a 
> release note to clang/docs/ReleaseNotes.rst so that users know there's a new 
> builtin coming.
>
> I suppose one thing to double-check: do you know of any other STL 
> implementations that might be using this identifier as part of their 
> implementation details? (We've had issues in the past where we accidentally 
> stole a reserved identifier that was being used by libstdc++ and it caused 
> issues.)

Neither libstdc++ nor the MSVC STL use the `__is_trivially_equality_comparable` 
AFAICT. A sourcegraph search also exclusively finds libc++: 
https://sourcegraph.com/search?q=context%3Aglobal+__is_trivially_equality_comparable=standard=1=repo
 (which only started using it in this release cycle, so it shouldn't be a 
problem).




Comment at: clang/lib/AST/Type.cpp:2598-2599
+static bool HasDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+

aaron.ballman wrote:
> Hmmm, is this correct? I thought there was a defaulted equality comparison 
> operator in this case, but it's defined as deleted.
> 
> http://eel.is/c++draft/class.compare.default#2
> 
> Perhaps this function is looking for a usable defaulted equality comparison 
> operator and not just "does it have one at all"?
Yes, this is looking for a usable one. I've renamed it. (Maybe someone has an 
idea for a better name?)



Comment at: clang/lib/AST/Type.cpp:2616-2617
+  }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return true;

aaron.ballman wrote:
> Do we have to look for fields with references per 
> http://eel.is/c++draft/class.compare.default#2 ?
Good catch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-06 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 511460.
philnik marked 4 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant::value && 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ah, I like this approach -- it keeps things roughly in sync with checking for 
unique object representations, which is great. I spotted a few questions, but 
in general this is heading in the right direction. You should also add a 
release note to clang/docs/ReleaseNotes.rst so that users know there's a new 
builtin coming.

I suppose one thing to double-check: do you know of any other STL 
implementations that might be using this identifier as part of their 
implementation details? (We've had issues in the past where we accidentally 
stole a reserved identifier that was being used by libstdc++ and it caused 
issues.)




Comment at: clang/include/clang/AST/DeclCXX.h:1449
   /// Notify the class that this destructor is now selected.
-  /// 
+  ///
   /// Important properties of the class depend on destructor properties. Since

Spurious whitespace change.



Comment at: clang/lib/AST/Type.cpp:2598-2599
+static bool HasDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+

Hmmm, is this correct? I thought there was a defaulted equality comparison 
operator in this case, but it's defined as deleted.

http://eel.is/c++draft/class.compare.default#2

Perhaps this function is looking for a usable defaulted equality comparison 
operator and not just "does it have one at all"?



Comment at: clang/lib/AST/Type.cpp:2616-2617
+  }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return true;

Do we have to look for fields with references per 
http://eel.is/c++draft/class.compare.default#2 ?



Comment at: clang/lib/AST/Type.cpp:4643-4645
+QualType Deduced, AutoTypeKeyword Keyword,
+bool IsDependent, ConceptDecl *CD,
+ArrayRef Arguments) {

Spurious whitespace changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-04 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 510887.
philnik added a comment.

Remove formatting changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant::value && is_integral<_Tp>::value &&
   

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-04 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 510865.
philnik marked 5 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant::value && 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-04 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D147175#4240572 , @aaron.ballman 
wrote:

> Hmmm, is this effectively `std::has_unique_object_representations` (ensuring 
> that all bits of the object representation contribute to the value)?

These two traits are indeed very similar. The main difference is that 
`has_unique_object_representations` requires that the type is trivially 
copyable, and `__is_trivially_equality_comparable` requires a defaulted 
equality comparison operator.




Comment at: clang/lib/AST/Type.cpp:2640
+
+  return false;
+}

aaron.ballman wrote:
> I think this might be missing cases, like complex integers, scoped 
> enumerations, vector types?, pointer types, atomic versions of these types...
I think this should be covered by the switch to using 
`hasUniqueObjectRepresentation`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Hmmm, is this effectively `std::has_unique_object_representations` (ensuring 
that all bits of the object representation contribute to the value)?




Comment at: clang/lib/AST/Type.cpp:2610
+
+  if (const auto *RecordDecl = CanonicalType->getAsCXXRecordDecl()) {
+if (!RecordDecl->isStandardLayout() || RecordDecl->isUnion())

Dependent types should probably return `false`?



Comment at: clang/lib/AST/Type.cpp:2640
+
+  return false;
+}

I think this might be missing cases, like complex integers, scoped 
enumerations, vector types?, pointer types, atomic versions of these types...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-03-30 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:3315
   Builder.Alignment, Builder.Alignment, CharUnits::Zero(),
   Builder.PrimaryBase, false, Builder.SharedVBPtrBase,
+  Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase, 
true,





Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:3316-3317
   Builder.PrimaryBase, false, Builder.SharedVBPtrBase,
-  Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase,
-  Builder.Bases, Builder.VBases);
+  Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase, 
true,
+  true, Builder.Bases, Builder.VBases);
 } else {

For 
[bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:3351
   EmptySubobjects.SizeOfLargestEmptySubobject, Builder.PrimaryBase,
-  Builder.PrimaryBaseIsVirtual, nullptr, false, false, Builder.Bases,
+  Builder.PrimaryBaseIsVirtual, nullptr, false, false,
+  Builder.HasInternalPadding, Builder.HasTailPadding, Builder.Bases,




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-03-30 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 509598.
philnik added a comment.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Try to fix CI


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147175/new/

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/RecordLayout.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/RecordLayout.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-03-29 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik created this revision.
philnik added a reviewer: aaron.ballman.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a new trait to allow standard libraries to forward `std::equal` 
calls to `memcmp` in more cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/RecordLayout.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/RecordLayout.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
 
 #define T(b) (b) ? 1 : -1
 #define F(b) (b) ? -1 : 1
@@ -570,7 +571,11 @@
   static_assert(__is_aggregate(DerivesAr), "");
   static_assert(__is_aggregate(DerivesArNB), "");
   static_assert(!__is_aggregate(HasCons), "");
+#if __cplusplus >= 202002L
+  static_assert(!__is_aggregate(HasDefaultCons), "");
+#else
   static_assert(__is_aggregate(HasDefaultCons), "");
+#endif
   static_assert(!__is_aggregate(HasExplicitDefaultCons), "");
   static_assert(!__is_aggregate(HasInheritedCons), "");
   static_assert(__is_aggregate(HasNoInheritedCons) == TrueAfterCpp14, "");
@@ -3055,6 +3060,139 @@
 
 } // namespace is_trivially_relocatable
 
+namespace is_trivially_equality_comparable {
+struct ForwardDeclared; // expected-note {{forward declaration of 'is_trivially_equality_comparable::ForwardDeclared'}}
+static_assert(!__is_trivially_equality_comparable(ForwardDeclared), ""); // expected-error {{incomplete type 'ForwardDeclared' used in type trait expression}}
+
+static_assert(!__is_trivially_equality_comparable(void), "");
+static_assert(__is_trivially_equality_comparable(int), "");
+static_assert(!__is_trivially_equality_comparable(int[]), "");
+static_assert(!__is_trivially_equality_comparable(int[3]), "");
+static_assert(!__is_trivially_equality_comparable(float), "");
+static_assert(!__is_trivially_equality_comparable(double), "");
+static_assert(!__is_trivially_equality_comparable(long double), "");
+
+struct TriviallyEqualityComparableNoDefaultedComparator {
+  int i;
+  int j;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator), "");
+
+#if __cplusplus >= 202002L
+
+struct TriviallyEqualityComparable {
+  int i;
+  int j;
+
+  void func();
+  bool operator==(int) const { return false; }
+
+  bool operator==(const TriviallyEqualityComparable&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), "");
+
+struct NotTriviallyEqualityComparableHasPadding {
+  short i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding), "");
+
+struct NotTriviallyEqualityComparableHasFloat {
+  float i;
+  int j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasFloat&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat), "");
+
+struct NotTriviallyEqualityComparableHasTailPadding {
+  int i;
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableHasTailPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding), "");
+
+struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding {
+  char j;
+
+  bool operator==(const NotTriviallyEqualityComparableBase&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase), "");
+
+struct