[PATCH] D154893: [Clang] Fix some triviality computations

2023-10-08 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

I, uh, got preoccupied by some recent events. Don't think I'll have the time 
for this unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D150075: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32

2023-09-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

@shafik @aaron.ballman does any of you want to commandeer this diff? seems 
simple enough of a change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150075

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


[PATCH] D154893: [Clang] Fix some triviality computations

2023-09-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D154893#4646405 , @cor3ntin wrote:

> @royjacobson ^

I did not have a lot of time for Clang the last few months unfortunately. I 
might take a look at this again next month when I'll have a bit more time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 543319.
royjacobson added a comment.

Update release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   !hasTrivialCopyConstructorForCall();
+   (needsImplicitCopyConstructor() &&
+!hasTrivialCopyConstructorForCall());
   }
 
   /// Determine whether this class has a trivial move constructor
@@ -1315,7 +1316,7 @@
   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
   bool hasNonTrivialCopyAssignment() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
-   !hasTrivialCopyAssignment();
+   (needsImplicitCopyAssignment() && !hasTrivialCopyAssignment());
   }
 
   /// Determine whether this class has a trivial move assignment operator
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,8 +67,10 @@
 
 ABI Changes in This Version
 ---
-- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
-  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
+- Two bugs in evaluating the ineligibility of some special member functions has
+  been fixed. This can make some classes trivially copyable that were not
+  trivially copyable before.
+  (`#62555 `_, `#63352 
`_)
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   !hasTrivialCopyConstructorForCall();
+   (needsImplicitCopyConstructor() &&
+!hasTrivialCopyConstructorForCall());
   }
 
   /// Determine whether this class has a trivial move constructor
@@ -1315,7 

[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:1269
   /// Determine whether this class has a non-trivial copy constructor
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {

shafik wrote:
> These references looks like they need to be updated. Same below and it looks 
> like `hasNonTrivialCopyConstructorForCall` is missing references all together.
TBH I don't think those functions actually need references to the standard? 
Whether the actual member functions are trivial or not is already calculated 
before. Do you think I can just remove it? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-10 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added a reviewer: shafik.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix #63352 and one other similar issue by slightly adjusting the computation 
for the existance of non
trivial special member functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154893

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   !hasTrivialCopyConstructorForCall();
+   (needsImplicitCopyConstructor() &&
+!hasTrivialCopyConstructorForCall());
   }
 
   /// Determine whether this class has a trivial move constructor
@@ -1315,7 +1316,7 @@
   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
   bool hasNonTrivialCopyAssignment() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
-   !hasTrivialCopyAssignment();
+   (needsImplicitCopyAssignment() && !hasTrivialCopyAssignment());
   }
 
   /// Determine whether this class has a trivial move assignment operator
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,8 +67,9 @@
 
 ABI Changes in This Version
 ---
-- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
-  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
+- Two bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable before.
+  (`#62555 `_, `#63352 
`_)
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   

[PATCH] D151650: [clang-tidy] Update UnusedReturnValueCheck types

2023-05-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG40af06ccc7bf: [clang-tidy] Update UnusedReturnValueCheck 
types (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151650

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -50,7 +50,7 @@
 
Semicolon-separated list of function return types to check.
By default the following function return types are checked:
-   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, 
`::abseil::Status`
+   `::std::error_code`, `::std::error_condition`, `::std::errc`, 
`::std::expected`, `::boost::system::error_code`
 
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -50,7 +50,7 @@
 
Semicolon-separated list of function return types to check.
By default the following function return types are checked:
-   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+   `::std::error_code`, `::std::error_condition`, `::std::errc`, `::std::expected`, `::boost::system::error_code`
 
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151650: [clang-tidy] Update UnusedReturnValueCheck types

2023-05-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 526468.
royjacobson added a comment.

Update docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151650

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -50,7 +50,7 @@
 
Semicolon-separated list of function return types to check.
By default the following function return types are checked:
-   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, 
`::abseil::Status`
+   `::std::error_code`, `::std::error_condition`, `::std::errc`, 
`::std::expected`, `::boost::system::error_code`
 
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -50,7 +50,7 @@
 
Semicolon-separated list of function return types to check.
By default the following function return types are checked:
-   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+   `::std::error_code`, `::std::error_condition`, `::std::errc`, `::std::expected`, `::boost::system::error_code`
 
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151650: [clang-tidy] Update UnusedReturnValueCheck types

2023-05-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 526440.

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

https://reviews.llvm.org/D151650

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151650: [clang-tidy] Update UnusedReturnValueCheck types

2023-05-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: chaitanyav, PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Update the types for UnusedReturnValueCheck after D151383 
.

1. Add std::errc, std:error_condition
2. Remove `absl::Status` - it's marked as `[[nodiscard]]` anyway so it's 
redundant (and might create double warnings) to check it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151650

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -126,10 +126,12 @@
"::strsignal;"
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
-  Options.get("CheckedReturnTypes", "::std::error_code;"
-"::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+  Options.get("CheckedReturnTypes",
+  "::std::error_code;",
+  "::std::error_condition;",
+  "::std::errc;",
+  "::std::expected;",
+  "::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -126,10 +126,12 @@
"::strsignal;"
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
-  Options.get("CheckedReturnTypes", "::std::error_code;"
-"::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+  Options.get("CheckedReturnTypes",
+  "::std::error_code;",
+  "::std::error_condition;",
+  "::std::errc;",
+  "::std::expected;",
+  "::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149961: [Sema] Mark ineligibility of special member functions correctly

2023-05-19 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f59bee3d58f: [Sema] Mark ineligibility of special member 
functions correctly (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D149961?vs=519857=523765#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149961

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -299,3 +299,16 @@
 static_assert(!__is_trivial(S));
 
 }
+
+namespace GH62555 {
+
+template 
+struct ExplicitTemplateArgs {
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2524,9 +2524,6 @@
 Constructor->getConstexprKind(), InheritedConstructor(),
 TrailingRequiresClause);
 Method->setRangeEnd(Constructor->getEndLoc());
-if (Constructor->isDefaultConstructor() ||
-Constructor->isCopyOrMoveConstructor())
-  Method->setIneligibleOrNotSelected(true);
   } else if (CXXDestructorDecl *Destructor = dyn_cast(D)) {
 Method = CXXDestructorDecl::Create(
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
@@ -2549,8 +2546,6 @@
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, SC,
 D->UsesFPIntrin(), D->isInlineSpecified(), D->getConstexprKind(),
 D->getEndLoc(), TrailingRequiresClause);
-if (D->isMoveAssignmentOperator() || D->isCopyAssignmentOperator())
-  Method->setIneligibleOrNotSelected(true);
   }
 
   if (D->isInlined())
@@ -2753,6 +2748,22 @@
   if (IsExplicitSpecialization && !isFriend)
 SemaRef.CompleteMemberSpecialization(Method, Previous);
 
+  // If the method is a special member function, we need to mark it as
+  // ineligible so that Owner->addDecl() won't mark the class as non trivial.
+  // At the end of the class instantiation, we calculate eligibility again and
+  // then we adjust trivility if needed.
+  // We need this check to happen only after the method parameters are set,
+  // because being e.g. a copy constructor depends on the instantiated
+  // arguments.
+  if (auto *Constructor = dyn_cast(Method)) {
+if (Constructor->isDefaultConstructor() ||
+Constructor->isCopyOrMoveConstructor())
+  Method->setIneligibleOrNotSelected(true);
+  } else if (Method->isCopyAssignmentOperator() ||
+ Method->isMoveAssignmentOperator()) {
+Method->setIneligibleOrNotSelected(true);
+  }
+
   // If there's a function template, let our caller handle it.
   if (FunctionTemplate) {
 // do nothing
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -58,7 +58,8 @@
 
 ABI Changes in This Version
 ---
-
+- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -299,3 +299,16 @@
 static_assert(!__is_trivial(S));
 
 }
+
+namespace GH62555 {
+
+template 
+struct ExplicitTemplateArgs {
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2524,9 +2524,6 @@
 Constructor->getConstexprKind(), InheritedConstructor(),
 TrailingRequiresClause);
 Method->setRangeEnd(Constructor->getEndLoc());
-if (Constructor->isDefaultConstructor() ||
-

[PATCH] D149961: [Sema] Mark ineligibility of special member functions correctly

2023-05-05 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: shafik, erichkeane.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I checked if the member function declaration was a copy constructor, but it's 
not sufficient; We need to check
the arguments against the instantiated class.

Fixed https://github.com/llvm/llvm-project/issues/62555


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149961

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -299,3 +299,16 @@
 static_assert(!__is_trivial(S));
 
 }
+
+namespace GH62555 {
+
+template 
+struct ExplicitTemplateArgs {
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2523,9 +2523,6 @@
 Constructor->getConstexprKind(), InheritedConstructor(),
 TrailingRequiresClause);
 Method->setRangeEnd(Constructor->getEndLoc());
-if (Constructor->isDefaultConstructor() ||
-Constructor->isCopyOrMoveConstructor())
-  Method->setIneligibleOrNotSelected(true);
   } else if (CXXDestructorDecl *Destructor = dyn_cast(D)) {
 Method = CXXDestructorDecl::Create(
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
@@ -2548,8 +2545,6 @@
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, SC,
 D->UsesFPIntrin(), D->isInlineSpecified(), D->getConstexprKind(),
 D->getEndLoc(), TrailingRequiresClause);
-if (D->isMoveAssignmentOperator() || D->isCopyAssignmentOperator())
-  Method->setIneligibleOrNotSelected(true);
   }
 
   if (D->isInlined())
@@ -2752,6 +2747,15 @@
   if (IsExplicitSpecialization && !isFriend)
 SemaRef.CompleteMemberSpecialization(Method, Previous);
 
+  if (auto *Constructor = dyn_cast(Method)) {
+if (Constructor->isDefaultConstructor() ||
+Constructor->isCopyOrMoveConstructor())
+  Method->setIneligibleOrNotSelected(true);
+  } else if (Method->isCopyAssignmentOperator() ||
+ Method->isMoveAssignmentOperator()) {
+Method->setIneligibleOrNotSelected(true);
+  }
+
   // If there's a function template, let our caller handle it.
   if (FunctionTemplate) {
 // do nothing
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -58,7 +58,8 @@
 
 ABI Changes in This Version
 ---
-
+- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -299,3 +299,16 @@
 static_assert(!__is_trivial(S));
 
 }
+
+namespace GH62555 {
+
+template 
+struct ExplicitTemplateArgs {
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2523,9 +2523,6 @@
 Constructor->getConstexprKind(), InheritedConstructor(),
 TrailingRequiresClause);
 Method->setRangeEnd(Constructor->getEndLoc());
-if (Constructor->isDefaultConstructor() ||
-Constructor->isCopyOrMoveConstructor())
-  Method->setIneligibleOrNotSelected(true);
   } else if (CXXDestructorDecl *Destructor = dyn_cast(D)) {
 Method = CXXDestructorDecl::Create(
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
@@ -2548,8 +2545,6 @@
 SemaRef.Context, Record, StartLoc, NameInfo, T, 

[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-04-10 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D141775#4255923 , @philnik wrote:

> Is this essentially "is_trivial_for_the_purposes_of_abi"?

I'd say so. Are you asking for a potential libc++ use case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141775

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


[PATCH] D147904: [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations

2023-04-10 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG016970d079c4: [Clang] Fix cast to BigIntType in 
hasUniqueObjectRepresentations (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147904

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@
   bool b = __has_unique_object_representations(T);
 };
 
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, 
"BitInt:");
+
+
 namespace PR46209 {
   // Foo has both a trivial assignment operator and a non-trivial one.
   struct Foo {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@
   // All integrals and enums are unique.
   if (Ty->isIntegralOrEnumerationType()) {
 // Except _BitInt types that have padding bits.
-if (const auto *BIT = dyn_cast(Ty))
+if (const auto *BIT = Ty->getAs())
   return getTypeSize(BIT) == BIT->getNumBits();
 
 return true;


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@
   bool b = __has_unique_object_representations(T);
 };
 
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, "BitInt:");
+
+
 namespace PR46209 {
   // Foo has both a trivial assignment operator and a non-trivial one.
   struct Foo {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@
   // All integrals and enums are unique.
   if (Ty->isIntegralOrEnumerationType()) {
 // Except _BitInt types that have padding bits.
-if (const auto *BIT = dyn_cast(Ty))
+if (const auto *BIT = Ty->getAs())
   return getTypeSize(BIT) == BIT->getNumBits();
 
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147904: [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations

2023-04-09 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: shafik, cjdb.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A bad QualType cast caused us not to detect _BigInt types if they were wrapped 
inside sugar types like SubstTemplateTypeParm.
Fix https://github.com/llvm/llvm-project/issues/62019


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147904

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@
   bool b = __has_unique_object_representations(T);
 };
 
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, 
"BitInt:");
+
+
 namespace PR46209 {
   // Foo has both a trivial assignment operator and a non-trivial one.
   struct Foo {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@
   // All integrals and enums are unique.
   if (Ty->isIntegralOrEnumerationType()) {
 // Except _BitInt types that have padding bits.
-if (const auto *BIT = dyn_cast(Ty))
+if (const auto *BIT = Ty->getAs())
   return getTypeSize(BIT) == BIT->getNumBits();
 
 return true;


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@
   bool b = __has_unique_object_representations(T);
 };
 
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, "BitInt:");
+
+
 namespace PR46209 {
   // Foo has both a trivial assignment operator and a non-trivial one.
   struct Foo {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@
   // All integrals and enums are unique.
   if (Ty->isIntegralOrEnumerationType()) {
 // Except _BitInt types that have padding bits.
-if (const auto *BIT = dyn_cast(Ty))
+if (const auto *BIT = Ty->getAs())
   return getTypeSize(BIT) == BIT->getNumBits();
 
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-07 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D147655#4250056 , @rsmith wrote:

> There has not been any stable ABI from any compiler targeting the Itanium C++ 
> ABI for constrained templates prior to this change. I don't think we need to 
> worry too much about people using unfinished compiler features being broken 
> when those features are finished.

The ABI has been stable for quite some time and people have been using concepts 
with it for almost 3 years now. I'm not sure we can still break ABI this 
easily. But then, I also have no data to say we can't.

> The ABI proposals haven't been accepted yet; I'm not intending to land this 
> change until the proposals have reached consensus in the Itanium C++ ABI 
> group.

Thanks for clarifying!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-06 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

I agree it doesn't affect too much code, but people do instantiate templates 
manually sometimes. IIUC, linking against shared libraries would break if that 
library does explicit instantiations of constrained functions. That concerns me 
a bit.

Also, do you know if GCC developers are planning on implementing this change as 
well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-04-01 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d4d21e2e095: [Clang][AST] Fix 
__has_unique_object_representations computation for unnamed… (authored by 
royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D145852?vs=509298=510273#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+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::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2716,6 +2716,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -291,6 +291,9 @@
   template parameters with different nested constraints.
 - Fix type equivalence comparison between auto types to take constraints into
   account.
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, "Alignment causes padding");
 static_assert(!has_unique_object_representations::value, "Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+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::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) 

[PATCH] D147288: [clang][NFC] updates cxx_status for P2113R0

2023-03-31 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

There was some discussion of this last year in this review: 
https://reviews.llvm.org/D128750

It's such an edge case that I don't think we should lose sleep about it 
until/unless the committee finds time to clarify the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147288

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


[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
royjacobson marked an inline comment as done.
Closed by commit rG0eb06cb3aa27: [Sema] Stop stripping CV quals from *this 
captures in lambdas (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146168

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 N(3.14);
   };
@@ -161,21 +157,21 @@
 auto L = [this]() {
   static_assert(is_same);
   auto M = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
   auto M = [] {
-static_assert(is_same);
+static_assert(is_same);
   };
 };
 auto N2 = [*this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
   auto M2 = [*this]() {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -190,14 +186,13 @@
 auto L = [*this]() mutable {
   auto M = [=](auto a) {
 auto N = [this] {
-  ++d;
-  static_assert(is_same);
+  static_assert(is_same);
   auto O = [*this] {
 static_assert(is_same);
   };
 };
 N();
-static_assert(is_same);
+static_assert(is_same);
   };
   return M;
 };
@@ -308,3 +303,22 @@
 z(id,3);
 }
 } // namespace PR45881
+
+
+namespace GH50866 {
+struct S;
+
+void f(S *) = delete; // expected-note {{would lose const qualifier}}
+void f(const S *) = delete; // expected-note {{candidate function has been explicitly deleted}}
+
+struct S {
+  void g() const {
+[*this]() mutable { f(this); }(); // expected-error {{call to deleted function}}
+  }
+};
+
+void g() {
+  S s{};
+  s.g();
+}
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,7 +1135,6 @@
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
   if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
@@ -1175,7 +1174,6 @@
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = 

[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added a comment.

In D146168#4231457 , @aaron.ballman 
wrote:

> LGTM aside from a minor nit, though I have some minor concerns that we may 
> silently break people's code by calling different overloads or instantiating 
> templates differently so I wonder if this is a potentially breaking change or 
> not. I think we can leave it out of the potentially breaking changes section 
> unless we get some reports about a behavior change organically during this 
> release cycle?

My rule of thumb here is since we change behavior to match other compilers it's 
probably not too disruptive.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:1138
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-  if (!CurLSI->Mutable)
+if (!CurLSI->Mutable)
 ClassType.addConst();

aaron.ballman wrote:
> This looks like an accidental formatting mistake that can be backed out.
ah, thanks for catching it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146168

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


[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 509436.
royjacobson added a comment.

fix unintended indentation & rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146168

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 N(3.14);
   };
@@ -161,21 +157,21 @@
 auto L = [this]() {
   static_assert(is_same);
   auto M = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
   auto M = [] {
-static_assert(is_same);
+static_assert(is_same);
   };
 };
 auto N2 = [*this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
   auto M2 = [*this]() {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -190,14 +186,13 @@
 auto L = [*this]() mutable {
   auto M = [=](auto a) {
 auto N = [this] {
-  ++d;
-  static_assert(is_same);
+  static_assert(is_same);
   auto O = [*this] {
 static_assert(is_same);
   };
 };
 N();
-static_assert(is_same);
+static_assert(is_same);
   };
   return M;
 };
@@ -308,3 +303,22 @@
 z(id,3);
 }
 } // namespace PR45881
+
+
+namespace GH50866 {
+struct S;
+
+void f(S *) = delete; // expected-note {{would lose const qualifier}}
+void f(const S *) = delete; // expected-note {{candidate function has been explicitly deleted}}
+
+struct S {
+  void g() const {
+[*this]() mutable { f(this); }(); // expected-error {{call to deleted function}}
+  }
+};
+
+void g() {
+  S s{};
+  s.g();
+}
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,7 +1135,6 @@
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
   if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
@@ -1175,7 +1174,6 @@
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = ThisTy->getPointeeType();
-  CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-}
+QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
 
 bool 

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 509298.
royjacobson added a comment.

Add some ((packed)) tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+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::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, "Alignment causes padding");
 static_assert(!has_unique_object_representations::value, "Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+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::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/test/SemaCXX/type-traits.cpp:2886-2889
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};

royjacobson wrote:
> shafik wrote:
> > aaron.ballman wrote:
> > > I think there's one more test to add:
> > > ```
> > > struct UnnamedEmptyBitfieldSplit {
> > >   short named;
> > >   int : 0;
> > >   short also_named;
> > > };
> > > static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2));
> > > static_assert(!has_unique_object_representations::value,
> > >  "Bitfield padding");
> > > ```
> > Do we also want to check packed structs as well?
> Do you have a test case where it would matter? Apparently `packed` is 
> specified to ignore zero width bit fields.
> 
small ping :) @shafik 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

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


[PATCH] D146329: [Clang] Fix defaulted equality operator so that it does not attempt to compare unnamed bit-fields

2023-03-20 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D146329#4203174 , @shafik wrote:

> I would have loved to test the case from 
> https://github.com/llvm/llvm-project/issues/61335 directly but I think in 
> order to do it nicely I need `__builtin_memset` to be usable in a constant 
> expression context. I will add this to my todo list. I am open to other 
> alternatives for testing this.

I managed to generate relatively readable LLVM IR for this: 
https://godbolt.org/z/z1YzoEcr3 (the generated equality operators are obviously 
not correct yet), I think matching against that is testing the issue pretty 
well.


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

https://reviews.llvm.org/D146329

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


[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-18 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 506295.
royjacobson added a comment.

Add the test case from the GH issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146168

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 N(3.14);
   };
@@ -161,21 +157,21 @@
 auto L = [this]() {
   static_assert(is_same);
   auto M = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
   auto M = [] {
-static_assert(is_same);
+static_assert(is_same);
   };
 };
 auto N2 = [*this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
   auto M2 = [*this]() {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -190,14 +186,13 @@
 auto L = [*this]() mutable {
   auto M = [=](auto a) {
 auto N = [this] {
-  ++d;
-  static_assert(is_same);
+  static_assert(is_same);
   auto O = [*this] {
 static_assert(is_same);
   };
 };
 N();
-static_assert(is_same);
+static_assert(is_same);
   };
   return M;
 };
@@ -308,3 +303,22 @@
 z(id,3);
 }
 } // namespace PR45881
+
+
+namespace GH50866 {
+struct S;
+
+void f(S *) = delete; // expected-note {{would lose const qualifier}}
+void f(const S *) = delete; // expected-note {{candidate function has been explicitly deleted}}
+
+struct S {
+  void g() const {
+[*this]() mutable { f(this); }(); // expected-error {{call to deleted function}}
+  }
+};
+
+void g() {
+  S s{};
+  s.g();
+}
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,8 +1135,7 @@
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-  if (!CurLSI->Mutable)
+if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
 }
@@ -1175,7 +1174,6 @@
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = ThisTy->getPointeeType();
-  CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-}
+QualType CaptureType = ByCopy ? 

[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-15 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG765d8a192180: [Clang][Sema] Fix incorrect deletion of 
default constructors for some unions (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D145851?vs=505620=505635#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGen/union-non-trivial-member.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp

Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,47 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) {}
+int x;
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+static_assert(U2().a == 1000, "");
+static_assert(U3().a == 1000, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'a' of union with active member 'b'}}
+static_assert(U2().b.x == 100, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'b' of union with active member 'a'}}
+static_assert(U3().b.x == 100, "");
+
+} // namespace GH48416
Index: clang/test/CodeGen/union-non-trivial-member.cpp
===
--- /dev/null
+++ clang/test/CodeGen/union-non-trivial-member.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 --std=c++17 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) { }
+int x;
+};
+
+union UnionInt {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union UnionNonTrivial {
+int a;
+non_trivial_constructor b{};
+};
+
+void f() {
+UnionInt u1;
+UnionNonTrivial u2;
+}
+
+// CHECK:  define dso_local void @_Z1fv()
+// CHECK:call void @_ZN8UnionIntC1Ev
+// CHECK-NEXT:   call void @_ZN15UnionNonTrivialC1Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC1Ev
+// CHECK:call void @_ZN8UnionIntC2Ev
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC1Ev
+// CHECK:call void @_ZN15UnionNonTrivialC2Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC2Ev
+// CHECK:store i32 1000
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC2Ev
+// CHECK:call void @_ZN23non_trivial_constructorC1Ev
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9158,7 +9158,18 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // [class.default.ctor]p2:
+  //   A defaulted default constructor for class X is defined as deleted if
+  //   - X is a union that has a variant member with a non-trivial default
+  // constructor and no variant member of X has a default member
+  // initializer
+  const auto *RD = cast(Field->getParent());
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else {
+  DiagKind = 4;
+}
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@
 - Fix an issue about ``decltype`` in the members of class templates derived from
   templates with related parameters.
   (`#58674 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 505624.
royjacobson added a comment.

rebase + release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146168

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 N(3.14);
   };
@@ -161,21 +157,21 @@
 auto L = [this]() {
   static_assert(is_same);
   auto M = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
   auto M = [] {
-static_assert(is_same);
+static_assert(is_same);
   };
 };
 auto N2 = [*this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
   auto M2 = [*this]() {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -190,14 +186,13 @@
 auto L = [*this]() mutable {
   auto M = [=](auto a) {
 auto N = [this] {
-  ++d;
-  static_assert(is_same);
+  static_assert(is_same);
   auto O = [*this] {
 static_assert(is_same);
   };
 };
 N();
-static_assert(is_same);
+static_assert(is_same);
   };
   return M;
 };
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,8 +1135,7 @@
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-  if (!CurLSI->Mutable)
+if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
 }
@@ -1175,7 +1174,6 @@
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = ThisTy->getPointeeType();
-  CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-}
+QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
 
 bool isNested = NumCapturingClosures > 1;
 CSI->addThisCapture(isNested, Loc, CaptureType, ByCopy);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,9 @@
 - Fix an issue about ``decltype`` in the members of class templates derived from
   templates with related parameters.
   

[PATCH] D146168: [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146168

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 N(3.14);
   };
@@ -161,21 +157,21 @@
 auto L = [this]() {
   static_assert(is_same);
   auto M = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
   auto M = [] {
-static_assert(is_same);
+static_assert(is_same);
   };
 };
 auto N2 = [*this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
   auto M2 = [*this]() {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [this] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -190,14 +186,13 @@
 auto L = [*this]() mutable {
   auto M = [=](auto a) {
 auto N = [this] {
-  ++d;
-  static_assert(is_same);
+  static_assert(is_same);
   auto O = [*this] {
 static_assert(is_same);
   };
 };
 N();
-static_assert(is_same);
+static_assert(is_same);
   };
   return M;
 };
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,8 +1135,7 @@
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-  if (!CurLSI->Mutable)
+if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
 }
@@ -1175,7 +1174,6 @@
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = ThisTy->getPointeeType();
-  CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-}
+QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
 
 bool isNested = NumCapturingClosures > 1;
 CSI->addThisCapture(isNested, Loc, CaptureType, ByCopy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 505620.
royjacobson marked an inline comment as done.
royjacobson added a comment.

slimmer codegen test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGen/union-non-trivial-member.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp

Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,47 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) {}
+int x;
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+static_assert(U2().a == 1000, "");
+static_assert(U3().a == 1000, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'a' of union with active member 'b'}}
+static_assert(U2().b.x == 100, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'b' of union with active member 'a'}}
+static_assert(U3().b.x == 100, "");
+
+} // namespace GH48416
Index: clang/test/CodeGen/union-non-trivial-member.cpp
===
--- /dev/null
+++ clang/test/CodeGen/union-non-trivial-member.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 --std=c++17 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) { }
+int x;
+};
+
+union UnionInt {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union UnionNonTrivial {
+int a;
+non_trivial_constructor b{};
+};
+
+void f() {
+UnionInt u1;
+UnionNonTrivial u2;
+}
+
+// CHECK:  define dso_local void @_Z1fv()
+// CHECK:call void @_ZN8UnionIntC1Ev
+// CHECK-NEXT:   call void @_ZN15UnionNonTrivialC1Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC1Ev
+// CHECK:call void @_ZN8UnionIntC2Ev
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC1Ev
+// CHECK:call void @_ZN15UnionNonTrivialC2Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC2Ev
+// CHECK:store i32 1000
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC2Ev
+// CHECK:call void @_ZN23non_trivial_constructorC1Ev
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,18 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // [class.default.ctor]p2:
+  //   A defaulted default constructor for class X is defined as deleted if
+  //   - X is a union that has a variant member with a non-trivial default
+  // constructor and no variant member of X has a default member
+  // initializer
+  const auto *RD = cast(Field->getParent());
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else {
+  DiagKind = 4;
+}
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added inline comments.



Comment at: clang/test/SemaCXX/type-traits.cpp:2886-2889
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};

shafik wrote:
> aaron.ballman wrote:
> > I think there's one more test to add:
> > ```
> > struct UnnamedEmptyBitfieldSplit {
> >   short named;
> >   int : 0;
> >   short also_named;
> > };
> > static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2));
> > static_assert(!has_unique_object_representations::value,
> >  "Bitfield padding");
> > ```
> Do we also want to check packed structs as well?
Do you have a test case where it would matter? Apparently `packed` is specified 
to ignore zero width bit fields.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

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


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 2 inline comments as done.
royjacobson added inline comments.



Comment at: clang/test/CodeGen/union-non-trivial-member.cpp:30
+// CHECK-NEXT: 
+// CHECK-NEXT: define linkonce_odr dso_local void @_ZN2UnionIntC2Ev(ptr 
noundef nonnull align 4 dereferenceable(4) %this) unnamed_addr #1 comdat align 
2 {
+// CHECK-NEXT: entry:

erichkeane wrote:
> Looking more closely, this test is a little over specific.  First, you can 
> just do CHECK: to start each function, that way you don't have the blank 
> lines.
> 
> In the top function, all we care about is the `call void `s, so the 
> rest of the lines can go away.  Since you're checking function's define line, 
> you can count on ordering that way rather than check-next.
> 
> This middle function should use more wildcard/placeholders, checking fully 
> specific names like `this` or `this.addr` is a mistake, as those aren't 
> guaranteed to be there.  Also, all the 'align' checks are likely to make this 
> fail in post-commit.
> 
> on the last function, we don't even care about the parameters list, so you 
> just need the `call void ` part.
removed the non-essential parts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

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


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Oops, sorry for the bad codegen test and thanks for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

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


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 505216.
royjacobson added a comment.

Fix the codegen test, add a standard ref to the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGen/union-non-trivial-member.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp

Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,47 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) {}
+int x;
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+static_assert(U2().a == 1000, "");
+static_assert(U3().a == 1000, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'a' of union with active member 'b'}}
+static_assert(U2().b.x == 100, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'b' of union with active member 'a'}}
+static_assert(U3().b.x == 100, "");
+
+} // namespace GH48416
Index: clang/test/CodeGen/union-non-trivial-member.cpp
===
--- /dev/null
+++ clang/test/CodeGen/union-non-trivial-member.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 --std=c++17 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) { }
+int x;
+};
+
+union UnionInt {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union UnionNonTrivial {
+int a;
+non_trivial_constructor b{};
+};
+
+void f() {
+UnionInt u1;
+UnionNonTrivial u2;
+}
+
+// CHECK:  define dso_local void @_Z1fv() {{.*}} {
+// CHECK-NEXT: entry:
+// CHECK:call void @_ZN8UnionIntC1Ev{{.*}}
+// CHECK-NEXT:   call void @_ZN15UnionNonTrivialC1Ev{{.*}}
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+// CHECK:  define {{.*}} void @_ZN8UnionIntC1Ev{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:call void @_ZN8UnionIntC2Ev{{.*}}
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+// CHECK:  define {{.*}} void @_ZN15UnionNonTrivialC1Ev{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:call void @_ZN15UnionNonTrivialC2Ev{{.*}}
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+// CHECK:  define {{.*}} void @_ZN8UnionIntC2Ev{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:store i32 1000{{.*}}
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+// CHECK:  define {{.*}} void @_ZN15UnionNonTrivialC2Ev{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:call void @_ZN23non_trivial_constructorC1Ev{{.*}}
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,18 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // [class.default.ctor]p2:
+  //   A defaulted default constructor for class X is defined as deleted if
+  //   - X is a union that has a variant member with a non-trivial default
+  // constructor and no variant member of X has a default member
+  // initializer
+  const auto *RD = cast(Field->getParent());
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else {
+  DiagKind = 4;
+}
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 2 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:2817
+// unique representation.
+if (Field->isUnnamedBitfield() && BitfieldSize > 0)
+  return std::nullopt;

aaron.ballman wrote:
> I think the check for a non-zero bit-field width might not be completely 
> correct in cases where it's used to split an allocation unit. I suggested a 
> test case below.
That was actually fine: the padding bits would not be a part of the unnamed bit 
field so they're detected.

Then I realized that the surrounding code just sums the object representation 
bits and checks if that equals `sizeof(T)`. But unnamed fields don't contribute 
any bits to the object representation. So a simpler way to fix this is to 
return 0 unconditionally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

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


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 504736.
royjacobson added a comment.

Add a test case, slightly simpler modeling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,29 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,29 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
 static_assert(has_unique_object_representations::value, "Bitfield padding");
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(has_unique_object_representations::value, "Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong size");
+static_assert(!has_unique_object_representations::value, "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^
___

[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 2 inline comments as done.
royjacobson added a comment.

In D145851#4189158 , @erichkeane 
wrote:

> Generally looks good to me.  Do we do anything special if there are multiple 
> initializers?  Also, can we have a codegen test that validates that we 
> actually construct it correctly (and perhaps a constexpr test for the same!)?

Added constexpr + codegen tests.

If we have multiple initializers it's an error that's already diagnosed, I 
assume the error recovery just drops any initializer after the first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

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


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 504724.
royjacobson added a comment.

Add more tests, small nit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGen/union-non-trivial-member.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp

Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,47 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) {}
+int x;
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+static_assert(U2().a == 1000, "");
+static_assert(U3().a == 1000, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'a' of union with active member 'b'}}
+static_assert(U2().b.x == 100, "");
+// expected-error@-1 {{static assertion expression is not an integral constant expression}}
+// expected-note@-2 {{read of member 'b' of union with active member 'a'}}
+static_assert(U3().b.x == 100, "");
+
+} // namespace GH48416
Index: clang/test/CodeGen/union-non-trivial-member.cpp
===
--- /dev/null
+++ clang/test/CodeGen/union-non-trivial-member.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 --std=c++17 -g0 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) { }
+int x;
+};
+
+union UnionInt {
+int a{};
+non_trivial_constructor b;
+};
+
+union UnionNonTrivial {
+int a;
+non_trivial_constructor b{};
+};
+
+UnionInt u1;
+UnionNonTrivial u2;
+
+// CHECK:  define dso_local void @_Z1fv() #0 {
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %u1 = alloca %union.UnionInt, align 4
+// CHECK-NEXT:   %u2 = alloca %union.UnionNonTrivial, align 4
+// CHECK-NEXT:   call void @_ZN2UnionIntC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %u1)
+// CHECK-NEXT:   call void @_ZN2UnionNonTrivialC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %u2)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+// CHECK-NEXT: 
+// CHECK-NEXT: define linkonce_odr dso_local void @_ZN2UnionIntC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %this) unnamed_addr #1 comdat align 2 {
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %this.addr = alloca ptr, align 8
+// CHECK-NEXT:   store ptr %this, ptr %this.addr, align 8
+// CHECK-NEXT:   %this1 = load ptr, ptr %this.addr, align 8
+// CHECK-NEXT:   store i32 0, ptr %this1, align 4
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+// CHECK-NEXT: 
+// CHECK-NEXT: define linkonce_odr dso_local void @_ZN2UnionNonTrivialC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %this) unnamed_addr #2 comdat align 2 {
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %this.addr = alloca ptr, align 8
+// CHECK-NEXT:   store ptr %this, ptr %this.addr, align 8
+// CHECK-NEXT:   %this1 = load ptr, ptr %this.addr, align 8
+// CHECK-NEXT:   call void @_ZN23non_trivial_constructorC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %this1)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,15 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // Default constructor of a union can also be valid if one of the
+  // members has an explicit initializer.
+  const auto *RD = cast(Field->getParent());
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else {
+  DiagKind = 4;
+}
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has 

[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 504391.
royjacobson added a comment.

Small cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp


Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,37 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default 
constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+non_trivial_constructor() {}
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default 
constructor}}
+};
+
+union U2 {
+int a{};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple 
members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+} // namespace GH48416
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,15 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // Default constructor of a union can also be valid if one of the
+  // members has an explicit initializer.
+  auto* RD = dyn_cast(Field->getParent());
+  assert(RD);
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else
+  DiagKind = 4;
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,37 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+non_trivial_constructor() {}
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+} // namespace GH48416
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,15 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // Default constructor of a union can also be valid if one of the
+  // members has an explicit initializer.
+  auto* RD = dyn_cast(Field->getParent());
+  assert(RD);
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else
+  DiagKind = 4;
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 504390.
royjacobson added a comment.

Handle 0-length unnamed bit fields as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,21 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2811,6 +2811,12 @@
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
+
+// If we have explicit padding bits, return nullopt to indicate no
+// unique representation.
+if (Field->isUnnamedBitfield() && BitfieldSize > 0)
+  return std::nullopt;
+
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
   cast(Field->getType())->getNumBits())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,21 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
 static_assert(has_unique_object_representations::value, "Bitfield padding");
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(has_unique_object_representations::value, "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2811,6 +2811,12 @@
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
+
+// If we have explicit padding bits, return nullopt to indicate no
+// unique representation.
+if (Field->isUnnamedBitfield() && BitfieldSize > 0)
+  return std::nullopt;
+
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
   cast(Field->getType())->getNumBits())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 504376.
royjacobson added a comment.

Change to a simpler fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,15 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,9 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+if (Field->isUnnamedBitfield())
+  return std::nullopt;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,15 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
 static_assert(has_unique_object_representations::value, "Bitfield padding");
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(!has_unique_object_representations::value, "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,9 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+if (Field->isUnnamedBitfield())
+  return std::nullopt;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As pointed out in https://github.com/llvm/llvm-project/issues/61336, objects 
with
unnamed bitfields aren't be uniquely representable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,15 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2831,13 +2831,17 @@
   return structHasUniqueObjectRepresentations(Context, RD);
 }
 
-template 
+template 
 static std::optional structSubobjectsHaveUniqueObjectRepresentations(
 const RangeT , int64_t CurOffsetInBits,
 const ASTContext , const clang::ASTRecordLayout ) {
   for (const auto *Subobject : Subobjects) {
 std::optional SizeInBits =
 getSubobjectSizeInBits(Subobject, Context);
+if constexpr (CheckUnnamedBitFields) {
+  if (Subobject->isUnnamedBitfield())
+return std::nullopt;
+}
 if (!SizeInBits)
   return std::nullopt;
 if (*SizeInBits != 0) {
@@ -2873,15 +2877,15 @@
 });
 
 std::optional OffsetAfterBases =
-structSubobjectsHaveUniqueObjectRepresentations(Bases, CurOffsetInBits,
-Context, Layout);
+structSubobjectsHaveUniqueObjectRepresentations(
+Bases, CurOffsetInBits, Context, Layout);
 if (!OffsetAfterBases)
   return std::nullopt;
 CurOffsetInBits = *OffsetAfterBases;
   }
 
   std::optional OffsetAfterFields =
-  structSubobjectsHaveUniqueObjectRepresentations(
+  structSubobjectsHaveUniqueObjectRepresentations(
   RD->fields(), CurOffsetInBits, Context, Layout);
   if (!OffsetAfterFields)
 return std::nullopt;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,15 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
 static_assert(has_unique_object_representations::value, "Bitfield padding");
 static_assert(!has_unique_object_representations::value, "Bitfield padding");
+static_assert(!has_unique_object_representations::value, "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2831,13 +2831,17 @@
   return structHasUniqueObjectRepresentations(Context, RD);
 }
 
-template 
+template 
 static std::optional structSubobjectsHaveUniqueObjectRepresentations(
 const RangeT , int64_t CurOffsetInBits,
 const ASTContext , const clang::ASTRecordLayout ) {
   for (const auto *Subobject : Subobjects) {
 std::optional SizeInBits =
 getSubobjectSizeInBits(Subobject, Context);
+if constexpr (CheckUnnamedBitFields) {
+  if (Subobject->isUnnamedBitfield())
+return std::nullopt;
+}
 if (!SizeInBits)
   return std::nullopt;
 if (*SizeInBits != 0) {
@@ -2873,15 +2877,15 @@
 });
 
 std::optional OffsetAfterBases =
-structSubobjectsHaveUniqueObjectRepresentations(Bases, CurOffsetInBits,
-Context, Layout);
+structSubobjectsHaveUniqueObjectRepresentations(
+   

[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes https://github.com/llvm/llvm-project/issues/48416.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145851

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp


Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,37 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default 
constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+non_trivial_constructor() {}
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default 
constructor}}
+};
+
+union U2 {
+int a{};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple 
members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+} // namespace GH48416
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,15 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // Default constructor of a union can also be valid if one of the
+  // members has an explicit initializer.
+  auto* Constructor = dyn_cast(Decl);
+  auto* RD = dyn_cast(Field->getParent());
+  if (!Constructor || !RD || !RD->hasInClassInitializer())
+DiagKind = 4;
+} else
+  DiagKind = 4;
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,37 @@
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+non_trivial_constructor() {}
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default constructor}}
+};
+
+union U2 {
+int a{};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+} // namespace GH48416
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -9157,7 +9157,15 @@
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // Default constructor of a union can also be valid if one of the
+  // members has an explicit initializer.
+  auto* Constructor = dyn_cast(Decl);
+  auto* RD = dyn_cast(Field->getParent());
+  if (!Constructor || !RD || !RD->hasInClassInitializer())
+DiagKind = 4;
+} else
+  DiagKind = 4;
   }
 
   if (DiagKind == -1)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,8 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   

[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-03-10 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D140996#4185795 , @bolshakov-a 
wrote:

> @royjacobson, I've added some test cases for using the new NTTP arguments in 
> clang modules. It uses serialization, in principle. Or more specialized tests 
> are still needed?

No, I think that's good. Thanks for adding them!


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

https://reviews.llvm.org/D140996

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


[PATCH] D145047: Fix broken link on Clang documentation page

2023-03-04 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc10715f9bb3: Fix broken link on Clang documentation page 
(authored by tupaschoal, committed by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145047

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145047: Fix broken link on Clang documentation page

2023-03-02 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson accepted this revision.
royjacobson added a comment.

Thanks! Do you need me to land this for you? If so, could you please provide 
name + email to sign the commit with?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145047

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


[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-26 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D143851#4153270 , @carlosgalvezp 
wrote:

> LGTM, thanks for the contribution! Do you have commit rights or would you 
> like that we land it for you? If so, please provide name and email for 
> attribution.

I have commit rights, but this is my first clang-tidy contribution :) Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

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


[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-26 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa56e66bf752: [clang-tidy] Tweak rule of 3/5 
checks to allow defaulting a destructor… (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
@@ -1,14 +1,26 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions, value: true}, {key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true}]}" --
 
+// Don't warn on destructors without definitions, they might be defaulted in another TU.
+class DeclaresDestructor {
+  ~DeclaresDestructor();
+};
+
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+DefinesDestructor::~DefinesDestructor() {}
+// CHECK-MESSAGES: [[@LINE-4]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
 };
 
+class DefinesDefaultedDestructorOutside {
+  ~DefinesDefaultedDestructorOutside();
+};
+
+DefinesDefaultedDestructorOutside::~DefinesDefaultedDestructorOutside() = default;
+
 class DefinesCopyConstructor {
   DefinesCopyConstructor(const DefinesCopyConstructor &);
 };
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesCopyConstructor {
   DefinesCopyConstructor(const DefinesCopyConstructor &);
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
@@ -25,15 +25,25 @@
 
 .. option:: AllowSoleDefaultDtor
 
-   When set to `true` (default is `false`), this check 

[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-02-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

There are no AST [de]serialization tests in this PR, right? Would be nice to 
add some.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140996

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


[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

friendly ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

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


[PATCH] D144572: [C++20] Stop claiming full support for consteval (for the moment!)

2023-02-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D144572#4145614 , @cor3ntin wrote:

> @aaron.ballman is the plan to backport that to clang 16? I think it probably 
> should.
> We ought to try to improve the situation for clang 17

cxx_status.html is always updated from trunk, no? I don't think we need to 
bother with backporting if that's the case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144572

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


[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-22 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG000ec50ef511: [Clang] Adjust triviality computation in 
QualType::isTrivialType to C++20 cases. (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D143891?vs=496884=499635#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143891

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -265,3 +265,37 @@
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template 
+struct X {
+X() requires false = default;
+};
+static_assert(!__is_trivial(X));
+
+template 
+struct S {
+S() requires(__is_trivially_constructible(T)) = default;
+
+S() requires(!__is_trivially_constructible(T) &&
+  __is_constructible(T)) {}
+
+T t;
+};
+
+struct D {
+D(int i) : i(i) {}
+int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S));
+static_assert(!__is_constructible(S));
+
+static_assert(__is_trivial(S));
+static_assert(!__is_trivial(S));
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2501,11 +2501,13 @@
 return true;
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  // C++11 [class]p6:
-  //   A trivial class is a class that has a default constructor,
-  //   has no non-trivial default constructors, and is trivially
-  //   copyable.
-  return ClassDecl->hasDefaultConstructor() &&
+  // C++20 [class]p6:
+  //   A trivial class is a class that is trivially copyable, and
+  // has one or more eligible default constructors such that each is
+  // trivial.
+  // FIXME: We should merge this definition of triviality into
+  // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+  return ClassDecl->hasTrivialDefaultConstructor() &&
  !ClassDecl->hasNonTrivialDefaultConstructor() &&
  ClassDecl->isTriviallyCopyable();
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -58,6 +58,8 @@
 
 ABI Changes in This Version
 ---
+- ``__is_trivial`` has changed for a small category of classes with 
constrained default constructors (`#60697 
`_).
+  *FIXME: Remove this note if we've backported this change to the Clang 16 
branch.*
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -265,3 +265,37 @@
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template 
+struct X {
+X() requires false = default;
+};
+static_assert(!__is_trivial(X));
+
+template 
+struct S {
+S() requires(__is_trivially_constructible(T)) = default;
+
+S() requires(!__is_trivially_constructible(T) &&
+  __is_constructible(T)) {}
+
+T t;
+};
+
+struct D {
+D(int i) : i(i) {}
+int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S));
+static_assert(!__is_constructible(S));
+
+static_assert(__is_trivial(S));
+static_assert(!__is_trivial(S));
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2501,11 +2501,13 @@
 return true;
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  // C++11 [class]p6:
-  //   A trivial class is a class that has a default constructor,
-  //   has no non-trivial default constructors, and is trivially
-  //   copyable.
-  return ClassDecl->hasDefaultConstructor() &&
+  // C++20 [class]p6:
+  //   A trivial class is a class that is trivially copyable, and
+  // has one or more eligible default constructors such that each is
+  // trivial.
+  // FIXME: We should merge 

[PATCH] D144572: [C++20] Stop claiming full support for consteval (for the moment!)

2023-02-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson accepted this revision.
royjacobson added a comment.
This revision is now accepted and ready to land.

+1 from me, at least as long as we don't define the feature test macro.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144572

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


[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

It's an interesting discussion, I just want to remind that this change is for 
triviality rules from P0848 (conditionally trivial member functions) which is 
only going to ship in Clang 16 anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143891

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


[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D143851#4126453 , @ClockMan wrote:

> Thing is that same issue may happen with all other members, what about 
> copy/move constructors defaulted in .cpp (just to speed up compilation for 
> classes with many members).
> Best thing would simply to check if all definitions are available. In that 
> case issues would be reported only for source file that corresponds to header 
> file with defined class.
> This would also reduce amount of generated warnings for a big project that 
> include such header with class in many places.
>
> Other good option would be to excluded classes defined in system headers, no 
> point to check if some boost class or std::vector got proper constructors.

Defaulting destructors is usually fine, but explicitly defaulting copy/move 
constructors implicitly deletes the other special member functions which this 
check should diagnose.
This is why this option was only available for destructors in the first place, 
I imagine.

About the second point - this sounds pretty general, doesn't clang-tidy already 
filter diagnostics in system headers? At least Clang does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-02-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson closed this revision.
royjacobson added a comment.

Landed in 
https://github.com/llvm/llvm-project/commit/be701ab08f12daf9437c2db6d08a1731cf1df34c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/lib/AST/Type.cpp:2495
+  // FIXME: We should merge this definition of triviality into
+  // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+  return ClassDecl->hasTrivialDefaultConstructor() &&

shafik wrote:
> Will you follow-up this change by updating `CXXRecordDecl::isTrivial` as well 
> or is that a more difficult issue?
I want to, but I need to check the call sites to make sure it won't change ABI 
or something. And I wanted a fix that I can safely backport :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143891

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


[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-02-13 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6259eca16f6: [Clang] Export CanPassInRegisters as a type 
trait (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D141775?vs=491102=497016#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141775

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,36 @@
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+struct C; // expected-note {{forward declaration}}
+
+union D {
+  int x;
+};
+
+static_assert(__can_pass_in_regs(A), "");
+static_assert(__can_pass_in_regs(A), "");
+static_assert(!__can_pass_in_regs(B), "");
+static_assert(__can_pass_in_regs(D), "");
+
+void test_errors() {
+  (void)__can_pass_in_regs(const A); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(A&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(A&&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(const A&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(C); // expected-error {{incomplete type}}
+  (void)__can_pass_in_regs(int); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(int&); // expected-error {{not an unqualified class type}}
+}
+}
+
 struct S {};
 template  using remove_const_t = __remove_const(T);
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4885,6 +4885,7 @@
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv void,
   // or an array of unknown bound. But GCC actually imposes the same constraints
   // as above.
@@ -5373,6 +5374,11 @@
 return T.isTriviallyRelocatableType(C);
   case UTT_IsReferenceable:
 return T.isReferenceable();
+  case UTT_CanPassInRegs:
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && !T.hasQualifiers())
+  return RD->canPassInRegisters();
+Self.Diag(KeyLoc, diag::err_builtin_pass_in_regs_non_class) << T;
+return false;
   }
 }
 
Index: clang/include/clang/Basic/TokenKinds.def
===
--- clang/include/clang/Basic/TokenKinds.def
+++ clang/include/clang/Basic/TokenKinds.def
@@ -523,6 +523,7 @@
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11794,4 +11794,8 @@
   "change type of '%0' to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information">;
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
+
+def err_builtin_pass_in_regs_non_class : Error<
+  "argument %0 is not an unqualified class type">;
+
 } // end of sema component.
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1401,6 +1401,10 @@
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__can_pass_in_regs`` (C++)
+  Returns whether a class can be passed in registers under the current
+  ABI. This type can only be applied to unqualified class types.
+  This is not a portable type trait.
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 496998.
royjacobson added a comment.

Address CR comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
@@ -1,14 +1,26 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions, value: true}, {key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true}]}" --
 
+// Don't warn on destructors without definitions, they might be defaulted in another TU.
+class DeclaresDestructor {
+  ~DeclaresDestructor();
+};
+
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+DefinesDestructor::~DefinesDestructor() {}
+// CHECK-MESSAGES: [[@LINE-4]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
 };
 
+class DefinesDefaultedDestructorOutside {
+  ~DefinesDefaultedDestructorOutside();
+};
+
+DefinesDefaultedDestructorOutside::~DefinesDefaultedDestructorOutside() = default;
+
 class DefinesCopyConstructor {
   DefinesCopyConstructor(const DefinesCopyConstructor &);
 };
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesCopyConstructor {
   DefinesCopyConstructor(const DefinesCopyConstructor &);
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
@@ -25,15 +25,25 @@
 
 .. option:: AllowSoleDefaultDtor
 
-   When set to `true` (default is `false`), this check doesn't flag classes with a sole, explicitly
-   defaulted destructor. An example for such a class is:
+   

[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D143891#4122660 , @aaron.ballman 
wrote:

> This is an ABI breaking change, isn't it? (The type trait now returns 
> something different than it did before, which could change instantiations or 
> object layout.)

Technically it is, but it only affects code that relies on constrained default 
constructors, which we're only going to support in Clang 16. So if we backport 
this to 16 it's not very problematic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143891

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


[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: erichkeane, cor3ntin.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Up to C++20, hasDefaultConstructor and !hasNonTrivialDefaultConstructor 
together implied
hasTrivialDefaultConstructor. In C++20, a constructor might be ineligible and 
can set
hasDefaultConstructor without setting hasNonTrivialDefaultConstructor.

Fix this by querying hasTrivialDefaultConstructor instead of 
hasDefaultConstructor.

I'd like to backport this to Clang 16.
I only change isTrivialType and in a way that should only affect code that uses
constrained constructors, so I think this is relatively safe to backport.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143891

Files:
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -265,3 +265,37 @@
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template 
+struct X {
+X() requires false = default;
+};
+static_assert(!__is_trivial(X));
+
+template 
+struct S {
+S() requires(__is_trivially_constructible(T)) = default;
+
+S() requires(!__is_trivially_constructible(T) &&
+  __is_constructible(T)) {}
+
+T t;
+};
+
+struct D {
+D(int i) : i(i) {}
+int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S));
+static_assert(!__is_constructible(S));
+
+static_assert(__is_trivial(S));
+static_assert(!__is_trivial(S));
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2487,11 +2487,13 @@
 return true;
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  // C++11 [class]p6:
-  //   A trivial class is a class that has a default constructor,
-  //   has no non-trivial default constructors, and is trivially
-  //   copyable.
-  return ClassDecl->hasDefaultConstructor() &&
+  // C++20 [class]p6:
+  //   A trivial class is a class that is trivially copyable, and
+  // has one or more eligible default constructors such that each is
+  // trivial.
+  // FIXME: We should merge this definition of triviality into
+  // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+  return ClassDecl->hasTrivialDefaultConstructor() &&
  !ClassDecl->hasNonTrivialDefaultConstructor() &&
  ClassDecl->isTriviallyCopyable();
 }


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -265,3 +265,37 @@
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template 
+struct X {
+X() requires false = default;
+};
+static_assert(!__is_trivial(X));
+
+template 
+struct S {
+S() requires(__is_trivially_constructible(T)) = default;
+
+S() requires(!__is_trivially_constructible(T) &&
+  __is_constructible(T)) {}
+
+T t;
+};
+
+struct D {
+D(int i) : i(i) {}
+int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S));
+static_assert(!__is_constructible(S));
+
+static_assert(__is_trivial(S));
+static_assert(!__is_trivial(S));
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2487,11 +2487,13 @@
 return true;
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  // C++11 [class]p6:
-  //   A trivial class is a class that has a default constructor,
-  //   has no non-trivial default constructors, and is trivially
-  //   copyable.
-  return ClassDecl->hasDefaultConstructor() &&
+  // C++20 [class]p6:
+  //   A trivial class is a class that is trivially copyable, and
+  // has one or more eligible default constructors such that each is
+  // trivial.
+  // FIXME: We should merge this definition of triviality into
+  // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+  return 

[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-12 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: carlosgalvezp, njames93, aaron.ballman.
Herald added subscribers: kbarton, xazax.hun, nemanjai.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

A somewhat common code-pattern is to default a destructor in the source file 
and not in the header.
For example, this is the way to use smart pointers with forward-declared 
classes:

  c++
  
  struct Impl;
  struct A {
~A(); // Can't be defaulted in the header.
  
  private:
std::unique_ptr impl;
  };

To be able to use this check with this pattern, I modified the behavior with 
`AllowSoleDefaultDtor`
to not trigger on destructors if they aren't defined yet.
Since a declared destructor should still be defined somewhere in the program, 
this doesn't
won't miss bad classes, just diagnose on less translation units.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143851

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp
@@ -1,14 +1,26 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions, value: true}, {key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true}]}" --
 
+// Don't warn on destructors without definitions, they might be defaulted in another TU.
+class DeclaresDestructor {
+  ~DeclaresDestructor();
+};
+
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+DefinesDestructor::~DefinesDestructor() {}
+// CHECK-MESSAGES: [[@LINE-4]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
 
 class DefinesDefaultedDestructor {
   ~DefinesDefaultedDestructor() = default;
 };
 
+class DefinesDefaultedDestructorOutside {
+  ~DefinesDefaultedDestructorOutside();
+};
+
+DefinesDefaultedDestructorOutside::~DefinesDefaultedDestructorOutside() = default;
+
 class DefinesCopyConstructor {
   DefinesCopyConstructor(const DefinesCopyConstructor &);
 };
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp
@@ -3,7 +3,7 @@
 class DefinesDestructor {
   ~DefinesDestructor();
 };
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-02-12 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a subscriber: clang-language-wg.
royjacobson marked 2 inline comments as done.
royjacobson added a comment.

friendly ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-02-12 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 496771.
royjacobson added a comment.

Rebase to include the RISC-V changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Download Page `_.
+ `the Releases Page `_.
 
 Introduction
 
@@ -23,43 +23,32 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
 `LLVM Web Site `_.
 
-Note that if you are reading this file from a Git checkout or the
-main Clang web page, this document applies to the *next* release, not
-the current one. To see the release notes for a specific release, please
-see the `releases page `_.
-
 Potentially Breaking Changes
 
 These changes are ones which we think may surprise users when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These flags have been silently ignored since Clang 15.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource directory path previously included the full clang version.
+  It now includes only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,17 +78,26 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
+
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
   .. code-block:: c
 
-  typedef char int8_a16 __attribute__((aligned(16)));
-  int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
+typedef char int8_a16 __attribute__((aligned(16)));
+int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will now propagate dllimport/export 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-30 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:16
  Release notes for previous releases can be found on
- `the Download Page `_.
+ `the Releases Page `_.
 

aaron.ballman wrote:
> Are you planning to merge the changes in generic text over to the trunk once 
> this lands?
Yeah, absolutely!



Comment at: clang/docs/ReleaseNotes.rst:43
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 

aaron.ballman wrote:
> Do we want to mention that this may also impact build-time performance of 
> projects relying on the default language standard mode, because C++17 pulls 
> in a lot more compile-time-intensive APIs like constexpr and more template 
> metaprogramming?
I agree this change is annoying and has real life impact - I'm not trying to 
minimize it - but I think newer language versions bring enough benefits that we 
shouldn't warn users about using them in the Clang release notes. Especially 
since this doesn't come with any balancing context (like 'you can now use 
template variables instead of instantiating a struct every time you check if 
two types are equal' ;) ) 



Comment at: clang/docs/ReleaseNotes.rst:46
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These flags have been silently ignored since 15.
 

aaron.ballman wrote:
> I don't know if we want to standardize on `Clang-15` or `Clang 15`, etc. Feel 
> free to edit as you see fit.
Changed to Clang 15


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-30 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 493360.
royjacobson marked 2 inline comments as done.
royjacobson added a comment.

15 -> Clang 15


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Download Page `_.
+ `the Releases Page `_.
 
 Introduction
 
@@ -23,43 +23,32 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
 `LLVM Web Site `_.
 
-Note that if you are reading this file from a Git checkout or the
-main Clang web page, this document applies to the *next* release, not
-the current one. To see the release notes for a specific release, please
-see the `releases page `_.
-
 Potentially Breaking Changes
 
 These changes are ones which we think may surprise users when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These flags have been silently ignored since Clang 15.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource directory path previously included the full clang version.
+  It now includes only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,17 +78,26 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
+
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
   .. code-block:: c
 
-  typedef char int8_a16 __attribute__((aligned(16)));
-  int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
+typedef char int8_a16 __attribute__((aligned(16)));
+int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will now 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added a comment.

In D142578#4088011 , @tschuett wrote:

> IDK. Clang 16 is fully is a fully conformant C++20 except for some DRs. Or 
> beginning with Clang 16, we start a long-term project to overhaul the 
> diagnostics.
>
> I agree that breaking changes are important.

I contemplated on this for a bit, and I don't have anything that I feel is 
representative enough and fits into one paragraph. I'm still not against the 
general idea though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-28 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 5 inline comments as done.
royjacobson added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:452-454
+
 - Now diagnoses use of a member access expression or array subscript expression
   within ``__builtin_offsetof`` and ``offsetof`` as being a Clang extension.

aaron.ballman wrote:
> aaron.ballman wrote:
> > Assuming https://github.com/llvm/llvm-project/issues/60337 gets ported to 
> > the 16.0 branch, this bullet can be removed entirely.
> and that did land in 84f3164c1d9ce024f59221dcfbc8ab050de73748
done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-28 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 493008.
royjacobson added a comment.

- Remove redundant paragraph from the intro
- Remove outdated bug fix bullet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Download Page `_.
+ `the Releases Page `_.
 
 Introduction
 
@@ -23,43 +23,32 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
 `LLVM Web Site `_.
 
-Note that if you are reading this file from a Git checkout or the
-main Clang web page, this document applies to the *next* release, not
-the current one. To see the release notes for a specific release, please
-see the `releases page `_.
-
 Potentially Breaking Changes
 
 These changes are ones which we think may surprise users when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These flags have been silently ignored since 15.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource directory path previously included the full clang version.
+  It now includes only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,17 +78,26 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
+
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
   .. code-block:: c
 
-  typedef char int8_a16 __attribute__((aligned(16)));
-  int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
+typedef char int8_a16 __attribute__((aligned(16)));
+int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-28 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D142578#4087974 , @tschuett wrote:

> I am not the only one who has a different background. If the introduction 
> says this is the introduction of the release notes, I am not super motivated 
> to read on. I would prefer to see some highlights to motivate the readers to 
> continue reading.

You've mentioned what I think are separate issues - that this document is 
difficult to read for readers from different backgrounds and that the 
introduction might be too long or unengaging.

I mostly agree about the first point - I've tried to do what I could to make it 
more accessible but I don't think it's enough.

About the second point - I'm not really sure what to change. I think the 
'potentially breaking changes' section is more important than the 'what's new' 
section, but the 'what's new' section IS the second section (and there's a 
table of contents). Are there specific topics you think we should remove from 
the introduction or move into the intro from the 'what's new' section? I'd like 
to avoid duplicating information if we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-26 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Thanks Erich and Emilia!

The html file is attached here, I think it's probably easier to proof read that 
way. (Took me a bit to figure out the CMake magic...)

F26271094: ReleaseNotes.html 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-26 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 492516.
royjacobson added a comment.

- Address comments from Erich and Emilia
- Validate that the rst actually builds an html file
- Fix some missing backticks and underscores


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -23,9 +23,9 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
@@ -42,24 +42,18 @@
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These flags have been silently ignored since 15.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource directory path previously included the full clang version.
+  It now includes only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,17 +83,26 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
+
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
   .. code-block:: c
 
-  typedef char int8_a16 __attribute__((aligned(16)));
-  int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
+typedef char int8_a16 __attribute__((aligned(16)));
+int8_a16 array[4]; // Now diagnosed as the element size not being a multiple of the array alignment.
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will now propagate dllimport/export declspecs in
-  explicit specializations of class template member functions (`Issue 54717
+  explicit specializations of class template member functions (`#54717
   `_):
 
   .. code-block:: c++
@@ -143,8 +146,8 @@
 - Clang now diagnoses use of a bit-field as an instruction operand in Microsoft
   style inline asm blocks as an error. Previously, a bit-field operand yielded
   the address of the allocation unit the bit-field was stored within; reads or
-  writes therefore had the potential to read or write nearby bit-fields. This
-  change fixes `issue 57791 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added subscribers: s.egerton, mstorsjo, simoncook, dschuff.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, sstefan1, aheejin.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Do a large edit of the Clang release notes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -23,9 +23,9 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
@@ -42,24 +42,18 @@
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These have been no-ops since 15.0.0.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource dir used to include the full clang version. It will now
+  include only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,6 +83,14 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
@@ -99,7 +101,7 @@
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will now propagate dllimport/export declspecs in
-  explicit specializations of class template member functions (`Issue 54717
+  explicit specializations of class template member functions (`#54717
   `_):
 
   .. code-block:: c++
@@ -143,8 +145,8 @@
 - Clang now diagnoses use of a bit-field as an instruction operand in Microsoft
   style inline asm blocks as an error. Previously, a bit-field operand yielded
   the address of the allocation unit the bit-field was stored within; reads or
-  writes therefore had the potential to read or write nearby bit-fields. This
-  change fixes `issue 57791 `_.
+  writes therefore had the potential to read or write nearby bit-fields.
+  (`#57791 `_)
 
   .. code-block:: c++
 
@@ -158,8 +160,35 @@
   }
 }
 
-- The ``-fexperimental-new-pass-manager`` and 

[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-01-21 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 491102.
royjacobson added a comment.

fix the test after diag change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141775

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,36 @@
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+struct C; // expected-note {{forward declaration}}
+
+union D {
+  int x;
+};
+
+static_assert(__can_pass_in_regs(A), "");
+static_assert(__can_pass_in_regs(A), "");
+static_assert(!__can_pass_in_regs(B), "");
+static_assert(__can_pass_in_regs(D), "");
+
+void test_errors() {
+  (void)__can_pass_in_regs(const A); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(A&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(A&&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(const A&); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(C); // expected-error {{incomplete type}}
+  (void)__can_pass_in_regs(int); // expected-error {{not an unqualified class type}}
+  (void)__can_pass_in_regs(int&); // expected-error {{not an unqualified class type}}
+}
+}
+
 struct S {};
 template  using remove_const_t = __remove_const(T);
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4883,6 +4883,7 @@
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv void,
   // or an array of unknown bound. But GCC actually imposes the same constraints
   // as above.
@@ -5371,6 +5372,11 @@
 return T.isTriviallyRelocatableType(C);
   case UTT_IsReferenceable:
 return T.isReferenceable();
+  case UTT_CanPassInRegs:
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && !T.hasQualifiers())
+  return RD->canPassInRegisters();
+Self.Diag(KeyLoc, diag::err_builtin_pass_in_regs_non_class) << T;
+return false;
   }
 }
 
Index: clang/include/clang/Basic/TokenKinds.def
===
--- clang/include/clang/Basic/TokenKinds.def
+++ clang/include/clang/Basic/TokenKinds.def
@@ -523,6 +523,7 @@
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11786,4 +11786,7 @@
   InGroup, DefaultIgnore;
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
+
+def err_builtin_pass_in_regs_non_class : Error<
+  "argument %0 is not an unqualified class type">;
 } // end of sema component.
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1398,6 +1398,10 @@
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__can_pass_in_regs`` (C++)
+  Returns whether a class can be passed in registers under the current
+  ABI. This type can only be applied to unqualified class types.
+  This is not a portable type trait.
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-01-17 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5387
+  return RD->canPassInRegisters();
+return true;
   }

shafik wrote:
> erichkeane wrote:
> > Is there good reason to return true for all non-record types?  Should we 
> > instead be limiting the types that can make it this far?
> Looking how it is used internally, I think it makes sense to restrict this to 
> records. 
My initial thinking was 'well references/builtins ARE passed by registers'. But 
I thought about this a bit and I agree with you, it's probably better to 
restrict this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141775

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


[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-01-17 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 489934.
royjacobson added a comment.

Reject non class types, update doc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141775

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,36 @@
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+struct C; // expected-note {{forward declaration}}
+
+union D {
+  int x;
+};
+
+static_assert(__can_pass_in_regs(A), "");
+static_assert(__can_pass_in_regs(A), "");
+static_assert(!__can_pass_in_regs(B), "");
+static_assert(__can_pass_in_regs(D), "");
+
+void test_errors() {
+  (void)__can_pass_in_regs(const A); // expected-error {{not a class type}}
+  (void)__can_pass_in_regs(A&); // expected-error {{not a class type}}
+  (void)__can_pass_in_regs(A&&); // expected-error {{not a class type}}
+  (void)__can_pass_in_regs(const A&); // expected-error {{not a class type}}
+  (void)__can_pass_in_regs(C); // expected-error {{incomplete type}}
+  (void)__can_pass_in_regs(int); // expected-error {{not a class type}}
+  (void)__can_pass_in_regs(int&); // expected-error {{not a class type}}
+}
+}
+
 struct S {};
 template  using remove_const_t = __remove_const(T);
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4883,6 +4883,7 @@
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv void,
   // or an array of unknown bound. But GCC actually imposes the same constraints
   // as above.
@@ -5371,6 +5372,11 @@
 return T.isTriviallyRelocatableType(C);
   case UTT_IsReferenceable:
 return T.isReferenceable();
+  case UTT_CanPassInRegs:
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && !T.hasQualifiers())
+  return RD->canPassInRegisters();
+Self.Diag(KeyLoc, diag::err_builtin_pass_in_regs_non_class) << T;
+return false;
   }
 }
 
Index: clang/include/clang/Basic/TokenKinds.def
===
--- clang/include/clang/Basic/TokenKinds.def
+++ clang/include/clang/Basic/TokenKinds.def
@@ -523,6 +523,7 @@
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11786,4 +11786,7 @@
   InGroup, DefaultIgnore;
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
+
+def err_builtin_pass_in_regs_non_class : Error<
+  "argument %0 is not an unqualified class type">;
 } // end of sema component.
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1398,6 +1398,10 @@
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__can_pass_in_regs`` (C++)
+  Returns whether a class can be passed in registers under the current
+  ABI. This type can only be applied to unqualified class types.
+  This is not a portable type trait.
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141803: [Clang] Reject in-class defaulting of previously declared comparison operators

2023-01-17 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a763343e29f: [Clang] Reject in-class defaulting of 
previously declared comparison operators (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D141803?vs=489607=489919#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Index: clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
@@ -165,22 +165,22 @@
 // FIXME: This rule creates problems for reordering of declarations; is this
 // really the right model?
 struct G;
-bool operator==(const G&, const G&);
-bool operator!=(const G&, const G&);
-std::strong_ordering operator<=>(const G&, const G&);
-bool operator<(const G&, const G&);
-bool operator<=(const G&, const G&);
-bool operator>(const G&, const G&);
-bool operator>=(const G&, const G&);
+bool operator==(const G&, const G&); // expected-note {{previous declaration}}
+bool operator!=(const G&, const G&); // expected-note {{previous declaration}}
+std::strong_ordering operator<=>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<=(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>=(const G&, const G&); // expected-note {{previous declaration}}
 struct G {
-  friend bool operator==(const G&, const G&) = default;
-  friend bool operator!=(const G&, const G&) = default;
-
-  friend std::strong_ordering operator<=>(const G&, const G&) = default;
-  friend bool operator<(const G&, const G&) = default;
-  friend bool operator<=(const G&, const G&) = default;
-  friend bool operator>(const G&, const G&) = default;
-  friend bool operator>=(const G&, const G&) = default;
+  friend bool operator==(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator!=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+
+  friend std::strong_ordering operator<=>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
 };
 bool operator==(const G&, const G&);
 bool operator!=(const G&, const G&);
Index: clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
@@ -139,13 +139,13 @@
 
 struct F;
 bool operator==(const F&, const F&);
-bool operator!=(const F&, const F&);
+bool operator!=(const F&, const F&); // expected-note {{previous declaration}}
 bool operator<=>(const F&, const F&);
-bool operator<(const F&, const F&);
+bool operator<(const F&, const F&); // expected-note {{previous declaration}}
 struct F {
   union { int a; };
   friend bool operator==(const F&, const F&) = default; // expected-error {{defaulting this equality comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator!=(const F&, const F&) = default;
+  friend bool operator!=(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
   friend bool operator<=>(const F&, const F&) = default; // expected-error {{defaulting this three-way comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator<(const F&, const F&) = default;
+  friend bool operator<(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
 };
Index: 

[PATCH] D141803: [Clang] Reject in-class defaulting of previously declared comparison operators

2023-01-16 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 489607.
royjacobson added a comment.

rebase on main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Index: clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
@@ -165,22 +165,22 @@
 // FIXME: This rule creates problems for reordering of declarations; is this
 // really the right model?
 struct G;
-bool operator==(const G&, const G&);
-bool operator!=(const G&, const G&);
-std::strong_ordering operator<=>(const G&, const G&);
-bool operator<(const G&, const G&);
-bool operator<=(const G&, const G&);
-bool operator>(const G&, const G&);
-bool operator>=(const G&, const G&);
+bool operator==(const G&, const G&); // expected-note {{previous declaration}}
+bool operator!=(const G&, const G&); // expected-note {{previous declaration}}
+std::strong_ordering operator<=>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<=(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>=(const G&, const G&); // expected-note {{previous declaration}}
 struct G {
-  friend bool operator==(const G&, const G&) = default;
-  friend bool operator!=(const G&, const G&) = default;
-
-  friend std::strong_ordering operator<=>(const G&, const G&) = default;
-  friend bool operator<(const G&, const G&) = default;
-  friend bool operator<=(const G&, const G&) = default;
-  friend bool operator>(const G&, const G&) = default;
-  friend bool operator>=(const G&, const G&) = default;
+  friend bool operator==(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator!=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+
+  friend std::strong_ordering operator<=>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
 };
 bool operator==(const G&, const G&);
 bool operator!=(const G&, const G&);
Index: clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
@@ -139,13 +139,13 @@
 
 struct F;
 bool operator==(const F&, const F&);
-bool operator!=(const F&, const F&);
+bool operator!=(const F&, const F&); // expected-note {{previous declaration}}
 bool operator<=>(const F&, const F&);
-bool operator<(const F&, const F&);
+bool operator<(const F&, const F&); // expected-note {{previous declaration}}
 struct F {
   union { int a; };
   friend bool operator==(const F&, const F&) = default; // expected-error {{defaulting this equality comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator!=(const F&, const F&) = default;
+  friend bool operator!=(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
   friend bool operator<=>(const F&, const F&) = default; // expected-error {{defaulting this three-way comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator<(const F&, const F&) = default;
+  friend bool operator<(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
 };
Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -179,6 +179,12 @@
 struct S5;   

[PATCH] D141803: [Clang] Reject in-class defaulting of previously declared comparison operators

2023-01-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added a reviewer: clang-language-wg.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Comparison operators are not allowed to be defaulted if they were previously 
declared outside the class.
Pretty low-impact, but it's nice to reject this without a linking error.
Fixes https://github.com/llvm/llvm-project/issues/51227.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Index: clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
@@ -165,22 +165,22 @@
 // FIXME: This rule creates problems for reordering of declarations; is this
 // really the right model?
 struct G;
-bool operator==(const G&, const G&);
-bool operator!=(const G&, const G&);
-std::strong_ordering operator<=>(const G&, const G&);
-bool operator<(const G&, const G&);
-bool operator<=(const G&, const G&);
-bool operator>(const G&, const G&);
-bool operator>=(const G&, const G&);
+bool operator==(const G&, const G&); // expected-note {{previous declaration}}
+bool operator!=(const G&, const G&); // expected-note {{previous declaration}}
+std::strong_ordering operator<=>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<=(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>=(const G&, const G&); // expected-note {{previous declaration}}
 struct G {
-  friend bool operator==(const G&, const G&) = default;
-  friend bool operator!=(const G&, const G&) = default;
-
-  friend std::strong_ordering operator<=>(const G&, const G&) = default;
-  friend bool operator<(const G&, const G&) = default;
-  friend bool operator<=(const G&, const G&) = default;
-  friend bool operator>(const G&, const G&) = default;
-  friend bool operator>=(const G&, const G&) = default;
+  friend bool operator==(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator!=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+
+  friend std::strong_ordering operator<=>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
 };
 bool operator==(const G&, const G&);
 bool operator!=(const G&, const G&);
Index: clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
@@ -139,13 +139,13 @@
 
 struct F;
 bool operator==(const F&, const F&);
-bool operator!=(const F&, const F&);
+bool operator!=(const F&, const F&); // expected-note {{previous declaration}}
 bool operator<=>(const F&, const F&);
-bool operator<(const F&, const F&);
+bool operator<(const F&, const F&); // expected-note {{previous declaration}}
 struct F {
   union { int a; };
   friend bool operator==(const F&, const F&) = default; // expected-error {{defaulting this equality comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator!=(const F&, const F&) = default;
+  friend bool operator!=(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
   friend bool operator<=>(const F&, const F&) = default; // expected-error {{defaulting this three-way comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator<(const F&, const F&) = default;
+  friend bool operator<(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
 };
Index: 

[PATCH] D141775: [Clang] Export CanPassInRegisters as a type trait

2023-01-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

While working on D140664 , I thought it would 
be nice to be able to write tests 
for parameter passing ABI. Currently we test this by dumping the AST and
matching the results which makes it hard to write new tests.
Adding this builtin will allow writing better ABI tests which
can help improve our coverage in this area.

While less useful, maybe some users would also find it useful for asserting
against pessimisations for their classes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141775

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


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,23 @@
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+static_assert(__can_pass_in_regs(A), "");
+static_assert(__can_pass_in_regs(A&), "");
+static_assert(!__can_pass_in_regs(B), "");
+static_assert(__can_pass_in_regs(B&), "");
+static_assert(__can_pass_in_regs(int), "");
+static_assert(__can_pass_in_regs(int&), "");
+
+}
+
 struct S {};
 template  using remove_const_t = __remove_const(T);
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4892,6 +4892,7 @@
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv 
void,
   // or an array of unknown bound. But GCC actually imposes the same 
constraints
   // as above.
@@ -5380,6 +5381,10 @@
 return T.isTriviallyRelocatableType(C);
   case UTT_IsReferenceable:
 return T.isReferenceable();
+  case UTT_CanPassInRegs:
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+  return RD->canPassInRegisters();
+return true;
   }
 }
 
Index: clang/include/clang/Basic/TokenKinds.def
===
--- clang/include/clang/Basic/TokenKinds.def
+++ clang/include/clang/Basic/TokenKinds.def
@@ -523,6 +523,7 @@
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1398,6 +1398,10 @@
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__can_pass_in_regs`` (C++)
+  Returns whether a class can be passed in registers under the current
+  ABI. Returns ``true`` for non-class types like builtins or references.
+  This is not a portable type trait.
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,23 @@
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+static_assert(__can_pass_in_regs(A), "");
+static_assert(__can_pass_in_regs(A&), "");
+static_assert(!__can_pass_in_regs(B), "");
+static_assert(__can_pass_in_regs(B&), "");
+static_assert(__can_pass_in_regs(int), "");
+static_assert(__can_pass_in_regs(int&), "");
+
+}
+
 struct S {};
 template  using remove_const_t = __remove_const(T);
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4892,6 +4892,7 @@
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv void,
   // or an array of unknown bound. But GCC actually imposes the same constraints
   // as above.
@@ -5380,6 +5381,10 @@
 return 

[PATCH] D140664: [Sema] Don't mark deleted special member functions as non-trivial

2023-01-05 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson reopened this revision.
royjacobson added a comment.
This revision is now accepted and ready to land.

So, I had a quick look at this. Turns out this fix changed the argument passing 
ABI for those classes on the Sony PS4. This is probably not acceptable :)

Putting this behind an ABI compat/Sony flag is probably good enough in this 
case, will try to write it up next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140664

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


[PATCH] D140664: [Sema] Don't mark deleted special member functions as non-trivial

2023-01-04 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5dd37ac139a: [Sema] Dont mark deleted special member 
functions as non-trivial (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/SemaCXX/GH59624.cpp

Index: clang/test/SemaCXX/GH59624.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH59624.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// expected-no-diagnostics
+
+namespace GH59624 {
+
+struct Foo{
+int x{0};
+};
+
+struct Bar{
+const Foo y;
+};
+
+// Deleted move assignment shouldn't make type non-trivially copyable:
+
+static_assert(__is_trivially_copyable(Bar), "");
+
+}
Index: clang/test/AST/ast-dump-funcs.cpp
===
--- clang/test/AST/ast-dump-funcs.cpp
+++ clang/test/AST/ast-dump-funcs.cpp
@@ -54,10 +54,10 @@
   virtual void g() = 0;
   // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:16 g 'void ()' virtual pure
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~S 'void ()' inline default noexcept-unevaluated
 };
 
@@ -70,9 +70,9 @@
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 100
   // CHECK-NEXT: OverrideAttr
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~T 'void ()' inline default noexcept-unevaluated
 };
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,11 +14475,6 @@
nullptr);
   CopyAssignment->setParams(FromParam);
 
-  CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-  : ClassDecl->hasTrivialCopyAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14489,6 +14484,11 @@
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
+  } else {
+CopyAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForCopyAssignment()
+? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,11 +14813,6 @@
nullptr);
   MoveAssignment->setParams(FromParam);
 
-  MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-  : ClassDecl->hasTrivialMoveAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
 
@@ -14827,6 +14822,11 @@
   if (ShouldDeleteSpecialMember(MoveAssignment, 

[PATCH] D140664: [Sema] Don't mark deleted special member functions as non-trivial

2023-01-04 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 486347.
royjacobson added a comment.

format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/SemaCXX/GH59624.cpp

Index: clang/test/SemaCXX/GH59624.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH59624.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// expected-no-diagnostics
+
+namespace GH59624 {
+
+struct Foo{
+int x{0};
+};
+
+struct Bar{
+const Foo y;
+};
+
+// Deleted move assignment shouldn't make type non-trivially copyable:
+
+static_assert(__is_trivially_copyable(Bar), "");
+
+}
Index: clang/test/AST/ast-dump-funcs.cpp
===
--- clang/test/AST/ast-dump-funcs.cpp
+++ clang/test/AST/ast-dump-funcs.cpp
@@ -54,10 +54,10 @@
   virtual void g() = 0;
   // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:16 g 'void ()' virtual pure
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~S 'void ()' inline default noexcept-unevaluated
 };
 
@@ -70,9 +70,9 @@
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 100
   // CHECK-NEXT: OverrideAttr
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~T 'void ()' inline default noexcept-unevaluated
 };
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,11 +14475,6 @@
nullptr);
   CopyAssignment->setParams(FromParam);
 
-  CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-  : ClassDecl->hasTrivialCopyAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14489,6 +14484,11 @@
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
+  } else {
+CopyAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForCopyAssignment()
+? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,11 +14813,6 @@
nullptr);
   MoveAssignment->setParams(FromParam);
 
-  MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-  : ClassDecl->hasTrivialMoveAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
 
@@ -14827,6 +14822,11 @@
   if (ShouldDeleteSpecialMember(MoveAssignment, CXXMoveAssignment)) {
 ClassDecl->setImplicitMoveAssignmentIsDeleted();
 SetDeclDeleted(MoveAssignment, ClassLoc);
+  } else {
+MoveAssignment->setTrivial(
+

[PATCH] D140664: [Sema] Don't mark deleted special member functions as non-trivial

2023-01-03 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 486105.
royjacobson edited the summary of this revision.
royjacobson added a comment.

Rebase + remove extra class


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/SemaCXX/GH59624.cpp

Index: clang/test/SemaCXX/GH59624.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH59624.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// expected-no-diagnostics
+
+namespace GH59624 {
+
+struct Foo{
+int x{0};
+};
+
+struct Bar{
+const Foo y;
+};
+
+// Deleted move assignment shouldn't make type non-trivially copyable:
+
+static_assert(__is_trivially_copyable(Bar), "");
+
+}
Index: clang/test/AST/ast-dump-funcs.cpp
===
--- clang/test/AST/ast-dump-funcs.cpp
+++ clang/test/AST/ast-dump-funcs.cpp
@@ -54,10 +54,10 @@
   virtual void g() = 0;
   // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:16 g 'void ()' virtual pure
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~S 'void ()' inline default noexcept-unevaluated
 };
 
@@ -70,9 +70,9 @@
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 100
   // CHECK-NEXT: OverrideAttr
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~T 'void ()' inline default noexcept-unevaluated
 };
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,11 +14475,6 @@
nullptr);
   CopyAssignment->setParams(FromParam);
 
-  CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-  : ClassDecl->hasTrivialCopyAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14489,6 +14484,11 @@
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
+  } else {
+CopyAssignment->setTrivial(
+  ClassDecl->needsOverloadResolutionForCopyAssignment()
+? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,10 +14813,6 @@
nullptr);
   MoveAssignment->setParams(FromParam);
 
-  MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-  : ClassDecl->hasTrivialMoveAssignment());
 
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
@@ -14827,6 +14823,11 @@
   if (ShouldDeleteSpecialMember(MoveAssignment, CXXMoveAssignment)) {
 ClassDecl->setImplicitMoveAssignmentIsDeleted();
 SetDeclDeleted(MoveAssignment, ClassLoc);
+  

[PATCH] D140876: [clang][C++20] Non-dependent access checks in requires expression.

2023-01-03 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D140876#4023286 , @ilya-biryukov 
wrote:

> Should access checks should happen in the context where `concept` is written 
> or where it's used? Is there a standard wording around it?

Unfortunately, only a standard wording issue :(
https://cplusplus.github.io/CWG/issues/2589.html

We're also allowed to cache atomic constraints regardless of the their 
(unspecified) scope, which makes this a bit more complicated.

There's some discussion about this in 
https://github.com/llvm/llvm-project/issues/58672


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140876

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


[PATCH] D140664: [Sema] Don't mark deleted special member functions as non-trivial

2022-12-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As noted in https://github.com/llvm/llvm-project/issues/59624, we sometimes 
mark implicitly
deleted special member functions as non-trivial. This is unnecessary work and 
leads to some
weird type traits errors.

This fixes the problem by making the implicitly deleted special member 
functions always
trivial.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/SemaCXX/GH59624.cpp

Index: clang/test/SemaCXX/GH59624.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH59624.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// expected-no-diagnostics
+
+namespace GH59624 {
+
+struct Foo{
+int x{0};
+};
+struct CFoo{
+const int x{0};
+};
+struct Bar{
+const Foo y;
+};
+
+// Deleted move assignment shouldn't make type non-trivially copyable:
+
+static_assert(__is_trivially_copyable(Bar), "");
+
+}
+
Index: clang/test/AST/ast-dump-funcs.cpp
===
--- clang/test/AST/ast-dump-funcs.cpp
+++ clang/test/AST/ast-dump-funcs.cpp
@@ -54,10 +54,10 @@
   virtual void g() = 0;
   // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:16 g 'void ()' virtual pure
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit S 'void (const S &)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(const S &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'S &(S &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~S 'void ()' inline default noexcept-unevaluated
 };
 
@@ -70,9 +70,9 @@
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 100
   // CHECK-NEXT: OverrideAttr
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}}  col:8 implicit T 'void (const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(const T &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}}  col:8 implicit operator= 'T &(T &&)' inline default_delete trivial noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}}  col:8 implicit ~T 'void ()' inline default noexcept-unevaluated
 };
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,11 +14475,6 @@
nullptr);
   CopyAssignment->setParams(FromParam);
 
-  CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-  : ClassDecl->hasTrivialCopyAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14489,6 +14484,11 @@
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
+  } else {
+CopyAssignment->setTrivial(
+  ClassDecl->needsOverloadResolutionForCopyAssignment()
+? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,10 +14813,6 @@
nullptr);
   MoveAssignment->setParams(FromParam);
 
-  MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-  : ClassDecl->hasTrivialMoveAssignment());
 
   // Note that 

[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-12-19 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

This seems to be stuck with no reviewers, is there any way to help here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

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


[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

2022-12-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Thanks for picking this up! :)

The (non-wording) paper makes a pretty convincing case to just apply this 
retroactively to any C++11 code 
(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2644r1.pdf). I think 
we should apply this retroactively, maybe add a pedantic warning when we do a 
lifetime extension on code before C++23.

Also, +1 to more tests. Specifically constexpr and dependent contexts would be 
good to see.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139586

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


[PATCH] D139038: [Clang] Don't consider default constructors ineligible if the more constrained constructor is a template

2022-12-05 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d58c95635cc: [Clang] Dont consider default 
constructors ineligible if the more constrained… (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139038

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -225,3 +225,43 @@
   S<2, 2> s2;
 }
 }
+
+namespace GH59206 {
+
+struct A {
+  A() = default; //eligible, second constructor unsatisfied
+  template
+  A(Args&&... args) requires (sizeof...(Args) > 0) {}
+};
+
+struct B {
+  B() = default; //ineligible, second constructor more constrained
+  template
+  B(Args&&... args) requires (sizeof...(Args) == 0) {}
+};
+
+struct C {
+  C() = default; //eligible, but
+  template //also eligible and non-trivial
+  C(Args&&... args) {}
+};
+
+struct D : B {};
+
+static_assert(__is_trivially_copyable(A), "");
+static_assert(__is_trivially_copyable(B), "");
+static_assert(__is_trivially_copyable(C), "");
+static_assert(__is_trivially_copyable(D), "");
+
+// FIXME: Update when https://github.com/llvm/llvm-project/issues/59206 is
+// resolved.
+static_assert(!__is_trivial(A), "");
+static_assert(!__is_trivial(B), "");
+static_assert(!__is_trivial(C), "");
+static_assert(__is_trivial(D), "");
+static_assert(__is_trivially_constructible(A), "");
+static_assert(__is_trivially_constructible(B), "");
+static_assert(__is_trivially_constructible(C), "");
+static_assert(__is_trivially_constructible(D), "");
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18193,8 +18193,11 @@
   CXXMethodDecl *M1,
   CXXMethodDecl *M2,
   Sema::CXXSpecialMember CSM) {
+  // We don't want to compare templates to non-templates: See
+  // https://github.com/llvm/llvm-project/issues/59206
   if (CSM == Sema::CXXDefaultConstructor)
-return true;
+return bool(M1->getDescribedFunctionTemplate()) ==
+   bool(M2->getDescribedFunctionTemplate());
   if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
M2->getParamDecl(0)->getType()))
 return false;
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -1378,7 +1378,11 @@
 }
 
 void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
-   unsigned SMKind) {
+   unsigned SMKind) {
+  // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
+  // a function template, but this needs CWG attention before we break ABI.
+  // See https://github.com/llvm/llvm-project/issues/59206
+
   if (const auto *DD = dyn_cast(MD)) {
 if (DD->isUserProvided())
   data().HasIrrelevantDestructor = false;


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -225,3 +225,43 @@
   S<2, 2> s2;
 }
 }
+
+namespace GH59206 {
+
+struct A {
+  A() = default; //eligible, second constructor unsatisfied
+  template
+  A(Args&&... args) requires (sizeof...(Args) > 0) {}
+};
+
+struct B {
+  B() = default; //ineligible, second constructor more constrained
+  template
+  B(Args&&... args) requires (sizeof...(Args) == 0) {}
+};
+
+struct C {
+  C() = default; //eligible, but
+  template //also eligible and non-trivial
+  C(Args&&... args) {}
+};
+
+struct D : B {};
+
+static_assert(__is_trivially_copyable(A), "");
+static_assert(__is_trivially_copyable(B), "");
+static_assert(__is_trivially_copyable(C), "");
+static_assert(__is_trivially_copyable(D), "");
+
+// FIXME: Update when https://github.com/llvm/llvm-project/issues/59206 is
+// resolved.
+static_assert(!__is_trivial(A), "");
+static_assert(!__is_trivial(B), "");
+static_assert(!__is_trivial(C), "");
+static_assert(__is_trivial(D), "");
+static_assert(__is_trivially_constructible(A), "");
+static_assert(__is_trivially_constructible(B), "");
+static_assert(__is_trivially_constructible(C), "");
+static_assert(__is_trivially_constructible(D), "");
+
+}
Index: clang/lib/Sema/SemaDecl.cpp

[PATCH] D139038: [Clang] Don't consider default constructors ineligible if the more constrained constructor is a template

2022-12-04 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson updated this revision to Diff 479935.
royjacobson added a comment.
royjacobson retitled this revision from "Draft fix for 59206" to "[Clang] Don't 
consider default constructors ineligible if the more constrained constructor is 
a template".
royjacobson edited the summary of this revision.
royjacobson added reviewers: erichkeane, clang-language-wg, 
hubert.reinterpretcast.
royjacobson published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update so this doesn't change type triviality.


Partially solves https://github.com/llvm/llvm-project/issues/59206:

We now mark trivial constructors as eligible even if there's a more constrained 
templated default constructor. Although technically non-conformant, this solves 
problems with pretty reasonable uses cases like

  template
  struct Foo {
constexpr Foo() = default;
  
template
Foo(Ts... vals) requires(sizeof...(Ts) == n) {}
  };

where we currently consider the default constructor to be ineligible and 
therefor inheriting/containing classes have non trivial constructors. This is 
aligned with GCC: 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=c75ebe76ae12ac4020f20a24f34606a594a40d15

This doesn't change `__is_trivial`. Although we're technically standard 
conformant in this regard, GCC/MSVC exhibit different behaviors that seem to 
make more sense. An issue has been filed to CWG and we await their response.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139038

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -225,3 +225,43 @@
   S<2, 2> s2;
 }
 }
+
+namespace GH59206 {
+
+struct A {
+  A() = default; //eligible, second constructor unsatisfied
+  template
+  A(Args&&... args) requires (sizeof...(Args) > 0) {}
+};
+
+struct B {
+  B() = default; //ineligible, second constructor more constrained
+  template
+  B(Args&&... args) requires (sizeof...(Args) == 0) {}
+};
+
+struct C {
+  C() = default; //eligible, but
+  template //also eligible and non-trivial
+  C(Args&&... args) {}
+};
+
+struct D : B {};
+
+static_assert(__is_trivially_copyable(A), "");
+static_assert(__is_trivially_copyable(B), "");
+static_assert(__is_trivially_copyable(C), "");
+static_assert(__is_trivially_copyable(D), "");
+
+// FIXME: Update when https://github.com/llvm/llvm-project/issues/59206 is
+// resolved.
+static_assert(!__is_trivial(A), "");
+static_assert(!__is_trivial(B), "");
+static_assert(!__is_trivial(C), "");
+static_assert(__is_trivial(D), "");
+static_assert(__is_trivially_constructible(A), "");
+static_assert(__is_trivially_constructible(B), "");
+static_assert(__is_trivially_constructible(C), "");
+static_assert(__is_trivially_constructible(D), "");
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18193,8 +18193,11 @@
   CXXMethodDecl *M1,
   CXXMethodDecl *M2,
   Sema::CXXSpecialMember CSM) {
+  // We don't want to compare templates to non-templates: See
+  // https://github.com/llvm/llvm-project/issues/59206
   if (CSM == Sema::CXXDefaultConstructor)
-return true;
+return bool(M1->getDescribedFunctionTemplate()) ==
+   bool(M2->getDescribedFunctionTemplate());
   if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
M2->getParamDecl(0)->getType()))
 return false;
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -1378,7 +1378,11 @@
 }
 
 void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
-   unsigned SMKind) {
+   unsigned SMKind) {
+  // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
+  // a function template, but this needs CWG attention before we break ABI.
+  // See https://github.com/llvm/llvm-project/issues/59206
+
   if (const auto *DD = dyn_cast(MD)) {
 if (DD->isUserProvided())
   data().HasIrrelevantDestructor = false;


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ 

[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13c32288354b: [Clang] Implement LWG3823 for __is_aggregate 
(authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return 

[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
royjacobson marked 2 inline comments as done.
Closed by commit rG3c75feab3bbd: [clang] Compare constraints before diagnosing 
mismatched ref qualifiers… (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.load/p2-0x.cpp

Index: clang/test/CXX/over/over.load/p2-0x.cpp
===
--- clang/test/CXX/over/over.load/p2-0x.cpp
+++ clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R == 2);
+};
+
+template
+concept test = requires { declval().func(); };
+
+static_assert(test&>);
+static_assert(test&&>);
+static_assert(test&>);
+static_assert(not test&&>);
+static_assert(not test&>);
+static_assert(test&&>);
+
+}
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly different - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 3 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:1324
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  // RC are most certainly different - these are overloads.
+  return true;

erichkeane wrote:
> cor3ntin wrote:
> > I know it's preexisting but, I'm not sure that comment adds anything.
> > If we want to keep it, "requires clauses are different, - these are 
> > overloads."
> The comment is definitely low quality here, I would probably prefer a little 
> more elaboration if we're going to keep it.
removed it.



Comment at: clang/lib/Sema/SemaOverload.cpp:1327
+
+if (NewRC) {
+  llvm::FoldingSetNodeID NewID, OldID;

erichkeane wrote:
> I did some work that extracted these at one point, and it matters because we 
> have to 'fix' the depths sometimes.  I suspect it wont' really come up here, 
> since we have already checked that these are both the same 'type' of template 
> parameter by now?  But at some point (perhaps not in this patch?) we might 
> find calling ` Sema::AreConstraintExpressionsEqual` necessary.
Went for `Sema::AreConstraintExpressionsEqual` to reduce code duplication. Only 
drawback is calling `CalculateTemplateDepthForConstraints` unnecessarily which 
seems reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

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


[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 478502.
royjacobson added a comment.

Remove redundant comments, use Sema::AreConstraintExpressionsEqual instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.load/p2-0x.cpp

Index: clang/test/CXX/over/over.load/p2-0x.cpp
===
--- clang/test/CXX/over/over.load/p2-0x.cpp
+++ clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R == 2);
+};
+
+template
+concept test = requires { declval().func(); };
+
+static_assert(test&>);
+static_assert(test&&>);
+static_assert(test&>);
+static_assert(not test&&>);
+static_assert(not test&>);
+static_assert(test&&>);
+
+}
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly different - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 478495.
royjacobson edited the summary of this revision.
royjacobson added a comment.

rebase to retry CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, 

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3faf1f17a5c3: [Clang] Implement static operator[] (authored 
by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D138387?vs=477550=478493#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1;>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator() {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+  Functor::operator[](401, 402);
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
===
--- clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
+++ clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
@@ -28,6 +28,7 @@
   f(101, 102);
   f.operator()(201, 202);
   Functor{}(301, 302);
+  Functor::operator()(401, 402);
 }
 
 // CHECK:  define {{.*}}call_static_call_operator{{.*}}
@@ -35,6 +36,7 @@
 // CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
 // CHECK-NEXT:   ret void
 // CHECK-NEXT: }
 
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning@-2 

[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-28 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added inline comments.



Comment at: clang/test/SemaCXX/type-traits.cpp:556
   static_assert(__is_aggregate(EmptyArMB), "");
   static_assert(!__is_aggregate(void), "");
   static_assert(!__is_aggregate(const volatile void), "");

cjdb wrote:
> shafik wrote:
> > Should this be `true` now or am I misunderstanding.
> This should stay false, because the change is only concerned with arrays of 
> incomplete types.
> Should this be `true` now or am I misunderstanding.

If you refer to the 'or cv' part, I think you're mixing up the completeness 
precondition with the builtin's actual value.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138603

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


[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-26 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As noticed in GH58962, we should only diagnose illegal overloads of member 
functions
when the ref qualifiers don't match if the trailing constraints are the same.

The fix is to move the existing constraints check earlier in Sema::IsOverload.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138749

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.load/p2-0x.cpp

Index: clang/test/CXX/over/over.load/p2-0x.cpp
===
--- clang/test/CXX/over/over.load/p2-0x.cpp
+++ clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R == 2);
+};
+
+template
+concept test = requires { declval().func(); };
+
+static_assert(test&>);
+static_assert(test&&>);
+static_assert(test&>);
+static_assert(not test&&>);
+static_assert(not test&>);
+static_assert(test&&>);
+
+}
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,24 @@
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  // RC are most certainly different - these are overloads.
+  return true;
+
+if (NewRC) {
+  llvm::FoldingSetNodeID NewID, OldID;
+  NewRC->Profile(NewID, Context, /*Canonical=*/true);
+  OldRC->Profile(OldID, Context, /*Canonical=*/true);
+  if (NewID != OldID)
+// RCs are not equivalent - these are overloads.
+return true;
+}
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1350,15 @@
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1422,6 @@
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly different - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

LWG3823 says that arrays of incomplete types are aggregates. Fix the clang 
builtin to match that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added a comment.

In D138387#3944211 , @cor3ntin wrote:

> Beside the formatting nitpick this looks good

Thanks! I'll wait until next week to let other people have a chance to take a 
look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138387

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


  1   2   3   4   >