[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 09:24:10 PDT 2024
================
@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
/*IsCopyConstructible=*/false);
}
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+ QualType CanonicalType = getCanonicalType();
+ if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType())
+ return false;
+ // Trivially copyable types are bitwise clonable, e.g. scalar types.
+ if (CanonicalType.isTriviallyCopyableType(Context))
+ return true;
+
+ if (CanonicalType->isArrayType())
+ return Context.getBaseElementType(CanonicalType)
+ .isBitwiseCloneableType(Context);
+
+ if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+ for (auto Base : RD->bases())
+ if (!Base.getType().isBitwiseCloneableType(Context))
+ return false;
+ for (auto VBase : RD->vbases())
+ if (!VBase.getType().isBitwiseCloneableType(Context))
+ return false;
+
+ for (auto *const Field : RD->fields()) {
+ QualType T = Context.getBaseElementType(Field->getType());
----------------
ilya-biryukov wrote:
Why do we need to call `getBaseElementType` here?
Why not simply call the `isBitwiseCloneableType(Field->getType())`?
https://github.com/llvm/llvm-project/pull/86512
More information about the cfe-commits
mailing list