Revert "[Sema] Don't mark deleted special member functions as non-trivial"
authorRoy Jacobson <roi.jacobson1@gmail.com>
Wed, 4 Jan 2023 20:39:04 +0000 (22:39 +0200)
committerRoy Jacobson <roi.jacobson1@gmail.com>
Wed, 4 Jan 2023 20:39:04 +0000 (22:39 +0200)
This reverts commit d5dd37ac139a74701e16f084eb2609ff58893770.

Apparently there's some ABI difference in the Sony builder that fails a test.
Will hopefully investigate tomorrow. https://lab.llvm.org/buildbot/#/builders/139/builds/33769

clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/ast-dump-funcs.cpp
clang/test/SemaCXX/GH59624.cpp [deleted file]

index 6430bf2..0fe0097 100644 (file)
@@ -754,9 +754,6 @@ ABI Changes in Clang
   classified such types as non-POD (for the purposes of Itanium ABI). Clang now
   matches the gcc behavior (except on Darwin and PS4). You can switch back to
   the old ABI behavior with the flag: ``-fclang-abi-compat=15.0``.
-- Some types with implicitly deleted special member functions were accidentally
-  marked as non-trivially copyable. This has been fixed
-  (`#59624 <https://github.com/llvm/llvm-project/issues/59624>`_).
 
 OpenMP Support in Clang
 -----------------------
index 19ecf21..9a80a48 100644 (file)
@@ -14475,6 +14475,11 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
                                                nullptr);
   CopyAssignment->setParams(FromParam);
 
+  CopyAssignment->setTrivial(
+    ClassDecl->needsOverloadResolutionForCopyAssignment()
+      ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+      : ClassDecl->hasTrivialCopyAssignment());
+
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14484,11 +14489,6 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
     ClassDecl->setImplicitCopyAssignmentIsDeleted();
     SetDeclDeleted(CopyAssignment, ClassLoc);
-  } else {
-    CopyAssignment->setTrivial(
-        ClassDecl->needsOverloadResolutionForCopyAssignment()
-            ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-            : ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,6 +14813,11 @@ CXXMethodDecl *Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
                                                nullptr);
   MoveAssignment->setParams(FromParam);
 
+  MoveAssignment->setTrivial(
+    ClassDecl->needsOverloadResolutionForMoveAssignment()
+      ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
+      : ClassDecl->hasTrivialMoveAssignment());
+
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
 
@@ -14822,11 +14827,6 @@ CXXMethodDecl *Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(MoveAssignment, CXXMoveAssignment)) {
     ClassDecl->setImplicitMoveAssignmentIsDeleted();
     SetDeclDeleted(MoveAssignment, ClassLoc);
-  } else {
-    MoveAssignment->setTrivial(
-        ClassDecl->needsOverloadResolutionForMoveAssignment()
-            ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-            : ClassDecl->hasTrivialMoveAssignment());
   }
 
   if (S)
@@ -15197,6 +15197,18 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(
                           /*TInfo=*/TSI, SC_None, nullptr);
   CopyConstructor->setParams(FromParam);
 
+  CopyConstructor->setTrivial(
+      ClassDecl->needsOverloadResolutionForCopyConstructor()
+          ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor)
+          : ClassDecl->hasTrivialCopyConstructor());
+
+  CopyConstructor->setTrivialForCall(
+      ClassDecl->hasAttr<TrivialABIAttr>() ||
+      (ClassDecl->needsOverloadResolutionForCopyConstructor()
+           ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor,
+             TAH_ConsiderTrivialABI)
+           : ClassDecl->hasTrivialCopyConstructorForCall()));
+
   // Note that we have declared this constructor.
   ++getASTContext().NumImplicitCopyConstructorsDeclared;
 
@@ -15206,18 +15218,6 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(
   if (ShouldDeleteSpecialMember(CopyConstructor, CXXCopyConstructor)) {
     ClassDecl->setImplicitCopyConstructorIsDeleted();
     SetDeclDeleted(CopyConstructor, ClassLoc);
-  } else {
-    CopyConstructor->setTrivial(
-        ClassDecl->needsOverloadResolutionForCopyConstructor()
-            ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor)
-            : ClassDecl->hasTrivialCopyConstructor());
-
-    CopyConstructor->setTrivialForCall(
-        ClassDecl->hasAttr<TrivialABIAttr>() ||
-        (ClassDecl->needsOverloadResolutionForCopyConstructor()
-             ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor,
-                                      TAH_ConsiderTrivialABI)
-             : ClassDecl->hasTrivialCopyConstructorForCall()));
   }
 
   if (S)
@@ -15331,6 +15331,18 @@ CXXConstructorDecl *Sema::DeclareImplicitMoveConstructor(
                                                SC_None, nullptr);
   MoveConstructor->setParams(FromParam);
 
+  MoveConstructor->setTrivial(
+      ClassDecl->needsOverloadResolutionForMoveConstructor()
+          ? SpecialMemberIsTrivial(MoveConstructor, CXXMoveConstructor)
+          : ClassDecl->hasTrivialMoveConstructor());
+
+  MoveConstructor->setTrivialForCall(
+      ClassDecl->hasAttr<TrivialABIAttr>() ||
+      (ClassDecl->needsOverloadResolutionForMoveConstructor()
+           ? SpecialMemberIsTrivial(MoveConstructor, CXXMoveConstructor,
+                                    TAH_ConsiderTrivialABI)
+           : ClassDecl->hasTrivialMoveConstructorForCall()));
+
   // Note that we have declared this constructor.
   ++getASTContext().NumImplicitMoveConstructorsDeclared;
 
@@ -15340,18 +15352,6 @@ CXXConstructorDecl *Sema::DeclareImplicitMoveConstructor(
   if (ShouldDeleteSpecialMember(MoveConstructor, CXXMoveConstructor)) {
     ClassDecl->setImplicitMoveConstructorIsDeleted();
     SetDeclDeleted(MoveConstructor, ClassLoc);
-  } else {
-    MoveConstructor->setTrivial(
-        ClassDecl->needsOverloadResolutionForMoveConstructor()
-            ? SpecialMemberIsTrivial(MoveConstructor, CXXMoveConstructor)
-            : ClassDecl->hasTrivialMoveConstructor());
-
-    MoveConstructor->setTrivialForCall(
-        ClassDecl->hasAttr<TrivialABIAttr>() ||
-        (ClassDecl->needsOverloadResolutionForMoveConstructor()
-             ? SpecialMemberIsTrivial(MoveConstructor, CXXMoveConstructor,
-                                      TAH_ConsiderTrivialABI)
-             : ClassDecl->hasTrivialMoveConstructorForCall()));
   }
 
   if (S)
@@ -17569,9 +17569,6 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) {
   //  A deleted function is implicitly inline.
   Fn->setImplicitlyInline();
   Fn->setDeletedAsWritten();
-
-  Fn->setTrivial(true);
-  Fn->setTrivialForCall(true);
 }
 
 void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) {
index fdf5abd..7d47893 100644 (file)
@@ -54,10 +54,10 @@ struct S {
   virtual void g() = 0;
   // CHECK: CXXMethodDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:22> col:16 g 'void ()' virtual pure
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}} <line:[[@LINE-33]]:8> col:8 implicit S 'void (const S &)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}} <line:[[@LINE-33]]:8> col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated
   // CHECK: CXXConstructorDecl 0x{{[^ ]*}} <col:8> col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'S &(const S &)' inline default_delete trivial noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'S &(S &&)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}} <col:8> col:8 implicit ~S 'void ()' inline default noexcept-unevaluated
 };
 
@@ -70,9 +70,9 @@ struct T : S { // T is not referenced, but S is
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:23> 'int' 100
   // CHECK-NEXT: OverrideAttr
 
-  // CHECK: CXXConstructorDecl 0x{{[^ ]*}} <line:[[@LINE-9]]:8> col:8 implicit T 'void (const T &)' inline default_delete trivial noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'T &(const T &)' inline default_delete trivial noexcept-unevaluated
-  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'T &(T &&)' inline default_delete trivial noexcept-unevaluated
+  // CHECK: CXXConstructorDecl 0x{{[^ ]*}} <line:[[@LINE-9]]:8> col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated
+  // CHECK: CXXMethodDecl 0x{{[^ ]*}} <col:8> col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated
   // CHECK: CXXDestructorDecl 0x{{[^ ]*}} <col:8> col:8 implicit ~T 'void ()' inline default noexcept-unevaluated
 };
 
diff --git a/clang/test/SemaCXX/GH59624.cpp b/clang/test/SemaCXX/GH59624.cpp
deleted file mode 100644 (file)
index 8d64f58..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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), "");
-
-}