[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-13 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

LGTM now, for what it's worth.

https://github.com/llvm/llvm-project/pull/93113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Add additional test coverage for `__is_trivially_relocatable(T)` (PR #91412)

2024-06-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

ping @corentin @shafik can you help me land this additional test coverage? It 
doesn't change any behavior, just documents the behavior we currently have.

https://github.com/llvm/llvm-project/pull/91412
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Add additional test coverage for `__is_trivially_relocatable(T)` (PR #91412)

2024-06-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/91412

>From 532e1c6976a1cb2abf897d0a9312813f2f1d13f1 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 8 May 2024 03:09:38 +0330
Subject: [PATCH] [clang] [test] Add additional test coverage for
 `__is_trivially_relocatable(T)`

---
 .../test/SemaCXX/is-trivially-relocatable.cpp | 332 ++
 clang/test/SemaCXX/type-traits.cpp| 102 ++
 2 files changed, 434 insertions(+)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/test/SemaCXX/is-trivially-relocatable.cpp 
b/clang/test/SemaCXX/is-trivially-relocatable.cpp
new file mode 100644
index 0..439f7a9ad49ae
--- /dev/null
+++ b/clang/test/SemaCXX/is-trivially-relocatable.cpp
@@ -0,0 +1,332 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s -triple 
x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s -triple 
x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s -triple 
x86_64-apple-darwin10
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s -triple 
x86_64-apple-darwin10
+
+// expected-no-diagnostics
+
+#if __cplusplus < 201103L
+#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__, "")
+// cxx98-error@-1 {{variadic macros are a C99 feature}}
+#endif
+
+template 
+struct Agg {
+  T t_;
+};
+
+template 
+struct Der : T {
+};
+
+template 
+struct Mut {
+  mutable T t_;
+};
+
+template 
+struct Non {
+  Non(); // make it a non-aggregate
+  T t_;
+};
+
+struct CompletelyTrivial {
+};
+static_assert(__is_trivially_relocatable(CompletelyTrivial));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor();
+};
+#if defined(_WIN64) && !defined(__MINGW32__)
+static_assert(__is_trivially_relocatable(NonTrivialDtor)); // bug #69394
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+#else
+static_assert(!__is_trivially_relocatable(NonTrivialDtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct NonTrivialCopyCtor {
+  NonTrivialCopyCtor(const NonTrivialCopyCtor&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialCopyCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+
+struct NonTrivialMutableCopyCtor {
+  NonTrivialMutableCopyCtor(NonTrivialMutableCopyCtor&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMutableCopyCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+
+#if __cplusplus >= 201103L
+struct NonTrivialMoveCtor {
+  NonTrivialMoveCtor(NonTrivialMoveCtor&&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMoveCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct NonTrivialCopyAssign {
+  NonTrivialCopyAssign& operator=(const NonTrivialCopyAssign&);
+};
+static_assert(__is_trivially_relocatable(NonTrivialCopyAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+struct NonTrivialMutableCopyAssign {
+  NonTrivialMutableCopyAssign& operator=(NonTrivialMutableCopyAssign&);
+};
+static_assert(__is_trivially_relocatable(NonTrivialMutableCopyAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+#if __cplusplus >= 201103L
+struct NonTrivialMoveAssign {
+  NonTrivialMoveAssign& operator=(NonTrivialMoveAssign&&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMoveAssign));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct ImplicitlyDeletedAssign {
+  int& r;
+};
+static_assert(__is_trivially_relocatable(ImplicitlyDeletedAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));

[clang] Sema: Fix CXXRecordDecl::isTriviallyCopyable() for classes with all deleted special functions. (PR #94831)

2024-06-08 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

You're currently checking whether there is at least one **deleted** member of 
**each** kind; but you should be checking whether there is at least one 
**non-deleted** member of **any** kind. A type that shows the difference is:
```
struct S {
  S(const S&) = default;
  S(S&) = delete;
  S(S&&) = delete;
  S& operator=(const S&) = default;
  S& operator=(S&) = delete;
  S& operator=(S&&) = delete;
};
static_assert(__is_trivially_copyable(S)); // should be true
```

https://github.com/llvm/llvm-project/pull/94831
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-05-23 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

This patch seems to break the following example (works in trunk, breaks after 
this patch). Could you please add a test case for this?
https://godbolt.org/z/rdn74xn9M
```
struct S {
  bool operator==(const S&) const = default;
};
struct Derived : S {
  int j_ = 0;
};

static_assert(!__is_trivially_equality_comparable(S));
static_assert(!__is_trivially_equality_comparable(Derived));

bool test1(Derived& a, Derived& b) {
  return a == b;
}

bool test2(Derived& a, Derived& b) {
  return a.j_ == b.j_;
}
```

https://github.com/llvm/llvm-project/pull/93113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-05-23 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

Could you explain a bit about why we check `Decl->isTriviallyCopyable()` here?


https://github.com/llvm/llvm-project/pull/93113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Add additional test coverage for `__is_trivially_relocatable(T)` (PR #91412)

2024-05-07 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/91412

None

>From 541910fc90064e5491622245d9e94759cffa4d15 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 8 May 2024 03:09:38 +0330
Subject: [PATCH] [clang]Add additional test coverage for
 `__is_trivially_relocatable(T)`

---
 clang/test/SemaCXX/type-traits.cpp | 45 ++
 1 file changed, 45 insertions(+)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 01991887b284a..05fef05dc6ce0 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1433,6 +1433,51 @@ void is_trivially_copyable2()
   static_assert(!__is_trivially_copyable(const volatile void));
 }
 
+void is_trivially_relocatable2()
+{
+  static_assert(__is_trivially_relocatable(char));
+  static_assert(__is_trivially_relocatable(int));
+  static_assert(__is_trivially_relocatable(long));
+  static_assert(__is_trivially_relocatable(short));
+  static_assert(__is_trivially_relocatable(signed char));
+  static_assert(__is_trivially_relocatable(wchar_t));
+  static_assert(__is_trivially_relocatable(bool));
+  static_assert(__is_trivially_relocatable(float));
+  static_assert(__is_trivially_relocatable(double));
+  static_assert(__is_trivially_relocatable(long double));
+  static_assert(__is_trivially_relocatable(unsigned char));
+  static_assert(__is_trivially_relocatable(unsigned int));
+  static_assert(__is_trivially_relocatable(unsigned long long));
+  static_assert(__is_trivially_relocatable(unsigned long));
+  static_assert(__is_trivially_relocatable(unsigned short));
+  static_assert(__is_trivially_relocatable(ClassType));
+  static_assert(__is_trivially_relocatable(Derives));
+  static_assert(__is_trivially_relocatable(Enum));
+  static_assert(__is_trivially_relocatable(IntAr));
+  static_assert(__is_trivially_relocatable(Union));
+  static_assert(__is_trivially_relocatable(UnionAr));
+  static_assert(__is_trivially_relocatable(TrivialStruct));
+  static_assert(__is_trivially_relocatable(NonTrivialStruct));
+  static_assert(__is_trivially_relocatable(AllDefaulted));
+  static_assert(!__is_trivially_relocatable(AllDeleted));
+
+  static_assert(!__is_trivially_relocatable(void));
+  static_assert(!__is_trivially_relocatable(SuperNonTrivialStruct));
+  static_assert(!__is_trivially_relocatable(NonTCStruct));
+  static_assert(!__is_trivially_relocatable(ExtDefaulted));
+
+  static_assert(__is_trivially_relocatable(const int));
+  static_assert(__is_trivially_relocatable(volatile int));
+
+  static_assert(__is_trivially_relocatable(ACompleteType));
+  static_assert(!__is_trivially_relocatable(AnIncompleteType)); // 
expected-error {{incomplete type}}
+  static_assert(!__is_trivially_relocatable(AnIncompleteType[])); // 
expected-error {{incomplete type}}
+  static_assert(!__is_trivially_relocatable(AnIncompleteType[1])); // 
expected-error {{incomplete type}}
+  static_assert(!__is_trivially_relocatable(void));
+  static_assert(!__is_trivially_relocatable(const volatile void));
+}
+
+
 struct CStruct {
   int one;
   int two;

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


[clang] [clang]Treat arguments to builtin type traits as template type arguments (PR #87132)

2024-04-17 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Thank you! I don't have the permission to merge. Could you merge it 
for me?

https://github.com/llvm/llvm-project/pull/87132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-04-16 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> We (users & implementers) have all collectively identified trivial 
> relocatability as an important optimization for vector-like containers, and 
> we're all looking for a solution to that. It feels like this attempt to 
> standardize this type trait is getting in the way of our collective ability 
> to add vendor extensions that were not necessarily intended to become 
> standards-track proposals.

Since people are asking for these semantics in Clang's vendor extension, how 
would people feel about proceeding in this direction for now, and adding a 
second type trait, named something like `__is_cpp_trivially_relocatable(T)`, 
for the P2786 version?

https://github.com/llvm/llvm-project/pull/84621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Treat arguments to builtin type traits as template type arguments (PR #87132)

2024-04-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@shafik, gentle ping!

https://github.com/llvm/llvm-project/pull/87132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Treat arguments to builtin type traits as template type arguments (PR #87132)

2024-04-08 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@fahadnayyar, does this PR address llvm#86997?

https://github.com/llvm/llvm-project/pull/87132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang]Treat arguments to builtin type traits as template type arguments (PR #87132)

2024-03-29 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/87132

This change improves error messages for builtins in case of empty parentheses.

Fixes llvm#86997

>From f8cc36bd3706cc5744eb3223b0c32df2f6f871f9 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 29 Mar 2024 11:29:53 +0330
Subject: [PATCH] [clang]Treat arguments to builtin type traits as template
 type arguments

This change improves error messages for builtins in case of empty parentheses.

Fixes llvm#86997
---
 clang/lib/Parse/ParseExprCXX.cpp   | 12 ++--
 clang/test/Sema/static-assert.c|  9 -
 clang/test/SemaCXX/builtins.cpp|  5 +
 clang/test/SemaCXX/deprecated-builtins.cpp |  5 +
 4 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 9471f6f725efb1..efe0c587830392 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3908,10 +3908,10 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty =
-ParseTypeName(/*SourceRange=*/nullptr,
-  getLangOpts().CPlusPlus ? DeclaratorContext::TemplateArg
-  : DeclaratorContext::TypeName);
+TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr,
+  getLangOpts().CPlusPlus
+  ? DeclaratorContext::TemplateTypeArg
+  : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3953,8 +3953,8 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty =
-  ParseTypeName(/*SourceRange=*/nullptr, DeclaratorContext::TemplateArg);
+  TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr,
+DeclaratorContext::TemplateTypeArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);
diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index ae5e8076e0beda..4e9e6b7ee558bd 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only 
-verify=expected,c %s
-// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS 
-fsyntax-only -verify=expected,ms,c %s
-// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only 
-verify=expected,ext,c %s
+// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS 
-fsyntax-only -verify=expected,ms %s
+// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only 
-verify=expected,ext %s
 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only 
-verify=expected,ext,cxx %s
 
 _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' 
is a C11 extension}}
@@ -57,8 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // c-error {{expected a type}} \
-   // cxx-error {{type name requires a specifier 
or qualifier}} \
+typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index 567094c94c171b..080b4476c7eec1 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -76,6 +76,11 @@ using ConstMemFnType = int (Dummy::*)() const;
 
 void foo() {}
 
+void test_builtin_empty_parentheses_diags() {
+  __is_trivially_copyable(); // expected-error {{expected a type}}
+  __is_trivially_copyable(1); // expected-error {{expected a type}}
+}
+
 void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
 MemFnType mfp, ConstMemFnType cmfp, int 
()[5]) {
   __builtin_launder(vp);   // expected-error {{void pointer argument to 
'__builtin_launder' is not allowed}}
diff --git a/clang/test/SemaCXX/deprecated-builtins.cpp 
b/clang/test/SemaCXX/deprecated-builtins.cpp
index 849b9b014fff25..fafc1da4da13eb 100644
--- a/clang/test/SemaCXX/deprecated-builtins.cpp
+++ b/clang/test/SemaCXX/deprecated-builtins.cpp
@@ -17,3 +17,8 @@ void f() {
 a = 

[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-29 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

I don't know, but it seems to me that ideally the `DSC` here would be 
`DSC_template_type_arg`, not just `DSC_template_arg`. Is there a way to make 
that happen?

https://github.com/llvm/llvm-project/pull/81298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/5] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits


@@ -826,6 +842,14 @@ void CXXRecordDecl::addedMember(Decl *D) {
   ? !Constructor->isImplicit()
   : (Constructor->isUserProvided() || Constructor->isExplicit()))
 data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- where no eligible copy constructor, move constructor, copy
+  // assignment operator, move assignment operator, or destructor is
+  // user-provided,
+  if (Constructor->isUserProvided() && (Constructor->isCopyConstructor() ||

AMP999 wrote:

Addressed in the latest commit. Thanks for bringing it up!

https://github.com/llvm/llvm-project/pull/84621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 edited https://github.com/llvm/llvm-project/pull/84621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits


@@ -857,8 +881,13 @@ void CXXRecordDecl::addedMember(Decl *D) {
 data().HasDeclaredCopyAssignmentWithConstParam = true;
 }
 
-if (Method->isMoveAssignmentOperator())
+if (Method->isMoveAssignmentOperator()) {
   SMKind |= SMF_MoveAssignment;
+}

AMP999 wrote:

It's been fixed in the new commit.

https://github.com/llvm/llvm-project/pull/84621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/4] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-12 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/3] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-12 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/3] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-12 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/2] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/4] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits


@@ -249,6 +249,12 @@ Bug Fixes in This Version
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
+  Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+

AMP999 wrote:

That's right! I've fixed it.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/3] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 2603e170c127aa614d499e5d527db8503a55c651 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/2] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [NFC] Eliminate trailing white space causing CI build failure (PR #84632)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/84632

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```

>From c122cc4e95f1e07c922983b787f95edf187b304c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 9 Mar 2024 18:25:07 +0330
Subject: [PATCH] [NFC] Eliminate trailing white space causing CI build failure

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..3b89d5a8720785 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,7 +409,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 2603e170c127aa614d499e5d527db8503a55c651 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@mordante Thank you! I've resolved merge conflicts. I've also added an NFC 
commit to remove empty messages from `static_assert`s for consistency with the 
rest of the file.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/2] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 71502300d47f3d5492e6073a3959fe32b0c9cf65 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/84621

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics. By these changes 
now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable. The `[[clang::trivial_abi]]` attribute always implies 
trivial-relocatability, even if it can't pass in registers. The trait has 
extensive tests for both old and new behaviors. Test aggregation of both kinds 
of types as data members; inheritance; virtual member functions and virtual 
bases; const and reference data members; and reference types.

Fixes llvm#69394

>From 191a98edecdbe7451d75adc3a71ee2f94bb046cd Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..ae9de533889f2c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ 

[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-08 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin All checks are green now. Could you help me land this patch for me?

https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-07 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 deleted 
https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-05 Thread Amirreza Ashouri via cfe-commits


@@ -2875,10 +2875,10 @@ struct __attribute__((packed)) PackedNoPadding2 {
   int j;
   short i;
 };
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding1), "Packed 
structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding2), "Packed 
structs have no padding");
 
-static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
+static_assert(!__has_unique_object_representations(int(int)), "Functions are 
not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");

AMP999 wrote:

By merging #81298 into the `main` branch, the elimination is now possible and 
it has been done in commit `2018c5a`.

https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-05 Thread Amirreza Ashouri via cfe-commits


@@ -214,56 +212,56 @@ struct HasVirtBase : virtual ACompleteType {};
 
 void is_pod()
 {
-  { int arr[T(__is_pod(int))]; }
-  { int arr[T(__is_pod(Enum))]; }
-  { int arr[T(__is_pod(POD))]; }
-  { int arr[T(__is_pod(Int))]; }
-  { int arr[T(__is_pod(IntAr))]; }
-  { int arr[T(__is_pod(Statics))]; }
-  { int arr[T(__is_pod(Empty))]; }
-  { int arr[T(__is_pod(EmptyUnion))]; }
-  { int arr[T(__is_pod(Union))]; }
-  { int arr[T(__is_pod(HasFunc))]; }
-  { int arr[T(__is_pod(HasOp))]; }
-  { int arr[T(__is_pod(HasConv))]; }
-  { int arr[T(__is_pod(HasAssign))]; }
-  { int arr[T(__is_pod(IntArNB))]; }
-  { int arr[T(__is_pod(HasAnonymousUnion))]; }
-  { int arr[T(__is_pod(Vector))]; }
-  { int arr[T(__is_pod(VectorExt))]; }
-  { int arr[T(__is_pod(Derives))]; }
-  { int arr[T(__is_pod(DerivesAr))]; }
-  { int arr[T(__is_pod(DerivesArNB))]; }
-  { int arr[T(__is_pod(DerivesEmpty))]; }
-  { int arr[T(__is_pod(HasPriv))]; }
-  { int arr[T(__is_pod(HasProt))]; }
-  { int arr[T(__is_pod(DerivesHasPriv))]; }
-  { int arr[T(__is_pod(DerivesHasProt))]; }
-
-  { int arr[F(__is_pod(HasCons))]; }
-  { int arr[F(__is_pod(HasCopyAssign))]; }
-  { int arr[F(__is_pod(HasMoveAssign))]; }
-  { int arr[F(__is_pod(HasDest))]; }
-  { int arr[F(__is_pod(HasRef))]; }
-  { int arr[F(__is_pod(HasVirt))]; }
-  { int arr[F(__is_pod(DerivesHasCons))]; }
-  { int arr[F(__is_pod(DerivesHasCopyAssign))]; }
-  { int arr[F(__is_pod(DerivesHasMoveAssign))]; }
-  { int arr[F(__is_pod(DerivesHasDest))]; }
-  { int arr[F(__is_pod(DerivesHasRef))]; }
-  { int arr[F(__is_pod(DerivesHasVirt))]; }
-  { int arr[F(__is_pod(NonPOD))]; }
-  { int arr[F(__is_pod(HasNonPOD))]; }
-  { int arr[F(__is_pod(NonPODAr))]; }
-  { int arr[F(__is_pod(NonPODArNB))]; }
-  { int arr[F(__is_pod(void))]; }
-  { int arr[F(__is_pod(cvoid))]; }
-// { int arr[F(__is_pod(NonPODUnion))]; }
-
-  { int arr[T(__is_pod(ACompleteType))]; }
-  { int arr[F(__is_pod(AnIncompleteType))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[]))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[1]))]; } // expected-error 
{{incomplete type}}
+  static_assert(__is_pod(int), "");

AMP999 wrote:

@cor3ntin Empty messages have been eliminated by commit `5e043de`. Should we 
also remove the messages in the `__has_unique_object_representations` section?

https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-04 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin I've reflected your suggestions in the code. Could you help me to 
land this PR, if you it looks good to you?

https://github.com/llvm/llvm-project/pull/81298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-04 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/8] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/8] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/8] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/8] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-04 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/7] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/7] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/7] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/7] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-04 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/6] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/6] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/6] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/6] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-26 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

How about also enabling some existing C++11 tests for C++03 mode, too? E.g. 
`Preprocessor/has_attribute.cpp`, `SemaCXX/attr-declspec-ignored.cpp`, 
`SemaCXX/attr-gnu.cpp`, don't run in C++03 mode today but they could be made to.

https://github.com/llvm/llvm-project/pull/83065
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-26 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/5] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/5] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/5] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/5] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-20 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/5] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/5] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/5] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/5] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-20 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/5] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/5] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/5] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/5] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-02-14 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

Thanks all for the review! @AaronBallman, Could you please land this patch for 
me?

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-02-12 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-12 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/3] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/3] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/3] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/2] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/2] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-02-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@AaronBallman, does this look okay to you? See 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r9.html#abstract-opdef-trivially-relocatable
 and 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2786r3.pdf#subsection.12.4
 which both agree on this point.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-22 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> I don't have a good idea here... I don't really know what it means to 
> 'relocate' a volatile.  

This PR doesn't take a position on what it means to relocate a volatile; it 
just makes the type-trait return the correct value on cv-qualified types, for 
consistency with `__is_trivially_copyable` and to implement the current 
Standard proposals.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-19 Thread Amirreza Ashouri via cfe-commits


@@ -2669,6 +2669,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {

AMP999 wrote:

You mean why is `isNonTrivialToPrimitiveDestructiveMove` different from 
`isTriviallyRelocatable`? I don't know, but I think it has to do with 
Objective-C, so I left it alone.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-12 Thread Amirreza Ashouri via cfe-commits


@@ -214,56 +212,56 @@ struct HasVirtBase : virtual ACompleteType {};
 
 void is_pod()
 {
-  { int arr[T(__is_pod(int))]; }
-  { int arr[T(__is_pod(Enum))]; }
-  { int arr[T(__is_pod(POD))]; }
-  { int arr[T(__is_pod(Int))]; }
-  { int arr[T(__is_pod(IntAr))]; }
-  { int arr[T(__is_pod(Statics))]; }
-  { int arr[T(__is_pod(Empty))]; }
-  { int arr[T(__is_pod(EmptyUnion))]; }
-  { int arr[T(__is_pod(Union))]; }
-  { int arr[T(__is_pod(HasFunc))]; }
-  { int arr[T(__is_pod(HasOp))]; }
-  { int arr[T(__is_pod(HasConv))]; }
-  { int arr[T(__is_pod(HasAssign))]; }
-  { int arr[T(__is_pod(IntArNB))]; }
-  { int arr[T(__is_pod(HasAnonymousUnion))]; }
-  { int arr[T(__is_pod(Vector))]; }
-  { int arr[T(__is_pod(VectorExt))]; }
-  { int arr[T(__is_pod(Derives))]; }
-  { int arr[T(__is_pod(DerivesAr))]; }
-  { int arr[T(__is_pod(DerivesArNB))]; }
-  { int arr[T(__is_pod(DerivesEmpty))]; }
-  { int arr[T(__is_pod(HasPriv))]; }
-  { int arr[T(__is_pod(HasProt))]; }
-  { int arr[T(__is_pod(DerivesHasPriv))]; }
-  { int arr[T(__is_pod(DerivesHasProt))]; }
-
-  { int arr[F(__is_pod(HasCons))]; }
-  { int arr[F(__is_pod(HasCopyAssign))]; }
-  { int arr[F(__is_pod(HasMoveAssign))]; }
-  { int arr[F(__is_pod(HasDest))]; }
-  { int arr[F(__is_pod(HasRef))]; }
-  { int arr[F(__is_pod(HasVirt))]; }
-  { int arr[F(__is_pod(DerivesHasCons))]; }
-  { int arr[F(__is_pod(DerivesHasCopyAssign))]; }
-  { int arr[F(__is_pod(DerivesHasMoveAssign))]; }
-  { int arr[F(__is_pod(DerivesHasDest))]; }
-  { int arr[F(__is_pod(DerivesHasRef))]; }
-  { int arr[F(__is_pod(DerivesHasVirt))]; }
-  { int arr[F(__is_pod(NonPOD))]; }
-  { int arr[F(__is_pod(HasNonPOD))]; }
-  { int arr[F(__is_pod(NonPODAr))]; }
-  { int arr[F(__is_pod(NonPODArNB))]; }
-  { int arr[F(__is_pod(void))]; }
-  { int arr[F(__is_pod(cvoid))]; }
-// { int arr[F(__is_pod(NonPODUnion))]; }
-
-  { int arr[T(__is_pod(ACompleteType))]; }
-  { int arr[F(__is_pod(AnIncompleteType))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[]))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[1]))]; } // expected-error 
{{incomplete type}}
+  static_assert(__is_pod(int), "");

AMP999 wrote:

Should we also remove the non-empty messages in the 
`__has_unique_object_representations` section? They seem mostly 
self-explanatory to me, and none of the other traits use non-empty messages. 
Like changing
`static_assert(!__has_unique_object_representations(PaddedBitfield), "Bitfield 
padding");` to 
`static_assert(!__has_unique_object_representations(PaddedBitfield));`

https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-12 Thread Amirreza Ashouri via cfe-commits


@@ -2875,10 +2875,10 @@ struct __attribute__((packed)) PackedNoPadding2 {
   int j;
   short i;
 };
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding1), "Packed 
structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding2), "Packed 
structs have no padding");
 
-static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
+static_assert(!__has_unique_object_representations(int(int)), "Functions are 
not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");

AMP999 wrote:

We'd like to eliminate this usage too, but the parser doesn't support it yet.
The issue is explained here: https://github.com/llvm/llvm-project/issues/77585

https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 edited https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From 5d8204ef66bea614d614b5c16a2ddf765402f710 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  9 ++---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f8bbc89d8949..0fc10a77a73964 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -664,9 +664,6 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
-- ``__is_trivially_relocatable`` no longer returns true for non-object types
-  such as references and functions.
-  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
@@ -699,6 +696,12 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
+
 - Fix assertion failure when initializing union containing struct with
   flexible array member using empty initializer list.
   Fixes (`#77085 `_)
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index b419fc8836b032..aa797de099b0c9 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2669,6 +2669,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..492f08142591a9 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // 

[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 edited https://github.com/llvm/llvm-project/pull/77584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-06 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> I think I would like some more eyes on this, I don't know if it is obvious to 
> me what it means to reallocate a volatile object.

"Both active 
[wg21.link/p1144](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r9.html)
 and 
[wg21.link/p2786](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2786r3.pdf)
 proposals agree that if a type is trivially copyable then it is trivially 
relocatable; and that the trait ignores top-level cv-qualifiers.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From fd01df837e8d2ae543b35e9075297db36599e179 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  9 ++---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c63ad96ca2e39..bb0012689d9e4c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -660,9 +660,6 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
-- ``__is_trivially_relocatable`` no longer returns true for non-object types
-  such as references and functions.
-  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
@@ -695,6 +692,12 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
+
 
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..219cc6f194f93b 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2653,6 +2653,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..492f08142591a9 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3113,6 +3136,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From e9339f02ae0ed9411cf01828dd55e566c8852ec1 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  9 ++---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c63ad96ca2e39..b0079521e9cfc8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -660,9 +660,6 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
-- ``__is_trivially_relocatable`` no longer returns true for non-object types
-  such as references and functions.
-  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
@@ -695,6 +692,12 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types 
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types. 
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
+
 
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..219cc6f194f93b 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2653,6 +2653,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..899a1ad900794b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]));
+static_assert(__is_trivially_relocatable(const int[10]));
+static_assert(__is_trivially_relocatable(volatile int[10]));
+
+static_assert(__is_trivially_relocatable(int[10][10]));
+static_assert(__is_trivially_relocatable(const int[10][10]));
+static_assert(__is_trivially_relocatable(volatile int[10][10]));
+
+static_assert(__is_trivially_relocatable(int[]));
+static_assert(__is_trivially_relocatable(const int[]));
+static_assert(__is_trivially_relocatable(volatile int[]));
+
+static_assert(__is_trivially_relocatable(int[][10]));
+static_assert(__is_trivially_relocatable(const int[][10]));
+static_assert(__is_trivially_relocatable(volatile int[][10]));
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3113,6 +3136,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From b13a2802ecbb8f8b9cb3771769895e069b869a81 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  9 ++---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c63ad96ca2e39..c2951197007639 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -660,9 +660,6 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
-- ``__is_trivially_relocatable`` no longer returns true for non-object types
-  such as references and functions.
-  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
@@ -695,6 +692,12 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types 
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types. 
+  Fixes (`#67498 `_) and
+  (`#77091 https://github.com/llvm/llvm-project/issues/77091`_)
+
+
 
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..219cc6f194f93b 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2653,6 +2653,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..899a1ad900794b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]));
+static_assert(__is_trivially_relocatable(const int[10]));
+static_assert(__is_trivially_relocatable(volatile int[10]));
+
+static_assert(__is_trivially_relocatable(int[10][10]));
+static_assert(__is_trivially_relocatable(const int[10][10]));
+static_assert(__is_trivially_relocatable(volatile int[10][10]));
+
+static_assert(__is_trivially_relocatable(int[]));
+static_assert(__is_trivially_relocatable(const int[]));
+static_assert(__is_trivially_relocatable(volatile int[]));
+
+static_assert(__is_trivially_relocatable(int[][10]));
+static_assert(__is_trivially_relocatable(const int[][10]));
+static_assert(__is_trivially_relocatable(volatile int[][10]));
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3113,6 +3136,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> We probably need a release note for that, don't we? LGTM otherwise

Sure, I'll add a release note to Clang.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits


@@ -2651,6 +2651,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (!BaseElementType->isObjectType()) {
 return false;
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;

AMP999 wrote:

OK! I changed the order.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From 7f590147964cf61f67c0d0a250b1a41211b29585 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 2 files changed, 33 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..219cc6f194f93b 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2653,6 +2653,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..899a1ad900794b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]));
+static_assert(__is_trivially_relocatable(const int[10]));
+static_assert(__is_trivially_relocatable(volatile int[10]));
+
+static_assert(__is_trivially_relocatable(int[10][10]));
+static_assert(__is_trivially_relocatable(const int[10][10]));
+static_assert(__is_trivially_relocatable(volatile int[10][10]));
+
+static_assert(__is_trivially_relocatable(int[]));
+static_assert(__is_trivially_relocatable(const int[]));
+static_assert(__is_trivially_relocatable(volatile int[]));
+
+static_assert(__is_trivially_relocatable(int[][10]));
+static_assert(__is_trivially_relocatable(const int[][10]));
+static_assert(__is_trivially_relocatable(volatile int[][10]));
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3113,6 +3136,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3131,12 +3156,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");
+static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialDtor), 
"");
 
 struct [[clang::trivial_abi]] TrivialAbiNontrivialCopyCtor {
   TrivialAbiNontrivialCopyCtor(const TrivialAbiNontrivialCopyCtor&) {}
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialCopyCtor), 
"");
+static_assert(__is_trivially_relocatable(volatile 
TrivialAbiNontrivialCopyCtor), "");
 
 // A more complete set of tests for the behavior of trivial_abi can be found in
 // clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -3145,6 +3174,8 @@ struct [[clang::trivial_abi]] 
TrivialAbiNontrivialMoveCtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor), "");
 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/77092

Consistent with `__is_trivially_copyable(volatile int) == true` and 
`__is_trivially_relocatable(volatile Trivial) == true`, 
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)

>From 0562fd18da7741df72f0516b3dfb0df2a12cfff6 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 12 
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..96278370d9ff7e 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2651,6 +2651,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (!BaseElementType->isObjectType()) {
 return false;
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..36991fa2ca1dc8 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3104,6 +3106,8 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3113,6 +3117,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3131,12 +3137,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");
+static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialDtor), 
"");
 
 struct [[clang::trivial_abi]] TrivialAbiNontrivialCopyCtor {
   TrivialAbiNontrivialCopyCtor(const TrivialAbiNontrivialCopyCtor&) {}
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialCopyCtor), 
"");
+static_assert(__is_trivially_relocatable(volatile 
TrivialAbiNontrivialCopyCtor), "");
 
 // A more complete set of tests for the behavior of trivial_abi can be found in
 // clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -3145,6 +3155,8 @@ struct [[clang::trivial_abi]] 
TrivialAbiNontrivialMoveCtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialMoveCtor), 
"");
+static_assert(__is_trivially_relocatable(volatile 
TrivialAbiNontrivialMoveCtor), "");
 
 } // namespace is_trivially_relocatable
 

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin I've fixed that.

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From 8cad09416a4e362ea59249e040d6e8aaee54dee3 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e2e8ee8d76d2e10..e4b0a2cb5e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -637,6 +637,9 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From a0b9798dc87b313d9dff08e9fa109bf2d65a863e Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e2e8ee8d76d2e10..8825fc03bf2d59f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,9 @@ Bug Fixes in This Version
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

Oh, Sure. I didn't noticed that.

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Could you land this for me, please?

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-26 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> LGTM, thanks!

You're welcome!

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-26 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From befa9931fb8c9e52bb05a9075dfbea7116ff14ea Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..3de99618158c94a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -617,6 +617,9 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-16 Thread Amirreza Ashouri via cfe-commits


@@ -477,10 +477,10 @@ Bug Fixes in This Version
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
-- Fix crash in __builtin_strncmp and related builtins when the size value
-  exceeded the maximum value representable by int64_t. Fixes
+- Fix crash in ``__builtin_strncmp`` and related builtins when the size value
+  exceeded the maximum value representable by ``int64_t``. Fixes
   (`#64876 `_)
-- Fixed an assertion if a function has cleanups and fatal erors.
+- Fixed an assertion if a function has cleanups and fatal errors.

AMP999 wrote:

Sure, it's done!

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-16 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From 187bfbf15993911f6fd17092fad2f7cd7172180b Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Thu, 16 Nov 2023 15:03:06 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..d5835c7b8ab5f06 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -557,6 +557,9 @@ Bug Fixes in This Version
   Fixes (`#67317 `_)
 - Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
   inside a lambda. (`#61460 
`_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-14 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From ffc19ddcab61b99c9ad71cdf96de32fef6ff666b Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 15:18:55 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  9 ++---
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 31 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..501c8c302438ba0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -477,10 +477,10 @@ Bug Fixes in This Version
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
-- Fix crash in __builtin_strncmp and related builtins when the size value
-  exceeded the maximum value representable by int64_t. Fixes
+- Fix crash in ``__builtin_strncmp`` and related builtins when the size value
+  exceeded the maximum value representable by ``int64_t``. Fixes
   (`#64876 `_)
-- Fixed an assertion if a function has cleanups and fatal erors.
+- Fixed an assertion if a function has cleanups and fatal errors.
   (`#48974 `_)
 - Clang now emits an error if it is not possible to deduce array size for a
   variable with incomplete array type.
@@ -557,6 +557,9 @@ Bug Fixes in This Version
   Fixes (`#67317 `_)
 - Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
   inside a lambda. (`#61460 
`_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

Thank you! No problem! I'll add the release notes.

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Gentle ping!

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-04 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Are these tests what you had in mind? Are they sufficient? What else 
should I add?

https://github.com/llvm/llvm-project/pull/69734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-04 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From a67c7b8f2af625145c805240fc51f1ecea392ef2 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 15:18:55 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4dd4e926c8104a4..4d3cf937d36b904 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2648,6 +2648,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-10-20 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/69734

Both active C++ proposals (P1144 and P2786) agree that 
`is_trivially_relocatable_v` and `is_trivially_relocatable_v` 
should be false, not true. Only complete object types can be trivially 
relocatable.

Fixes #67498

>From 64335289e35c4985ff83c5e07a6e951d04822cac Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 15:18:55 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/lib/AST/Type.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 8389b1423058197..bdeff1e4ac5b604 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {

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


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Can you land this for me?

https://github.com/llvm/llvm-project/pull/68506
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From cac3c586a85e1070b2d4aa2ccbc1589c1c84105c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 0c4a81f0385f4c20f636103875a100d5322a79d8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From baeace156163bf367a92d54704dc844d9b5b704d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 11 Oct 2023 15:27:53 +0330
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++---
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index aa3e3322faa42e3..5eaae6bdd2bc63e 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ 

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> I think there is an opportunity for a small refactor here, but feel free to 
> land this and we can handle the refactor later as an NFC change if you prefer

Is this (344455e) what you had in mind? I only found a few places that could 
use the factored-out function, and in the "CodeGenFunction.cpp" case, I'm not 
even sure it applies. It looks like that codepath is intended to be hit when we 
codegen the `operator()` of a lambda with captures under `-fsanitize=null`, but 
I couldn't see any null-check in the generated code even when the lambda did 
have captures, so I'm not sure I understand it. That codepath is 
@zygoloid's from 2017 (376c28e). Should I keep that diff, or revert it?

https://github.com/llvm/llvm-project/pull/68506
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 344455e5451b515b077b0f6358f99db7ee26faf9 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 11 Oct 2023 15:27:53 +0330
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++---
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From edd82edc6dd1ca1a143b4e667d5e4a30d8e7a1d4 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++---
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From e7a5141ca78d0182cf3a372838bdc40b209e56b1 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 95f963747225adea8cf03de6a649a4fc49b80597 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From 32bcab427637432621590a64afaad1677fe832cb Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 6cd6d63fbc38e09f181ecbc93b2c5ecca89d4a71 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 896fbb672c6361588af392343eb217477c066e18 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-08 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From ae2cd56b1c68353aae6c74524e71973ce6ca6904 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/2] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From d703c4a219f94342db942c2a786eaae86587d242 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/2] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

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


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-08 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From ae2cd56b1c68353aae6c74524e71973ce6ca6904 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/2] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From a584b4bdd6bad3a8c8db3249b096e18c5e955839 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:07:32 +0330
Subject: [PATCH 2/2] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if (lam1 == lam2) compiles, then lam1 and lam2 must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp | 828 +++--
 clang/test/SemaCXX/type-traits.cpp |  11 +
 2 files changed, 452 insertions(+), 387 deletions(-)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..324f5321e631b52 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -59,21 +59,21 @@ using namespace clang;
 
 bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
   return (*this != Other) &&
-// CVR qualifiers superset
-(((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
-// ObjC GC qualifiers superset
-((getObjCGCAttr() == Other.getObjCGCAttr()) ||
- (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
-// Address space superset.
-((getAddressSpace() == Other.getAddressSpace()) ||
- (hasAddressSpace()&& !Other.hasAddressSpace())) &&
-// Lifetime qualifier superset.
-((getObjCLifetime() == Other.getObjCLifetime()) ||
- (hasObjCLifetime() && !Other.hasObjCLifetime()));
-}
-
-const IdentifierInfo* QualType::getBaseTypeIdentifier() const {
-  const Type* ty = getTypePtr();
+ // CVR qualifiers superset
+ (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
+ // ObjC GC qualifiers superset
+ ((getObjCGCAttr() == Other.getObjCGCAttr()) ||
+  (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
+ // Address space superset.
+ ((getAddressSpace() == Other.getAddressSpace()) ||
+  (hasAddressSpace() && !Other.hasAddressSpace())) &&
+ // Lifetime qualifier superset.
+ ((getObjCLifetime() == Other.getObjCLifetime()) ||
+  (hasObjCLifetime() && !Other.hasObjCLifetime()));
+}
+
+const IdentifierInfo *QualType::getBaseTypeIdentifier() const {
+  const Type *ty = getTypePtr();
   NamedDecl *ND = nullptr;
   if (ty->isPointerType() || ty->isReferenceType())
 return ty->getPointeeType().getBaseTypeIdentifier();
@@ -84,8 +84,9 @@ const IdentifierInfo* QualType::getBaseTypeIdentifier() const 
{
   else if (ty->getTypeClass() == Type::Typedef)
 ND = ty->castAs()->getDecl();
   else if (ty->isArrayType())
-return ty->castAsArrayTypeUnsafe()->
-getElementType().getBaseTypeIdentifier();
+return ty->castAsArrayTypeUnsafe()
+->getElementType()
+.getBaseTypeIdentifier();
 
   if (ND)
 return ND->getIdentifier();
@@ -114,7 +115,7 @@ bool QualType::isConstant(QualType T, const ASTContext 
) {
 
 std::optional
 QualType::isNonConstantStorage(const 

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-08 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/68506

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if (lam1 == lam2) compiles, then lam1 and lam2 must have
the same type, and be always-equal, and be empty.

>From ae2cd56b1c68353aae6c74524e71973ce6ca6904 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/2] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From ef0ad97b1dee9f4d7547f551b4b8b96a51221c51 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:07:32 +0330
Subject: [PATCH 2/2] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if (lam1 == lam2) compiles, then lam1 and lam2 must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..f0e419de3b1ee84 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,8 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() && (Decl->getLambdaCaptureDefault() == 
LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

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