From 8503ff3e70e585a4a3597e3ee8111269f48105cc Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 5 Oct 2023 13:18:14 +0300 Subject: [PATCH 1/3] [clang] Align Type and ExtQuals on 16-byte boundary --- clang/include/clang/AST/Type.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index a78d8f60462b23..4e98858f6e9432 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,7 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers should be straightforward as // long as you don't make 'const' non-fast. // 1. Qualifiers: @@ -1507,6 +1507,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { + static_assert(alignof(decltype(*this)) % TypeAlignment == 0, + "Insufficient alignment!"); + assert(Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers"); assert(!Quals.hasFastQualifiers() @@ -1594,7 +1597,7 @@ enum class AutoTypeKeyword { /// /// Types, once created, are immutable. /// -class alignas(8) Type : public ExtQualsTypeCommonBase { +class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { public: enum TypeClass { #define TYPE(Class, Base) Class, @@ -1982,9 +1985,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { - static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), + static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); - static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, + static_assert(alignof(decltype(*this)) % TypeAlignment == 0, "Insufficient alignment!"); TypeBits.TC = tc; TypeBits.Dependence = static_cast(Dependence); @@ -5348,7 +5351,7 @@ class DeducedType : public Type { /// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained /// by a type-constraint. -class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode { +class AutoType : public DeducedType, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these ConceptDecl *TypeConstraintConcept; @@ -5456,7 +5459,7 @@ class DeducedTemplateSpecializationType : public DeducedType, /// TemplateArguments, followed by a QualType representing the /// non-canonical aliased type when the template is a type alias /// template. -class alignas(8) TemplateSpecializationType +class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these @@ -5872,7 +5875,7 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { /// Represents a template specialization type whose template cannot be /// resolved, e.g. /// A::template B -class alignas(8) DependentTemplateSpecializationType +class DependentTemplateSpecializationType : public TypeWithKeyword, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these From d08f8f92026026e9d02502307bd1810e516f4f06 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 06:32:27 +0300 Subject: [PATCH 2/3] Run clang-format --- clang/include/clang/AST/Type.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 4e98858f6e9432..2ba82d66111124 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,8 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, + public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers should be straightforward as // long as you don't make 'const' non-fast. // 1. Qualifiers: @@ -5459,9 +5460,7 @@ class DeducedTemplateSpecializationType : public DeducedType, /// TemplateArguments, followed by a QualType representing the /// non-canonical aliased type when the template is a type alias /// template. -class TemplateSpecializationType - : public Type, - public llvm::FoldingSetNode { +class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these /// The name of the template being specialized. This is @@ -5875,9 +5874,8 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { /// Represents a template specialization type whose template cannot be /// resolved, e.g. /// A::template B -class DependentTemplateSpecializationType - : public TypeWithKeyword, - public llvm::FoldingSetNode { +class DependentTemplateSpecializationType : public TypeWithKeyword, + public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these /// The nested name specifier containing the qualifier. From d117d289c8da787b1bd97c5f39e7c68a85ace3fd Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sat, 7 Oct 2023 10:04:05 +0300 Subject: [PATCH 3/3] Address review feedback --- clang/include/clang/AST/Type.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 2ba82d66111124..3e7e4f4f75b58b 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1508,9 +1508,6 @@ class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { - static_assert(alignof(decltype(*this)) % TypeAlignment == 0, - "Insufficient alignment!"); - assert(Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers"); assert(!Quals.hasFastQualifiers() @@ -1986,7 +1983,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { - static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), + static_assert(sizeof(*this) <= + alignof(decltype(*this)) + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); static_assert(alignof(decltype(*this)) % TypeAlignment == 0, "Insufficient alignment!");