| 1 | //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements serialization for Declarations. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "ASTCommon.h" |
| 14 | #include "clang/AST/Attr.h" |
| 15 | #include "clang/AST/DeclCXX.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/AST/DeclVisitor.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | #include "clang/AST/OpenMPClause.h" |
| 20 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 21 | #include "clang/Basic/SourceManager.h" |
| 22 | #include "clang/Serialization/ASTReader.h" |
| 23 | #include "clang/Serialization/ASTRecordWriter.h" |
| 24 | #include "llvm/Bitstream/BitstreamWriter.h" |
| 25 | #include "llvm/Support/ErrorHandling.h" |
| 26 | using namespace clang; |
| 27 | using namespace serialization; |
| 28 | |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | // Utility functions |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | // Helper function that returns true if the decl passed in the argument is |
| 36 | // a defintion in dependent contxt. |
| 37 | template <typename DT> bool isDefinitionInDependentContext(DT *D) { |
| 38 | return D->isDependentContext() && D->isThisDeclarationADefinition(); |
| 39 | } |
| 40 | |
| 41 | } // namespace |
| 42 | |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | // Declaration serialization |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | |
| 47 | namespace clang { |
| 48 | class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { |
| 49 | ASTWriter &Writer; |
| 50 | ASTRecordWriter Record; |
| 51 | |
| 52 | serialization::DeclCode Code; |
| 53 | unsigned AbbrevToUse; |
| 54 | |
| 55 | bool GeneratingReducedBMI = false; |
| 56 | |
| 57 | public: |
| 58 | ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, |
| 59 | ASTWriter::RecordDataImpl &Record, bool GeneratingReducedBMI) |
| 60 | : Writer(Writer), Record(Context, Writer, Record), |
| 61 | Code((serialization::DeclCode)0), AbbrevToUse(0), |
| 62 | GeneratingReducedBMI(GeneratingReducedBMI) {} |
| 63 | |
| 64 | uint64_t Emit(Decl *D) { |
| 65 | if (!Code) |
| 66 | llvm::report_fatal_error(reason: StringRef("unexpected declaration kind '" ) + |
| 67 | D->getDeclKindName() + "'" ); |
| 68 | return Record.Emit(Code, Abbrev: AbbrevToUse); |
| 69 | } |
| 70 | |
| 71 | void Visit(Decl *D); |
| 72 | |
| 73 | void VisitDecl(Decl *D); |
| 74 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
| 75 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
| 76 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 77 | void VisitNamedDecl(NamedDecl *D); |
| 78 | void VisitLabelDecl(LabelDecl *LD); |
| 79 | void VisitNamespaceDecl(NamespaceDecl *D); |
| 80 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 81 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 82 | void VisitTypeDecl(TypeDecl *D); |
| 83 | void VisitTypedefNameDecl(TypedefNameDecl *D); |
| 84 | void VisitTypedefDecl(TypedefDecl *D); |
| 85 | void VisitTypeAliasDecl(TypeAliasDecl *D); |
| 86 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 87 | void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D); |
| 88 | void VisitTagDecl(TagDecl *D); |
| 89 | void VisitEnumDecl(EnumDecl *D); |
| 90 | void VisitRecordDecl(RecordDecl *D); |
| 91 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 92 | void VisitClassTemplateSpecializationDecl( |
| 93 | ClassTemplateSpecializationDecl *D); |
| 94 | void VisitClassTemplatePartialSpecializationDecl( |
| 95 | ClassTemplatePartialSpecializationDecl *D); |
| 96 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 97 | void VisitVarTemplatePartialSpecializationDecl( |
| 98 | VarTemplatePartialSpecializationDecl *D); |
| 99 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 100 | void VisitValueDecl(ValueDecl *D); |
| 101 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
| 102 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 103 | void VisitDeclaratorDecl(DeclaratorDecl *D); |
| 104 | void VisitFunctionDecl(FunctionDecl *D); |
| 105 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); |
| 106 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 107 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 108 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 109 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
| 110 | void VisitFieldDecl(FieldDecl *D); |
| 111 | void VisitMSPropertyDecl(MSPropertyDecl *D); |
| 112 | void VisitMSGuidDecl(MSGuidDecl *D); |
| 113 | void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D); |
| 114 | void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); |
| 115 | void VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 116 | void VisitVarDecl(VarDecl *D); |
| 117 | void VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 118 | void VisitParmVarDecl(ParmVarDecl *D); |
| 119 | void VisitDecompositionDecl(DecompositionDecl *D); |
| 120 | void VisitBindingDecl(BindingDecl *D); |
| 121 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 122 | void VisitTemplateDecl(TemplateDecl *D); |
| 123 | void VisitConceptDecl(ConceptDecl *D); |
| 124 | void VisitImplicitConceptSpecializationDecl( |
| 125 | ImplicitConceptSpecializationDecl *D); |
| 126 | void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); |
| 127 | void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
| 128 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 129 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
| 130 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| 131 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 132 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 133 | void VisitUsingDecl(UsingDecl *D); |
| 134 | void VisitUsingEnumDecl(UsingEnumDecl *D); |
| 135 | void VisitUsingPackDecl(UsingPackDecl *D); |
| 136 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
| 137 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
| 138 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 139 | void VisitExportDecl(ExportDecl *D); |
| 140 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
| 141 | void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); |
| 142 | void VisitImportDecl(ImportDecl *D); |
| 143 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
| 144 | void VisitFriendDecl(FriendDecl *D); |
| 145 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 146 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
| 147 | void VisitBlockDecl(BlockDecl *D); |
| 148 | void VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D); |
| 149 | void VisitCapturedDecl(CapturedDecl *D); |
| 150 | void VisitEmptyDecl(EmptyDecl *D); |
| 151 | void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
| 152 | void VisitDeclContext(DeclContext *DC); |
| 153 | template <typename T> void VisitRedeclarable(Redeclarable<T> *D); |
| 154 | void VisitHLSLBufferDecl(HLSLBufferDecl *D); |
| 155 | |
| 156 | // FIXME: Put in the same order is DeclNodes.td? |
| 157 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 158 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 159 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 160 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 161 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 162 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 163 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 164 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 165 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 166 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 167 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 168 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 169 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 170 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 171 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
| 172 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
| 173 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
| 174 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
| 175 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
| 176 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
| 177 | |
| 178 | void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D); |
| 179 | void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D); |
| 180 | |
| 181 | /// Add an Objective-C type parameter list to the given record. |
| 182 | void AddObjCTypeParamList(ObjCTypeParamList *typeParams) { |
| 183 | // Empty type parameter list. |
| 184 | if (!typeParams) { |
| 185 | Record.push_back(N: 0); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | Record.push_back(N: typeParams->size()); |
| 190 | for (auto *typeParam : *typeParams) { |
| 191 | Record.AddDeclRef(D: typeParam); |
| 192 | } |
| 193 | Record.AddSourceLocation(Loc: typeParams->getLAngleLoc()); |
| 194 | Record.AddSourceLocation(Loc: typeParams->getRAngleLoc()); |
| 195 | } |
| 196 | |
| 197 | /// Collect the first declaration from each module file that provides a |
| 198 | /// declaration of D. |
| 199 | void CollectFirstDeclFromEachModule( |
| 200 | const Decl *D, bool IncludeLocal, |
| 201 | llvm::MapVector<ModuleFile *, const Decl *> &Firsts) { |
| 202 | |
| 203 | // FIXME: We can skip entries that we know are implied by others. |
| 204 | for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) { |
| 205 | if (R->isFromASTFile()) |
| 206 | Firsts[Writer.Chain->getOwningModuleFile(D: R)] = R; |
| 207 | else if (IncludeLocal) |
| 208 | Firsts[nullptr] = R; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /// Add to the record the first declaration from each module file that |
| 213 | /// provides a declaration of D. The intent is to provide a sufficient |
| 214 | /// set such that reloading this set will load all current redeclarations. |
| 215 | void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) { |
| 216 | llvm::MapVector<ModuleFile *, const Decl *> Firsts; |
| 217 | CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts); |
| 218 | |
| 219 | for (const auto &F : Firsts) |
| 220 | Record.AddDeclRef(D: F.second); |
| 221 | } |
| 222 | |
| 223 | template <typename T> bool shouldSkipWritingSpecializations(T *Spec) { |
| 224 | // Now we will only avoid writing specializations if we're generating |
| 225 | // reduced BMI. |
| 226 | if (!GeneratingReducedBMI) |
| 227 | return false; |
| 228 | |
| 229 | assert((isa<FunctionDecl, ClassTemplateSpecializationDecl, |
| 230 | VarTemplateSpecializationDecl>(Spec))); |
| 231 | |
| 232 | ArrayRef<TemplateArgument> Args; |
| 233 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Spec)) |
| 234 | Args = CTSD->getTemplateArgs().asArray(); |
| 235 | else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Spec)) |
| 236 | Args = VTSD->getTemplateArgs().asArray(); |
| 237 | else |
| 238 | Args = cast<FunctionDecl>(Spec) |
| 239 | ->getTemplateSpecializationArgs() |
| 240 | ->asArray(); |
| 241 | |
| 242 | // If there is any template argument is TULocal, we can avoid writing the |
| 243 | // specialization since the consumers of reduced BMI won't get the |
| 244 | // specialization anyway. |
| 245 | for (const TemplateArgument &TA : Args) { |
| 246 | switch (TA.getKind()) { |
| 247 | case TemplateArgument::Type: { |
| 248 | Linkage L = TA.getAsType()->getLinkage(); |
| 249 | if (!isExternallyVisible(L)) |
| 250 | return true; |
| 251 | break; |
| 252 | } |
| 253 | case TemplateArgument::Declaration: |
| 254 | if (!TA.getAsDecl()->isExternallyVisible()) |
| 255 | return true; |
| 256 | break; |
| 257 | default: |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | /// Add to the record the first template specialization from each module |
| 266 | /// file that provides a declaration of D. We store the DeclId and an |
| 267 | /// ODRHash of the template arguments of D which should provide enough |
| 268 | /// information to load D only if the template instantiator needs it. |
| 269 | void AddFirstSpecializationDeclFromEachModule( |
| 270 | const Decl *D, llvm::SmallVectorImpl<const Decl *> &SpecsInMap, |
| 271 | llvm::SmallVectorImpl<const Decl *> &PartialSpecsInMap) { |
| 272 | assert((isa<ClassTemplateSpecializationDecl>(D) || |
| 273 | isa<VarTemplateSpecializationDecl>(D) || isa<FunctionDecl>(D)) && |
| 274 | "Must not be called with other decls" ); |
| 275 | llvm::MapVector<ModuleFile *, const Decl *> Firsts; |
| 276 | CollectFirstDeclFromEachModule(D, /*IncludeLocal*/ true, Firsts); |
| 277 | |
| 278 | for (const auto &F : Firsts) { |
| 279 | if (shouldSkipWritingSpecializations(Spec: F.second)) |
| 280 | continue; |
| 281 | |
| 282 | if (isa<ClassTemplatePartialSpecializationDecl, |
| 283 | VarTemplatePartialSpecializationDecl>(Val: F.second)) |
| 284 | PartialSpecsInMap.push_back(Elt: F.second); |
| 285 | else |
| 286 | SpecsInMap.push_back(Elt: F.second); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /// Get the specialization decl from an entry in the specialization list. |
| 291 | template <typename EntryType> |
| 292 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType * |
| 293 | getSpecializationDecl(EntryType &T) { |
| 294 | return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T); |
| 295 | } |
| 296 | |
| 297 | /// Get the list of partial specializations from a template's common ptr. |
| 298 | template<typename T> |
| 299 | decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) { |
| 300 | return Common->PartialSpecializations; |
| 301 | } |
| 302 | MutableArrayRef<FunctionTemplateSpecializationInfo> |
| 303 | getPartialSpecializations(FunctionTemplateDecl::Common *) { |
| 304 | return {}; |
| 305 | } |
| 306 | |
| 307 | template<typename DeclTy> |
| 308 | void AddTemplateSpecializations(DeclTy *D) { |
| 309 | auto *Common = D->getCommonPtr(); |
| 310 | |
| 311 | // If we have any lazy specializations, and the external AST source is |
| 312 | // our chained AST reader, we can just write out the DeclIDs. Otherwise, |
| 313 | // we need to resolve them to actual declarations. |
| 314 | if (Writer.Chain != Record.getASTContext().getExternalSource() && |
| 315 | Writer.Chain && Writer.Chain->haveUnloadedSpecializations(D)) { |
| 316 | D->LoadLazySpecializations(); |
| 317 | assert(!Writer.Chain->haveUnloadedSpecializations(D)); |
| 318 | } |
| 319 | |
| 320 | // AddFirstSpecializationDeclFromEachModule might trigger deserialization, |
| 321 | // invalidating *Specializations iterators. |
| 322 | llvm::SmallVector<const Decl *, 16> AllSpecs; |
| 323 | for (auto &Entry : Common->Specializations) |
| 324 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
| 325 | for (auto &Entry : getPartialSpecializations(Common)) |
| 326 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
| 327 | |
| 328 | llvm::SmallVector<const Decl *, 16> Specs; |
| 329 | llvm::SmallVector<const Decl *, 16> PartialSpecs; |
| 330 | for (auto *D : AllSpecs) { |
| 331 | assert(D->isCanonicalDecl() && "non-canonical decl in set" ); |
| 332 | AddFirstSpecializationDeclFromEachModule(D, SpecsInMap&: Specs, PartialSpecsInMap&: PartialSpecs); |
| 333 | } |
| 334 | |
| 335 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
| 336 | D, Specializations&: Specs, /*IsPartial=*/false)); |
| 337 | |
| 338 | // Function Template Decl doesn't have partial decls. |
| 339 | if (isa<FunctionTemplateDecl>(D)) { |
| 340 | assert(PartialSpecs.empty()); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
| 345 | D, Specializations&: PartialSpecs, /*IsPartial=*/true)); |
| 346 | } |
| 347 | |
| 348 | /// Ensure that this template specialization is associated with the specified |
| 349 | /// template on reload. |
| 350 | void RegisterTemplateSpecialization(const Decl *Template, |
| 351 | const Decl *Specialization) { |
| 352 | Template = Template->getCanonicalDecl(); |
| 353 | |
| 354 | // If the canonical template is local, we'll write out this specialization |
| 355 | // when we emit it. |
| 356 | // FIXME: We can do the same thing if there is any local declaration of |
| 357 | // the template, to avoid emitting an update record. |
| 358 | if (!Template->isFromASTFile()) |
| 359 | return; |
| 360 | |
| 361 | // We only need to associate the first local declaration of the |
| 362 | // specialization. The other declarations will get pulled in by it. |
| 363 | if (Writer.getFirstLocalDecl(D: Specialization) != Specialization) |
| 364 | return; |
| 365 | |
| 366 | if (isa<ClassTemplatePartialSpecializationDecl, |
| 367 | VarTemplatePartialSpecializationDecl>(Val: Specialization)) |
| 368 | Writer.PartialSpecializationsUpdates[cast<NamedDecl>(Val: Template)] |
| 369 | .push_back(Elt: cast<NamedDecl>(Val: Specialization)); |
| 370 | else |
| 371 | Writer.SpecializationsUpdates[cast<NamedDecl>(Val: Template)].push_back( |
| 372 | Elt: cast<NamedDecl>(Val: Specialization)); |
| 373 | } |
| 374 | }; |
| 375 | } |
| 376 | |
| 377 | // When building a C++20 module interface unit or a partition unit, a |
| 378 | // strong definition in the module interface is provided by the |
| 379 | // compilation of that unit, not by its users. (Inline variables are still |
| 380 | // emitted in module users.) |
| 381 | static bool shouldVarGenerateHereOnly(const VarDecl *VD) { |
| 382 | if (VD->getStorageDuration() != SD_Static) |
| 383 | return false; |
| 384 | |
| 385 | if (VD->getDescribedVarTemplate()) |
| 386 | return false; |
| 387 | |
| 388 | Module *M = VD->getOwningModule(); |
| 389 | if (!M) |
| 390 | return false; |
| 391 | |
| 392 | M = M->getTopLevelModule(); |
| 393 | ASTContext &Ctx = VD->getASTContext(); |
| 394 | if (!M->isInterfaceOrPartition() && |
| 395 | (!VD->hasAttr<DLLExportAttr>() || |
| 396 | !Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
| 397 | return false; |
| 398 | |
| 399 | return Ctx.GetGVALinkageForVariable(VD) >= GVA_StrongExternal; |
| 400 | } |
| 401 | |
| 402 | static bool shouldFunctionGenerateHereOnly(const FunctionDecl *FD) { |
| 403 | if (FD->isDependentContext()) |
| 404 | return false; |
| 405 | |
| 406 | ASTContext &Ctx = FD->getASTContext(); |
| 407 | auto Linkage = Ctx.GetGVALinkageForFunction(FD); |
| 408 | if (Ctx.getLangOpts().ModulesCodegen || |
| 409 | (FD->hasAttr<DLLExportAttr>() && |
| 410 | Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
| 411 | // Under -fmodules-codegen, codegen is performed for all non-internal, |
| 412 | // non-always_inline functions, unless they are available elsewhere. |
| 413 | if (!FD->hasAttr<AlwaysInlineAttr>() && Linkage != GVA_Internal && |
| 414 | Linkage != GVA_AvailableExternally) |
| 415 | return true; |
| 416 | |
| 417 | Module *M = FD->getOwningModule(); |
| 418 | if (!M) |
| 419 | return false; |
| 420 | |
| 421 | M = M->getTopLevelModule(); |
| 422 | if (M->isInterfaceOrPartition()) |
| 423 | if (Linkage >= GVA_StrongExternal) |
| 424 | return true; |
| 425 | |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | bool clang::CanElideDeclDef(const Decl *D) { |
| 430 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
| 431 | if (FD->isInlined() || FD->isConstexpr() || FD->isConsteval()) |
| 432 | return false; |
| 433 | |
| 434 | // If the function should be generated somewhere else, we shouldn't elide |
| 435 | // it. |
| 436 | if (!shouldFunctionGenerateHereOnly(FD)) |
| 437 | return false; |
| 438 | } |
| 439 | |
| 440 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
| 441 | if (VD->getDeclContext()->isDependentContext()) |
| 442 | return false; |
| 443 | |
| 444 | // Constant initialized variable may not affect the ABI, but they |
| 445 | // may be used in constant evaluation in the frontend, so we have |
| 446 | // to remain them. |
| 447 | if (VD->hasConstantInitialization() || VD->isConstexpr()) |
| 448 | return false; |
| 449 | |
| 450 | // If the variable should be generated somewhere else, we shouldn't elide |
| 451 | // it. |
| 452 | if (!shouldVarGenerateHereOnly(VD)) |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | void ASTDeclWriter::Visit(Decl *D) { |
| 460 | DeclVisitor<ASTDeclWriter>::Visit(D); |
| 461 | |
| 462 | // Source locations require array (variable-length) abbreviations. The |
| 463 | // abbreviation infrastructure requires that arrays are encoded last, so |
| 464 | // we handle it here in the case of those classes derived from DeclaratorDecl |
| 465 | if (auto *DD = dyn_cast<DeclaratorDecl>(Val: D)) { |
| 466 | if (auto *TInfo = DD->getTypeSourceInfo()) |
| 467 | Record.AddTypeLoc(TL: TInfo->getTypeLoc()); |
| 468 | } |
| 469 | |
| 470 | // Handle FunctionDecl's body here and write it after all other Stmts/Exprs |
| 471 | // have been written. We want it last because we will not read it back when |
| 472 | // retrieving it from the AST, we'll just lazily set the offset. |
| 473 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
| 474 | if (!GeneratingReducedBMI || !CanElideDeclDef(D: FD)) { |
| 475 | Record.push_back(N: FD->doesThisDeclarationHaveABody()); |
| 476 | if (FD->doesThisDeclarationHaveABody()) |
| 477 | Record.AddFunctionDefinition(FD); |
| 478 | } else |
| 479 | Record.push_back(N: 0); |
| 480 | } |
| 481 | |
| 482 | // Similar to FunctionDecls, handle VarDecl's initializer here and write it |
| 483 | // after all other Stmts/Exprs. We will not read the initializer until after |
| 484 | // we have finished recursive deserialization, because it can recursively |
| 485 | // refer back to the variable. |
| 486 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
| 487 | if (!GeneratingReducedBMI || !CanElideDeclDef(D: VD)) |
| 488 | Record.AddVarDeclInit(VD); |
| 489 | else |
| 490 | Record.push_back(N: 0); |
| 491 | } |
| 492 | |
| 493 | // And similarly for FieldDecls. We already serialized whether there is a |
| 494 | // default member initializer. |
| 495 | if (auto *FD = dyn_cast<FieldDecl>(Val: D)) { |
| 496 | if (FD->hasInClassInitializer()) { |
| 497 | if (Expr *Init = FD->getInClassInitializer()) { |
| 498 | Record.push_back(N: 1); |
| 499 | Record.AddStmt(S: Init); |
| 500 | } else { |
| 501 | Record.push_back(N: 0); |
| 502 | // Initializer has not been instantiated yet. |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | // If this declaration is also a DeclContext, write blocks for the |
| 508 | // declarations that lexically stored inside its context and those |
| 509 | // declarations that are visible from its context. |
| 510 | if (auto *DC = dyn_cast<DeclContext>(Val: D)) |
| 511 | VisitDeclContext(DC); |
| 512 | } |
| 513 | |
| 514 | void ASTDeclWriter::VisitDecl(Decl *D) { |
| 515 | BitsPacker DeclBits; |
| 516 | |
| 517 | // The order matters here. It will be better to put the bit with higher |
| 518 | // probability to be 0 in the end of the bits. |
| 519 | // |
| 520 | // Since we're using VBR6 format to store it. |
| 521 | // It will be pretty effient if all the higher bits are 0. |
| 522 | // For example, if we need to pack 8 bits into a value and the stored value |
| 523 | // is 0xf0, the actual stored value will be 0b000111'110000, which takes 12 |
| 524 | // bits actually. However, if we changed the order to be 0x0f, then we can |
| 525 | // store it as 0b001111, which takes 6 bits only now. |
| 526 | DeclBits.addBits(Value: (uint64_t)D->getModuleOwnershipKind(), /*BitWidth=*/BitsWidth: 3); |
| 527 | DeclBits.addBit(Value: D->isReferenced()); |
| 528 | DeclBits.addBit(Value: D->isUsed(CheckUsedAttr: false)); |
| 529 | DeclBits.addBits(Value: D->getAccess(), /*BitWidth=*/BitsWidth: 2); |
| 530 | DeclBits.addBit(Value: D->isImplicit()); |
| 531 | DeclBits.addBit(Value: D->getDeclContext() != D->getLexicalDeclContext()); |
| 532 | DeclBits.addBit(Value: D->hasAttrs()); |
| 533 | DeclBits.addBit(Value: D->isTopLevelDeclInObjCContainer()); |
| 534 | DeclBits.addBit(Value: D->isInvalidDecl()); |
| 535 | Record.push_back(N: DeclBits); |
| 536 | |
| 537 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getDeclContext())); |
| 538 | if (D->getDeclContext() != D->getLexicalDeclContext()) |
| 539 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getLexicalDeclContext())); |
| 540 | |
| 541 | if (D->hasAttrs()) |
| 542 | Record.AddAttributes(Attrs: D->getAttrs()); |
| 543 | |
| 544 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getOwningModule())); |
| 545 | |
| 546 | // If this declaration injected a name into a context different from its |
| 547 | // lexical context, and that context is an imported namespace, we need to |
| 548 | // update its visible declarations to include this name. |
| 549 | // |
| 550 | // This happens when we instantiate a class with a friend declaration or a |
| 551 | // function with a local extern declaration, for instance. |
| 552 | // |
| 553 | // FIXME: Can we handle this in AddedVisibleDecl instead? |
| 554 | if (D->isOutOfLine()) { |
| 555 | auto *DC = D->getDeclContext(); |
| 556 | while (auto *NS = dyn_cast<NamespaceDecl>(Val: DC->getRedeclContext())) { |
| 557 | if (!NS->isFromASTFile()) |
| 558 | break; |
| 559 | Writer.UpdatedDeclContexts.insert(X: NS->getPrimaryContext()); |
| 560 | if (!NS->isInlineNamespace()) |
| 561 | break; |
| 562 | DC = NS->getParent(); |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | void ASTDeclWriter::(PragmaCommentDecl *D) { |
| 568 | StringRef Arg = D->getArg(); |
| 569 | Record.push_back(N: Arg.size()); |
| 570 | VisitDecl(D); |
| 571 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 572 | Record.push_back(N: D->getCommentKind()); |
| 573 | Record.AddString(Str: Arg); |
| 574 | Code = serialization::DECL_PRAGMA_COMMENT; |
| 575 | } |
| 576 | |
| 577 | void ASTDeclWriter::VisitPragmaDetectMismatchDecl( |
| 578 | PragmaDetectMismatchDecl *D) { |
| 579 | StringRef Name = D->getName(); |
| 580 | StringRef Value = D->getValue(); |
| 581 | Record.push_back(N: Name.size() + 1 + Value.size()); |
| 582 | VisitDecl(D); |
| 583 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 584 | Record.AddString(Str: Name); |
| 585 | Record.AddString(Str: Value); |
| 586 | Code = serialization::DECL_PRAGMA_DETECT_MISMATCH; |
| 587 | } |
| 588 | |
| 589 | void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 590 | llvm_unreachable("Translation units aren't directly serialized" ); |
| 591 | } |
| 592 | |
| 593 | void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { |
| 594 | VisitDecl(D); |
| 595 | Record.AddDeclarationName(Name: D->getDeclName()); |
| 596 | Record.push_back(N: needsAnonymousDeclarationNumber(D) |
| 597 | ? Writer.getAnonymousDeclarationNumber(D) |
| 598 | : 0); |
| 599 | } |
| 600 | |
| 601 | void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { |
| 602 | VisitNamedDecl(D); |
| 603 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 604 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
| 605 | } |
| 606 | |
| 607 | void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) { |
| 608 | VisitRedeclarable(D); |
| 609 | VisitTypeDecl(D); |
| 610 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
| 611 | Record.push_back(N: D->isModed()); |
| 612 | if (D->isModed()) |
| 613 | Record.AddTypeRef(T: D->getUnderlyingType()); |
| 614 | Record.AddDeclRef(D: D->getAnonDeclWithTypedefName(AnyRedecl: false)); |
| 615 | } |
| 616 | |
| 617 | void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { |
| 618 | VisitTypedefNameDecl(D); |
| 619 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 620 | !D->hasAttrs() && |
| 621 | !D->isImplicit() && |
| 622 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 623 | !D->isInvalidDecl() && |
| 624 | !D->isTopLevelDeclInObjCContainer() && |
| 625 | !D->isModulePrivate() && |
| 626 | !needsAnonymousDeclarationNumber(D) && |
| 627 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 628 | AbbrevToUse = Writer.getDeclTypedefAbbrev(); |
| 629 | |
| 630 | Code = serialization::DECL_TYPEDEF; |
| 631 | } |
| 632 | |
| 633 | void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 634 | VisitTypedefNameDecl(D); |
| 635 | Record.AddDeclRef(D: D->getDescribedAliasTemplate()); |
| 636 | Code = serialization::DECL_TYPEALIAS; |
| 637 | } |
| 638 | |
| 639 | void ASTDeclWriter::VisitTagDecl(TagDecl *D) { |
| 640 | static_assert(DeclContext::NumTagDeclBits == 23, |
| 641 | "You need to update the serializer after you change the " |
| 642 | "TagDeclBits" ); |
| 643 | |
| 644 | VisitRedeclarable(D); |
| 645 | VisitTypeDecl(D); |
| 646 | Record.push_back(N: D->getIdentifierNamespace()); |
| 647 | |
| 648 | BitsPacker TagDeclBits; |
| 649 | TagDeclBits.addBits(Value: llvm::to_underlying(E: D->getTagKind()), /*BitWidth=*/BitsWidth: 3); |
| 650 | TagDeclBits.addBit(Value: !isa<CXXRecordDecl>(Val: D) ? D->isCompleteDefinition() : 0); |
| 651 | TagDeclBits.addBit(Value: D->isEmbeddedInDeclarator()); |
| 652 | TagDeclBits.addBit(Value: D->isFreeStanding()); |
| 653 | TagDeclBits.addBit(Value: D->isCompleteDefinitionRequired()); |
| 654 | TagDeclBits.addBits( |
| 655 | Value: D->hasExtInfo() ? 1 : (D->getTypedefNameForAnonDecl() ? 2 : 0), |
| 656 | /*BitWidth=*/BitsWidth: 2); |
| 657 | Record.push_back(N: TagDeclBits); |
| 658 | |
| 659 | Record.AddSourceRange(Range: D->getBraceRange()); |
| 660 | |
| 661 | if (D->hasExtInfo()) { |
| 662 | Record.AddQualifierInfo(Info: *D->getExtInfo()); |
| 663 | } else if (auto *TD = D->getTypedefNameForAnonDecl()) { |
| 664 | Record.AddDeclRef(D: TD); |
| 665 | Record.AddIdentifierRef(II: TD->getDeclName().getAsIdentifierInfo()); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { |
| 670 | static_assert(DeclContext::NumEnumDeclBits == 43, |
| 671 | "You need to update the serializer after you change the " |
| 672 | "EnumDeclBits" ); |
| 673 | |
| 674 | VisitTagDecl(D); |
| 675 | Record.AddTypeSourceInfo(TInfo: D->getIntegerTypeSourceInfo()); |
| 676 | if (!D->getIntegerTypeSourceInfo()) |
| 677 | Record.AddTypeRef(T: D->getIntegerType()); |
| 678 | Record.AddTypeRef(T: D->getPromotionType()); |
| 679 | |
| 680 | BitsPacker EnumDeclBits; |
| 681 | EnumDeclBits.addBits(Value: D->getNumPositiveBits(), /*BitWidth=*/BitsWidth: 8); |
| 682 | EnumDeclBits.addBits(Value: D->getNumNegativeBits(), /*BitWidth=*/BitsWidth: 8); |
| 683 | EnumDeclBits.addBit(Value: D->isScoped()); |
| 684 | EnumDeclBits.addBit(Value: D->isScopedUsingClassTag()); |
| 685 | EnumDeclBits.addBit(Value: D->isFixed()); |
| 686 | Record.push_back(N: EnumDeclBits); |
| 687 | |
| 688 | Record.push_back(N: D->getODRHash()); |
| 689 | |
| 690 | if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { |
| 691 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 692 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 693 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 694 | } else { |
| 695 | Record.AddDeclRef(D: nullptr); |
| 696 | } |
| 697 | |
| 698 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 699 | !D->isInvalidDecl() && !D->isImplicit() && !D->hasExtInfo() && |
| 700 | !D->getTypedefNameForAnonDecl() && |
| 701 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 702 | !D->isTopLevelDeclInObjCContainer() && |
| 703 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
| 704 | !D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() && |
| 705 | !needsAnonymousDeclarationNumber(D) && |
| 706 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 707 | AbbrevToUse = Writer.getDeclEnumAbbrev(); |
| 708 | |
| 709 | Code = serialization::DECL_ENUM; |
| 710 | } |
| 711 | |
| 712 | void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { |
| 713 | static_assert(DeclContext::NumRecordDeclBits == 64, |
| 714 | "You need to update the serializer after you change the " |
| 715 | "RecordDeclBits" ); |
| 716 | |
| 717 | VisitTagDecl(D); |
| 718 | |
| 719 | BitsPacker RecordDeclBits; |
| 720 | RecordDeclBits.addBit(Value: D->hasFlexibleArrayMember()); |
| 721 | RecordDeclBits.addBit(Value: D->isAnonymousStructOrUnion()); |
| 722 | RecordDeclBits.addBit(Value: D->hasObjectMember()); |
| 723 | RecordDeclBits.addBit(Value: D->hasVolatileMember()); |
| 724 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDefaultInitialize()); |
| 725 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveCopy()); |
| 726 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDestroy()); |
| 727 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDefaultInitializeCUnion()); |
| 728 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDestructCUnion()); |
| 729 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveCopyCUnion()); |
| 730 | RecordDeclBits.addBit(Value: D->hasUninitializedExplicitInitFields()); |
| 731 | RecordDeclBits.addBit(Value: D->isParamDestroyedInCallee()); |
| 732 | RecordDeclBits.addBits(Value: llvm::to_underlying(E: D->getArgPassingRestrictions()), BitsWidth: 2); |
| 733 | Record.push_back(N: RecordDeclBits); |
| 734 | |
| 735 | // Only compute this for C/Objective-C, in C++ this is computed as part |
| 736 | // of CXXRecordDecl. |
| 737 | if (!isa<CXXRecordDecl>(Val: D)) |
| 738 | Record.push_back(N: D->getODRHash()); |
| 739 | |
| 740 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 741 | !D->isImplicit() && !D->isInvalidDecl() && !D->hasExtInfo() && |
| 742 | !D->getTypedefNameForAnonDecl() && |
| 743 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 744 | !D->isTopLevelDeclInObjCContainer() && |
| 745 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
| 746 | !needsAnonymousDeclarationNumber(D) && |
| 747 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 748 | AbbrevToUse = Writer.getDeclRecordAbbrev(); |
| 749 | |
| 750 | Code = serialization::DECL_RECORD; |
| 751 | } |
| 752 | |
| 753 | void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { |
| 754 | VisitNamedDecl(D); |
| 755 | Record.AddTypeRef(T: D->getType()); |
| 756 | } |
| 757 | |
| 758 | void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 759 | VisitValueDecl(D); |
| 760 | Record.push_back(N: D->getInitExpr()? 1 : 0); |
| 761 | if (D->getInitExpr()) |
| 762 | Record.AddStmt(S: D->getInitExpr()); |
| 763 | Record.AddAPSInt(Value: D->getInitVal()); |
| 764 | |
| 765 | Code = serialization::DECL_ENUM_CONSTANT; |
| 766 | } |
| 767 | |
| 768 | void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { |
| 769 | VisitValueDecl(D); |
| 770 | Record.AddSourceLocation(Loc: D->getInnerLocStart()); |
| 771 | Record.push_back(N: D->hasExtInfo()); |
| 772 | if (D->hasExtInfo()) { |
| 773 | DeclaratorDecl::ExtInfo *Info = D->getExtInfo(); |
| 774 | Record.AddQualifierInfo(Info: *Info); |
| 775 | Record.AddStmt( |
| 776 | S: const_cast<Expr *>(Info->TrailingRequiresClause.ConstraintExpr)); |
| 777 | Record.writeUnsignedOrNone(Value: Info->TrailingRequiresClause.ArgPackSubstIndex); |
| 778 | } |
| 779 | // The location information is deferred until the end of the record. |
| 780 | Record.AddTypeRef(T: D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType() |
| 781 | : QualType()); |
| 782 | } |
| 783 | |
| 784 | void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { |
| 785 | static_assert(DeclContext::NumFunctionDeclBits == 45, |
| 786 | "You need to update the serializer after you change the " |
| 787 | "FunctionDeclBits" ); |
| 788 | |
| 789 | VisitRedeclarable(D); |
| 790 | |
| 791 | Record.push_back(N: D->getTemplatedKind()); |
| 792 | switch (D->getTemplatedKind()) { |
| 793 | case FunctionDecl::TK_NonTemplate: |
| 794 | break; |
| 795 | case FunctionDecl::TK_DependentNonTemplate: |
| 796 | Record.AddDeclRef(D: D->getInstantiatedFromDecl()); |
| 797 | break; |
| 798 | case FunctionDecl::TK_FunctionTemplate: |
| 799 | Record.AddDeclRef(D: D->getDescribedFunctionTemplate()); |
| 800 | break; |
| 801 | case FunctionDecl::TK_MemberSpecialization: { |
| 802 | MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); |
| 803 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 804 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 805 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 806 | break; |
| 807 | } |
| 808 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 809 | FunctionTemplateSpecializationInfo * |
| 810 | FTSInfo = D->getTemplateSpecializationInfo(); |
| 811 | |
| 812 | RegisterTemplateSpecialization(Template: FTSInfo->getTemplate(), Specialization: D); |
| 813 | |
| 814 | Record.AddDeclRef(D: FTSInfo->getTemplate()); |
| 815 | Record.push_back(N: FTSInfo->getTemplateSpecializationKind()); |
| 816 | |
| 817 | // Template arguments. |
| 818 | Record.AddTemplateArgumentList(TemplateArgs: FTSInfo->TemplateArguments); |
| 819 | |
| 820 | // Template args as written. |
| 821 | Record.push_back(N: FTSInfo->TemplateArgumentsAsWritten != nullptr); |
| 822 | if (FTSInfo->TemplateArgumentsAsWritten) |
| 823 | Record.AddASTTemplateArgumentListInfo( |
| 824 | ASTTemplArgList: FTSInfo->TemplateArgumentsAsWritten); |
| 825 | |
| 826 | Record.AddSourceLocation(Loc: FTSInfo->getPointOfInstantiation()); |
| 827 | |
| 828 | if (MemberSpecializationInfo *MemberInfo = |
| 829 | FTSInfo->getMemberSpecializationInfo()) { |
| 830 | Record.push_back(N: 1); |
| 831 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 832 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 833 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 834 | } else { |
| 835 | Record.push_back(N: 0); |
| 836 | } |
| 837 | |
| 838 | if (D->isCanonicalDecl()) { |
| 839 | // Write the template that contains the specializations set. We will |
| 840 | // add a FunctionTemplateSpecializationInfo to it when reading. |
| 841 | Record.AddDeclRef(D: FTSInfo->getTemplate()->getCanonicalDecl()); |
| 842 | } |
| 843 | break; |
| 844 | } |
| 845 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 846 | DependentFunctionTemplateSpecializationInfo * |
| 847 | DFTSInfo = D->getDependentSpecializationInfo(); |
| 848 | |
| 849 | // Candidates. |
| 850 | Record.push_back(N: DFTSInfo->getCandidates().size()); |
| 851 | for (FunctionTemplateDecl *FTD : DFTSInfo->getCandidates()) |
| 852 | Record.AddDeclRef(D: FTD); |
| 853 | |
| 854 | // Templates args. |
| 855 | Record.push_back(N: DFTSInfo->TemplateArgumentsAsWritten != nullptr); |
| 856 | if (DFTSInfo->TemplateArgumentsAsWritten) |
| 857 | Record.AddASTTemplateArgumentListInfo( |
| 858 | ASTTemplArgList: DFTSInfo->TemplateArgumentsAsWritten); |
| 859 | break; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | VisitDeclaratorDecl(D); |
| 864 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 865 | Record.push_back(N: D->getIdentifierNamespace()); |
| 866 | |
| 867 | // The order matters here. It will be better to put the bit with higher |
| 868 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
| 869 | // for details. |
| 870 | BitsPacker FunctionDeclBits; |
| 871 | // FIXME: stable encoding |
| 872 | FunctionDeclBits.addBits(Value: llvm::to_underlying(E: D->getLinkageInternal()), BitsWidth: 3); |
| 873 | FunctionDeclBits.addBits(Value: (uint32_t)D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
| 874 | FunctionDeclBits.addBit(Value: D->isInlineSpecified()); |
| 875 | FunctionDeclBits.addBit(Value: D->isInlined()); |
| 876 | FunctionDeclBits.addBit(Value: D->hasSkippedBody()); |
| 877 | FunctionDeclBits.addBit(Value: D->isVirtualAsWritten()); |
| 878 | FunctionDeclBits.addBit(Value: D->isPureVirtual()); |
| 879 | FunctionDeclBits.addBit(Value: D->hasInheritedPrototype()); |
| 880 | FunctionDeclBits.addBit(Value: D->hasWrittenPrototype()); |
| 881 | FunctionDeclBits.addBit(Value: D->isDeletedBit()); |
| 882 | FunctionDeclBits.addBit(Value: D->isTrivial()); |
| 883 | FunctionDeclBits.addBit(Value: D->isTrivialForCall()); |
| 884 | FunctionDeclBits.addBit(Value: D->isDefaulted()); |
| 885 | FunctionDeclBits.addBit(Value: D->isExplicitlyDefaulted()); |
| 886 | FunctionDeclBits.addBit(Value: D->isIneligibleOrNotSelected()); |
| 887 | FunctionDeclBits.addBits(Value: (uint64_t)(D->getConstexprKind()), /*BitWidth=*/BitsWidth: 2); |
| 888 | FunctionDeclBits.addBit(Value: D->hasImplicitReturnZero()); |
| 889 | FunctionDeclBits.addBit(Value: D->isMultiVersion()); |
| 890 | FunctionDeclBits.addBit(Value: D->isLateTemplateParsed()); |
| 891 | FunctionDeclBits.addBit(Value: D->isInstantiatedFromMemberTemplate()); |
| 892 | FunctionDeclBits.addBit(Value: D->FriendConstraintRefersToEnclosingTemplate()); |
| 893 | FunctionDeclBits.addBit(Value: D->usesSEHTry()); |
| 894 | FunctionDeclBits.addBit(Value: D->isDestroyingOperatorDelete()); |
| 895 | FunctionDeclBits.addBit(Value: D->isTypeAwareOperatorNewOrDelete()); |
| 896 | Record.push_back(N: FunctionDeclBits); |
| 897 | |
| 898 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 899 | if (D->isExplicitlyDefaulted()) |
| 900 | Record.AddSourceLocation(Loc: D->getDefaultLoc()); |
| 901 | |
| 902 | Record.push_back(N: D->getODRHash()); |
| 903 | |
| 904 | if (D->isDefaulted() || D->isDeletedAsWritten()) { |
| 905 | if (auto *FDI = D->getDefalutedOrDeletedInfo()) { |
| 906 | // Store both that there is an DefaultedOrDeletedInfo and whether it |
| 907 | // contains a DeletedMessage. |
| 908 | StringLiteral *DeletedMessage = FDI->getDeletedMessage(); |
| 909 | Record.push_back(N: 1 | (DeletedMessage ? 2 : 0)); |
| 910 | if (DeletedMessage) |
| 911 | Record.AddStmt(S: DeletedMessage); |
| 912 | |
| 913 | Record.push_back(N: FDI->getUnqualifiedLookups().size()); |
| 914 | for (DeclAccessPair P : FDI->getUnqualifiedLookups()) { |
| 915 | Record.AddDeclRef(D: P.getDecl()); |
| 916 | Record.push_back(N: P.getAccess()); |
| 917 | } |
| 918 | } else { |
| 919 | Record.push_back(N: 0); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | if (D->getFriendObjectKind()) { |
| 924 | // For a friend function defined inline within a class template, we have to |
| 925 | // force the definition to be the one inside the definition of the template |
| 926 | // class. Remember this relation to deserialize them together. |
| 927 | if (auto *RD = dyn_cast<CXXRecordDecl>(Val: D->getLexicalParent()); |
| 928 | RD && isDefinitionInDependentContext(D: RD)) { |
| 929 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: RD)].push_back( |
| 930 | Elt: Writer.GetDeclRef(D)); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | Record.push_back(N: D->param_size()); |
| 935 | for (auto *P : D->parameters()) |
| 936 | Record.AddDeclRef(D: P); |
| 937 | Code = serialization::DECL_FUNCTION; |
| 938 | } |
| 939 | |
| 940 | static void addExplicitSpecifier(ExplicitSpecifier ES, |
| 941 | ASTRecordWriter &Record) { |
| 942 | uint64_t Kind = static_cast<uint64_t>(ES.getKind()); |
| 943 | Kind = Kind << 1 | static_cast<bool>(ES.getExpr()); |
| 944 | Record.push_back(N: Kind); |
| 945 | if (ES.getExpr()) { |
| 946 | Record.AddStmt(S: ES.getExpr()); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
| 951 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
| 952 | Record.AddDeclRef(D: D->Ctor); |
| 953 | VisitFunctionDecl(D); |
| 954 | Record.push_back(N: static_cast<unsigned char>(D->getDeductionCandidateKind())); |
| 955 | Record.AddDeclRef(D: D->getSourceDeductionGuide()); |
| 956 | Record.push_back( |
| 957 | N: static_cast<unsigned char>(D->getSourceDeductionGuideKind())); |
| 958 | Code = serialization::DECL_CXX_DEDUCTION_GUIDE; |
| 959 | } |
| 960 | |
| 961 | void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 962 | static_assert(DeclContext::NumObjCMethodDeclBits == 37, |
| 963 | "You need to update the serializer after you change the " |
| 964 | "ObjCMethodDeclBits" ); |
| 965 | |
| 966 | VisitNamedDecl(D); |
| 967 | // FIXME: convert to LazyStmtPtr? |
| 968 | // Unlike C/C++, method bodies will never be in header files. |
| 969 | bool HasBodyStuff = D->getBody() != nullptr; |
| 970 | Record.push_back(N: HasBodyStuff); |
| 971 | if (HasBodyStuff) { |
| 972 | Record.AddStmt(S: D->getBody()); |
| 973 | } |
| 974 | Record.AddDeclRef(D: D->getSelfDecl()); |
| 975 | Record.AddDeclRef(D: D->getCmdDecl()); |
| 976 | Record.push_back(N: D->isInstanceMethod()); |
| 977 | Record.push_back(N: D->isVariadic()); |
| 978 | Record.push_back(N: D->isPropertyAccessor()); |
| 979 | Record.push_back(N: D->isSynthesizedAccessorStub()); |
| 980 | Record.push_back(N: D->isDefined()); |
| 981 | Record.push_back(N: D->isOverriding()); |
| 982 | Record.push_back(N: D->hasSkippedBody()); |
| 983 | |
| 984 | Record.push_back(N: D->isRedeclaration()); |
| 985 | Record.push_back(N: D->hasRedeclaration()); |
| 986 | if (D->hasRedeclaration()) { |
| 987 | assert(Record.getASTContext().getObjCMethodRedeclaration(D)); |
| 988 | Record.AddDeclRef(D: Record.getASTContext().getObjCMethodRedeclaration(MD: D)); |
| 989 | } |
| 990 | |
| 991 | // FIXME: stable encoding for @required/@optional |
| 992 | Record.push_back(N: llvm::to_underlying(E: D->getImplementationControl())); |
| 993 | // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability |
| 994 | Record.push_back(N: D->getObjCDeclQualifier()); |
| 995 | Record.push_back(N: D->hasRelatedResultType()); |
| 996 | Record.AddTypeRef(T: D->getReturnType()); |
| 997 | Record.AddTypeSourceInfo(TInfo: D->getReturnTypeSourceInfo()); |
| 998 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 999 | Record.push_back(N: D->param_size()); |
| 1000 | for (const auto *P : D->parameters()) |
| 1001 | Record.AddDeclRef(D: P); |
| 1002 | |
| 1003 | Record.push_back(N: D->getSelLocsKind()); |
| 1004 | unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); |
| 1005 | SourceLocation *SelLocs = D->getStoredSelLocs(); |
| 1006 | Record.push_back(N: NumStoredSelLocs); |
| 1007 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
| 1008 | Record.AddSourceLocation(Loc: SelLocs[i]); |
| 1009 | |
| 1010 | Code = serialization::DECL_OBJC_METHOD; |
| 1011 | } |
| 1012 | |
| 1013 | void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 1014 | VisitTypedefNameDecl(D); |
| 1015 | Record.push_back(N: D->Variance); |
| 1016 | Record.push_back(N: D->Index); |
| 1017 | Record.AddSourceLocation(Loc: D->VarianceLoc); |
| 1018 | Record.AddSourceLocation(Loc: D->ColonLoc); |
| 1019 | |
| 1020 | Code = serialization::DECL_OBJC_TYPE_PARAM; |
| 1021 | } |
| 1022 | |
| 1023 | void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 1024 | static_assert(DeclContext::NumObjCContainerDeclBits == 64, |
| 1025 | "You need to update the serializer after you change the " |
| 1026 | "ObjCContainerDeclBits" ); |
| 1027 | |
| 1028 | VisitNamedDecl(D); |
| 1029 | Record.AddSourceLocation(Loc: D->getAtStartLoc()); |
| 1030 | Record.AddSourceRange(Range: D->getAtEndRange()); |
| 1031 | // Abstract class (no need to define a stable serialization::DECL code). |
| 1032 | } |
| 1033 | |
| 1034 | void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| 1035 | VisitRedeclarable(D); |
| 1036 | VisitObjCContainerDecl(D); |
| 1037 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
| 1038 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
| 1039 | |
| 1040 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1041 | if (D->isThisDeclarationADefinition()) { |
| 1042 | // Write the DefinitionData |
| 1043 | ObjCInterfaceDecl::DefinitionData &Data = D->data(); |
| 1044 | |
| 1045 | Record.AddTypeSourceInfo(TInfo: D->getSuperClassTInfo()); |
| 1046 | Record.AddSourceLocation(Loc: D->getEndOfDefinitionLoc()); |
| 1047 | Record.push_back(N: Data.HasDesignatedInitializers); |
| 1048 | Record.push_back(N: D->getODRHash()); |
| 1049 | |
| 1050 | // Write out the protocols that are directly referenced by the @interface. |
| 1051 | Record.push_back(N: Data.ReferencedProtocols.size()); |
| 1052 | for (const auto *P : D->protocols()) |
| 1053 | Record.AddDeclRef(D: P); |
| 1054 | for (const auto &PL : D->protocol_locs()) |
| 1055 | Record.AddSourceLocation(Loc: PL); |
| 1056 | |
| 1057 | // Write out the protocols that are transitively referenced. |
| 1058 | Record.push_back(N: Data.AllReferencedProtocols.size()); |
| 1059 | for (ObjCList<ObjCProtocolDecl>::iterator |
| 1060 | P = Data.AllReferencedProtocols.begin(), |
| 1061 | PEnd = Data.AllReferencedProtocols.end(); |
| 1062 | P != PEnd; ++P) |
| 1063 | Record.AddDeclRef(D: *P); |
| 1064 | |
| 1065 | |
| 1066 | if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { |
| 1067 | // Ensure that we write out the set of categories for this class. |
| 1068 | Writer.ObjCClassesWithCategories.insert(X: D); |
| 1069 | |
| 1070 | // Make sure that the categories get serialized. |
| 1071 | for (; Cat; Cat = Cat->getNextClassCategoryRaw()) |
| 1072 | (void)Writer.GetDeclRef(D: Cat); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | Code = serialization::DECL_OBJC_INTERFACE; |
| 1077 | } |
| 1078 | |
| 1079 | void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 1080 | VisitFieldDecl(D); |
| 1081 | // FIXME: stable encoding for @public/@private/@protected/@package |
| 1082 | Record.push_back(N: D->getAccessControl()); |
| 1083 | Record.push_back(N: D->getSynthesize()); |
| 1084 | |
| 1085 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1086 | !D->hasAttrs() && |
| 1087 | !D->isImplicit() && |
| 1088 | !D->isUsed(CheckUsedAttr: false) && |
| 1089 | !D->isInvalidDecl() && |
| 1090 | !D->isReferenced() && |
| 1091 | !D->isModulePrivate() && |
| 1092 | !D->getBitWidth() && |
| 1093 | !D->hasExtInfo() && |
| 1094 | D->getDeclName()) |
| 1095 | AbbrevToUse = Writer.getDeclObjCIvarAbbrev(); |
| 1096 | |
| 1097 | Code = serialization::DECL_OBJC_IVAR; |
| 1098 | } |
| 1099 | |
| 1100 | void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| 1101 | VisitRedeclarable(D); |
| 1102 | VisitObjCContainerDecl(D); |
| 1103 | |
| 1104 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1105 | if (D->isThisDeclarationADefinition()) { |
| 1106 | Record.push_back(N: D->protocol_size()); |
| 1107 | for (const auto *I : D->protocols()) |
| 1108 | Record.AddDeclRef(D: I); |
| 1109 | for (const auto &PL : D->protocol_locs()) |
| 1110 | Record.AddSourceLocation(Loc: PL); |
| 1111 | Record.push_back(N: D->getODRHash()); |
| 1112 | } |
| 1113 | |
| 1114 | Code = serialization::DECL_OBJC_PROTOCOL; |
| 1115 | } |
| 1116 | |
| 1117 | void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
| 1118 | VisitFieldDecl(D); |
| 1119 | Code = serialization::DECL_OBJC_AT_DEFS_FIELD; |
| 1120 | } |
| 1121 | |
| 1122 | void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 1123 | VisitObjCContainerDecl(D); |
| 1124 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
| 1125 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
| 1126 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
| 1127 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1128 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
| 1129 | Record.push_back(N: D->protocol_size()); |
| 1130 | for (const auto *I : D->protocols()) |
| 1131 | Record.AddDeclRef(D: I); |
| 1132 | for (const auto &PL : D->protocol_locs()) |
| 1133 | Record.AddSourceLocation(Loc: PL); |
| 1134 | Code = serialization::DECL_OBJC_CATEGORY; |
| 1135 | } |
| 1136 | |
| 1137 | void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { |
| 1138 | VisitNamedDecl(D); |
| 1139 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1140 | Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; |
| 1141 | } |
| 1142 | |
| 1143 | void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 1144 | VisitNamedDecl(D); |
| 1145 | Record.AddSourceLocation(Loc: D->getAtLoc()); |
| 1146 | Record.AddSourceLocation(Loc: D->getLParenLoc()); |
| 1147 | Record.AddTypeRef(T: D->getType()); |
| 1148 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
| 1149 | // FIXME: stable encoding |
| 1150 | Record.push_back(N: (unsigned)D->getPropertyAttributes()); |
| 1151 | Record.push_back(N: (unsigned)D->getPropertyAttributesAsWritten()); |
| 1152 | // FIXME: stable encoding |
| 1153 | Record.push_back(N: (unsigned)D->getPropertyImplementation()); |
| 1154 | Record.AddDeclarationName(Name: D->getGetterName()); |
| 1155 | Record.AddSourceLocation(Loc: D->getGetterNameLoc()); |
| 1156 | Record.AddDeclarationName(Name: D->getSetterName()); |
| 1157 | Record.AddSourceLocation(Loc: D->getSetterNameLoc()); |
| 1158 | Record.AddDeclRef(D: D->getGetterMethodDecl()); |
| 1159 | Record.AddDeclRef(D: D->getSetterMethodDecl()); |
| 1160 | Record.AddDeclRef(D: D->getPropertyIvarDecl()); |
| 1161 | Code = serialization::DECL_OBJC_PROPERTY; |
| 1162 | } |
| 1163 | |
| 1164 | void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { |
| 1165 | VisitObjCContainerDecl(D); |
| 1166 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1167 | // Abstract class (no need to define a stable serialization::DECL code). |
| 1168 | } |
| 1169 | |
| 1170 | void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 1171 | VisitObjCImplDecl(D); |
| 1172 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
| 1173 | Code = serialization::DECL_OBJC_CATEGORY_IMPL; |
| 1174 | } |
| 1175 | |
| 1176 | void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 1177 | VisitObjCImplDecl(D); |
| 1178 | Record.AddDeclRef(D: D->getSuperClass()); |
| 1179 | Record.AddSourceLocation(Loc: D->getSuperClassLoc()); |
| 1180 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
| 1181 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
| 1182 | Record.push_back(N: D->hasNonZeroConstructors()); |
| 1183 | Record.push_back(N: D->hasDestructors()); |
| 1184 | Record.push_back(N: D->NumIvarInitializers); |
| 1185 | if (D->NumIvarInitializers) |
| 1186 | Record.AddCXXCtorInitializers( |
| 1187 | CtorInits: llvm::ArrayRef(D->init_begin(), D->init_end())); |
| 1188 | Code = serialization::DECL_OBJC_IMPLEMENTATION; |
| 1189 | } |
| 1190 | |
| 1191 | void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 1192 | VisitDecl(D); |
| 1193 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1194 | Record.AddDeclRef(D: D->getPropertyDecl()); |
| 1195 | Record.AddDeclRef(D: D->getPropertyIvarDecl()); |
| 1196 | Record.AddSourceLocation(Loc: D->getPropertyIvarDeclLoc()); |
| 1197 | Record.AddDeclRef(D: D->getGetterMethodDecl()); |
| 1198 | Record.AddDeclRef(D: D->getSetterMethodDecl()); |
| 1199 | Record.AddStmt(S: D->getGetterCXXConstructor()); |
| 1200 | Record.AddStmt(S: D->getSetterCXXAssignment()); |
| 1201 | Code = serialization::DECL_OBJC_PROPERTY_IMPL; |
| 1202 | } |
| 1203 | |
| 1204 | void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { |
| 1205 | VisitDeclaratorDecl(D); |
| 1206 | Record.push_back(N: D->isMutable()); |
| 1207 | |
| 1208 | Record.push_back(N: (D->StorageKind << 1) | D->BitField); |
| 1209 | if (D->StorageKind == FieldDecl::ISK_CapturedVLAType) |
| 1210 | Record.AddTypeRef(T: QualType(D->getCapturedVLAType(), 0)); |
| 1211 | else if (D->BitField) |
| 1212 | Record.AddStmt(S: D->getBitWidth()); |
| 1213 | |
| 1214 | if (!D->getDeclName() || D->isPlaceholderVar(LangOpts: Writer.getLangOpts())) |
| 1215 | Record.AddDeclRef( |
| 1216 | D: Record.getASTContext().getInstantiatedFromUnnamedFieldDecl(Field: D)); |
| 1217 | |
| 1218 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1219 | !D->hasAttrs() && |
| 1220 | !D->isImplicit() && |
| 1221 | !D->isUsed(CheckUsedAttr: false) && |
| 1222 | !D->isInvalidDecl() && |
| 1223 | !D->isReferenced() && |
| 1224 | !D->isTopLevelDeclInObjCContainer() && |
| 1225 | !D->isModulePrivate() && |
| 1226 | !D->getBitWidth() && |
| 1227 | !D->hasInClassInitializer() && |
| 1228 | !D->hasCapturedVLAType() && |
| 1229 | !D->hasExtInfo() && |
| 1230 | !ObjCIvarDecl::classofKind(K: D->getKind()) && |
| 1231 | !ObjCAtDefsFieldDecl::classofKind(K: D->getKind()) && |
| 1232 | D->getDeclName()) |
| 1233 | AbbrevToUse = Writer.getDeclFieldAbbrev(); |
| 1234 | |
| 1235 | Code = serialization::DECL_FIELD; |
| 1236 | } |
| 1237 | |
| 1238 | void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) { |
| 1239 | VisitDeclaratorDecl(D); |
| 1240 | Record.AddIdentifierRef(II: D->getGetterId()); |
| 1241 | Record.AddIdentifierRef(II: D->getSetterId()); |
| 1242 | Code = serialization::DECL_MS_PROPERTY; |
| 1243 | } |
| 1244 | |
| 1245 | void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) { |
| 1246 | VisitValueDecl(D); |
| 1247 | MSGuidDecl::Parts Parts = D->getParts(); |
| 1248 | Record.push_back(N: Parts.Part1); |
| 1249 | Record.push_back(N: Parts.Part2); |
| 1250 | Record.push_back(N: Parts.Part3); |
| 1251 | Record.append(begin: std::begin(arr&: Parts.Part4And5), end: std::end(arr&: Parts.Part4And5)); |
| 1252 | Code = serialization::DECL_MS_GUID; |
| 1253 | } |
| 1254 | |
| 1255 | void ASTDeclWriter::VisitUnnamedGlobalConstantDecl( |
| 1256 | UnnamedGlobalConstantDecl *D) { |
| 1257 | VisitValueDecl(D); |
| 1258 | Record.AddAPValue(Value: D->getValue()); |
| 1259 | Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT; |
| 1260 | } |
| 1261 | |
| 1262 | void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { |
| 1263 | VisitValueDecl(D); |
| 1264 | Record.AddAPValue(Value: D->getValue()); |
| 1265 | Code = serialization::DECL_TEMPLATE_PARAM_OBJECT; |
| 1266 | } |
| 1267 | |
| 1268 | void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 1269 | VisitValueDecl(D); |
| 1270 | Record.push_back(N: D->getChainingSize()); |
| 1271 | |
| 1272 | for (const auto *P : D->chain()) |
| 1273 | Record.AddDeclRef(D: P); |
| 1274 | Code = serialization::DECL_INDIRECTFIELD; |
| 1275 | } |
| 1276 | |
| 1277 | void ASTDeclWriter::VisitVarDecl(VarDecl *D) { |
| 1278 | VisitRedeclarable(D); |
| 1279 | VisitDeclaratorDecl(D); |
| 1280 | |
| 1281 | // The order matters here. It will be better to put the bit with higher |
| 1282 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
| 1283 | // for details. |
| 1284 | BitsPacker VarDeclBits; |
| 1285 | VarDeclBits.addBits(Value: llvm::to_underlying(E: D->getLinkageInternal()), |
| 1286 | /*BitWidth=*/BitsWidth: 3); |
| 1287 | |
| 1288 | bool ModulesCodegen = shouldVarGenerateHereOnly(VD: D); |
| 1289 | VarDeclBits.addBit(Value: ModulesCodegen); |
| 1290 | |
| 1291 | VarDeclBits.addBits(Value: D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
| 1292 | VarDeclBits.addBits(Value: D->getTSCSpec(), /*BitWidth=*/BitsWidth: 2); |
| 1293 | VarDeclBits.addBits(Value: D->getInitStyle(), /*BitWidth=*/BitsWidth: 2); |
| 1294 | VarDeclBits.addBit(Value: D->isARCPseudoStrong()); |
| 1295 | |
| 1296 | bool HasDeducedType = false; |
| 1297 | if (!isa<ParmVarDecl>(Val: D)) { |
| 1298 | VarDeclBits.addBit(Value: D->isThisDeclarationADemotedDefinition()); |
| 1299 | VarDeclBits.addBit(Value: D->isExceptionVariable()); |
| 1300 | VarDeclBits.addBit(Value: D->isNRVOVariable()); |
| 1301 | VarDeclBits.addBit(Value: D->isCXXForRangeDecl()); |
| 1302 | |
| 1303 | VarDeclBits.addBit(Value: D->isInline()); |
| 1304 | VarDeclBits.addBit(Value: D->isInlineSpecified()); |
| 1305 | VarDeclBits.addBit(Value: D->isConstexpr()); |
| 1306 | VarDeclBits.addBit(Value: D->isInitCapture()); |
| 1307 | VarDeclBits.addBit(Value: D->isPreviousDeclInSameBlockScope()); |
| 1308 | |
| 1309 | VarDeclBits.addBit(Value: D->isEscapingByref()); |
| 1310 | HasDeducedType = D->getType()->getContainedDeducedType(); |
| 1311 | VarDeclBits.addBit(Value: HasDeducedType); |
| 1312 | |
| 1313 | if (const auto *IPD = dyn_cast<ImplicitParamDecl>(Val: D)) |
| 1314 | VarDeclBits.addBits(Value: llvm::to_underlying(E: IPD->getParameterKind()), |
| 1315 | /*Width=*/BitsWidth: 3); |
| 1316 | else |
| 1317 | VarDeclBits.addBits(Value: 0, /*Width=*/BitsWidth: 3); |
| 1318 | |
| 1319 | VarDeclBits.addBit(Value: D->isObjCForDecl()); |
| 1320 | } |
| 1321 | |
| 1322 | Record.push_back(N: VarDeclBits); |
| 1323 | |
| 1324 | if (ModulesCodegen) |
| 1325 | Writer.AddDeclRef(D, Record&: Writer.ModularCodegenDecls); |
| 1326 | |
| 1327 | if (D->hasAttr<BlocksAttr>()) { |
| 1328 | BlockVarCopyInit Init = Record.getASTContext().getBlockVarCopyInit(VD: D); |
| 1329 | Record.AddStmt(S: Init.getCopyExpr()); |
| 1330 | if (Init.getCopyExpr()) |
| 1331 | Record.push_back(N: Init.canThrow()); |
| 1332 | } |
| 1333 | |
| 1334 | enum { |
| 1335 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1336 | }; |
| 1337 | if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) { |
| 1338 | Record.push_back(N: VarTemplate); |
| 1339 | Record.AddDeclRef(D: TemplD); |
| 1340 | } else if (MemberSpecializationInfo *SpecInfo |
| 1341 | = D->getMemberSpecializationInfo()) { |
| 1342 | Record.push_back(N: StaticDataMemberSpecialization); |
| 1343 | Record.AddDeclRef(D: SpecInfo->getInstantiatedFrom()); |
| 1344 | Record.push_back(N: SpecInfo->getTemplateSpecializationKind()); |
| 1345 | Record.AddSourceLocation(Loc: SpecInfo->getPointOfInstantiation()); |
| 1346 | } else { |
| 1347 | Record.push_back(N: VarNotTemplate); |
| 1348 | } |
| 1349 | |
| 1350 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 1351 | !D->isTopLevelDeclInObjCContainer() && |
| 1352 | !needsAnonymousDeclarationNumber(D) && |
| 1353 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1354 | !D->hasExtInfo() && D->getFirstDecl() == D->getMostRecentDecl() && |
| 1355 | D->getKind() == Decl::Var && !D->isInline() && !D->isConstexpr() && |
| 1356 | !D->isInitCapture() && !D->isPreviousDeclInSameBlockScope() && |
| 1357 | !D->hasInitWithSideEffects() && !D->isEscapingByref() && |
| 1358 | !HasDeducedType && D->getStorageDuration() != SD_Static && |
| 1359 | !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() && |
| 1360 | !D->isObjCForDecl() && !isa<ImplicitParamDecl>(Val: D) && |
| 1361 | !D->isEscapingByref()) |
| 1362 | AbbrevToUse = Writer.getDeclVarAbbrev(); |
| 1363 | |
| 1364 | Code = serialization::DECL_VAR; |
| 1365 | } |
| 1366 | |
| 1367 | void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 1368 | VisitVarDecl(D); |
| 1369 | Code = serialization::DECL_IMPLICIT_PARAM; |
| 1370 | } |
| 1371 | |
| 1372 | void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { |
| 1373 | VisitVarDecl(D); |
| 1374 | |
| 1375 | // See the implementation of `ParmVarDecl::getParameterIndex()`, which may |
| 1376 | // exceed the size of the normal bitfield. So it may be better to not pack |
| 1377 | // these bits. |
| 1378 | Record.push_back(N: D->getFunctionScopeIndex()); |
| 1379 | |
| 1380 | BitsPacker ParmVarDeclBits; |
| 1381 | ParmVarDeclBits.addBit(Value: D->isObjCMethodParameter()); |
| 1382 | ParmVarDeclBits.addBits(Value: D->getFunctionScopeDepth(), /*BitsWidth=*/7); |
| 1383 | // FIXME: stable encoding |
| 1384 | ParmVarDeclBits.addBits(Value: D->getObjCDeclQualifier(), /*BitsWidth=*/7); |
| 1385 | ParmVarDeclBits.addBit(Value: D->isKNRPromoted()); |
| 1386 | ParmVarDeclBits.addBit(Value: D->hasInheritedDefaultArg()); |
| 1387 | ParmVarDeclBits.addBit(Value: D->hasUninstantiatedDefaultArg()); |
| 1388 | ParmVarDeclBits.addBit(Value: D->getExplicitObjectParamThisLoc().isValid()); |
| 1389 | Record.push_back(N: ParmVarDeclBits); |
| 1390 | |
| 1391 | if (D->hasUninstantiatedDefaultArg()) |
| 1392 | Record.AddStmt(S: D->getUninstantiatedDefaultArg()); |
| 1393 | if (D->getExplicitObjectParamThisLoc().isValid()) |
| 1394 | Record.AddSourceLocation(Loc: D->getExplicitObjectParamThisLoc()); |
| 1395 | Code = serialization::DECL_PARM_VAR; |
| 1396 | |
| 1397 | // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here |
| 1398 | // we dynamically check for the properties that we optimize for, but don't |
| 1399 | // know are true of all PARM_VAR_DECLs. |
| 1400 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 1401 | !D->hasExtInfo() && D->getStorageClass() == 0 && !D->isInvalidDecl() && |
| 1402 | !D->isTopLevelDeclInObjCContainer() && |
| 1403 | D->getInitStyle() == VarDecl::CInit && // Can params have anything else? |
| 1404 | D->getInit() == nullptr) // No default expr. |
| 1405 | AbbrevToUse = Writer.getDeclParmVarAbbrev(); |
| 1406 | |
| 1407 | // Check things we know are true of *every* PARM_VAR_DECL, which is more than |
| 1408 | // just us assuming it. |
| 1409 | assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS" ); |
| 1410 | assert(!D->isThisDeclarationADemotedDefinition() |
| 1411 | && "PARM_VAR_DECL can't be demoted definition." ); |
| 1412 | assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private" ); |
| 1413 | assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var" ); |
| 1414 | assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl" ); |
| 1415 | assert(!D->isStaticDataMember() && |
| 1416 | "PARM_VAR_DECL can't be static data member" ); |
| 1417 | } |
| 1418 | |
| 1419 | void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) { |
| 1420 | // Record the number of bindings first to simplify deserialization. |
| 1421 | Record.push_back(N: D->bindings().size()); |
| 1422 | |
| 1423 | VisitVarDecl(D); |
| 1424 | for (auto *B : D->bindings()) |
| 1425 | Record.AddDeclRef(D: B); |
| 1426 | Code = serialization::DECL_DECOMPOSITION; |
| 1427 | } |
| 1428 | |
| 1429 | void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) { |
| 1430 | VisitValueDecl(D); |
| 1431 | Record.AddStmt(S: D->getBinding()); |
| 1432 | Code = serialization::DECL_BINDING; |
| 1433 | } |
| 1434 | |
| 1435 | void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 1436 | VisitDecl(D); |
| 1437 | Record.AddStmt(S: D->getAsmStringExpr()); |
| 1438 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
| 1439 | Code = serialization::DECL_FILE_SCOPE_ASM; |
| 1440 | } |
| 1441 | |
| 1442 | void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { |
| 1443 | VisitDecl(D); |
| 1444 | Record.AddStmt(S: D->getStmt()); |
| 1445 | Code = serialization::DECL_TOP_LEVEL_STMT_DECL; |
| 1446 | } |
| 1447 | |
| 1448 | void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) { |
| 1449 | VisitDecl(D); |
| 1450 | Code = serialization::DECL_EMPTY; |
| 1451 | } |
| 1452 | |
| 1453 | void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl( |
| 1454 | LifetimeExtendedTemporaryDecl *D) { |
| 1455 | VisitDecl(D); |
| 1456 | Record.AddDeclRef(D: D->getExtendingDecl()); |
| 1457 | Record.AddStmt(S: D->getTemporaryExpr()); |
| 1458 | Record.push_back(N: static_cast<bool>(D->getValue())); |
| 1459 | if (D->getValue()) |
| 1460 | Record.AddAPValue(Value: *D->getValue()); |
| 1461 | Record.push_back(N: D->getManglingNumber()); |
| 1462 | Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY; |
| 1463 | } |
| 1464 | void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { |
| 1465 | VisitDecl(D); |
| 1466 | Record.AddStmt(S: D->getBody()); |
| 1467 | Record.AddTypeSourceInfo(TInfo: D->getSignatureAsWritten()); |
| 1468 | Record.push_back(N: D->param_size()); |
| 1469 | for (ParmVarDecl *P : D->parameters()) |
| 1470 | Record.AddDeclRef(D: P); |
| 1471 | Record.push_back(N: D->isVariadic()); |
| 1472 | Record.push_back(N: D->blockMissingReturnType()); |
| 1473 | Record.push_back(N: D->isConversionFromLambda()); |
| 1474 | Record.push_back(N: D->doesNotEscape()); |
| 1475 | Record.push_back(N: D->canAvoidCopyToHeap()); |
| 1476 | Record.push_back(N: D->capturesCXXThis()); |
| 1477 | Record.push_back(N: D->getNumCaptures()); |
| 1478 | for (const auto &capture : D->captures()) { |
| 1479 | Record.AddDeclRef(D: capture.getVariable()); |
| 1480 | |
| 1481 | unsigned flags = 0; |
| 1482 | if (capture.isByRef()) flags |= 1; |
| 1483 | if (capture.isNested()) flags |= 2; |
| 1484 | if (capture.hasCopyExpr()) flags |= 4; |
| 1485 | Record.push_back(N: flags); |
| 1486 | |
| 1487 | if (capture.hasCopyExpr()) Record.AddStmt(S: capture.getCopyExpr()); |
| 1488 | } |
| 1489 | |
| 1490 | Code = serialization::DECL_BLOCK; |
| 1491 | } |
| 1492 | |
| 1493 | void ASTDeclWriter::VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D) { |
| 1494 | Record.push_back(N: D->getNumParams()); |
| 1495 | VisitDecl(D); |
| 1496 | for (unsigned I = 0; I < D->getNumParams(); ++I) |
| 1497 | Record.AddDeclRef(D: D->getParam(i: I)); |
| 1498 | Record.push_back(N: D->isNothrow() ? 1 : 0); |
| 1499 | Record.AddStmt(S: D->getBody()); |
| 1500 | Code = serialization::DECL_OUTLINEDFUNCTION; |
| 1501 | } |
| 1502 | |
| 1503 | void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) { |
| 1504 | Record.push_back(N: CD->getNumParams()); |
| 1505 | VisitDecl(D: CD); |
| 1506 | Record.push_back(N: CD->getContextParamPosition()); |
| 1507 | Record.push_back(N: CD->isNothrow() ? 1 : 0); |
| 1508 | // Body is stored by VisitCapturedStmt. |
| 1509 | for (unsigned I = 0; I < CD->getNumParams(); ++I) |
| 1510 | Record.AddDeclRef(D: CD->getParam(i: I)); |
| 1511 | Code = serialization::DECL_CAPTURED; |
| 1512 | } |
| 1513 | |
| 1514 | void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 1515 | static_assert(DeclContext::NumLinkageSpecDeclBits == 17, |
| 1516 | "You need to update the serializer after you change the" |
| 1517 | "LinkageSpecDeclBits" ); |
| 1518 | |
| 1519 | VisitDecl(D); |
| 1520 | Record.push_back(N: llvm::to_underlying(E: D->getLanguage())); |
| 1521 | Record.AddSourceLocation(Loc: D->getExternLoc()); |
| 1522 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1523 | Code = serialization::DECL_LINKAGE_SPEC; |
| 1524 | } |
| 1525 | |
| 1526 | void ASTDeclWriter::VisitExportDecl(ExportDecl *D) { |
| 1527 | VisitDecl(D); |
| 1528 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1529 | Code = serialization::DECL_EXPORT; |
| 1530 | } |
| 1531 | |
| 1532 | void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) { |
| 1533 | VisitNamedDecl(D); |
| 1534 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1535 | Code = serialization::DECL_LABEL; |
| 1536 | } |
| 1537 | |
| 1538 | |
| 1539 | void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1540 | VisitRedeclarable(D); |
| 1541 | VisitNamedDecl(D); |
| 1542 | |
| 1543 | BitsPacker NamespaceDeclBits; |
| 1544 | NamespaceDeclBits.addBit(Value: D->isInline()); |
| 1545 | NamespaceDeclBits.addBit(Value: D->isNested()); |
| 1546 | Record.push_back(N: NamespaceDeclBits); |
| 1547 | |
| 1548 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1549 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1550 | |
| 1551 | if (D->isFirstDecl()) |
| 1552 | Record.AddDeclRef(D: D->getAnonymousNamespace()); |
| 1553 | Code = serialization::DECL_NAMESPACE; |
| 1554 | |
| 1555 | if (Writer.hasChain() && D->isAnonymousNamespace() && |
| 1556 | D == D->getMostRecentDecl()) { |
| 1557 | // This is a most recent reopening of the anonymous namespace. If its parent |
| 1558 | // is in a previous PCH (or is the TU), mark that parent for update, because |
| 1559 | // the original namespace always points to the latest re-opening of its |
| 1560 | // anonymous namespace. |
| 1561 | Decl *Parent = cast<Decl>( |
| 1562 | Val: D->getParent()->getRedeclContext()->getPrimaryContext()); |
| 1563 | if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Val: Parent)) { |
| 1564 | Writer.DeclUpdates[Parent].push_back( |
| 1565 | Elt: ASTWriter::DeclUpdate(DeclUpdateKind::CXXAddedAnonymousNamespace, D)); |
| 1566 | } |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1571 | VisitRedeclarable(D); |
| 1572 | VisitNamedDecl(D); |
| 1573 | Record.AddSourceLocation(Loc: D->getNamespaceLoc()); |
| 1574 | Record.AddSourceLocation(Loc: D->getTargetNameLoc()); |
| 1575 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1576 | Record.AddDeclRef(D: D->getNamespace()); |
| 1577 | Code = serialization::DECL_NAMESPACE_ALIAS; |
| 1578 | } |
| 1579 | |
| 1580 | void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { |
| 1581 | VisitNamedDecl(D); |
| 1582 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1583 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1584 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 1585 | Record.AddDeclRef(D: D->FirstUsingShadow.getPointer()); |
| 1586 | Record.push_back(N: D->hasTypename()); |
| 1587 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingDecl(Inst: D)); |
| 1588 | Code = serialization::DECL_USING; |
| 1589 | } |
| 1590 | |
| 1591 | void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) { |
| 1592 | VisitNamedDecl(D); |
| 1593 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1594 | Record.AddSourceLocation(Loc: D->getEnumLoc()); |
| 1595 | Record.AddTypeSourceInfo(TInfo: D->getEnumType()); |
| 1596 | Record.AddDeclRef(D: D->FirstUsingShadow.getPointer()); |
| 1597 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingEnumDecl(Inst: D)); |
| 1598 | Code = serialization::DECL_USING_ENUM; |
| 1599 | } |
| 1600 | |
| 1601 | void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1602 | Record.push_back(N: D->NumExpansions); |
| 1603 | VisitNamedDecl(D); |
| 1604 | Record.AddDeclRef(D: D->getInstantiatedFromUsingDecl()); |
| 1605 | for (auto *E : D->expansions()) |
| 1606 | Record.AddDeclRef(D: E); |
| 1607 | Code = serialization::DECL_USING_PACK; |
| 1608 | } |
| 1609 | |
| 1610 | void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 1611 | VisitRedeclarable(D); |
| 1612 | VisitNamedDecl(D); |
| 1613 | Record.AddDeclRef(D: D->getTargetDecl()); |
| 1614 | Record.push_back(N: D->getIdentifierNamespace()); |
| 1615 | Record.AddDeclRef(D: D->UsingOrNextShadow); |
| 1616 | Record.AddDeclRef( |
| 1617 | D: Record.getASTContext().getInstantiatedFromUsingShadowDecl(Inst: D)); |
| 1618 | |
| 1619 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1620 | D->getFirstDecl() == D->getMostRecentDecl() && !D->hasAttrs() && |
| 1621 | !needsAnonymousDeclarationNumber(D) && |
| 1622 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 1623 | AbbrevToUse = Writer.getDeclUsingShadowAbbrev(); |
| 1624 | |
| 1625 | Code = serialization::DECL_USING_SHADOW; |
| 1626 | } |
| 1627 | |
| 1628 | void ASTDeclWriter::VisitConstructorUsingShadowDecl( |
| 1629 | ConstructorUsingShadowDecl *D) { |
| 1630 | VisitUsingShadowDecl(D); |
| 1631 | Record.AddDeclRef(D: D->NominatedBaseClassShadowDecl); |
| 1632 | Record.AddDeclRef(D: D->ConstructedBaseClassShadowDecl); |
| 1633 | Record.push_back(N: D->IsVirtual); |
| 1634 | Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW; |
| 1635 | } |
| 1636 | |
| 1637 | void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 1638 | VisitNamedDecl(D); |
| 1639 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1640 | Record.AddSourceLocation(Loc: D->getNamespaceKeyLocation()); |
| 1641 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1642 | Record.AddDeclRef(D: D->getNominatedNamespace()); |
| 1643 | Record.AddDeclRef(D: dyn_cast<Decl>(Val: D->getCommonAncestor())); |
| 1644 | Code = serialization::DECL_USING_DIRECTIVE; |
| 1645 | } |
| 1646 | |
| 1647 | void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| 1648 | VisitValueDecl(D); |
| 1649 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1650 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1651 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 1652 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
| 1653 | Code = serialization::DECL_UNRESOLVED_USING_VALUE; |
| 1654 | } |
| 1655 | |
| 1656 | void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( |
| 1657 | UnresolvedUsingTypenameDecl *D) { |
| 1658 | VisitTypeDecl(D); |
| 1659 | Record.AddSourceLocation(Loc: D->getTypenameLoc()); |
| 1660 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1661 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
| 1662 | Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; |
| 1663 | } |
| 1664 | |
| 1665 | void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl( |
| 1666 | UnresolvedUsingIfExistsDecl *D) { |
| 1667 | VisitNamedDecl(D); |
| 1668 | Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS; |
| 1669 | } |
| 1670 | |
| 1671 | void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 1672 | VisitRecordDecl(D); |
| 1673 | |
| 1674 | enum { |
| 1675 | CXXRecNotTemplate = 0, |
| 1676 | CXXRecTemplate, |
| 1677 | CXXRecMemberSpecialization, |
| 1678 | CXXLambda |
| 1679 | }; |
| 1680 | if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { |
| 1681 | Record.push_back(N: CXXRecTemplate); |
| 1682 | Record.AddDeclRef(D: TemplD); |
| 1683 | } else if (MemberSpecializationInfo *MSInfo |
| 1684 | = D->getMemberSpecializationInfo()) { |
| 1685 | Record.push_back(N: CXXRecMemberSpecialization); |
| 1686 | Record.AddDeclRef(D: MSInfo->getInstantiatedFrom()); |
| 1687 | Record.push_back(N: MSInfo->getTemplateSpecializationKind()); |
| 1688 | Record.AddSourceLocation(Loc: MSInfo->getPointOfInstantiation()); |
| 1689 | } else if (D->isLambda()) { |
| 1690 | // For a lambda, we need some information early for merging. |
| 1691 | Record.push_back(N: CXXLambda); |
| 1692 | if (auto *Context = D->getLambdaContextDecl()) { |
| 1693 | Record.AddDeclRef(D: Context); |
| 1694 | Record.push_back(N: D->getLambdaIndexInContext()); |
| 1695 | } else { |
| 1696 | Record.push_back(N: 0); |
| 1697 | } |
| 1698 | // For lambdas inside template functions, remember the mapping to |
| 1699 | // deserialize them together. |
| 1700 | if (auto *FD = llvm::dyn_cast_or_null<FunctionDecl>(Val: D->getDeclContext()); |
| 1701 | FD && isDefinitionInDependentContext(D: FD)) { |
| 1702 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: FD)].push_back( |
| 1703 | Elt: Writer.GetDeclRef(D: D->getLambdaCallOperator())); |
| 1704 | } |
| 1705 | } else { |
| 1706 | Record.push_back(N: CXXRecNotTemplate); |
| 1707 | } |
| 1708 | |
| 1709 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1710 | if (D->isThisDeclarationADefinition()) |
| 1711 | Record.AddCXXDefinitionData(D); |
| 1712 | |
| 1713 | if (D->isCompleteDefinition() && D->isInNamedModule()) |
| 1714 | Writer.AddDeclRef(D, Record&: Writer.ModularCodegenDecls); |
| 1715 | |
| 1716 | // Store (what we currently believe to be) the key function to avoid |
| 1717 | // deserializing every method so we can compute it. |
| 1718 | // |
| 1719 | // FIXME: Avoid adding the key function if the class is defined in |
| 1720 | // module purview since in that case the key function is meaningless. |
| 1721 | if (D->isCompleteDefinition()) |
| 1722 | Record.AddDeclRef(D: Record.getASTContext().getCurrentKeyFunction(RD: D)); |
| 1723 | |
| 1724 | Code = serialization::DECL_CXX_RECORD; |
| 1725 | } |
| 1726 | |
| 1727 | void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 1728 | VisitFunctionDecl(D); |
| 1729 | if (D->isCanonicalDecl()) { |
| 1730 | Record.push_back(N: D->size_overridden_methods()); |
| 1731 | for (const CXXMethodDecl *MD : D->overridden_methods()) |
| 1732 | Record.AddDeclRef(D: MD); |
| 1733 | } else { |
| 1734 | // We only need to record overridden methods once for the canonical decl. |
| 1735 | Record.push_back(N: 0); |
| 1736 | } |
| 1737 | |
| 1738 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1739 | D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() && |
| 1740 | !D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() && |
| 1741 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1742 | !D->hasExtInfo() && !D->isExplicitlyDefaulted()) { |
| 1743 | if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate || |
| 1744 | D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate || |
| 1745 | D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization || |
| 1746 | D->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate) |
| 1747 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1748 | else if (D->getTemplatedKind() == |
| 1749 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 1750 | FunctionTemplateSpecializationInfo *FTSInfo = |
| 1751 | D->getTemplateSpecializationInfo(); |
| 1752 | |
| 1753 | if (FTSInfo->TemplateArguments->size() == 1) { |
| 1754 | const TemplateArgument &TA = FTSInfo->TemplateArguments->get(Idx: 0); |
| 1755 | if (TA.getKind() == TemplateArgument::Type && |
| 1756 | !FTSInfo->TemplateArgumentsAsWritten && |
| 1757 | !FTSInfo->getMemberSpecializationInfo()) |
| 1758 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1759 | } |
| 1760 | } else if (D->getTemplatedKind() == |
| 1761 | FunctionDecl::TK_DependentFunctionTemplateSpecialization) { |
| 1762 | DependentFunctionTemplateSpecializationInfo *DFTSInfo = |
| 1763 | D->getDependentSpecializationInfo(); |
| 1764 | if (!DFTSInfo->TemplateArgumentsAsWritten) |
| 1765 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | Code = serialization::DECL_CXX_METHOD; |
| 1770 | } |
| 1771 | |
| 1772 | void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 1773 | static_assert(DeclContext::NumCXXConstructorDeclBits == 64, |
| 1774 | "You need to update the serializer after you change the " |
| 1775 | "CXXConstructorDeclBits" ); |
| 1776 | |
| 1777 | Record.push_back(N: D->getTrailingAllocKind()); |
| 1778 | addExplicitSpecifier(ES: D->getExplicitSpecifierInternal(), Record); |
| 1779 | if (auto Inherited = D->getInheritedConstructor()) { |
| 1780 | Record.AddDeclRef(D: Inherited.getShadowDecl()); |
| 1781 | Record.AddDeclRef(D: Inherited.getConstructor()); |
| 1782 | } |
| 1783 | |
| 1784 | VisitCXXMethodDecl(D); |
| 1785 | Code = serialization::DECL_CXX_CONSTRUCTOR; |
| 1786 | } |
| 1787 | |
| 1788 | void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 1789 | VisitCXXMethodDecl(D); |
| 1790 | |
| 1791 | Record.AddDeclRef(D: D->getOperatorDelete()); |
| 1792 | if (D->getOperatorDelete()) |
| 1793 | Record.AddStmt(S: D->getOperatorDeleteThisArg()); |
| 1794 | |
| 1795 | Code = serialization::DECL_CXX_DESTRUCTOR; |
| 1796 | } |
| 1797 | |
| 1798 | void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 1799 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
| 1800 | VisitCXXMethodDecl(D); |
| 1801 | Code = serialization::DECL_CXX_CONVERSION; |
| 1802 | } |
| 1803 | |
| 1804 | void ASTDeclWriter::VisitImportDecl(ImportDecl *D) { |
| 1805 | VisitDecl(D); |
| 1806 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getImportedModule())); |
| 1807 | ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs(); |
| 1808 | Record.push_back(N: !IdentifierLocs.empty()); |
| 1809 | if (IdentifierLocs.empty()) { |
| 1810 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 1811 | Record.push_back(N: 1); |
| 1812 | } else { |
| 1813 | for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I) |
| 1814 | Record.AddSourceLocation(Loc: IdentifierLocs[I]); |
| 1815 | Record.push_back(N: IdentifierLocs.size()); |
| 1816 | } |
| 1817 | // Note: the number of source locations must always be the last element in |
| 1818 | // the record. |
| 1819 | Code = serialization::DECL_IMPORT; |
| 1820 | } |
| 1821 | |
| 1822 | void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1823 | VisitDecl(D); |
| 1824 | Record.AddSourceLocation(Loc: D->getColonLoc()); |
| 1825 | Code = serialization::DECL_ACCESS_SPEC; |
| 1826 | } |
| 1827 | |
| 1828 | void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { |
| 1829 | // Record the number of friend type template parameter lists here |
| 1830 | // so as to simplify memory allocation during deserialization. |
| 1831 | Record.push_back(N: D->NumTPLists); |
| 1832 | VisitDecl(D); |
| 1833 | bool hasFriendDecl = isa<NamedDecl *>(Val: D->Friend); |
| 1834 | Record.push_back(N: hasFriendDecl); |
| 1835 | if (hasFriendDecl) |
| 1836 | Record.AddDeclRef(D: D->getFriendDecl()); |
| 1837 | else |
| 1838 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
| 1839 | for (unsigned i = 0; i < D->NumTPLists; ++i) |
| 1840 | Record.AddTemplateParameterList(TemplateParams: D->getFriendTypeTemplateParameterList(N: i)); |
| 1841 | Record.AddDeclRef(D: D->getNextFriend()); |
| 1842 | Record.push_back(N: D->UnsupportedFriend); |
| 1843 | Record.AddSourceLocation(Loc: D->FriendLoc); |
| 1844 | Record.AddSourceLocation(Loc: D->EllipsisLoc); |
| 1845 | Code = serialization::DECL_FRIEND; |
| 1846 | } |
| 1847 | |
| 1848 | void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| 1849 | VisitDecl(D); |
| 1850 | Record.push_back(N: D->getNumTemplateParameters()); |
| 1851 | for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) |
| 1852 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameterList(i)); |
| 1853 | Record.push_back(N: D->getFriendDecl() != nullptr); |
| 1854 | if (D->getFriendDecl()) |
| 1855 | Record.AddDeclRef(D: D->getFriendDecl()); |
| 1856 | else |
| 1857 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
| 1858 | Record.AddSourceLocation(Loc: D->getFriendLoc()); |
| 1859 | Code = serialization::DECL_FRIEND_TEMPLATE; |
| 1860 | } |
| 1861 | |
| 1862 | void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { |
| 1863 | VisitNamedDecl(D); |
| 1864 | |
| 1865 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 1866 | Record.AddDeclRef(D: D->getTemplatedDecl()); |
| 1867 | } |
| 1868 | |
| 1869 | void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) { |
| 1870 | VisitTemplateDecl(D); |
| 1871 | Record.AddStmt(S: D->getConstraintExpr()); |
| 1872 | Code = serialization::DECL_CONCEPT; |
| 1873 | } |
| 1874 | |
| 1875 | void ASTDeclWriter::VisitImplicitConceptSpecializationDecl( |
| 1876 | ImplicitConceptSpecializationDecl *D) { |
| 1877 | Record.push_back(N: D->getTemplateArguments().size()); |
| 1878 | VisitDecl(D); |
| 1879 | for (const TemplateArgument &Arg : D->getTemplateArguments()) |
| 1880 | Record.AddTemplateArgument(Arg); |
| 1881 | Code = serialization::DECL_IMPLICIT_CONCEPT_SPECIALIZATION; |
| 1882 | } |
| 1883 | |
| 1884 | void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { |
| 1885 | Code = serialization::DECL_REQUIRES_EXPR_BODY; |
| 1886 | } |
| 1887 | |
| 1888 | void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
| 1889 | VisitRedeclarable(D); |
| 1890 | |
| 1891 | // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that |
| 1892 | // getCommonPtr() can be used while this is still initializing. |
| 1893 | if (D->isFirstDecl()) { |
| 1894 | // This declaration owns the 'common' pointer, so serialize that data now. |
| 1895 | Record.AddDeclRef(D: D->getInstantiatedFromMemberTemplate()); |
| 1896 | if (D->getInstantiatedFromMemberTemplate()) |
| 1897 | Record.push_back(N: D->isMemberSpecialization()); |
| 1898 | } |
| 1899 | |
| 1900 | VisitTemplateDecl(D); |
| 1901 | Record.push_back(N: D->getIdentifierNamespace()); |
| 1902 | } |
| 1903 | |
| 1904 | void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 1905 | VisitRedeclarableTemplateDecl(D); |
| 1906 | |
| 1907 | if (D->isFirstDecl()) |
| 1908 | AddTemplateSpecializations(D); |
| 1909 | |
| 1910 | // Force emitting the corresponding deduction guide in reduced BMI mode. |
| 1911 | // Otherwise, the deduction guide may be optimized out incorrectly. |
| 1912 | if (Writer.isGeneratingReducedBMI()) { |
| 1913 | auto Name = |
| 1914 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName(TD: D); |
| 1915 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
| 1916 | Writer.GetDeclRef(D: DG->getCanonicalDecl()); |
| 1917 | } |
| 1918 | |
| 1919 | Code = serialization::DECL_CLASS_TEMPLATE; |
| 1920 | } |
| 1921 | |
| 1922 | void ASTDeclWriter::VisitClassTemplateSpecializationDecl( |
| 1923 | ClassTemplateSpecializationDecl *D) { |
| 1924 | RegisterTemplateSpecialization(Template: D->getSpecializedTemplate(), Specialization: D); |
| 1925 | |
| 1926 | VisitCXXRecordDecl(D); |
| 1927 | |
| 1928 | llvm::PointerUnion<ClassTemplateDecl *, |
| 1929 | ClassTemplatePartialSpecializationDecl *> InstFrom |
| 1930 | = D->getSpecializedTemplateOrPartial(); |
| 1931 | if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) { |
| 1932 | Record.AddDeclRef(D: InstFromD); |
| 1933 | } else { |
| 1934 | Record.AddDeclRef(D: cast<ClassTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
| 1935 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
| 1936 | } |
| 1937 | |
| 1938 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
| 1939 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
| 1940 | Record.push_back(N: D->getSpecializationKind()); |
| 1941 | Record.push_back(N: D->hasStrictPackMatch()); |
| 1942 | Record.push_back(N: D->isCanonicalDecl()); |
| 1943 | |
| 1944 | if (D->isCanonicalDecl()) { |
| 1945 | // When reading, we'll add it to the folding set of the following template. |
| 1946 | Record.AddDeclRef(D: D->getSpecializedTemplate()->getCanonicalDecl()); |
| 1947 | } |
| 1948 | |
| 1949 | bool ExplicitInstantiation = |
| 1950 | D->getTemplateSpecializationKind() == |
| 1951 | TSK_ExplicitInstantiationDeclaration || |
| 1952 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
| 1953 | Record.push_back(N: ExplicitInstantiation); |
| 1954 | if (ExplicitInstantiation) { |
| 1955 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
| 1956 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
| 1957 | } |
| 1958 | |
| 1959 | const ASTTemplateArgumentListInfo *ArgsWritten = |
| 1960 | D->getTemplateArgsAsWritten(); |
| 1961 | Record.push_back(N: !!ArgsWritten); |
| 1962 | if (ArgsWritten) |
| 1963 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
| 1964 | |
| 1965 | // Mention the implicitly generated C++ deduction guide to make sure the |
| 1966 | // deduction guide will be rewritten as expected. |
| 1967 | // |
| 1968 | // FIXME: Would it be more efficient to add a callback register function |
| 1969 | // in sema to register the deduction guide? |
| 1970 | if (Writer.isWritingStdCXXNamedModules()) { |
| 1971 | auto Name = |
| 1972 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName( |
| 1973 | TD: D->getSpecializedTemplate()); |
| 1974 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
| 1975 | Writer.GetDeclRef(D: DG->getCanonicalDecl()); |
| 1976 | } |
| 1977 | |
| 1978 | Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; |
| 1979 | } |
| 1980 | |
| 1981 | void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( |
| 1982 | ClassTemplatePartialSpecializationDecl *D) { |
| 1983 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 1984 | |
| 1985 | VisitClassTemplateSpecializationDecl(D); |
| 1986 | |
| 1987 | // These are read/set from/to the first declaration. |
| 1988 | if (D->getPreviousDecl() == nullptr) { |
| 1989 | Record.AddDeclRef(D: D->getInstantiatedFromMember()); |
| 1990 | Record.push_back(N: D->isMemberSpecialization()); |
| 1991 | } |
| 1992 | |
| 1993 | Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; |
| 1994 | } |
| 1995 | |
| 1996 | void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 1997 | VisitRedeclarableTemplateDecl(D); |
| 1998 | |
| 1999 | if (D->isFirstDecl()) |
| 2000 | AddTemplateSpecializations(D); |
| 2001 | Code = serialization::DECL_VAR_TEMPLATE; |
| 2002 | } |
| 2003 | |
| 2004 | void ASTDeclWriter::VisitVarTemplateSpecializationDecl( |
| 2005 | VarTemplateSpecializationDecl *D) { |
| 2006 | RegisterTemplateSpecialization(Template: D->getSpecializedTemplate(), Specialization: D); |
| 2007 | |
| 2008 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
| 2009 | InstFrom = D->getSpecializedTemplateOrPartial(); |
| 2010 | if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) { |
| 2011 | Record.AddDeclRef(D: InstFromD); |
| 2012 | } else { |
| 2013 | Record.AddDeclRef(D: cast<VarTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
| 2014 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
| 2015 | } |
| 2016 | |
| 2017 | bool ExplicitInstantiation = |
| 2018 | D->getTemplateSpecializationKind() == |
| 2019 | TSK_ExplicitInstantiationDeclaration || |
| 2020 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
| 2021 | Record.push_back(N: ExplicitInstantiation); |
| 2022 | if (ExplicitInstantiation) { |
| 2023 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
| 2024 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
| 2025 | } |
| 2026 | |
| 2027 | const ASTTemplateArgumentListInfo *ArgsWritten = |
| 2028 | D->getTemplateArgsAsWritten(); |
| 2029 | Record.push_back(N: !!ArgsWritten); |
| 2030 | if (ArgsWritten) |
| 2031 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
| 2032 | |
| 2033 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
| 2034 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
| 2035 | Record.push_back(N: D->getSpecializationKind()); |
| 2036 | Record.push_back(N: D->IsCompleteDefinition); |
| 2037 | |
| 2038 | VisitVarDecl(D); |
| 2039 | |
| 2040 | Record.push_back(N: D->isCanonicalDecl()); |
| 2041 | |
| 2042 | if (D->isCanonicalDecl()) { |
| 2043 | // When reading, we'll add it to the folding set of the following template. |
| 2044 | Record.AddDeclRef(D: D->getSpecializedTemplate()->getCanonicalDecl()); |
| 2045 | } |
| 2046 | |
| 2047 | Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION; |
| 2048 | } |
| 2049 | |
| 2050 | void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl( |
| 2051 | VarTemplatePartialSpecializationDecl *D) { |
| 2052 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 2053 | |
| 2054 | VisitVarTemplateSpecializationDecl(D); |
| 2055 | |
| 2056 | // These are read/set from/to the first declaration. |
| 2057 | if (D->getPreviousDecl() == nullptr) { |
| 2058 | Record.AddDeclRef(D: D->getInstantiatedFromMember()); |
| 2059 | Record.push_back(N: D->isMemberSpecialization()); |
| 2060 | } |
| 2061 | |
| 2062 | Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION; |
| 2063 | } |
| 2064 | |
| 2065 | void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 2066 | VisitRedeclarableTemplateDecl(D); |
| 2067 | |
| 2068 | if (D->isFirstDecl()) |
| 2069 | AddTemplateSpecializations(D); |
| 2070 | Code = serialization::DECL_FUNCTION_TEMPLATE; |
| 2071 | } |
| 2072 | |
| 2073 | void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 2074 | Record.push_back(N: D->hasTypeConstraint()); |
| 2075 | VisitTypeDecl(D); |
| 2076 | |
| 2077 | Record.push_back(N: D->wasDeclaredWithTypename()); |
| 2078 | |
| 2079 | const TypeConstraint *TC = D->getTypeConstraint(); |
| 2080 | if (D->hasTypeConstraint()) |
| 2081 | Record.push_back(/*TypeConstraintInitialized=*/N: TC != nullptr); |
| 2082 | if (TC) { |
| 2083 | auto *CR = TC->getConceptReference(); |
| 2084 | Record.push_back(N: CR != nullptr); |
| 2085 | if (CR) |
| 2086 | Record.AddConceptReference(CR); |
| 2087 | Record.AddStmt(S: TC->getImmediatelyDeclaredConstraint()); |
| 2088 | Record.writeUnsignedOrNone(Value: TC->getArgPackSubstIndex()); |
| 2089 | Record.writeUnsignedOrNone(Value: D->getNumExpansionParameters()); |
| 2090 | } |
| 2091 | |
| 2092 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2093 | !D->defaultArgumentWasInherited(); |
| 2094 | Record.push_back(N: OwnsDefaultArg); |
| 2095 | if (OwnsDefaultArg) |
| 2096 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2097 | |
| 2098 | if (!D->hasTypeConstraint() && !OwnsDefaultArg && |
| 2099 | D->getDeclContext() == D->getLexicalDeclContext() && |
| 2100 | !D->isInvalidDecl() && !D->hasAttrs() && |
| 2101 | !D->isTopLevelDeclInObjCContainer() && !D->isImplicit() && |
| 2102 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 2103 | AbbrevToUse = Writer.getDeclTemplateTypeParmAbbrev(); |
| 2104 | |
| 2105 | Code = serialization::DECL_TEMPLATE_TYPE_PARM; |
| 2106 | } |
| 2107 | |
| 2108 | void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 2109 | // For an expanded parameter pack, record the number of expansion types here |
| 2110 | // so that it's easier for deserialization to allocate the right amount of |
| 2111 | // memory. |
| 2112 | Record.push_back(N: D->hasPlaceholderTypeConstraint()); |
| 2113 | if (D->isExpandedParameterPack()) |
| 2114 | Record.push_back(N: D->getNumExpansionTypes()); |
| 2115 | |
| 2116 | VisitDeclaratorDecl(D); |
| 2117 | // TemplateParmPosition. |
| 2118 | Record.push_back(N: D->getDepth()); |
| 2119 | Record.push_back(N: D->getPosition()); |
| 2120 | |
| 2121 | if (D->hasPlaceholderTypeConstraint()) |
| 2122 | Record.AddStmt(S: D->getPlaceholderTypeConstraint()); |
| 2123 | |
| 2124 | if (D->isExpandedParameterPack()) { |
| 2125 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
| 2126 | Record.AddTypeRef(T: D->getExpansionType(I)); |
| 2127 | Record.AddTypeSourceInfo(TInfo: D->getExpansionTypeSourceInfo(I)); |
| 2128 | } |
| 2129 | |
| 2130 | Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; |
| 2131 | } else { |
| 2132 | // Rest of NonTypeTemplateParmDecl. |
| 2133 | Record.push_back(N: D->isParameterPack()); |
| 2134 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2135 | !D->defaultArgumentWasInherited(); |
| 2136 | Record.push_back(N: OwnsDefaultArg); |
| 2137 | if (OwnsDefaultArg) |
| 2138 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2139 | Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 2144 | // For an expanded parameter pack, record the number of expansion types here |
| 2145 | // so that it's easier for deserialization to allocate the right amount of |
| 2146 | // memory. |
| 2147 | if (D->isExpandedParameterPack()) |
| 2148 | Record.push_back(N: D->getNumExpansionTemplateParameters()); |
| 2149 | |
| 2150 | VisitTemplateDecl(D); |
| 2151 | Record.push_back(N: D->wasDeclaredWithTypename()); |
| 2152 | // TemplateParmPosition. |
| 2153 | Record.push_back(N: D->getDepth()); |
| 2154 | Record.push_back(N: D->getPosition()); |
| 2155 | |
| 2156 | if (D->isExpandedParameterPack()) { |
| 2157 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2158 | I != N; ++I) |
| 2159 | Record.AddTemplateParameterList(TemplateParams: D->getExpansionTemplateParameters(I)); |
| 2160 | Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK; |
| 2161 | } else { |
| 2162 | // Rest of TemplateTemplateParmDecl. |
| 2163 | Record.push_back(N: D->isParameterPack()); |
| 2164 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2165 | !D->defaultArgumentWasInherited(); |
| 2166 | Record.push_back(N: OwnsDefaultArg); |
| 2167 | if (OwnsDefaultArg) |
| 2168 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2169 | Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2174 | VisitRedeclarableTemplateDecl(D); |
| 2175 | Code = serialization::DECL_TYPE_ALIAS_TEMPLATE; |
| 2176 | } |
| 2177 | |
| 2178 | void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2179 | VisitDecl(D); |
| 2180 | Record.AddStmt(S: D->getAssertExpr()); |
| 2181 | Record.push_back(N: D->isFailed()); |
| 2182 | Record.AddStmt(S: D->getMessage()); |
| 2183 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
| 2184 | Code = serialization::DECL_STATIC_ASSERT; |
| 2185 | } |
| 2186 | |
| 2187 | /// Emit the DeclContext part of a declaration context decl. |
| 2188 | void ASTDeclWriter::VisitDeclContext(DeclContext *DC) { |
| 2189 | static_assert(DeclContext::NumDeclContextBits == 13, |
| 2190 | "You need to update the serializer after you change the " |
| 2191 | "DeclContextBits" ); |
| 2192 | LookupBlockOffsets Offsets; |
| 2193 | |
| 2194 | if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(Val: DC) && |
| 2195 | cast<NamespaceDecl>(Val: DC)->isFromExplicitGlobalModule()) { |
| 2196 | // In reduced BMI, delay writing lexical and visible block for namespace |
| 2197 | // in the global module fragment. See the comments of DelayedNamespace for |
| 2198 | // details. |
| 2199 | Writer.DelayedNamespace.push_back(Elt: cast<NamespaceDecl>(Val: DC)); |
| 2200 | } else { |
| 2201 | Offsets.LexicalOffset = |
| 2202 | Writer.WriteDeclContextLexicalBlock(Context&: Record.getASTContext(), DC); |
| 2203 | Writer.WriteDeclContextVisibleBlock(Context&: Record.getASTContext(), DC, Offsets); |
| 2204 | } |
| 2205 | |
| 2206 | Record.AddLookupOffsets(Offsets); |
| 2207 | } |
| 2208 | |
| 2209 | const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) { |
| 2210 | assert(IsLocalDecl(D) && "expected a local declaration" ); |
| 2211 | |
| 2212 | const Decl *Canon = D->getCanonicalDecl(); |
| 2213 | if (IsLocalDecl(D: Canon)) |
| 2214 | return Canon; |
| 2215 | |
| 2216 | const Decl *&CacheEntry = FirstLocalDeclCache[Canon]; |
| 2217 | if (CacheEntry) |
| 2218 | return CacheEntry; |
| 2219 | |
| 2220 | for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl()) |
| 2221 | if (IsLocalDecl(D: Redecl)) |
| 2222 | D = Redecl; |
| 2223 | return CacheEntry = D; |
| 2224 | } |
| 2225 | |
| 2226 | template <typename T> |
| 2227 | void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { |
| 2228 | T *First = D->getFirstDecl(); |
| 2229 | T *MostRecent = First->getMostRecentDecl(); |
| 2230 | T *DAsT = static_cast<T *>(D); |
| 2231 | if (MostRecent != First) { |
| 2232 | assert(isRedeclarableDeclKind(DAsT->getKind()) && |
| 2233 | "Not considered redeclarable?" ); |
| 2234 | |
| 2235 | Record.AddDeclRef(D: First); |
| 2236 | |
| 2237 | // Write out a list of local redeclarations of this declaration if it's the |
| 2238 | // first local declaration in the chain. |
| 2239 | const Decl *FirstLocal = Writer.getFirstLocalDecl(D: DAsT); |
| 2240 | if (DAsT == FirstLocal) { |
| 2241 | // Emit a list of all imported first declarations so that we can be sure |
| 2242 | // that all redeclarations visible to this module are before D in the |
| 2243 | // redecl chain. |
| 2244 | unsigned I = Record.size(); |
| 2245 | Record.push_back(N: 0); |
| 2246 | if (Writer.Chain) |
| 2247 | AddFirstDeclFromEachModule(D: DAsT, /*IncludeLocal*/false); |
| 2248 | // This is the number of imported first declarations + 1. |
| 2249 | Record[I] = Record.size() - I; |
| 2250 | |
| 2251 | // Collect the set of local redeclarations of this declaration, from |
| 2252 | // newest to oldest. |
| 2253 | ASTWriter::RecordData LocalRedecls; |
| 2254 | ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls); |
| 2255 | for (const Decl *Prev = FirstLocal->getMostRecentDecl(); |
| 2256 | Prev != FirstLocal; Prev = Prev->getPreviousDecl()) |
| 2257 | if (!Prev->isFromASTFile()) |
| 2258 | LocalRedeclWriter.AddDeclRef(D: Prev); |
| 2259 | |
| 2260 | // If we have any redecls, write them now as a separate record preceding |
| 2261 | // the declaration itself. |
| 2262 | if (LocalRedecls.empty()) |
| 2263 | Record.push_back(N: 0); |
| 2264 | else |
| 2265 | Record.AddOffset(BitOffset: LocalRedeclWriter.Emit(Code: LOCAL_REDECLARATIONS)); |
| 2266 | } else { |
| 2267 | Record.push_back(N: 0); |
| 2268 | Record.AddDeclRef(D: FirstLocal); |
| 2269 | } |
| 2270 | |
| 2271 | // Make sure that we serialize both the previous and the most-recent |
| 2272 | // declarations, which (transitively) ensures that all declarations in the |
| 2273 | // chain get serialized. |
| 2274 | // |
| 2275 | // FIXME: This is not correct; when we reach an imported declaration we |
| 2276 | // won't emit its previous declaration. |
| 2277 | (void)Writer.GetDeclRef(D: D->getPreviousDecl()); |
| 2278 | (void)Writer.GetDeclRef(D: MostRecent); |
| 2279 | } else { |
| 2280 | // We use the sentinel value 0 to indicate an only declaration. |
| 2281 | Record.push_back(N: 0); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl *D) { |
| 2286 | VisitNamedDecl(D); |
| 2287 | VisitDeclContext(DC: D); |
| 2288 | Record.push_back(N: D->isCBuffer()); |
| 2289 | Record.AddSourceLocation(Loc: D->getLocStart()); |
| 2290 | Record.AddSourceLocation(Loc: D->getLBraceLoc()); |
| 2291 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 2292 | |
| 2293 | Code = serialization::DECL_HLSL_BUFFER; |
| 2294 | } |
| 2295 | |
| 2296 | void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2297 | Record.writeOMPChildren(Data: D->Data); |
| 2298 | VisitDecl(D); |
| 2299 | Code = serialization::DECL_OMP_THREADPRIVATE; |
| 2300 | } |
| 2301 | |
| 2302 | void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
| 2303 | Record.writeOMPChildren(Data: D->Data); |
| 2304 | VisitDecl(D); |
| 2305 | Code = serialization::DECL_OMP_ALLOCATE; |
| 2306 | } |
| 2307 | |
| 2308 | void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) { |
| 2309 | Record.writeOMPChildren(Data: D->Data); |
| 2310 | VisitDecl(D); |
| 2311 | Code = serialization::DECL_OMP_REQUIRES; |
| 2312 | } |
| 2313 | |
| 2314 | void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
| 2315 | static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15, |
| 2316 | "You need to update the serializer after you change the " |
| 2317 | "NumOMPDeclareReductionDeclBits" ); |
| 2318 | |
| 2319 | VisitValueDecl(D); |
| 2320 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 2321 | Record.AddStmt(S: D->getCombinerIn()); |
| 2322 | Record.AddStmt(S: D->getCombinerOut()); |
| 2323 | Record.AddStmt(S: D->getCombiner()); |
| 2324 | Record.AddStmt(S: D->getInitOrig()); |
| 2325 | Record.AddStmt(S: D->getInitPriv()); |
| 2326 | Record.AddStmt(S: D->getInitializer()); |
| 2327 | Record.push_back(N: llvm::to_underlying(E: D->getInitializerKind())); |
| 2328 | Record.AddDeclRef(D: D->getPrevDeclInScope()); |
| 2329 | Code = serialization::DECL_OMP_DECLARE_REDUCTION; |
| 2330 | } |
| 2331 | |
| 2332 | void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
| 2333 | Record.writeOMPChildren(Data: D->Data); |
| 2334 | VisitValueDecl(D); |
| 2335 | Record.AddDeclarationName(Name: D->getVarName()); |
| 2336 | Record.AddDeclRef(D: D->getPrevDeclInScope()); |
| 2337 | Code = serialization::DECL_OMP_DECLARE_MAPPER; |
| 2338 | } |
| 2339 | |
| 2340 | void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
| 2341 | VisitVarDecl(D); |
| 2342 | Code = serialization::DECL_OMP_CAPTUREDEXPR; |
| 2343 | } |
| 2344 | |
| 2345 | void ASTDeclWriter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) { |
| 2346 | Record.writeUInt32(Value: D->clauses().size()); |
| 2347 | VisitDecl(D); |
| 2348 | Record.writeEnum(value: D->DirKind); |
| 2349 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
| 2350 | Record.AddSourceLocation(Loc: D->EndLoc); |
| 2351 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
| 2352 | Code = serialization::DECL_OPENACC_DECLARE; |
| 2353 | } |
| 2354 | void ASTDeclWriter::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) { |
| 2355 | Record.writeUInt32(Value: D->clauses().size()); |
| 2356 | VisitDecl(D); |
| 2357 | Record.writeEnum(value: D->DirKind); |
| 2358 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
| 2359 | Record.AddSourceLocation(Loc: D->EndLoc); |
| 2360 | Record.AddSourceRange(Range: D->ParensLoc); |
| 2361 | Record.AddStmt(S: D->FuncRef); |
| 2362 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
| 2363 | Code = serialization::DECL_OPENACC_ROUTINE; |
| 2364 | } |
| 2365 | |
| 2366 | //===----------------------------------------------------------------------===// |
| 2367 | // ASTWriter Implementation |
| 2368 | //===----------------------------------------------------------------------===// |
| 2369 | |
| 2370 | namespace { |
| 2371 | template <FunctionDecl::TemplatedKind Kind> |
| 2372 | std::shared_ptr<llvm::BitCodeAbbrev> |
| 2373 | getFunctionDeclAbbrev(serialization::DeclCode Code) { |
| 2374 | using namespace llvm; |
| 2375 | |
| 2376 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
| 2377 | Abv->Add(OpInfo: BitCodeAbbrevOp(Code)); |
| 2378 | // RedeclarableDecl |
| 2379 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // CanonicalDecl |
| 2380 | Abv->Add(OpInfo: BitCodeAbbrevOp(Kind)); |
| 2381 | if constexpr (Kind == FunctionDecl::TK_NonTemplate) { |
| 2382 | |
| 2383 | } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) { |
| 2384 | // DescribedFunctionTemplate |
| 2385 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2386 | } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) { |
| 2387 | // Instantiated From Decl |
| 2388 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2389 | } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) { |
| 2390 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom |
| 2391 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2392 | 3)); // TemplateSpecializationKind |
| 2393 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location |
| 2394 | } else if constexpr (Kind == |
| 2395 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2396 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template |
| 2397 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2398 | 3)); // TemplateSpecializationKind |
| 2399 | Abv->Add(OpInfo: BitCodeAbbrevOp(1)); // Template Argument Size |
| 2400 | Abv->Add(OpInfo: BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind |
| 2401 | Abv->Add( |
| 2402 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type |
| 2403 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted |
| 2404 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
| 2405 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2406 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2407 | Abv->Add( |
| 2408 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template |
| 2409 | } else if constexpr (Kind == FunctionDecl:: |
| 2410 | TK_DependentFunctionTemplateSpecialization) { |
| 2411 | // Candidates of specialization |
| 2412 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2413 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
| 2414 | } else { |
| 2415 | llvm_unreachable("Unknown templated kind?" ); |
| 2416 | } |
| 2417 | // Decl |
| 2418 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2419 | 8)); // Packed DeclBits: ModuleOwnershipKind, |
| 2420 | // isUsed, isReferenced, AccessSpecifier, |
| 2421 | // isImplicit |
| 2422 | // |
| 2423 | // The following bits should be 0: |
| 2424 | // HasStandaloneLexicalDC, HasAttrs, |
| 2425 | // TopLevelDeclInObjCContainer, |
| 2426 | // isInvalidDecl |
| 2427 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2428 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2429 | // NamedDecl |
| 2430 | Abv->Add(OpInfo: BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind |
| 2431 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier |
| 2432 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2433 | // ValueDecl |
| 2434 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2435 | // DeclaratorDecl |
| 2436 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart |
| 2437 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // HasExtInfo |
| 2438 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2439 | // FunctionDecl |
| 2440 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
| 2441 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2442 | BitCodeAbbrevOp::Fixed, |
| 2443 | 28)); // Packed Function Bits: StorageClass, Inline, InlineSpecified, |
| 2444 | // VirtualAsWritten, Pure, HasInheritedProto, HasWrittenProto, |
| 2445 | // Deleted, Trivial, TrivialForCall, Defaulted, ExplicitlyDefaulted, |
| 2446 | // IsIneligibleOrNotSelected, ImplicitReturnZero, Constexpr, |
| 2447 | // UsesSEHTry, SkippedBody, MultiVersion, LateParsed, |
| 2448 | // FriendConstraintRefersToEnclosingTemplate, Linkage, |
| 2449 | // ShouldSkipCheckingODR |
| 2450 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd |
| 2451 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash |
| 2452 | // This Array slurps the rest of the record. Fortunately we want to encode |
| 2453 | // (nearly) all the remaining (variable number of) fields in the same way. |
| 2454 | // |
| 2455 | // This is: |
| 2456 | // NumParams and Params[] from FunctionDecl, and |
| 2457 | // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl. |
| 2458 | // |
| 2459 | // Add an AbbrevOp for 'size then elements' and use it here. |
| 2460 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2461 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2462 | return Abv; |
| 2463 | } |
| 2464 | |
| 2465 | template <FunctionDecl::TemplatedKind Kind> |
| 2466 | std::shared_ptr<llvm::BitCodeAbbrev> getCXXMethodAbbrev() { |
| 2467 | return getFunctionDeclAbbrev<Kind>(serialization::DECL_CXX_METHOD); |
| 2468 | } |
| 2469 | } // namespace |
| 2470 | |
| 2471 | void ASTWriter::WriteDeclAbbrevs() { |
| 2472 | using namespace llvm; |
| 2473 | |
| 2474 | std::shared_ptr<BitCodeAbbrev> Abv; |
| 2475 | |
| 2476 | // Abbreviation for DECL_FIELD |
| 2477 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2478 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_FIELD)); |
| 2479 | // Decl |
| 2480 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2481 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2482 | // isUsed, isReferenced, AccessSpecifier, |
| 2483 | // |
| 2484 | // The following bits should be 0: |
| 2485 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2486 | // TopLevelDeclInObjCContainer, |
| 2487 | // isInvalidDecl |
| 2488 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2489 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2490 | // NamedDecl |
| 2491 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2492 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2493 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2494 | // ValueDecl |
| 2495 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2496 | // DeclaratorDecl |
| 2497 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2498 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2499 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2500 | // FieldDecl |
| 2501 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
| 2502 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // StorageKind |
| 2503 | // Type Source Info |
| 2504 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2505 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2506 | DeclFieldAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2507 | |
| 2508 | // Abbreviation for DECL_OBJC_IVAR |
| 2509 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2510 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR)); |
| 2511 | // Decl |
| 2512 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2513 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2514 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2515 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2516 | // AccessSpecifier, ModuleOwnershipKind |
| 2517 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2518 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2519 | // NamedDecl |
| 2520 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2521 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2522 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2523 | // ValueDecl |
| 2524 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2525 | // DeclaratorDecl |
| 2526 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2527 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2528 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2529 | // FieldDecl |
| 2530 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
| 2531 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // InitStyle |
| 2532 | // ObjC Ivar |
| 2533 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl |
| 2534 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize |
| 2535 | // Type Source Info |
| 2536 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2537 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2538 | DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2539 | |
| 2540 | // Abbreviation for DECL_ENUM |
| 2541 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2542 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_ENUM)); |
| 2543 | // Redeclarable |
| 2544 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2545 | // Decl |
| 2546 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2547 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2548 | // isUsed, isReferenced, AccessSpecifier, |
| 2549 | // |
| 2550 | // The following bits should be 0: |
| 2551 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2552 | // TopLevelDeclInObjCContainer, |
| 2553 | // isInvalidDecl |
| 2554 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2555 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2556 | // NamedDecl |
| 2557 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2558 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2559 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2560 | // TypeDecl |
| 2561 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2562 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2563 | // TagDecl |
| 2564 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
| 2565 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2566 | BitCodeAbbrevOp::Fixed, |
| 2567 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
| 2568 | // EmbeddedInDeclarator, IsFreeStanding, |
| 2569 | // isCompleteDefinitionRequired, ExtInfoKind |
| 2570 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2571 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2572 | // EnumDecl |
| 2573 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef |
| 2574 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType |
| 2575 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType |
| 2576 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits |
| 2577 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash |
| 2578 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum |
| 2579 | // DC |
| 2580 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
| 2581 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
| 2582 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
| 2583 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
| 2584 | DeclEnumAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2585 | |
| 2586 | // Abbreviation for DECL_RECORD |
| 2587 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2588 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_RECORD)); |
| 2589 | // Redeclarable |
| 2590 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2591 | // Decl |
| 2592 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2593 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2594 | // isUsed, isReferenced, AccessSpecifier, |
| 2595 | // |
| 2596 | // The following bits should be 0: |
| 2597 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2598 | // TopLevelDeclInObjCContainer, |
| 2599 | // isInvalidDecl |
| 2600 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2601 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2602 | // NamedDecl |
| 2603 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2604 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2605 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2606 | // TypeDecl |
| 2607 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2608 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2609 | // TagDecl |
| 2610 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
| 2611 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2612 | BitCodeAbbrevOp::Fixed, |
| 2613 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
| 2614 | // EmbeddedInDeclarator, IsFreeStanding, |
| 2615 | // isCompleteDefinitionRequired, ExtInfoKind |
| 2616 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2617 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2618 | // RecordDecl |
| 2619 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2620 | BitCodeAbbrevOp::Fixed, |
| 2621 | 14)); // Packed Record Decl Bits: FlexibleArrayMember, |
| 2622 | // AnonymousStructUnion, hasObjectMember, hasVolatileMember, |
| 2623 | // isNonTrivialToPrimitiveDefaultInitialize, |
| 2624 | // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy, |
| 2625 | // hasNonTrivialToPrimitiveDefaultInitializeCUnion, |
| 2626 | // hasNonTrivialToPrimitiveDestructCUnion, |
| 2627 | // hasNonTrivialToPrimitiveCopyCUnion, |
| 2628 | // hasUninitializedExplicitInitFields, isParamDestroyedInCallee, |
| 2629 | // getArgPassingRestrictions |
| 2630 | // ODRHash |
| 2631 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26)); |
| 2632 | |
| 2633 | // DC |
| 2634 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
| 2635 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
| 2636 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
| 2637 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
| 2638 | DeclRecordAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2639 | |
| 2640 | // Abbreviation for DECL_PARM_VAR |
| 2641 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2642 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); |
| 2643 | // Redeclarable |
| 2644 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2645 | // Decl |
| 2646 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2647 | 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed, |
| 2648 | // isReferenced, AccessSpecifier, |
| 2649 | // HasStandaloneLexicalDC, HasAttrs, isImplicit, |
| 2650 | // TopLevelDeclInObjCContainer, |
| 2651 | // isInvalidDecl, |
| 2652 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2653 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2654 | // NamedDecl |
| 2655 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2656 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2657 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2658 | // ValueDecl |
| 2659 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2660 | // DeclaratorDecl |
| 2661 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2662 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2663 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2664 | // VarDecl |
| 2665 | Abv->Add( |
| 2666 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2667 | 12)); // Packed Var Decl bits: SClass, TSCSpec, InitStyle, |
| 2668 | // isARCPseudoStrong, Linkage, ModulesCodegen |
| 2669 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
| 2670 | // ParmVarDecl |
| 2671 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex |
| 2672 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2673 | BitCodeAbbrevOp::Fixed, |
| 2674 | 19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth, |
| 2675 | // ObjCDeclQualifier, KNRPromoted, |
| 2676 | // HasInheritedDefaultArg, HasUninstantiatedDefaultArg |
| 2677 | // Type Source Info |
| 2678 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2679 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2680 | DeclParmVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2681 | |
| 2682 | // Abbreviation for DECL_TYPEDEF |
| 2683 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2684 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); |
| 2685 | // Redeclarable |
| 2686 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2687 | // Decl |
| 2688 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2689 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2690 | // isReferenced, isUsed, AccessSpecifier. Other |
| 2691 | // higher bits should be 0: isImplicit, |
| 2692 | // HasStandaloneLexicalDC, HasAttrs, |
| 2693 | // TopLevelDeclInObjCContainer, isInvalidDecl |
| 2694 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2695 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2696 | // NamedDecl |
| 2697 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2698 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2699 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2700 | // TypeDecl |
| 2701 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2702 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2703 | // TypedefDecl |
| 2704 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2705 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2706 | DeclTypedefAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2707 | |
| 2708 | // Abbreviation for DECL_VAR |
| 2709 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2710 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_VAR)); |
| 2711 | // Redeclarable |
| 2712 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2713 | // Decl |
| 2714 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2715 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2716 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2717 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2718 | // AccessSpecifier, ModuleOwnershipKind |
| 2719 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2720 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2721 | // NamedDecl |
| 2722 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2723 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2724 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2725 | // ValueDecl |
| 2726 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2727 | // DeclaratorDecl |
| 2728 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2729 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2730 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2731 | // VarDecl |
| 2732 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2733 | BitCodeAbbrevOp::Fixed, |
| 2734 | 22)); // Packed Var Decl bits: Linkage, ModulesCodegen, |
| 2735 | // SClass, TSCSpec, InitStyle, |
| 2736 | // isARCPseudoStrong, IsThisDeclarationADemotedDefinition, |
| 2737 | // isExceptionVariable, isNRVOVariable, isCXXForRangeDecl, |
| 2738 | // isInline, isInlineSpecified, isConstexpr, |
| 2739 | // isInitCapture, isPrevDeclInSameScope, hasInitWithSideEffects, |
| 2740 | // EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl |
| 2741 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
| 2742 | // Type Source Info |
| 2743 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2744 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2745 | DeclVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2746 | |
| 2747 | // Abbreviation for DECL_CXX_METHOD |
| 2748 | DeclCXXMethodAbbrev = |
| 2749 | Stream.EmitAbbrev(Abbv: getCXXMethodAbbrev<FunctionDecl::TK_NonTemplate>()); |
| 2750 | DeclTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2751 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplate>()); |
| 2752 | DeclDependentNonTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2753 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_DependentNonTemplate>()); |
| 2754 | DeclMemberSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2755 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_MemberSpecialization>()); |
| 2756 | DeclTemplateSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2757 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplateSpecialization>()); |
| 2758 | DeclDependentSpecializationCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2759 | Abbv: getCXXMethodAbbrev< |
| 2760 | FunctionDecl::TK_DependentFunctionTemplateSpecialization>()); |
| 2761 | |
| 2762 | // Abbreviation for DECL_TEMPLATE_TYPE_PARM |
| 2763 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2764 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TEMPLATE_TYPE_PARM)); |
| 2765 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasTypeConstraint |
| 2766 | // Decl |
| 2767 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2768 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2769 | // isReferenced, isUsed, AccessSpecifier. Other |
| 2770 | // higher bits should be 0: isImplicit, |
| 2771 | // HasStandaloneLexicalDC, HasAttrs, |
| 2772 | // TopLevelDeclInObjCContainer, isInvalidDecl |
| 2773 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2774 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2775 | // NamedDecl |
| 2776 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2777 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2778 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2779 | // TypeDecl |
| 2780 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2781 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2782 | // TemplateTypeParmDecl |
| 2783 | Abv->Add( |
| 2784 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename |
| 2785 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // OwnsDefaultArg |
| 2786 | DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2787 | |
| 2788 | // Abbreviation for DECL_USING_SHADOW |
| 2789 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2790 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_USING_SHADOW)); |
| 2791 | // Redeclarable |
| 2792 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2793 | // Decl |
| 2794 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2795 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2796 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2797 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2798 | // AccessSpecifier, ModuleOwnershipKind |
| 2799 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2800 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2801 | // NamedDecl |
| 2802 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2803 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2804 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2805 | // UsingShadowDecl |
| 2806 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl |
| 2807 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
| 2808 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow |
| 2809 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, |
| 2810 | 6)); // InstantiatedFromUsingShadowDecl |
| 2811 | DeclUsingShadowAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2812 | |
| 2813 | // Abbreviation for EXPR_DECL_REF |
| 2814 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2815 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); |
| 2816 | // Stmt |
| 2817 | // Expr |
| 2818 | // PackingBits: DependenceKind, ValueKind. ObjectKind should be 0. |
| 2819 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); |
| 2820 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2821 | // DeclRefExpr |
| 2822 | // Packing Bits: , HadMultipleCandidates, RefersToEnclosingVariableOrCapture, |
| 2823 | // IsImmediateEscalating, NonOdrUseReason. |
| 2824 | // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0. |
| 2825 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2826 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef |
| 2827 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2828 | DeclRefExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2829 | |
| 2830 | // Abbreviation for EXPR_INTEGER_LITERAL |
| 2831 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2832 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL)); |
| 2833 | //Stmt |
| 2834 | // Expr |
| 2835 | // DependenceKind, ValueKind, ObjectKind |
| 2836 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2837 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2838 | // Integer Literal |
| 2839 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2840 | Abv->Add(OpInfo: BitCodeAbbrevOp(32)); // Bit Width |
| 2841 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value |
| 2842 | IntegerLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2843 | |
| 2844 | // Abbreviation for EXPR_CHARACTER_LITERAL |
| 2845 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2846 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL)); |
| 2847 | //Stmt |
| 2848 | // Expr |
| 2849 | // DependenceKind, ValueKind, ObjectKind |
| 2850 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2851 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2852 | // Character Literal |
| 2853 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue |
| 2854 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2855 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind |
| 2856 | CharacterLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2857 | |
| 2858 | // Abbreviation for EXPR_IMPLICIT_CAST |
| 2859 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2860 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST)); |
| 2861 | // Stmt |
| 2862 | // Expr |
| 2863 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2864 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2865 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2866 | // CastExpr |
| 2867 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // PathSize |
| 2868 | // Packing Bits: CastKind, StoredFPFeatures, isPartOfExplicitCast |
| 2869 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 9)); |
| 2870 | // ImplicitCastExpr |
| 2871 | ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2872 | |
| 2873 | // Abbreviation for EXPR_BINARY_OPERATOR |
| 2874 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2875 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_BINARY_OPERATOR)); |
| 2876 | // Stmt |
| 2877 | // Expr |
| 2878 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
| 2879 | // be 0 in this case. |
| 2880 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2881 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2882 | // BinaryOperator |
| 2883 | Abv->Add( |
| 2884 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
| 2885 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2886 | BinaryOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2887 | |
| 2888 | // Abbreviation for EXPR_COMPOUND_ASSIGN_OPERATOR |
| 2889 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2890 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_COMPOUND_ASSIGN_OPERATOR)); |
| 2891 | // Stmt |
| 2892 | // Expr |
| 2893 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
| 2894 | // be 0 in this case. |
| 2895 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2896 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2897 | // BinaryOperator |
| 2898 | // Packing Bits: OpCode. The HasFPFeatures bit should be 0 |
| 2899 | Abv->Add( |
| 2900 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
| 2901 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2902 | // CompoundAssignOperator |
| 2903 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHSType |
| 2904 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Result Type |
| 2905 | CompoundAssignOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2906 | |
| 2907 | // Abbreviation for EXPR_CALL |
| 2908 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2909 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CALL)); |
| 2910 | // Stmt |
| 2911 | // Expr |
| 2912 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2913 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2914 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2915 | // CallExpr |
| 2916 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2917 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2918 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2919 | CallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2920 | |
| 2921 | // Abbreviation for EXPR_CXX_OPERATOR_CALL |
| 2922 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2923 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_OPERATOR_CALL)); |
| 2924 | // Stmt |
| 2925 | // Expr |
| 2926 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2927 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2928 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2929 | // CallExpr |
| 2930 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2931 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2932 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2933 | // CXXOperatorCallExpr |
| 2934 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind |
| 2935 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2936 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2937 | CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2938 | |
| 2939 | // Abbreviation for EXPR_CXX_MEMBER_CALL |
| 2940 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2941 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_MEMBER_CALL)); |
| 2942 | // Stmt |
| 2943 | // Expr |
| 2944 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2945 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2946 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2947 | // CallExpr |
| 2948 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2949 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2950 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2951 | // CXXMemberCallExpr |
| 2952 | CXXMemberCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2953 | |
| 2954 | // Abbreviation for STMT_COMPOUND |
| 2955 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2956 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::STMT_COMPOUND)); |
| 2957 | // Stmt |
| 2958 | // CompoundStmt |
| 2959 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Num Stmts |
| 2960 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasStoredFPFeatures |
| 2961 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2962 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2963 | CompoundStmtAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2964 | |
| 2965 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2966 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); |
| 2967 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2968 | DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2969 | |
| 2970 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2971 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); |
| 2972 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2973 | DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2974 | |
| 2975 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2976 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_MODULE_LOCAL_VISIBLE)); |
| 2977 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2978 | DeclModuleLocalVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2979 | |
| 2980 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2981 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_TU_LOCAL_VISIBLE)); |
| 2982 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2983 | DeclTULocalLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2984 | |
| 2985 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2986 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_SPECIALIZATIONS)); |
| 2987 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2988 | DeclSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2989 | |
| 2990 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2991 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARTIAL_SPECIALIZATIONS)); |
| 2992 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2993 | DeclPartialSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2994 | } |
| 2995 | |
| 2996 | /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by |
| 2997 | /// consumers of the AST. |
| 2998 | /// |
| 2999 | /// Such decls will always be deserialized from the AST file, so we would like |
| 3000 | /// this to be as restrictive as possible. Currently the predicate is driven by |
| 3001 | /// code generation requirements, if other clients have a different notion of |
| 3002 | /// what is "required" then we may have to consider an alternate scheme where |
| 3003 | /// clients can iterate over the top-level decls and get information on them, |
| 3004 | /// without necessary deserializing them. We could explicitly require such |
| 3005 | /// clients to use a separate API call to "realize" the decl. This should be |
| 3006 | /// relatively painless since they would presumably only do it for top-level |
| 3007 | /// decls. |
| 3008 | static bool isRequiredDecl(const Decl *D, ASTContext &Context, |
| 3009 | Module *WritingModule) { |
| 3010 | // Named modules have different semantics than header modules. Every named |
| 3011 | // module units owns a translation unit. So the importer of named modules |
| 3012 | // doesn't need to deserilize everything ahead of time. |
| 3013 | if (WritingModule && WritingModule->isNamedModule()) { |
| 3014 | // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension. |
| 3015 | // And the behavior of MSVC for such cases will leak this to the module |
| 3016 | // users. Given pragma is not a standard thing, the compiler has the space |
| 3017 | // to do their own decision. Let's follow MSVC here. |
| 3018 | if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(Val: D)) |
| 3019 | return true; |
| 3020 | return false; |
| 3021 | } |
| 3022 | |
| 3023 | // An ObjCMethodDecl is never considered as "required" because its |
| 3024 | // implementation container always is. |
| 3025 | |
| 3026 | // File scoped assembly or obj-c or OMP declare target implementation must be |
| 3027 | // seen. |
| 3028 | if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(Val: D)) |
| 3029 | return true; |
| 3030 | |
| 3031 | if (WritingModule && isPartOfPerModuleInitializer(D)) { |
| 3032 | // These declarations are part of the module initializer, and are emitted |
| 3033 | // if and when the module is imported, rather than being emitted eagerly. |
| 3034 | return false; |
| 3035 | } |
| 3036 | |
| 3037 | return Context.DeclMustBeEmitted(D); |
| 3038 | } |
| 3039 | |
| 3040 | void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { |
| 3041 | PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(), |
| 3042 | "serializing" ); |
| 3043 | |
| 3044 | // Determine the ID for this declaration. |
| 3045 | LocalDeclID ID; |
| 3046 | assert(!D->isFromASTFile() && "should not be emitting imported decl" ); |
| 3047 | LocalDeclID &IDR = DeclIDs[D]; |
| 3048 | if (IDR.isInvalid()) |
| 3049 | IDR = NextDeclID++; |
| 3050 | |
| 3051 | ID = IDR; |
| 3052 | |
| 3053 | assert(ID >= FirstDeclID && "invalid decl ID" ); |
| 3054 | |
| 3055 | RecordData Record; |
| 3056 | ASTDeclWriter W(*this, Context, Record, GeneratingReducedBMI); |
| 3057 | |
| 3058 | // Build a record for this declaration |
| 3059 | W.Visit(D); |
| 3060 | |
| 3061 | // Emit this declaration to the bitstream. |
| 3062 | uint64_t Offset = W.Emit(D); |
| 3063 | |
| 3064 | // Record the offset for this declaration |
| 3065 | SourceLocation Loc = D->getLocation(); |
| 3066 | SourceLocationEncoding::RawLocEncoding RawLoc = |
| 3067 | getRawSourceLocationEncoding(Loc: getAdjustedLocation(Loc)); |
| 3068 | |
| 3069 | unsigned Index = ID.getRawValue() - FirstDeclID.getRawValue(); |
| 3070 | if (DeclOffsets.size() == Index) |
| 3071 | DeclOffsets.emplace_back(args&: RawLoc, args&: Offset, args&: DeclTypesBlockStartOffset); |
| 3072 | else if (DeclOffsets.size() < Index) { |
| 3073 | // FIXME: Can/should this happen? |
| 3074 | DeclOffsets.resize(new_size: Index+1); |
| 3075 | DeclOffsets[Index].setRawLoc(RawLoc); |
| 3076 | DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset); |
| 3077 | } else { |
| 3078 | llvm_unreachable("declarations should be emitted in ID order" ); |
| 3079 | } |
| 3080 | |
| 3081 | SourceManager &SM = Context.getSourceManager(); |
| 3082 | if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) |
| 3083 | associateDeclWithFile(D, ID); |
| 3084 | |
| 3085 | // Note declarations that should be deserialized eagerly so that we can add |
| 3086 | // them to a record in the AST file later. |
| 3087 | if (isRequiredDecl(D, Context, WritingModule)) |
| 3088 | AddDeclRef(D, Record&: EagerlyDeserializedDecls); |
| 3089 | } |
| 3090 | |
| 3091 | void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) { |
| 3092 | // Switch case IDs are per function body. |
| 3093 | Writer->ClearSwitchCaseIDs(); |
| 3094 | |
| 3095 | assert(FD->doesThisDeclarationHaveABody()); |
| 3096 | bool ModulesCodegen = shouldFunctionGenerateHereOnly(FD); |
| 3097 | Record->push_back(Elt: ModulesCodegen); |
| 3098 | if (ModulesCodegen) |
| 3099 | Writer->AddDeclRef(D: FD, Record&: Writer->ModularCodegenDecls); |
| 3100 | if (auto *CD = dyn_cast<CXXConstructorDecl>(Val: FD)) { |
| 3101 | Record->push_back(Elt: CD->getNumCtorInitializers()); |
| 3102 | if (CD->getNumCtorInitializers()) |
| 3103 | AddCXXCtorInitializers(CtorInits: llvm::ArrayRef(CD->init_begin(), CD->init_end())); |
| 3104 | } |
| 3105 | AddStmt(S: FD->getBody()); |
| 3106 | } |
| 3107 | |