Skip to content

Commit 4c6cba3

Browse files
authored
[clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (#68377)
While working on LLDB visualizer for `QualType`, I stumbled upon `Type` and `ExtQuals` defined with `alignas(8)`. Such alignment leaves only 3 lower bits available for pointer tagging, whereas `QualType` requires 4 (3 qualifiers + discriminator between `Type *` and `ExtQuals *`). Turns out `Type` and its derived classes are allocated with `TypeAlignment == 16` passed to `Allocate()`. So I'm removing misleading `alignas(8)` and fixing corresponding static asserts. Since they are already allocated with 16-byte alignment, this is a non-functional change.
1 parent b56488c commit 4c6cba3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

clang/include/clang/AST/Type.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ class ExtQualsTypeCommonBase {
14821482
/// in three low bits on the QualType pointer; a fourth bit records whether
14831483
/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
14841484
/// Objective-C GC attributes) are much more rare.
1485-
class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
1485+
class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase,
1486+
public llvm::FoldingSetNode {
14861487
// NOTE: changing the fast qualifiers should be straightforward as
14871488
// long as you don't make 'const' non-fast.
14881489
// 1. Qualifiers:
@@ -1594,7 +1595,7 @@ enum class AutoTypeKeyword {
15941595
///
15951596
/// Types, once created, are immutable.
15961597
///
1597-
class alignas(8) Type : public ExtQualsTypeCommonBase {
1598+
class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
15981599
public:
15991600
enum TypeClass {
16001601
#define TYPE(Class, Base) Class,
@@ -1982,9 +1983,10 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
19821983
Type(TypeClass tc, QualType canon, TypeDependence Dependence)
19831984
: ExtQualsTypeCommonBase(this,
19841985
canon.isNull() ? QualType(this_(), 0) : canon) {
1985-
static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase),
1986+
static_assert(sizeof(*this) <=
1987+
alignof(decltype(*this)) + sizeof(ExtQualsTypeCommonBase),
19861988
"changing bitfields changed sizeof(Type)!");
1987-
static_assert(alignof(decltype(*this)) % sizeof(void *) == 0,
1989+
static_assert(alignof(decltype(*this)) % TypeAlignment == 0,
19881990
"Insufficient alignment!");
19891991
TypeBits.TC = tc;
19901992
TypeBits.Dependence = static_cast<unsigned>(Dependence);
@@ -5348,7 +5350,7 @@ class DeducedType : public Type {
53485350

53495351
/// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
53505352
/// by a type-constraint.
5351-
class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode {
5353+
class AutoType : public DeducedType, public llvm::FoldingSetNode {
53525354
friend class ASTContext; // ASTContext creates these
53535355

53545356
ConceptDecl *TypeConstraintConcept;
@@ -5456,9 +5458,7 @@ class DeducedTemplateSpecializationType : public DeducedType,
54565458
/// TemplateArguments, followed by a QualType representing the
54575459
/// non-canonical aliased type when the template is a type alias
54585460
/// template.
5459-
class alignas(8) TemplateSpecializationType
5460-
: public Type,
5461-
public llvm::FoldingSetNode {
5461+
class TemplateSpecializationType : public Type, public llvm::FoldingSetNode {
54625462
friend class ASTContext; // ASTContext creates these
54635463

54645464
/// The name of the template being specialized. This is
@@ -5872,9 +5872,8 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
58725872
/// Represents a template specialization type whose template cannot be
58735873
/// resolved, e.g.
58745874
/// A<T>::template B<T>
5875-
class alignas(8) DependentTemplateSpecializationType
5876-
: public TypeWithKeyword,
5877-
public llvm::FoldingSetNode {
5875+
class DependentTemplateSpecializationType : public TypeWithKeyword,
5876+
public llvm::FoldingSetNode {
58785877
friend class ASTContext; // ASTContext creates these
58795878

58805879
/// The nested name specifier containing the qualifier.

0 commit comments

Comments
 (0)