frederick-vs-ja wrote:
IIUC this intrinsic is unrelated to assignment operators. Do you have any plan
for `__is_bitwise_assignable`, which should determine whether the assignment
operator equivalently copies the value representation, possibly modulo the
vptrs?
```C++
struct Cat {}; //
https://github.com/hokein closed https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 3ce87797dbc36ae792b4d82077cd8f27f1eee53e Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH] [clang] Implement a bitwise_copyable builtin type trait.
This patch
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 0eec9639530a137da6c4c4b2cc4249a3f9dd9939 Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH] [clang] Implement a bitwise_copyable builtin type trait.
This patch
ilya-biryukov wrote:
Also, we need to fix formatting errors and make sure the CI is green.
E.g. the newly added test fails (needs an update to capture some notes).
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
@@ -2749,6 +2749,41 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ auto CanonicalType =
@@ -4016,6 +4016,34 @@ Note that the `size` argument must be a compile time
constant.
Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+``__is_bitwise_cloneable``
+--
+
+A type trait is used to check whether a type can be
@@ -1120,6 +1120,22 @@ class QualType {
/// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
bool isTriviallyCopyableType(const ASTContext ) const;
+ /// Return true if the type is safe to bitwise copy using memcpy/memmove.
+ ///
+ /// This is
https://github.com/ilya-biryukov approved this pull request.
LGTM with a few NITs to fix before submitting.
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://github.com/ilya-biryukov edited
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
hokein wrote:
Add @eugenis as a reviewer, could you take a look on the sanitizer bit?
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
hokein wrote:
> Could we rewrite the description and documentation to capture what the type
> trait is doing now? We have a lot of references to the
> `is_trivially_copyable`, which is almost fully irrelevant to the current
> implementation.
Thanks, I updated the PR description and
@@ -4016,6 +4016,34 @@ Note that the `size` argument must be a compile time
constant.
Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+``__is_bitwise_cloneable``
+--
+
+A type trait is used to check whether a type can be
@@ -2749,6 +2749,17 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ if (const auto *RD =
@@ -1120,6 +1120,14 @@ class QualType {
/// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
bool isTriviallyCopyableType(const ASTContext ) const;
+ /// Return true if the type is safe to bitwise copy by memcpy.
+ ///
+ /// This is an extension
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 011d6bbb434bdb46efe92891fe356885f82c4445 Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH] ination of 2 commits.
[clang] Implement a bitwise_copyable builtin
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -4016,6 +4016,34 @@ Note that the `size` argument must be a compile time
constant.
Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+``__is_bitwise_cloneable``
+--
+
+A type trait is used to check whether a type can be
@@ -2749,6 +2749,17 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ if (const auto *RD =
@@ -1120,6 +1120,14 @@ class QualType {
/// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
bool isTriviallyCopyableType(const ASTContext ) const;
+ /// Return true if the type is safe to bitwise copy by memcpy.
+ ///
+ /// This is an extension
https://github.com/ilya-biryukov edited
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/ilya-biryukov requested changes to this pull request.
Could we rewrite the description and documentation to capture what the type
trait is doing now?
We have a lot of references to the `is_trivially_copyable`, which is almost
fully irrelevant to the current implementation.
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 49747cde60dc8a1f4ed4ddcee020f71c88f35287 Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH] [clang] Implement a bitwise_copyable builtin type trait.
This patch
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ QualType CanonicalType =
https://github.com/hokein commented:
thanks for the review.
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -3958,6 +3958,50 @@ Note that the `size` argument must be a compile time
constant.
Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+``__is_bitwise_cloneable``
+-
+
+A type trait is used to check whether a type can be
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 10d06e728d836f4aaad7dbf1a6b06b57e4092bb1 Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH 1/3] [clang] Implement a bitwise_copyable builtin type trait.
This
https://github.com/ilya-biryukov edited
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
@@ -3958,6 +3958,50 @@ Note that the `size` argument must be a compile time
constant.
Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+``__is_bitwise_cloneable``
+-
+
+A type trait is used to check whether a type can be
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar
ilya-biryukov wrote:
A few comments from me to move this review forward.
The major question I have is about the tests and how reference members should
affect the results of that trait.
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits
hokein wrote:
Friendly ping, it is ready for the second round of review.
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -917,6 +917,18 @@ 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 bitwise copyable type.
+ ///
+ /// This is an extension in clang:
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
hokein wrote:
Done, added one,
@@ -917,6 +917,18 @@ 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 bitwise copyable type.
+ ///
+ /// This is an extension in clang:
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
hokein wrote:
switched to
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise copyable.
+static_assert(__is_bitwise_copyable(int));
+static_assert(__is_bitwise_copyable(int*));
+// array
+static_assert(__is_bitwise_copyable(int[10]));
+
+
+struct
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -5056,6 +5056,8 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema ,
TypeTrait UTT,
case UTT_IsStandardLayout:
case UTT_IsPOD:
case UTT_IsLiteral:
+ // Clang extension:
hokein wrote:
Removed.
https://github.com/llvm/llvm-project/pull/86512
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
hokein wrote:
OK, renamed to
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
https://github.com/hokein updated
https://github.com/llvm/llvm-project/pull/86512
>From 10d4b9e505d5ad7476071153d2d13799f5b5cf1f Mon Sep 17 00:00:00 2001
From: Haojian Wu
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH 1/2] [clang] Implement a bitwise_copyable builtin type trait.
This
@@ -5056,6 +5056,8 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema ,
TypeTrait UTT,
case UTT_IsStandardLayout:
case UTT_IsPOD:
case UTT_IsLiteral:
+ // Clang extension:
sam-mccall wrote:
AFAIK these are all clang extensions (the `__`
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
sam-mccall wrote:
naming
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise copyable.
+static_assert(__is_bitwise_copyable(int));
+static_assert(__is_bitwise_copyable(int*));
+// array
+static_assert(__is_bitwise_copyable(int[10]));
+
+
+struct
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
sam-mccall wrote:
naming
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
sam-mccall wrote:
why c++ only?
@@ -526,6 +526,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible,
KEYCXX)
#include "clang/Basic/TransformTypeTraits.def"
// Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
sam-mccall wrote:
this new
@@ -2667,6 +2667,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext
) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+ QualType CanonicalType =
https://github.com/sam-mccall edited
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/sam-mccall commented:
I'm in favour of this, but we should have someone less-attached to it sign off
on at least the basic design.
One question this doesn't explicitly address: after memcpying, does user code
need to bless the bits somehow to start the new object's
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 5a744776bb6192dae04360609457c9f49dce43a2
481627e3bacf2e9fa5ca71adece32e4ca5fa94ef --
github-actions[bot] wrote:
:white_check_mark: With the latest revision this PR passed the Python code
formatter.
https://github.com/llvm/llvm-project/pull/86512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Haojian Wu (hokein)
Changes
This patch implements a `__is_bitwise_copyable` builtin in clang.
The bitwise copyable types act as the trivially copyable types, but they
support a wider range of types (e.g. classes with virtual methods) --
https://github.com/hokein created
https://github.com/llvm/llvm-project/pull/86512
This patch implements a `__is_bitwise_copyable` builtin in clang.
The bitwise copyable types act as the trivially copyable types, but they
support a wider range of types (e.g. classes with virtual methods) --
69 matches
Mail list logo