Skip to content

Commit a6d0e87

Browse files
authored
[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.
1 parent f3f0672 commit a6d0e87

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,16 +1515,14 @@ class DeclContext {
15151515
uint64_t IsThisDeclarationADemotedDefinition : 1;
15161516
};
15171517

1518-
/// Number of non-inherited bits in TagDeclBitfields.
1519-
enum { NumTagDeclBits = 10 };
1518+
/// Number of inherited and non-inherited bits in TagDeclBitfields.
1519+
enum { NumTagDeclBits = NumDeclContextBits + 10 };
15201520

15211521
/// Stores the bits used by EnumDecl.
15221522
/// If modified NumEnumDeclBit and the accessor
15231523
/// methods in EnumDecl should be updated appropriately.
15241524
class EnumDeclBitfields {
15251525
friend class EnumDecl;
1526-
/// For the bits in DeclContextBitfields.
1527-
uint64_t : NumDeclContextBits;
15281526
/// For the bits in TagDeclBitfields.
15291527
uint64_t : NumTagDeclBits;
15301528

@@ -1554,16 +1552,14 @@ class DeclContext {
15541552
uint64_t HasODRHash : 1;
15551553
};
15561554

1557-
/// Number of non-inherited bits in EnumDeclBitfields.
1558-
enum { NumEnumDeclBits = 20 };
1555+
/// Number of inherited and non-inherited bits in EnumDeclBitfields.
1556+
enum { NumEnumDeclBits = NumTagDeclBits + 20 };
15591557

15601558
/// Stores the bits used by RecordDecl.
15611559
/// If modified NumRecordDeclBits and the accessor
15621560
/// methods in RecordDecl should be updated appropriately.
15631561
class RecordDeclBitfields {
15641562
friend class RecordDecl;
1565-
/// For the bits in DeclContextBitfields.
1566-
uint64_t : NumDeclContextBits;
15671563
/// For the bits in TagDeclBitfields.
15681564
uint64_t : NumTagDeclBits;
15691565

@@ -1615,8 +1611,8 @@ class DeclContext {
16151611
uint64_t ODRHash : 26;
16161612
};
16171613

1618-
/// Number of non-inherited bits in RecordDeclBitfields.
1619-
enum { NumRecordDeclBits = 41 };
1614+
/// Number of inherited and non-inherited bits in RecordDeclBitfields.
1615+
enum { NumRecordDeclBits = NumTagDeclBits + 41 };
16201616

16211617
/// Stores the bits used by OMPDeclareReductionDecl.
16221618
/// If modified NumOMPDeclareReductionDeclBits and the accessor
@@ -1631,8 +1627,9 @@ class DeclContext {
16311627
uint64_t InitializerKind : 2;
16321628
};
16331629

1634-
/// Number of non-inherited bits in OMPDeclareReductionDeclBitfields.
1635-
enum { NumOMPDeclareReductionDeclBits = 2 };
1630+
/// Number of inherited and non-inherited bits in
1631+
/// OMPDeclareReductionDeclBitfields.
1632+
enum { NumOMPDeclareReductionDeclBits = NumDeclContextBits + 2 };
16361633

16371634
/// Stores the bits used by FunctionDecl.
16381635
/// If modified NumFunctionDeclBits and the accessor
@@ -1711,16 +1708,14 @@ class DeclContext {
17111708
uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
17121709
};
17131710

1714-
/// Number of non-inherited bits in FunctionDeclBitfields.
1715-
enum { NumFunctionDeclBits = 31 };
1711+
/// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1712+
enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
17161713

17171714
/// Stores the bits used by CXXConstructorDecl. If modified
17181715
/// NumCXXConstructorDeclBits and the accessor
17191716
/// methods in CXXConstructorDecl should be updated appropriately.
17201717
class CXXConstructorDeclBitfields {
17211718
friend class CXXConstructorDecl;
1722-
/// For the bits in DeclContextBitfields.
1723-
uint64_t : NumDeclContextBits;
17241719
/// For the bits in FunctionDeclBitfields.
17251720
uint64_t : NumFunctionDeclBits;
17261721

@@ -1739,10 +1734,8 @@ class DeclContext {
17391734
uint64_t IsSimpleExplicit : 1;
17401735
};
17411736

1742-
/// Number of non-inherited bits in CXXConstructorDeclBitfields.
1743-
enum {
1744-
NumCXXConstructorDeclBits = 64 - NumDeclContextBits - NumFunctionDeclBits
1745-
};
1737+
/// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1738+
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
17461739

17471740
/// Stores the bits used by ObjCMethodDecl.
17481741
/// If modified NumObjCMethodDeclBits and the accessor
@@ -1803,8 +1796,8 @@ class DeclContext {
18031796
uint64_t HasSkippedBody : 1;
18041797
};
18051798

1806-
/// Number of non-inherited bits in ObjCMethodDeclBitfields.
1807-
enum { NumObjCMethodDeclBits = 24 };
1799+
/// Number of inherited and non-inherited bits in ObjCMethodDeclBitfields.
1800+
enum { NumObjCMethodDeclBits = NumDeclContextBits + 24 };
18081801

18091802
/// Stores the bits used by ObjCContainerDecl.
18101803
/// If modified NumObjCContainerDeclBits and the accessor
@@ -1819,10 +1812,10 @@ class DeclContext {
18191812
SourceLocation AtStart;
18201813
};
18211814

1822-
/// Number of non-inherited bits in ObjCContainerDeclBitfields.
1815+
/// Number of inherited and non-inherited bits in ObjCContainerDeclBitfields.
18231816
/// Note that here we rely on the fact that SourceLocation is 32 bits
18241817
/// wide. We check this with the static_assert in the ctor of DeclContext.
1825-
enum { NumObjCContainerDeclBits = 64 - NumDeclContextBits };
1818+
enum { NumObjCContainerDeclBits = 64 };
18261819

18271820
/// Stores the bits used by LinkageSpecDecl.
18281821
/// If modified NumLinkageSpecDeclBits and the accessor
@@ -1843,8 +1836,8 @@ class DeclContext {
18431836
uint64_t HasBraces : 1;
18441837
};
18451838

1846-
/// Number of non-inherited bits in LinkageSpecDeclBitfields.
1847-
enum { NumLinkageSpecDeclBits = 4 };
1839+
/// Number of inherited and non-inherited bits in LinkageSpecDeclBitfields.
1840+
enum { NumLinkageSpecDeclBits = NumDeclContextBits + 4 };
18481841

18491842
/// Stores the bits used by BlockDecl.
18501843
/// If modified NumBlockDeclBits and the accessor
@@ -1869,8 +1862,8 @@ class DeclContext {
18691862
uint64_t CanAvoidCopyToHeap : 1;
18701863
};
18711864

1872-
/// Number of non-inherited bits in BlockDeclBitfields.
1873-
enum { NumBlockDeclBits = 5 };
1865+
/// Number of inherited and non-inherited bits in BlockDeclBitfields.
1866+
enum { NumBlockDeclBits = NumDeclContextBits + 5 };
18741867

18751868
/// Pointer to the data structure used to lookup declarations
18761869
/// within this context (or a DependentStoredDeclsMap if this is a

clang/include/clang/AST/Type.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,11 +1663,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
16631663
/// Actually an ArrayType::ArraySizeModifier.
16641664
unsigned SizeModifier : 3;
16651665
};
1666+
enum { NumArrayTypeBits = NumTypeBits + 6 };
16661667

16671668
class ConstantArrayTypeBitfields {
16681669
friend class ConstantArrayType;
16691670

1670-
unsigned : NumTypeBits + 3 + 3;
1671+
unsigned : NumArrayTypeBits;
16711672

16721673
/// Whether we have a stored size expression.
16731674
unsigned HasStoredSizeExpr : 1;
@@ -1780,7 +1781,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
17801781
unsigned Keyword : 8;
17811782
};
17821783

1783-
enum { NumTypeWithKeywordBits = 8 };
1784+
enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
17841785

17851786
class ElaboratedTypeBitfields {
17861787
friend class ElaboratedType;
@@ -1913,7 +1914,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
19131914
class DependentTemplateSpecializationTypeBitfields {
19141915
friend class DependentTemplateSpecializationType;
19151916

1916-
unsigned : NumTypeBits;
19171917
unsigned : NumTypeWithKeywordBits;
19181918

19191919
/// The number of template arguments named in this class template

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
431431
}
432432

433433
void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
434-
static_assert(DeclContext::NumTagDeclBits == 10,
434+
static_assert(DeclContext::NumTagDeclBits == 23,
435435
"You need to update the serializer after you change the "
436436
"TagDeclBits");
437437

@@ -459,7 +459,7 @@ void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
459459
}
460460

461461
void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
462-
static_assert(DeclContext::NumEnumDeclBits == 20,
462+
static_assert(DeclContext::NumEnumDeclBits == 43,
463463
"You need to update the serializer after you change the "
464464
"EnumDeclBits");
465465

@@ -506,7 +506,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
506506
}
507507

508508
void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
509-
static_assert(DeclContext::NumRecordDeclBits == 41,
509+
static_assert(DeclContext::NumRecordDeclBits == 64,
510510
"You need to update the serializer after you change the "
511511
"RecordDeclBits");
512512

@@ -578,7 +578,7 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
578578
}
579579

580580
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
581-
static_assert(DeclContext::NumFunctionDeclBits == 31,
581+
static_assert(DeclContext::NumFunctionDeclBits == 44,
582582
"You need to update the serializer after you change the "
583583
"FunctionDeclBits");
584584

@@ -726,7 +726,7 @@ void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
726726
}
727727

728728
void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
729-
static_assert(DeclContext::NumObjCMethodDeclBits == 24,
729+
static_assert(DeclContext::NumObjCMethodDeclBits == 37,
730730
"You need to update the serializer after you change the "
731731
"ObjCMethodDeclBits");
732732

@@ -788,7 +788,7 @@ void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
788788
}
789789

790790
void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
791-
static_assert(DeclContext::NumObjCContainerDeclBits == 51,
791+
static_assert(DeclContext::NumObjCContainerDeclBits == 64,
792792
"You need to update the serializer after you change the "
793793
"ObjCContainerDeclBits");
794794

@@ -1268,7 +1268,7 @@ void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
12681268
}
12691269

12701270
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1271-
static_assert(DeclContext::NumLinkageSpecDeclBits == 4,
1271+
static_assert(DeclContext::NumLinkageSpecDeclBits == 17,
12721272
"You need to update the serializer after you change the"
12731273
"LinkageSpecDeclBits");
12741274

@@ -1479,7 +1479,7 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
14791479
}
14801480

14811481
void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
1482-
static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
1482+
static_assert(DeclContext::NumCXXConstructorDeclBits == 64,
14831483
"You need to update the serializer after you change the "
14841484
"CXXConstructorDeclBits");
14851485

@@ -1960,7 +1960,7 @@ void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
19601960
}
19611961

19621962
void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1963-
static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 2,
1963+
static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15,
19641964
"You need to update the serializer after you change the "
19651965
"NumOMPDeclareReductionDeclBits");
19661966

0 commit comments

Comments
 (0)