[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Thank you @cor3ntin  for your guidance being a new contributor to LLVM your 
guidance was very helpful and as my First PR gets approved this makes me more 
excited to work and contribute more to the org.


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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/13] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits


@@ -2634,16 +2637,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
 
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  if (!ClassDecl->isTriviallyCopyable()) return false;
+  if (IsCopyConstructible) {
+return ClassDecl->isTriviallyCopyConstructible();
+  } else {
+return ClassDecl->isTriviallyCopyable();
+  }
 }
-
 return true;
   }
-
   // No other types can match.
   return false;
 }
 
+bool QualType::isTriviallyCopyableType(const ASTContext ) const {
+  return isTriviallyCopyableTypeImpl(*this, Context,
+ /*IsCopyConstructible*/ false);

cor3ntin wrote:

```suggestion
 /*IsCopyConstructible=*/false);
```

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM
Make sure to rebase to fix the conflict. 

Thanks for working on this

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/12] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread via cfe-commits

cor3ntin wrote:

In bug fixes is fine, thanks!

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

The release notes being quite extensive where should I add it, In bug fixes? or 
in improvements?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread via cfe-commits

cor3ntin wrote:

Thanks.
Can you also add a release note mentioning the issue is fixed? Thanks 
(clang/docs/ReleaseNotes.rst)

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/11] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/10] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread via cfe-commits


@@ -2604,19 +2604,22 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
   return false;
 }
 
-bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  if ((*this)->isArrayType())
-return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
+static bool isTriviallyCopyableTypeImpl(const QualType ,
+const ASTContext ,
+bool copy_constructible) {

cor3ntin wrote:

```suggestion
bool IsCopyConstructible) {
```

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread via cfe-commits

https://github.com/cor3ntin commented:

Looking good beside a small nitpick

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-05 Thread via cfe-commits

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/9] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Hello @cor3ntin I have made changes as you suggested.
Thank you

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/8] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

sorry from my end I will correct them and make a commit,Thank you

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/5] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -2605,18 +2605,26 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
 }
 
 bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  if ((*this)->isArrayType())
-return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
+  return isTriviallyCopyableTypeImpl(*this,Context,false);
+}
 
-  if (hasNonTrivialObjCLifetime())
+bool QualType::isTriviallyCopyConstructibleType(const ASTContext ) 
const {
+  return isTriviallyCopyableTypeImpl(*this,Context,true);
+}
+
+bool QualType::isTriviallyCopyableTypeImpl(const QualType , const 
ASTContext ,bool copy_constructible){

cor3ntin wrote:

By static, I meant something like that. Sorry if that wasn't clear.

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -766,6 +766,8 @@ class QualType {
 
   bool UseExcessPrecision(const ASTContext );
 
+  static bool isTriviallyCopyableTypeImpl(const QualType , const 
ASTContext ,bool copy_constructible);

cor3ntin wrote:

You can remove that (it will be a non member function with internal linkage in 
the source file)

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -911,12 +913,16 @@ class QualType {
   /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
   bool isCXX11PODType(const ASTContext ) const;
 
+

cor3ntin wrote:

Can you revert that?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -2605,18 +2605,26 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
 }
 
 bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  if ((*this)->isArrayType())
-return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
+  return isTriviallyCopyableTypeImpl(*this,Context,false);

cor3ntin wrote:

```suggestion
  return isTriviallyCopyableTypeImpl(*this,Context, 
/*IsCopyConstructible=*/false);
```

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -2605,18 +2605,26 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
 }
 
 bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  if ((*this)->isArrayType())
-return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
+  return isTriviallyCopyableTypeImpl(*this,Context,false);
+}
 
-  if (hasNonTrivialObjCLifetime())
+bool QualType::isTriviallyCopyConstructibleType(const ASTContext ) 
const {
+  return isTriviallyCopyableTypeImpl(*this,Context,true);

cor3ntin wrote:

```suggestion
  return isTriviallyCopyableTypeImpl(*this,Context, 
/*IsCopyConstructible=*/true);
```

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits


@@ -2605,18 +2605,26 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
 }
 
 bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  if ((*this)->isArrayType())
-return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
+  return isTriviallyCopyableTypeImpl(*this,Context,false);
+}
 
-  if (hasNonTrivialObjCLifetime())
+bool QualType::isTriviallyCopyConstructibleType(const ASTContext ) 
const {
+  return isTriviallyCopyableTypeImpl(*this,Context,true);
+}
+
+bool QualType::isTriviallyCopyableTypeImpl(const QualType , const 
ASTContext ,bool copy_constructible){

cor3ntin wrote:

```suggestion
static bool isTriviallyCopyableTypeImpl(const QualType , const ASTContext 
,bool IsCopyConstructible){
```

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 90c397fc56b7a04dd53cdad8103de1ead9686104 
c346904caff1bf97605d84bdd0120cefe1ca35f4 -- clang/include/clang/AST/DeclCXX.h 
clang/include/clang/AST/Type.h clang/lib/AST/DeclCXX.cpp clang/lib/AST/Type.cpp 
clang/lib/Sema/SemaStmt.cpp 
clang/test/SemaCXX/warn-range-loop-analysis-trivially-copyable.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 4532cfe63e..e4a3f7671e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -766,7 +766,9 @@ public:
 
   bool UseExcessPrecision(const ASTContext );
 
-  static bool isTriviallyCopyableTypeImpl(const QualType , const 
ASTContext ,bool copy_constructible);
+  static bool isTriviallyCopyableTypeImpl(const QualType ,
+  const ASTContext ,
+  bool copy_constructible);
 
   /// Retrieves a pointer to the underlying (unqualified) type.
   ///
@@ -913,7 +915,6 @@ public:
   /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
   bool isCXX11PODType(const ASTContext ) const;
 
-
   /// Return true if this is a trivial type per (C++0x [basic.types]p9)
   bool isTrivialType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 964df0bd1c..61661f73e1 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2605,16 +2605,20 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
 }
 
 bool QualType::isTriviallyCopyableType(const ASTContext ) const {
-  return isTriviallyCopyableTypeImpl(*this,Context,false);
+  return isTriviallyCopyableTypeImpl(*this, Context, false);
 }
 
-bool QualType::isTriviallyCopyConstructibleType(const ASTContext ) 
const {
-  return isTriviallyCopyableTypeImpl(*this,Context,true);
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  return isTriviallyCopyableTypeImpl(*this, Context, true);
 }
 
-bool QualType::isTriviallyCopyableTypeImpl(const QualType , const 
ASTContext ,bool copy_constructible){
+bool QualType::isTriviallyCopyableTypeImpl(const QualType ,
+   const ASTContext ,
+   bool copy_constructible) {
   if (type->isArrayType())
-return 
Context.getBaseElementType(type).isTriviallyCopyableTypeImpl(type,Context,copy_constructible);
+return Context.getBaseElementType(type).isTriviallyCopyableTypeImpl(
+type, Context, copy_constructible);
 
   if (type.hasNonTrivialObjCLifetime())
 return false;

``




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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-04 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/3] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-03 Thread Vlad Serebrennikov via cfe-commits


@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(

Endilll wrote:

Go ahead, but it would be nice if we don't regress performance along the way 
(by i.e. using type-erased wrapper for callable).

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-03 Thread Bhuminjay Soni via cfe-commits


@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(

11happy wrote:

Yes I think that would be good, so should I do that?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-03 Thread via cfe-commits


@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(

cor3ntin wrote:

Given that this function is exactly the same as the previous one, maybe we could
introduce a (non member static) `isTriviallyCopyableTypeImpl` function that 
checks either isTriviallyCopyableType or isTriviallyCopyConstructibleType , by 
either using a boolean or a callable, which isTriviallyCopyConstructibleType 
and isTriviallyCopyableType would dispatch to

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-02 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Hello @Endilll Can I work on some other issues also till this PR get reviewed?
Thank you

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have added the tests as well.


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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/2] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext ) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext  = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Sure I can , I have also tested the code that was giving erroneous warnings, 
> so should I add that example as well??

Yes. Clang has a special mode which check which diagnostics are emitted: 
https://clang.llvm.org/docs/InternalsManual.html#verifying-diagnostics

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Sure I can , I have also tested the code that was giving erroneous warnings, so 
should I add that example as well?? 

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Can you add some tests?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bhuminjay Soni (11happy)


Changes

**Overview:**
This pull request fixes #47355 where in the Clang compiler's 
range-loop-analysis incorrectly checks for trivial copyability instead of 
trivial copy constructibility, leading to erroneous warnings.

**Changes Made:**
- The changes made in this commit address the issue by introducing a new member 
function `isTriviallyCopyConstructible` in the `CXXRecordDecl` class and 
implementing it in the associated files `(clang/include/clang/AST/DeclCXX.h, 
clang/lib/AST/DeclCXX.cpp)`. Additionally, modifications are made in 
`clang/include/clang/AST/Type.h` and `clang/lib/AST/Type.cpp` to support the 
new function. The implementation checks for trivial copy constructibility, 
distinguishing it from the existing `isTriviallyCopyable` check. The issue in 
`clang/lib/Sema/SemaStmt.cpp` is also addressed by updating the conditional 
check in the `DiagnoseForRangeConstVariableCopies` function to use the new 
`isTriviallyCopyConstructibleType` function. Overall, these changes aim to 
correct the range-loop-analysis by ensuring it checks for trivial copy 
constructibility rather than trivial copyability.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-01 
19-50-20](https://github.com/llvm/llvm-project/assets/76656712/c664f01a-522e-45e4-8363-39f13d8cc241)


**Dependencies:**
- No dependencies on other pull requests.

**References:**
- https://cplusplus.com/reference/type_traits/is_trivially_copy_constructible/
- https://en.cppreference.com/w/cpp/named_req/CopyConstructible
- https://cplusplus.com/reference/type_traits/is_trivially_copyable/

**CC:**
- @Endilll , @r4nt , @AaronBallman 


---
Full diff: https://github.com/llvm/llvm-project/pull/76680.diff


5 Files Affected:

- (modified) clang/include/clang/AST/DeclCXX.h (+3) 
- (modified) clang/include/clang/AST/Type.h (+3) 
- (modified) clang/lib/AST/DeclCXX.cpp (+13) 
- (modified) clang/lib/AST/Type.cpp (+43) 
- (modified) clang/lib/Sema/SemaStmt.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/76680

**Overview:**
This pull request fixes #47355 where in the Clang compiler's 
range-loop-analysis incorrectly checks for trivial copyability instead of 
trivial copy constructibility, leading to erroneous warnings.

**Changes Made:**
- The changes made in this commit address the issue by introducing a new member 
function `isTriviallyCopyConstructible` in the `CXXRecordDecl` class and 
implementing it in the associated files `(clang/include/clang/AST/DeclCXX.h, 
clang/lib/AST/DeclCXX.cpp)`. Additionally, modifications are made in 
`clang/include/clang/AST/Type.h` and `clang/lib/AST/Type.cpp` to support the 
new function. The implementation checks for trivial copy constructibility, 
distinguishing it from the existing `isTriviallyCopyable` check. The issue in 
`clang/lib/Sema/SemaStmt.cpp` is also addressed by updating the conditional 
check in the `DiagnoseForRangeConstVariableCopies` function to use the new 
`isTriviallyCopyConstructibleType` function. Overall, these changes aim to 
correct the range-loop-analysis by ensuring it checks for trivial copy 
constructibility rather than trivial copyability.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-01 
19-50-20](https://github.com/llvm/llvm-project/assets/76656712/c664f01a-522e-45e4-8363-39f13d8cc241)


**Dependencies:**
- No dependencies on other pull requests.

**References:**
- https://cplusplus.com/reference/type_traits/is_trivially_copy_constructible/
- https://en.cppreference.com/w/cpp/named_req/CopyConstructible
- https://cplusplus.com/reference/type_traits/is_trivially_copyable/

**CC:**
- @Endilll , @r4nt , @AaronBallman 


>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext ) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext ) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called