This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc79635cce845: [NFC] [Serialization] Add static assert for 
the size of the decls to (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141992/new/

https://reviews.llvm.org/D141992

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp

Index: clang/lib/Serialization/ASTWriterDecl.cpp
===================================================================
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -300,6 +300,9 @@
 }
 
 void ASTDeclWriter::VisitDecl(Decl *D) {
+  static_assert(sizeof(Decl) == 40, "You need to update the serializer after "
+                                    "you change the fields of Decls.");
+
   Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
   if (D->getDeclContext() != D->getLexicalDeclContext())
     Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
@@ -339,6 +342,10 @@
 }
 
 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
+  static_assert(sizeof(PragmaCommentDecl) == 40,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   StringRef Arg = D->getArg();
   Record.push_back(Arg.size());
   VisitDecl(D);
@@ -350,6 +357,10 @@
 
 void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
     PragmaDetectMismatchDecl *D) {
+  static_assert(sizeof(PragmaDetectMismatchDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   StringRef Name = D->getName();
   StringRef Value = D->getValue();
   Record.push_back(Name.size() + 1 + Value.size());
@@ -365,6 +376,10 @@
 }
 
 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
+  static_assert(sizeof(NamedDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddDeclarationName(D->getDeclName());
   Record.push_back(needsAnonymousDeclarationNumber(D)
@@ -373,12 +388,20 @@
 }
 
 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
+  static_assert(sizeof(TypeDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
 }
 
 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
+  static_assert(sizeof(TypedefNameDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitTypeDecl(D);
   Record.AddTypeSourceInfo(D->getTypeSourceInfo());
@@ -389,6 +412,10 @@
 }
 
 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
+  static_assert(sizeof(TypedefDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTypedefNameDecl(D);
   if (D->getDeclContext() == D->getLexicalDeclContext() &&
       !D->hasAttrs() &&
@@ -405,12 +432,20 @@
 }
 
 void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
+  static_assert(sizeof(TypeAliasDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTypedefNameDecl(D);
   Record.AddDeclRef(D->getDescribedAliasTemplate());
   Code = serialization::DECL_TYPEALIAS;
 }
 
 void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
+  static_assert(DeclContext::NumTagDeclBits == 10 && sizeof(TagDecl) == 128,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitTypeDecl(D);
   Record.push_back(D->getIdentifierNamespace());
@@ -435,6 +470,10 @@
 }
 
 void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
+  static_assert(DeclContext::NumEnumDeclBits == 20 && sizeof(EnumDecl) == 160,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTagDecl(D);
   Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
   if (!D->getIntegerTypeSourceInfo())
@@ -478,6 +517,11 @@
 }
 
 void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
+  static_assert(DeclContext::NumRecordDeclBits == 15 &&
+                    sizeof(RecordDecl) == 128,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTagDecl(D);
   Record.push_back(D->hasFlexibleArrayMember());
   Record.push_back(D->isAnonymousStructOrUnion());
@@ -513,11 +557,19 @@
 }
 
 void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
+  static_assert(sizeof(ValueDecl) == 56,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddTypeRef(D->getType());
 }
 
 void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
+  static_assert(sizeof(EnumConstantDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.push_back(D->getInitExpr()? 1 : 0);
   if (D->getInitExpr())
@@ -528,6 +580,10 @@
 }
 
 void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
+  static_assert(sizeof(DeclaratorDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddSourceLocation(D->getInnerLocStart());
   Record.push_back(D->hasExtInfo());
@@ -542,6 +598,11 @@
 }
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
+  static_assert(DeclContext::NumFunctionDeclBits == 29 &&
+                    sizeof(FunctionDecl) == 168,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
 
   Record.push_back(D->getTemplatedKind());
@@ -685,6 +746,10 @@
 }
 
 void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
+  static_assert(sizeof(CXXDeductionGuideDecl) == 184,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   addExplicitSpecifier(D->getExplicitSpecifier(), Record);
   Record.AddDeclRef(D->Ctor);
   VisitFunctionDecl(D);
@@ -693,6 +758,11 @@
 }
 
 void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
+  static_assert(DeclContext::NumObjCMethodDeclBits == 24 &&
+                    sizeof(ObjCMethodDecl) == 136,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   // FIXME: convert to LazyStmtPtr?
   // Unlike C/C++, method bodies will never be in header files.
@@ -741,6 +811,10 @@
 }
 
 void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
+  static_assert(sizeof(ObjCTypeParamDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTypedefNameDecl(D);
   Record.push_back(D->Variance);
   Record.push_back(D->Index);
@@ -751,6 +825,11 @@
 }
 
 void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
+  static_assert(DeclContext::NumObjCContainerDeclBits == 51 &&
+                    sizeof(ObjCContainerDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getAtStartLoc());
   Record.AddSourceRange(D->getAtEndRange());
@@ -758,6 +837,10 @@
 }
 
 void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
+  static_assert(sizeof(ObjCInterfaceDecl) == 128,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitObjCContainerDecl(D);
   Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
@@ -802,6 +885,10 @@
 }
 
 void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
+  static_assert(sizeof(ObjCIvarDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitFieldDecl(D);
   // FIXME: stable encoding for @public/@private/@protected/@package
   Record.push_back(D->getAccessControl());
@@ -823,6 +910,10 @@
 }
 
 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
+  static_assert(sizeof(ObjCProtocolDecl) == 112,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitObjCContainerDecl(D);
 
@@ -840,11 +931,19 @@
 }
 
 void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
+  static_assert(sizeof(ObjCAtDefsFieldDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitFieldDecl(D);
   Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
 }
 
 void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
+  static_assert(sizeof(ObjCCategoryDecl) == 152,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitObjCContainerDecl(D);
   Record.AddSourceLocation(D->getCategoryNameLoc());
   Record.AddSourceLocation(D->getIvarLBraceLoc());
@@ -860,12 +959,20 @@
 }
 
 void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
+  static_assert(sizeof(ObjCCompatibleAliasDecl) == 56,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddDeclRef(D->getClassInterface());
   Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
 }
 
 void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
+  static_assert(sizeof(ObjCPropertyDecl) == 128,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getAtLoc());
   Record.AddSourceLocation(D->getLParenLoc());
@@ -887,18 +994,30 @@
 }
 
 void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
+  static_assert(sizeof(ObjCImplDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitObjCContainerDecl(D);
   Record.AddDeclRef(D->getClassInterface());
   // Abstract class (no need to define a stable serialization::DECL code).
 }
 
 void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
+  static_assert(sizeof(ObjCCategoryImplDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitObjCImplDecl(D);
   Record.AddSourceLocation(D->getCategoryNameLoc());
   Code = serialization::DECL_OBJC_CATEGORY_IMPL;
 }
 
 void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
+  static_assert(sizeof(ObjCImplementationDecl) == 136,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitObjCImplDecl(D);
   Record.AddDeclRef(D->getSuperClass());
   Record.AddSourceLocation(D->getSuperClassLoc());
@@ -914,6 +1033,10 @@
 }
 
 void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
+  static_assert(sizeof(ObjCPropertyImplDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddDeclRef(D->getPropertyDecl());
@@ -927,6 +1050,10 @@
 }
 
 void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
+  static_assert(sizeof(FieldDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDeclaratorDecl(D);
   Record.push_back(D->isMutable());
 
@@ -963,6 +1090,10 @@
 }
 
 void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
+  static_assert(sizeof(MSPropertyDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDeclaratorDecl(D);
   Record.AddIdentifierRef(D->getGetterId());
   Record.AddIdentifierRef(D->getSetterId());
@@ -970,6 +1101,10 @@
 }
 
 void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) {
+  static_assert(sizeof(MSGuidDecl) == 152,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   MSGuidDecl::Parts Parts = D->getParts();
   Record.push_back(Parts.Part1);
@@ -981,18 +1116,30 @@
 
 void ASTDeclWriter::VisitUnnamedGlobalConstantDecl(
     UnnamedGlobalConstantDecl *D) {
+  static_assert(sizeof(UnnamedGlobalConstantDecl) == 136,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddAPValue(D->getValue());
   Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT;
 }
 
 void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) {
+  static_assert(sizeof(TemplateParamObjectDecl) == 136,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddAPValue(D->getValue());
   Code = serialization::DECL_TEMPLATE_PARAM_OBJECT;
 }
 
 void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
+  static_assert(sizeof(IndirectFieldDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.push_back(D->getChainingSize());
 
@@ -1002,6 +1149,10 @@
 }
 
 void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
+  static_assert(sizeof(VarDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitDeclaratorDecl(D);
   Record.push_back(D->getStorageClass());
@@ -1099,11 +1250,19 @@
 }
 
 void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
+  static_assert(sizeof(ImplicitParamDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitVarDecl(D);
   Code = serialization::DECL_IMPLICIT_PARAM;
 }
 
 void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
+  static_assert(sizeof(ParmVarDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitVarDecl(D);
   Record.push_back(D->isObjCMethodParameter());
   Record.push_back(D->getFunctionScopeDepth());
@@ -1161,12 +1320,20 @@
 }
 
 void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
+  static_assert(sizeof(BindingDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddStmt(D->getBinding());
   Code = serialization::DECL_BINDING;
 }
 
 void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
+  static_assert(sizeof(FileScopeAsmDecl) == 56,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddStmt(D->getAsmString());
   Record.AddSourceLocation(D->getRParenLoc());
@@ -1174,18 +1341,30 @@
 }
 
 void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
+  static_assert(sizeof(TopLevelStmtDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddStmt(D->getStmt());
   Code = serialization::DECL_TOP_LEVEL_STMT_DECL;
 }
 
 void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
+  static_assert(sizeof(EmptyDecl) == 40,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Code = serialization::DECL_EMPTY;
 }
 
 void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(
     LifetimeExtendedTemporaryDecl *D) {
+  static_assert(sizeof(LifetimeExtendedTemporaryDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddDeclRef(D->getExtendingDecl());
   Record.AddStmt(D->getTemporaryExpr());
@@ -1196,6 +1375,10 @@
   Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY;
 }
 void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
+  static_assert(DeclContext::NumBlockDeclBits == 5 && sizeof(BlockDecl) == 128,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddStmt(D->getBody());
   Record.AddTypeSourceInfo(D->getSignatureAsWritten());
@@ -1225,6 +1408,10 @@
 }
 
 void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
+  static_assert(sizeof(CapturedDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.push_back(CD->getNumParams());
   VisitDecl(CD);
   Record.push_back(CD->getContextParamPosition());
@@ -1236,6 +1423,11 @@
 }
 
 void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
+  static_assert(DeclContext::NumLinkageSpecDeclBits == 4 &&
+                    sizeof(LinkageSpecDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.push_back(D->getLanguage());
   Record.AddSourceLocation(D->getExternLoc());
@@ -1244,12 +1436,20 @@
 }
 
 void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
+  static_assert(sizeof(ExportDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddSourceLocation(D->getRBraceLoc());
   Code = serialization::DECL_EXPORT;
 }
 
 void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
+  static_assert(sizeof(LabelDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Code = serialization::DECL_LABEL;
@@ -1257,6 +1457,10 @@
 
 
 void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
+  static_assert(sizeof(NamespaceDecl) == 112,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitNamedDecl(D);
   Record.push_back(D->isInline());
@@ -1284,6 +1488,10 @@
 }
 
 void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+  static_assert(sizeof(NamespaceAliasDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getNamespaceLoc());
@@ -1294,6 +1502,10 @@
 }
 
 void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
+  static_assert(sizeof(UsingDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getUsingLoc());
   Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
@@ -1305,6 +1517,10 @@
 }
 
 void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) {
+  static_assert(sizeof(UsingEnumDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getUsingLoc());
   Record.AddSourceLocation(D->getEnumLoc());
@@ -1315,6 +1531,10 @@
 }
 
 void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
+  static_assert(sizeof(UsingPackDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.push_back(D->NumExpansions);
   VisitNamedDecl(D);
   Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
@@ -1324,6 +1544,10 @@
 }
 
 void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
+  static_assert(sizeof(UsingShadowDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
   VisitNamedDecl(D);
   Record.AddDeclRef(D->getTargetDecl());
@@ -1335,6 +1559,10 @@
 
 void ASTDeclWriter::VisitConstructorUsingShadowDecl(
     ConstructorUsingShadowDecl *D) {
+  static_assert(sizeof(ConstructorUsingShadowDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitUsingShadowDecl(D);
   Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
   Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
@@ -1343,6 +1571,10 @@
 }
 
 void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+  static_assert(sizeof(UsingDirectiveDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getUsingLoc());
   Record.AddSourceLocation(D->getNamespaceKeyLocation());
@@ -1353,6 +1585,10 @@
 }
 
 void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
+  static_assert(sizeof(UnresolvedUsingValueDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddSourceLocation(D->getUsingLoc());
   Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
@@ -1363,6 +1599,10 @@
 
 void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
                                                UnresolvedUsingTypenameDecl *D) {
+  static_assert(sizeof(UnresolvedUsingTypenameDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTypeDecl(D);
   Record.AddSourceLocation(D->getTypenameLoc());
   Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
@@ -1372,11 +1612,19 @@
 
 void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl(
     UnresolvedUsingIfExistsDecl *D) {
+  static_assert(sizeof(UnresolvedUsingIfExistsDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS;
 }
 
 void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
+  static_assert(sizeof(CXXRecordDecl) == 144,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRecordDecl(D);
 
   enum {
@@ -1408,6 +1656,10 @@
 }
 
 void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
+  static_assert(sizeof(CXXMethodDecl) == 168,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitFunctionDecl(D);
   if (D->isCanonicalDecl()) {
     Record.push_back(D->size_overridden_methods());
@@ -1431,6 +1683,11 @@
 }
 
 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
+  static_assert(DeclContext::NumCXXConstructorDeclBits == 22 &&
+                    sizeof(CXXConstructorDecl) == 176,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.push_back(D->getTrailingAllocKind());
   addExplicitSpecifier(D->getExplicitSpecifier(), Record);
   if (auto Inherited = D->getInheritedConstructor()) {
@@ -1443,6 +1700,10 @@
 }
 
 void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
+  static_assert(sizeof(CXXDestructorDecl) == 184,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitCXXMethodDecl(D);
 
   Record.AddDeclRef(D->getOperatorDelete());
@@ -1453,12 +1714,20 @@
 }
 
 void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
+  static_assert(sizeof(CXXConversionDecl) == 176,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   addExplicitSpecifier(D->getExplicitSpecifier(), Record);
   VisitCXXMethodDecl(D);
   Code = serialization::DECL_CXX_CONVERSION;
 }
 
 void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
+  static_assert(sizeof(ImportDecl) == 56,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
   ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
@@ -1477,12 +1746,20 @@
 }
 
 void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
+  static_assert(sizeof(AccessSpecDecl) == 40,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddSourceLocation(D->getColonLoc());
   Code = serialization::DECL_ACCESS_SPEC;
 }
 
 void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
+  static_assert(sizeof(FriendDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   // Record the number of friend type template parameter lists here
   // so as to simplify memory allocation during deserialization.
   Record.push_back(D->NumTPLists);
@@ -1502,6 +1779,10 @@
 }
 
 void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
+  static_assert(sizeof(FriendTemplateDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.push_back(D->getNumTemplateParameters());
   for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
@@ -1516,6 +1797,10 @@
 }
 
 void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
+  static_assert(sizeof(TemplateDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
 
   Record.AddTemplateParameterList(D->getTemplateParameters());
@@ -1523,6 +1808,10 @@
 }
 
 void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) {
+  static_assert(sizeof(ConceptDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitTemplateDecl(D);
   Record.AddStmt(D->getConstraintExpr());
   Code = serialization::DECL_CONCEPT;
@@ -1530,6 +1819,10 @@
 
 void ASTDeclWriter::VisitImplicitConceptSpecializationDecl(
     ImplicitConceptSpecializationDecl *D) {
+  static_assert(sizeof(ImplicitConceptSpecializationDecl) == 40,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.push_back(D->getTemplateArguments().size());
   VisitDecl(D);
   for (const TemplateArgument &Arg : D->getTemplateArguments())
@@ -1538,10 +1831,18 @@
 }
 
 void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
+  static_assert(sizeof(RequiresExprBodyDecl) == 72,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Code = serialization::DECL_REQUIRES_EXPR_BODY;
 }
 
 void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
+  static_assert(sizeof(RedeclarableTemplateDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarable(D);
 
   // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
@@ -1558,6 +1859,10 @@
 }
 
 void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
+  static_assert(sizeof(ClassTemplateDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarableTemplateDecl(D);
 
   if (D->isFirstDecl())
@@ -1567,6 +1872,10 @@
 
 void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
                                            ClassTemplateSpecializationDecl *D) {
+  static_assert(sizeof(ClassTemplateSpecializationDecl) == 184,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
 
   VisitCXXRecordDecl(D);
@@ -1603,6 +1912,10 @@
 
 void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
                                     ClassTemplatePartialSpecializationDecl *D) {
+  static_assert(sizeof(ClassTemplatePartialSpecializationDecl) == 208,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.AddTemplateParameterList(D->getTemplateParameters());
   Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
 
@@ -1618,6 +1931,10 @@
 }
 
 void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
+  static_assert(sizeof(VarTemplateDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarableTemplateDecl(D);
 
   if (D->isFirstDecl())
@@ -1627,6 +1944,10 @@
 
 void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
     VarTemplateSpecializationDecl *D) {
+  static_assert(sizeof(VarTemplateSpecializationDecl) == 152,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
 
   llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
@@ -1664,6 +1985,10 @@
 
 void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
     VarTemplatePartialSpecializationDecl *D) {
+  static_assert(sizeof(VarTemplatePartialSpecializationDecl) == 176,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.AddTemplateParameterList(D->getTemplateParameters());
   Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
 
@@ -1680,6 +2005,10 @@
 
 void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
                                     ClassScopeFunctionSpecializationDecl *D) {
+  static_assert(sizeof(ClassScopeFunctionSpecializationDecl) == 56,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddDeclRef(D->getSpecialization());
   Record.push_back(D->hasExplicitTemplateArgs());
@@ -1690,6 +2019,10 @@
 
 
 void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
+  static_assert(sizeof(FunctionTemplateDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarableTemplateDecl(D);
 
   if (D->isFirstDecl())
@@ -1698,6 +2031,10 @@
 }
 
 void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
+  static_assert(sizeof(TemplateTypeParmDecl) == 80,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.push_back(D->hasTypeConstraint());
   VisitTypeDecl(D);
 
@@ -1728,6 +2065,10 @@
 }
 
 void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
+  static_assert(sizeof(NonTypeTemplateParmDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   // For an expanded parameter pack, record the number of expansion types here
   // so that it's easier for deserialization to allocate the right amount of
   // memory.
@@ -1763,6 +2104,10 @@
 }
 
 void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
+  static_assert(sizeof(TemplateTemplateParmDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   // For an expanded parameter pack, record the number of expansion types here
   // so that it's easier for deserialization to allocate the right amount of
   // memory.
@@ -1792,11 +2137,19 @@
 }
 
 void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
+  static_assert(sizeof(TypeAliasTemplateDecl) == 88,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitRedeclarableTemplateDecl(D);
   Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
 }
 
 void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
+  static_assert(sizeof(StaticAssertDecl) == 64,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitDecl(D);
   Record.AddStmt(D->getAssertExpr());
   Record.push_back(D->isFailed());
@@ -1807,6 +2160,11 @@
 
 /// Emit the DeclContext part of a declaration context decl.
 void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
+  static_assert(DeclContext::NumDeclContextBits == 13 &&
+                    sizeof(DeclContext) == 32,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
   Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
 }
@@ -1888,6 +2246,10 @@
 }
 
 void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
+  static_assert(sizeof(HLSLBufferDecl) == 96,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitNamedDecl(D);
   VisitDeclContext(D);
   Record.push_back(D->isCBuffer());
@@ -1899,24 +2261,41 @@
 }
 
 void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
+  static_assert(sizeof(OMPThreadPrivateDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.writeOMPChildren(D->Data);
   VisitDecl(D);
   Code = serialization::DECL_OMP_THREADPRIVATE;
 }
 
 void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
+  static_assert(sizeof(OMPAllocateDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.writeOMPChildren(D->Data);
   VisitDecl(D);
   Code = serialization::DECL_OMP_ALLOCATE;
 }
 
 void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
+  static_assert(sizeof(OMPRequiresDecl) == 48,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.writeOMPChildren(D->Data);
   VisitDecl(D);
   Code = serialization::DECL_OMP_REQUIRES;
 }
 
 void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
+  static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 2 &&
+                    sizeof(OMPDeclareReductionDecl) == 144,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitValueDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddStmt(D->getCombinerIn());
@@ -1931,6 +2310,10 @@
 }
 
 void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
+  static_assert(sizeof(OMPDeclareMapperDecl) == 120,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   Record.writeOMPChildren(D->Data);
   VisitValueDecl(D);
   Record.AddDeclarationName(D->getVarName());
@@ -1939,6 +2322,10 @@
 }
 
 void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
+  static_assert(sizeof(OMPCapturedExprDecl) == 104,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   VisitVarDecl(D);
   Code = serialization::DECL_OMP_CAPTUREDEXPR;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===================================================================
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5899,6 +5899,11 @@
 }
 
 void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
+  static_assert(sizeof(decltype(D->data())) == 104 &&
+                    sizeof(CXXRecordDecl::LambdaDefinitionData) == 144,
+                "You need to update the serializer after you change the fields "
+                "of Decls.");
+
   auto &Data = D->data();
   Record->push_back(Data.IsLambda);
 
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1389,6 +1389,8 @@
 class DeclContext {
   /// For makeDeclVisibleInContextImpl
   friend class ASTDeclReader;
+  /// For checking the new bits in the Serialization part.
+  friend class ASTDeclWriter;
   /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap,
   /// hasNeedToReconcileExternalVisibleStorage
   friend class ExternalASTSource;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to