[clang] a6d0e87 - [clang][NFC] Refactor enums that hold size of `Type` and `DeclContext` bit-fields (#70296)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 08:22:57 PDT 2023
Author: Vlad Serebrennikov
Date: 2023-10-26T19:22:52+04:00
New Revision: a6d0e8791e1015a12f8277e6032eae9fdab686fe
URL: https://github.com/llvm/llvm-project/commit/a6d0e8791e1015a12f8277e6032eae9fdab686fe
DIFF: https://github.com/llvm/llvm-project/commit/a6d0e8791e1015a12f8277e6032eae9fdab686fe.diff
LOG: [clang][NFC] Refactor enums that hold size of `Type` and `DeclContext` bit-fields (#70296)
This patch refactor said enums to hold total size of a bit-field, and not just non-inherited bits. This brings `Type` and `DeclContext` in line with `Comment` and `Stmt`. It also makes it unnecessary to list all transitive bases of a bit-field as unnamed bit-fields, which makes it more friendly towards debuggers.
Added:
Modified:
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/Type.h
clang/lib/Serialization/ASTWriterDecl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..978e4255e877ec2 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1515,16 +1515,14 @@ class DeclContext {
uint64_t IsThisDeclarationADemotedDefinition : 1;
};
- /// Number of non-inherited bits in TagDeclBitfields.
- enum { NumTagDeclBits = 10 };
+ /// Number of inherited and non-inherited bits in TagDeclBitfields.
+ enum { NumTagDeclBits = NumDeclContextBits + 10 };
/// Stores the bits used by EnumDecl.
/// If modified NumEnumDeclBit and the accessor
/// methods in EnumDecl should be updated appropriately.
class EnumDeclBitfields {
friend class EnumDecl;
- /// For the bits in DeclContextBitfields.
- uint64_t : NumDeclContextBits;
/// For the bits in TagDeclBitfields.
uint64_t : NumTagDeclBits;
@@ -1554,16 +1552,14 @@ class DeclContext {
uint64_t HasODRHash : 1;
};
- /// Number of non-inherited bits in EnumDeclBitfields.
- enum { NumEnumDeclBits = 20 };
+ /// Number of inherited and non-inherited bits in EnumDeclBitfields.
+ enum { NumEnumDeclBits = NumTagDeclBits + 20 };
/// Stores the bits used by RecordDecl.
/// If modified NumRecordDeclBits and the accessor
/// methods in RecordDecl should be updated appropriately.
class RecordDeclBitfields {
friend class RecordDecl;
- /// For the bits in DeclContextBitfields.
- uint64_t : NumDeclContextBits;
/// For the bits in TagDeclBitfields.
uint64_t : NumTagDeclBits;
@@ -1615,8 +1611,8 @@ class DeclContext {
uint64_t ODRHash : 26;
};
- /// Number of non-inherited bits in RecordDeclBitfields.
- enum { NumRecordDeclBits = 41 };
+ /// Number of inherited and non-inherited bits in RecordDeclBitfields.
+ enum { NumRecordDeclBits = NumTagDeclBits + 41 };
/// Stores the bits used by OMPDeclareReductionDecl.
/// If modified NumOMPDeclareReductionDeclBits and the accessor
@@ -1631,8 +1627,9 @@ class DeclContext {
uint64_t InitializerKind : 2;
};
- /// Number of non-inherited bits in OMPDeclareReductionDeclBitfields.
- enum { NumOMPDeclareReductionDeclBits = 2 };
+ /// Number of inherited and non-inherited bits in
+ /// OMPDeclareReductionDeclBitfields.
+ enum { NumOMPDeclareReductionDeclBits = NumDeclContextBits + 2 };
/// Stores the bits used by FunctionDecl.
/// If modified NumFunctionDeclBits and the accessor
@@ -1711,16 +1708,14 @@ class DeclContext {
uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
};
- /// Number of non-inherited bits in FunctionDeclBitfields.
- enum { NumFunctionDeclBits = 31 };
+ /// Number of inherited and non-inherited bits in FunctionDeclBitfields.
+ enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
/// Stores the bits used by CXXConstructorDecl. If modified
/// NumCXXConstructorDeclBits and the accessor
/// methods in CXXConstructorDecl should be updated appropriately.
class CXXConstructorDeclBitfields {
friend class CXXConstructorDecl;
- /// For the bits in DeclContextBitfields.
- uint64_t : NumDeclContextBits;
/// For the bits in FunctionDeclBitfields.
uint64_t : NumFunctionDeclBits;
@@ -1739,10 +1734,8 @@ class DeclContext {
uint64_t IsSimpleExplicit : 1;
};
- /// Number of non-inherited bits in CXXConstructorDeclBitfields.
- enum {
- NumCXXConstructorDeclBits = 64 - NumDeclContextBits - NumFunctionDeclBits
- };
+ /// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
+ enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
/// Stores the bits used by ObjCMethodDecl.
/// If modified NumObjCMethodDeclBits and the accessor
@@ -1803,8 +1796,8 @@ class DeclContext {
uint64_t HasSkippedBody : 1;
};
- /// Number of non-inherited bits in ObjCMethodDeclBitfields.
- enum { NumObjCMethodDeclBits = 24 };
+ /// Number of inherited and non-inherited bits in ObjCMethodDeclBitfields.
+ enum { NumObjCMethodDeclBits = NumDeclContextBits + 24 };
/// Stores the bits used by ObjCContainerDecl.
/// If modified NumObjCContainerDeclBits and the accessor
@@ -1819,10 +1812,10 @@ class DeclContext {
SourceLocation AtStart;
};
- /// Number of non-inherited bits in ObjCContainerDeclBitfields.
+ /// Number of inherited and non-inherited bits in ObjCContainerDeclBitfields.
/// Note that here we rely on the fact that SourceLocation is 32 bits
/// wide. We check this with the static_assert in the ctor of DeclContext.
- enum { NumObjCContainerDeclBits = 64 - NumDeclContextBits };
+ enum { NumObjCContainerDeclBits = 64 };
/// Stores the bits used by LinkageSpecDecl.
/// If modified NumLinkageSpecDeclBits and the accessor
@@ -1843,8 +1836,8 @@ class DeclContext {
uint64_t HasBraces : 1;
};
- /// Number of non-inherited bits in LinkageSpecDeclBitfields.
- enum { NumLinkageSpecDeclBits = 4 };
+ /// Number of inherited and non-inherited bits in LinkageSpecDeclBitfields.
+ enum { NumLinkageSpecDeclBits = NumDeclContextBits + 4 };
/// Stores the bits used by BlockDecl.
/// If modified NumBlockDeclBits and the accessor
@@ -1869,8 +1862,8 @@ class DeclContext {
uint64_t CanAvoidCopyToHeap : 1;
};
- /// Number of non-inherited bits in BlockDeclBitfields.
- enum { NumBlockDeclBits = 5 };
+ /// Number of inherited and non-inherited bits in BlockDeclBitfields.
+ enum { NumBlockDeclBits = NumDeclContextBits + 5 };
/// Pointer to the data structure used to lookup declarations
/// within this context (or a DependentStoredDeclsMap if this is a
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index e3dbe3b8a45cc3e..1e8e1303e65f6ba 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1663,11 +1663,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// Actually an ArrayType::ArraySizeModifier.
unsigned SizeModifier : 3;
};
+ enum { NumArrayTypeBits = NumTypeBits + 6 };
class ConstantArrayTypeBitfields {
friend class ConstantArrayType;
- unsigned : NumTypeBits + 3 + 3;
+ unsigned : NumArrayTypeBits;
/// Whether we have a stored size expression.
unsigned HasStoredSizeExpr : 1;
@@ -1780,7 +1781,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
unsigned Keyword : 8;
};
- enum { NumTypeWithKeywordBits = 8 };
+ enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
class ElaboratedTypeBitfields {
friend class ElaboratedType;
@@ -1913,7 +1914,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
class DependentTemplateSpecializationTypeBitfields {
friend class DependentTemplateSpecializationType;
- unsigned : NumTypeBits;
unsigned : NumTypeWithKeywordBits;
/// The number of template arguments named in this class template
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 8a2ea7c7624ceb8..b3364113abf15ba 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -431,7 +431,7 @@ void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
}
void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
- static_assert(DeclContext::NumTagDeclBits == 10,
+ static_assert(DeclContext::NumTagDeclBits == 23,
"You need to update the serializer after you change the "
"TagDeclBits");
@@ -459,7 +459,7 @@ void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
}
void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
- static_assert(DeclContext::NumEnumDeclBits == 20,
+ static_assert(DeclContext::NumEnumDeclBits == 43,
"You need to update the serializer after you change the "
"EnumDeclBits");
@@ -506,7 +506,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
}
void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
- static_assert(DeclContext::NumRecordDeclBits == 41,
+ static_assert(DeclContext::NumRecordDeclBits == 64,
"You need to update the serializer after you change the "
"RecordDeclBits");
@@ -578,7 +578,7 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
}
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
- static_assert(DeclContext::NumFunctionDeclBits == 31,
+ static_assert(DeclContext::NumFunctionDeclBits == 44,
"You need to update the serializer after you change the "
"FunctionDeclBits");
@@ -726,7 +726,7 @@ void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
}
void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
- static_assert(DeclContext::NumObjCMethodDeclBits == 24,
+ static_assert(DeclContext::NumObjCMethodDeclBits == 37,
"You need to update the serializer after you change the "
"ObjCMethodDeclBits");
@@ -788,7 +788,7 @@ void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
}
void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
- static_assert(DeclContext::NumObjCContainerDeclBits == 51,
+ static_assert(DeclContext::NumObjCContainerDeclBits == 64,
"You need to update the serializer after you change the "
"ObjCContainerDeclBits");
@@ -1268,7 +1268,7 @@ void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
}
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
- static_assert(DeclContext::NumLinkageSpecDeclBits == 4,
+ static_assert(DeclContext::NumLinkageSpecDeclBits == 17,
"You need to update the serializer after you change the"
"LinkageSpecDeclBits");
@@ -1479,7 +1479,7 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
}
void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
- static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
+ static_assert(DeclContext::NumCXXConstructorDeclBits == 64,
"You need to update the serializer after you change the "
"CXXConstructorDeclBits");
@@ -1960,7 +1960,7 @@ void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
}
void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
- static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 2,
+ static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15,
"You need to update the serializer after you change the "
"NumOMPDeclareReductionDeclBits");
More information about the cfe-commits
mailing list