clang 20.0.0git
ASTWriter.cpp
Go to the documentation of this file.
1//===- ASTWriter.cpp - AST File Writer ------------------------------------===//
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 defines the ASTWriter class, which writes AST files.
10//
11//===----------------------------------------------------------------------===//
12
13#include "ASTCommon.h"
14#include "ASTReaderInternals.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/DeclBase.h"
23#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclObjC.h"
29#include "clang/AST/Expr.h"
30#include "clang/AST/ExprCXX.h"
37#include "clang/AST/Type.h"
38#include "clang/AST/TypeLoc.h"
46#include "clang/Basic/LLVM.h"
47#include "clang/Basic/Lambda.h"
49#include "clang/Basic/Module.h"
59#include "clang/Basic/Version.h"
62#include "clang/Lex/MacroInfo.h"
63#include "clang/Lex/ModuleMap.h"
67#include "clang/Lex/Token.h"
70#include "clang/Sema/Sema.h"
71#include "clang/Sema/SemaCUDA.h"
72#include "clang/Sema/SemaObjC.h"
73#include "clang/Sema/Weak.h"
81#include "llvm/ADT/APFloat.h"
82#include "llvm/ADT/APInt.h"
83#include "llvm/ADT/APSInt.h"
84#include "llvm/ADT/ArrayRef.h"
85#include "llvm/ADT/DenseMap.h"
86#include "llvm/ADT/DenseSet.h"
87#include "llvm/ADT/Hashing.h"
88#include "llvm/ADT/PointerIntPair.h"
89#include "llvm/ADT/STLExtras.h"
90#include "llvm/ADT/ScopeExit.h"
91#include "llvm/ADT/SmallPtrSet.h"
92#include "llvm/ADT/SmallString.h"
93#include "llvm/ADT/SmallVector.h"
94#include "llvm/ADT/StringMap.h"
95#include "llvm/ADT/StringRef.h"
96#include "llvm/Bitstream/BitCodes.h"
97#include "llvm/Bitstream/BitstreamWriter.h"
98#include "llvm/Support/Casting.h"
99#include "llvm/Support/Compression.h"
100#include "llvm/Support/DJB.h"
101#include "llvm/Support/Endian.h"
102#include "llvm/Support/EndianStream.h"
103#include "llvm/Support/Error.h"
104#include "llvm/Support/ErrorHandling.h"
105#include "llvm/Support/LEB128.h"
106#include "llvm/Support/MemoryBuffer.h"
107#include "llvm/Support/OnDiskHashTable.h"
108#include "llvm/Support/Path.h"
109#include "llvm/Support/SHA1.h"
110#include "llvm/Support/TimeProfiler.h"
111#include "llvm/Support/VersionTuple.h"
112#include "llvm/Support/raw_ostream.h"
113#include <algorithm>
114#include <cassert>
115#include <cstdint>
116#include <cstdlib>
117#include <cstring>
118#include <ctime>
119#include <limits>
120#include <memory>
121#include <optional>
122#include <queue>
123#include <tuple>
124#include <utility>
125#include <vector>
126
127using namespace clang;
128using namespace clang::serialization;
129
130template <typename T, typename Allocator>
131static StringRef bytes(const std::vector<T, Allocator> &v) {
132 if (v.empty()) return StringRef();
133 return StringRef(reinterpret_cast<const char*>(&v[0]),
134 sizeof(T) * v.size());
135}
136
137template <typename T>
138static StringRef bytes(const SmallVectorImpl<T> &v) {
139 return StringRef(reinterpret_cast<const char*>(v.data()),
140 sizeof(T) * v.size());
141}
142
143static std::string bytes(const std::vector<bool> &V) {
144 std::string Str;
145 Str.reserve(V.size() / 8);
146 for (unsigned I = 0, E = V.size(); I < E;) {
147 char Byte = 0;
148 for (unsigned Bit = 0; Bit < 8 && I < E; ++Bit, ++I)
149 Byte |= V[I] << Bit;
150 Str += Byte;
151 }
152 return Str;
153}
154
155//===----------------------------------------------------------------------===//
156// Type serialization
157//===----------------------------------------------------------------------===//
158
160 switch (id) {
161#define TYPE_BIT_CODE(CLASS_ID, CODE_ID, CODE_VALUE) \
162 case Type::CLASS_ID: return TYPE_##CODE_ID;
163#include "clang/Serialization/TypeBitCodes.def"
164 case Type::Builtin:
165 llvm_unreachable("shouldn't be serializing a builtin type this way");
166 }
167 llvm_unreachable("bad type kind");
168}
169
170namespace {
171
172struct AffectingModuleMaps {
173 llvm::DenseSet<FileID> DefinitionFileIDs;
174 llvm::DenseSet<const FileEntry *> DefinitionFiles;
175};
176
177std::optional<AffectingModuleMaps>
178GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
179 if (!PP.getHeaderSearchInfo()
182 return std::nullopt;
183
184 const HeaderSearch &HS = PP.getHeaderSearchInfo();
185 const SourceManager &SM = PP.getSourceManager();
186 const ModuleMap &MM = HS.getModuleMap();
187
188 // Module maps used only by textual headers are special. Their FileID is
189 // non-affecting, but their FileEntry is (i.e. must be written as InputFile).
190 enum AffectedReason : bool {
191 AR_TextualHeader = 0,
192 AR_ImportOrTextualHeader = 1,
193 };
194 auto AssignMostImportant = [](AffectedReason &LHS, AffectedReason RHS) {
195 LHS = std::max(LHS, RHS);
196 };
197 llvm::DenseMap<FileID, AffectedReason> ModuleMaps;
198 llvm::DenseMap<const Module *, AffectedReason> ProcessedModules;
199 auto CollectModuleMapsForHierarchy = [&](const Module *M,
200 AffectedReason Reason) {
201 M = M->getTopLevelModule();
202
203 // We need to process the header either when it was not present or when we
204 // previously flagged module map as textual headers and now we found a
205 // proper import.
206 if (auto [It, Inserted] = ProcessedModules.insert({M, Reason});
207 !Inserted && Reason <= It->second) {
208 return;
209 } else {
210 It->second = Reason;
211 }
212
213 std::queue<const Module *> Q;
214 Q.push(M);
215 while (!Q.empty()) {
216 const Module *Mod = Q.front();
217 Q.pop();
218
219 // The containing module map is affecting, because it's being pointed
220 // into by Module::DefinitionLoc.
221 if (auto F = MM.getContainingModuleMapFileID(Mod); F.isValid())
222 AssignMostImportant(ModuleMaps[F], Reason);
223 // For inferred modules, the module map that allowed inferring is not
224 // related to the virtual containing module map file. It did affect the
225 // compilation, though.
226 if (auto UniqF = MM.getModuleMapFileIDForUniquing(Mod); UniqF.isValid())
227 AssignMostImportant(ModuleMaps[UniqF], Reason);
228
229 for (auto *SubM : Mod->submodules())
230 Q.push(SubM);
231 }
232 };
233
234 // Handle all the affecting modules referenced from the root module.
235
236 CollectModuleMapsForHierarchy(RootModule, AR_ImportOrTextualHeader);
237
238 std::queue<const Module *> Q;
239 Q.push(RootModule);
240 while (!Q.empty()) {
241 const Module *CurrentModule = Q.front();
242 Q.pop();
243
244 for (const Module *ImportedModule : CurrentModule->Imports)
245 CollectModuleMapsForHierarchy(ImportedModule, AR_ImportOrTextualHeader);
246 for (const Module *UndeclaredModule : CurrentModule->UndeclaredUses)
247 CollectModuleMapsForHierarchy(UndeclaredModule, AR_ImportOrTextualHeader);
248
249 for (auto *M : CurrentModule->submodules())
250 Q.push(M);
251 }
252
253 // Handle textually-included headers that belong to other modules.
254
256 HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
257
258 if (FilesByUID.size() > HS.header_file_size())
259 FilesByUID.resize(HS.header_file_size());
260
261 for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
262 OptionalFileEntryRef File = FilesByUID[UID];
263 if (!File)
264 continue;
265
267 if (!HFI)
268 continue; // We have no information on this being a header file.
269 if (!HFI->isCompilingModuleHeader && HFI->isModuleHeader)
270 continue; // Modular header, handled in the above module-based loop.
272 continue; // Non-modular header not included locally is not affecting.
273
274 for (const auto &KH : HS.findResolvedModulesForHeader(*File))
275 if (const Module *M = KH.getModule())
276 CollectModuleMapsForHierarchy(M, AR_TextualHeader);
277 }
278
279 // FIXME: This algorithm is not correct for module map hierarchies where
280 // module map file defining a (sub)module of a top-level module X includes
281 // a module map file that defines a (sub)module of another top-level module Y.
282 // Whenever X is affecting and Y is not, "replaying" this PCM file will fail
283 // when parsing module map files for X due to not knowing about the `extern`
284 // module map for Y.
285 //
286 // We don't have a good way to fix it here. We could mark all children of
287 // affecting module map files as being affecting as well, but that's
288 // expensive. SourceManager does not model the edge from parent to child
289 // SLocEntries, so instead, we would need to iterate over leaf module map
290 // files, walk up their include hierarchy and check whether we arrive at an
291 // affecting module map.
292 //
293 // Instead of complicating and slowing down this function, we should probably
294 // just ban module map hierarchies where module map defining a (sub)module X
295 // includes a module map defining a module that's not a submodule of X.
296
297 llvm::DenseSet<const FileEntry *> ModuleFileEntries;
298 llvm::DenseSet<FileID> ModuleFileIDs;
299 for (auto [FID, Reason] : ModuleMaps) {
300 if (Reason == AR_ImportOrTextualHeader)
301 ModuleFileIDs.insert(FID);
302 if (auto *FE = SM.getFileEntryForID(FID))
303 ModuleFileEntries.insert(FE);
304 }
305
306 AffectingModuleMaps R;
307 R.DefinitionFileIDs = std::move(ModuleFileIDs);
308 R.DefinitionFiles = std::move(ModuleFileEntries);
309 return std::move(R);
310}
311
312class ASTTypeWriter {
313 ASTWriter &Writer;
315 ASTRecordWriter BasicWriter;
316
317public:
318 ASTTypeWriter(ASTContext &Context, ASTWriter &Writer)
319 : Writer(Writer), BasicWriter(Context, Writer, Record) {}
320
321 uint64_t write(QualType T) {
322 if (T.hasLocalNonFastQualifiers()) {
323 Qualifiers Qs = T.getLocalQualifiers();
324 BasicWriter.writeQualType(T.getLocalUnqualifiedType());
325 BasicWriter.writeQualifiers(Qs);
326 return BasicWriter.Emit(TYPE_EXT_QUAL, Writer.getTypeExtQualAbbrev());
327 }
328
329 const Type *typePtr = T.getTypePtr();
331 atw.write(typePtr);
332 return BasicWriter.Emit(getTypeCodeForTypeClass(typePtr->getTypeClass()),
333 /*abbrev*/ 0);
334 }
335};
336
337class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> {
338 using LocSeq = SourceLocationSequence;
339
341 LocSeq *Seq;
342
343 void addSourceLocation(SourceLocation Loc) {
344 Record.AddSourceLocation(Loc, Seq);
345 }
346 void addSourceRange(SourceRange Range) { Record.AddSourceRange(Range, Seq); }
347
348public:
349 TypeLocWriter(ASTRecordWriter &Record, LocSeq *Seq)
350 : Record(Record), Seq(Seq) {}
351
352#define ABSTRACT_TYPELOC(CLASS, PARENT)
353#define TYPELOC(CLASS, PARENT) \
354 void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
355#include "clang/AST/TypeLocNodes.def"
356
357 void VisitArrayTypeLoc(ArrayTypeLoc TyLoc);
358 void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc);
359};
360
361} // namespace
362
363void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
364 // nothing to do
365}
366
367void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
368 addSourceLocation(TL.getBuiltinLoc());
369 if (TL.needsExtraLocalData()) {
370 Record.push_back(TL.getWrittenTypeSpec());
371 Record.push_back(static_cast<uint64_t>(TL.getWrittenSignSpec()));
372 Record.push_back(static_cast<uint64_t>(TL.getWrittenWidthSpec()));
373 Record.push_back(TL.hasModeAttr());
374 }
375}
376
377void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) {
378 addSourceLocation(TL.getNameLoc());
379}
380
381void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
382 addSourceLocation(TL.getStarLoc());
383}
384
385void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
386 // nothing to do
387}
388
389void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
390 // nothing to do
391}
392
393void TypeLocWriter::VisitArrayParameterTypeLoc(ArrayParameterTypeLoc TL) {
394 // nothing to do
395}
396
397void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
398 addSourceLocation(TL.getCaretLoc());
399}
400
401void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
402 addSourceLocation(TL.getAmpLoc());
403}
404
405void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
406 addSourceLocation(TL.getAmpAmpLoc());
407}
408
409void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
410 addSourceLocation(TL.getStarLoc());
411 Record.AddTypeSourceInfo(TL.getClassTInfo());
412}
413
414void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) {
415 addSourceLocation(TL.getLBracketLoc());
416 addSourceLocation(TL.getRBracketLoc());
417 Record.push_back(TL.getSizeExpr() ? 1 : 0);
418 if (TL.getSizeExpr())
419 Record.AddStmt(TL.getSizeExpr());
420}
421
422void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
423 VisitArrayTypeLoc(TL);
424}
425
426void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
427 VisitArrayTypeLoc(TL);
428}
429
430void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
431 VisitArrayTypeLoc(TL);
432}
433
434void TypeLocWriter::VisitDependentSizedArrayTypeLoc(
436 VisitArrayTypeLoc(TL);
437}
438
439void TypeLocWriter::VisitDependentAddressSpaceTypeLoc(
441 addSourceLocation(TL.getAttrNameLoc());
443 addSourceLocation(range.getBegin());
444 addSourceLocation(range.getEnd());
445 Record.AddStmt(TL.getAttrExprOperand());
446}
447
448void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
450 addSourceLocation(TL.getNameLoc());
451}
452
453void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
454 addSourceLocation(TL.getNameLoc());
455}
456
457void TypeLocWriter::VisitDependentVectorTypeLoc(
459 addSourceLocation(TL.getNameLoc());
460}
461
462void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
463 addSourceLocation(TL.getNameLoc());
464}
465
466void TypeLocWriter::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) {
467 addSourceLocation(TL.getAttrNameLoc());
469 addSourceLocation(range.getBegin());
470 addSourceLocation(range.getEnd());
471 Record.AddStmt(TL.getAttrRowOperand());
472 Record.AddStmt(TL.getAttrColumnOperand());
473}
474
475void TypeLocWriter::VisitDependentSizedMatrixTypeLoc(
477 addSourceLocation(TL.getAttrNameLoc());
479 addSourceLocation(range.getBegin());
480 addSourceLocation(range.getEnd());
481 Record.AddStmt(TL.getAttrRowOperand());
482 Record.AddStmt(TL.getAttrColumnOperand());
483}
484
485void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
486 addSourceLocation(TL.getLocalRangeBegin());
487 addSourceLocation(TL.getLParenLoc());
488 addSourceLocation(TL.getRParenLoc());
489 addSourceRange(TL.getExceptionSpecRange());
490 addSourceLocation(TL.getLocalRangeEnd());
491 for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i)
492 Record.AddDeclRef(TL.getParam(i));
493}
494
495void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
496 VisitFunctionTypeLoc(TL);
497}
498
499void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
500 VisitFunctionTypeLoc(TL);
501}
502
503void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
504 addSourceLocation(TL.getNameLoc());
505}
506
507void TypeLocWriter::VisitUsingTypeLoc(UsingTypeLoc TL) {
508 addSourceLocation(TL.getNameLoc());
509}
510
511void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
512 addSourceLocation(TL.getNameLoc());
513}
514
515void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
516 if (TL.getNumProtocols()) {
517 addSourceLocation(TL.getProtocolLAngleLoc());
518 addSourceLocation(TL.getProtocolRAngleLoc());
519 }
520 for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
521 addSourceLocation(TL.getProtocolLoc(i));
522}
523
524void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
525 addSourceLocation(TL.getTypeofLoc());
526 addSourceLocation(TL.getLParenLoc());
527 addSourceLocation(TL.getRParenLoc());
528}
529
530void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
531 addSourceLocation(TL.getTypeofLoc());
532 addSourceLocation(TL.getLParenLoc());
533 addSourceLocation(TL.getRParenLoc());
534 Record.AddTypeSourceInfo(TL.getUnmodifiedTInfo());
535}
536
537void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
538 addSourceLocation(TL.getDecltypeLoc());
539 addSourceLocation(TL.getRParenLoc());
540}
541
542void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
543 addSourceLocation(TL.getKWLoc());
544 addSourceLocation(TL.getLParenLoc());
545 addSourceLocation(TL.getRParenLoc());
546 Record.AddTypeSourceInfo(TL.getUnderlyingTInfo());
547}
548
550 assert(CR);
556 push_back(CR->getTemplateArgsAsWritten() != nullptr);
557 if (CR->getTemplateArgsAsWritten())
559}
560
561void TypeLocWriter::VisitPackIndexingTypeLoc(PackIndexingTypeLoc TL) {
562 addSourceLocation(TL.getEllipsisLoc());
563}
564
565void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) {
566 addSourceLocation(TL.getNameLoc());
567 auto *CR = TL.getConceptReference();
568 Record.push_back(TL.isConstrained() && CR);
569 if (TL.isConstrained() && CR)
570 Record.AddConceptReference(CR);
571 Record.push_back(TL.isDecltypeAuto());
572 if (TL.isDecltypeAuto())
573 addSourceLocation(TL.getRParenLoc());
574}
575
576void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
578 addSourceLocation(TL.getTemplateNameLoc());
579}
580
581void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) {
582 addSourceLocation(TL.getNameLoc());
583}
584
585void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) {
586 addSourceLocation(TL.getNameLoc());
587}
588
589void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
590 Record.AddAttr(TL.getAttr());
591}
592
593void TypeLocWriter::VisitCountAttributedTypeLoc(CountAttributedTypeLoc TL) {
594 // Nothing to do
595}
596
597void TypeLocWriter::VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) {
598 // Nothing to do.
599}
600
601void TypeLocWriter::VisitHLSLAttributedResourceTypeLoc(
603 // Nothing to do.
604}
605
606void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
607 addSourceLocation(TL.getNameLoc());
608}
609
610void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc(
612 addSourceLocation(TL.getNameLoc());
613}
614
615void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc(
617 addSourceLocation(TL.getNameLoc());
618}
619
620void TypeLocWriter::VisitTemplateSpecializationTypeLoc(
622 addSourceLocation(TL.getTemplateKeywordLoc());
623 addSourceLocation(TL.getTemplateNameLoc());
624 addSourceLocation(TL.getLAngleLoc());
625 addSourceLocation(TL.getRAngleLoc());
626 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
627 Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(),
628 TL.getArgLoc(i).getLocInfo());
629}
630
631void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) {
632 addSourceLocation(TL.getLParenLoc());
633 addSourceLocation(TL.getRParenLoc());
634}
635
636void TypeLocWriter::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
637 addSourceLocation(TL.getExpansionLoc());
638}
639
640void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
641 addSourceLocation(TL.getElaboratedKeywordLoc());
642 Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
643}
644
645void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
646 addSourceLocation(TL.getNameLoc());
647}
648
649void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
650 addSourceLocation(TL.getElaboratedKeywordLoc());
651 Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
652 addSourceLocation(TL.getNameLoc());
653}
654
655void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc(
657 addSourceLocation(TL.getElaboratedKeywordLoc());
658 Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
659 addSourceLocation(TL.getTemplateKeywordLoc());
660 addSourceLocation(TL.getTemplateNameLoc());
661 addSourceLocation(TL.getLAngleLoc());
662 addSourceLocation(TL.getRAngleLoc());
663 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
664 Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(),
665 TL.getArgLoc(I).getLocInfo());
666}
667
668void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
669 addSourceLocation(TL.getEllipsisLoc());
670}
671
672void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
673 addSourceLocation(TL.getNameLoc());
674 addSourceLocation(TL.getNameEndLoc());
675}
676
677void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
678 Record.push_back(TL.hasBaseTypeAsWritten());
679 addSourceLocation(TL.getTypeArgsLAngleLoc());
680 addSourceLocation(TL.getTypeArgsRAngleLoc());
681 for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i)
682 Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i));
683 addSourceLocation(TL.getProtocolLAngleLoc());
684 addSourceLocation(TL.getProtocolRAngleLoc());
685 for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
686 addSourceLocation(TL.getProtocolLoc(i));
687}
688
689void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
690 addSourceLocation(TL.getStarLoc());
691}
692
693void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
694 addSourceLocation(TL.getKWLoc());
695 addSourceLocation(TL.getLParenLoc());
696 addSourceLocation(TL.getRParenLoc());
697}
698
699void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) {
700 addSourceLocation(TL.getKWLoc());
701}
702
703void TypeLocWriter::VisitBitIntTypeLoc(clang::BitIntTypeLoc TL) {
704 addSourceLocation(TL.getNameLoc());
705}
706void TypeLocWriter::VisitDependentBitIntTypeLoc(
708 addSourceLocation(TL.getNameLoc());
709}
710
711void ASTWriter::WriteTypeAbbrevs() {
712 using namespace llvm;
713
714 std::shared_ptr<BitCodeAbbrev> Abv;
715
716 // Abbreviation for TYPE_EXT_QUAL
717 Abv = std::make_shared<BitCodeAbbrev>();
718 Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL));
719 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
720 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals
721 TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv));
722}
723
724//===----------------------------------------------------------------------===//
725// ASTWriter Implementation
726//===----------------------------------------------------------------------===//
727
728static void EmitBlockID(unsigned ID, const char *Name,
729 llvm::BitstreamWriter &Stream,
731 Record.clear();
732 Record.push_back(ID);
733 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
734
735 // Emit the block name if present.
736 if (!Name || Name[0] == 0)
737 return;
738 Record.clear();
739 while (*Name)
740 Record.push_back(*Name++);
741 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
742}
743
744static void EmitRecordID(unsigned ID, const char *Name,
745 llvm::BitstreamWriter &Stream,
747 Record.clear();
748 Record.push_back(ID);
749 while (*Name)
750 Record.push_back(*Name++);
751 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
752}
753
754static void AddStmtsExprs(llvm::BitstreamWriter &Stream,
756#define RECORD(X) EmitRecordID(X, #X, Stream, Record)
885#undef RECORD
886}
887
888void ASTWriter::WriteBlockInfoBlock() {
890 Stream.EnterBlockInfoBlock();
891
892#define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record)
893#define RECORD(X) EmitRecordID(X, #X, Stream, Record)
894
895 // Control Block.
896 BLOCK(CONTROL_BLOCK);
901 RECORD(IMPORT);
905
906 BLOCK(OPTIONS_BLOCK);
912
913 BLOCK(INPUT_FILES_BLOCK);
916
917 // AST Top-Level Block.
918 BLOCK(AST_BLOCK);
976
977 // SourceManager Block.
978 BLOCK(SOURCE_MANAGER_BLOCK);
984
985 // Preprocessor Block.
986 BLOCK(PREPROCESSOR_BLOCK);
992
993 // Submodule Block.
994 BLOCK(SUBMODULE_BLOCK);
1014
1015 // Comments Block.
1016 BLOCK(COMMENTS_BLOCK);
1018
1019 // Decls and Types block.
1020 BLOCK(DECLTYPES_BLOCK);
1022 RECORD(TYPE_COMPLEX);
1023 RECORD(TYPE_POINTER);
1024 RECORD(TYPE_BLOCK_POINTER);
1025 RECORD(TYPE_LVALUE_REFERENCE);
1026 RECORD(TYPE_RVALUE_REFERENCE);
1027 RECORD(TYPE_MEMBER_POINTER);
1028 RECORD(TYPE_CONSTANT_ARRAY);
1029 RECORD(TYPE_INCOMPLETE_ARRAY);
1030 RECORD(TYPE_VARIABLE_ARRAY);
1031 RECORD(TYPE_VECTOR);
1032 RECORD(TYPE_EXT_VECTOR);
1033 RECORD(TYPE_FUNCTION_NO_PROTO);
1034 RECORD(TYPE_FUNCTION_PROTO);
1035 RECORD(TYPE_TYPEDEF);
1036 RECORD(TYPE_TYPEOF_EXPR);
1037 RECORD(TYPE_TYPEOF);
1038 RECORD(TYPE_RECORD);
1039 RECORD(TYPE_ENUM);
1040 RECORD(TYPE_OBJC_INTERFACE);
1041 RECORD(TYPE_OBJC_OBJECT_POINTER);
1042 RECORD(TYPE_DECLTYPE);
1043 RECORD(TYPE_ELABORATED);
1044 RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM);
1045 RECORD(TYPE_UNRESOLVED_USING);
1046 RECORD(TYPE_INJECTED_CLASS_NAME);
1047 RECORD(TYPE_OBJC_OBJECT);
1048 RECORD(TYPE_TEMPLATE_TYPE_PARM);
1049 RECORD(TYPE_TEMPLATE_SPECIALIZATION);
1050 RECORD(TYPE_DEPENDENT_NAME);
1051 RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION);
1052 RECORD(TYPE_DEPENDENT_SIZED_ARRAY);
1053 RECORD(TYPE_PAREN);
1054 RECORD(TYPE_MACRO_QUALIFIED);
1055 RECORD(TYPE_PACK_EXPANSION);
1056 RECORD(TYPE_ATTRIBUTED);
1057 RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK);
1058 RECORD(TYPE_AUTO);
1059 RECORD(TYPE_UNARY_TRANSFORM);
1060 RECORD(TYPE_ATOMIC);
1061 RECORD(TYPE_DECAYED);
1062 RECORD(TYPE_ADJUSTED);
1063 RECORD(TYPE_OBJC_TYPE_PARAM);
1138
1139 // Statements and Exprs can occur in the Decls and Types block.
1140 AddStmtsExprs(Stream, Record);
1141
1142 BLOCK(PREPROCESSOR_DETAIL_BLOCK);
1146
1147 // Decls and Types block.
1148 BLOCK(EXTENSION_BLOCK);
1150
1151 BLOCK(UNHASHED_CONTROL_BLOCK);
1159
1160#undef RECORD
1161#undef BLOCK
1162 Stream.ExitBlock();
1163}
1164
1165/// Prepares a path for being written to an AST file by converting it
1166/// to an absolute path and removing nested './'s.
1167///
1168/// \return \c true if the path was changed.
1169static bool cleanPathForOutput(FileManager &FileMgr,
1171 bool Changed = FileMgr.makeAbsolutePath(Path);
1172 return Changed | llvm::sys::path::remove_dots(Path);
1173}
1174
1175/// Adjusts the given filename to only write out the portion of the
1176/// filename that is not part of the system root directory.
1177///
1178/// \param Filename the file name to adjust.
1179///
1180/// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and
1181/// the returned filename will be adjusted by this root directory.
1182///
1183/// \returns either the original filename (if it needs no adjustment) or the
1184/// adjusted filename (which points into the @p Filename parameter).
1185static const char *
1186adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) {
1187 assert(Filename && "No file name to adjust?");
1188
1189 if (BaseDir.empty())
1190 return Filename;
1191
1192 // Verify that the filename and the system root have the same prefix.
1193 unsigned Pos = 0;
1194 for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos)
1195 if (Filename[Pos] != BaseDir[Pos])
1196 return Filename; // Prefixes don't match.
1197
1198 // We hit the end of the filename before we hit the end of the system root.
1199 if (!Filename[Pos])
1200 return Filename;
1201
1202 // If there's not a path separator at the end of the base directory nor
1203 // immediately after it, then this isn't within the base directory.
1204 if (!llvm::sys::path::is_separator(Filename[Pos])) {
1205 if (!llvm::sys::path::is_separator(BaseDir.back()))
1206 return Filename;
1207 } else {
1208 // If the file name has a '/' at the current position, skip over the '/'.
1209 // We distinguish relative paths from absolute paths by the
1210 // absence of '/' at the beginning of relative paths.
1211 //
1212 // FIXME: This is wrong. We distinguish them by asking if the path is
1213 // absolute, which isn't the same thing. And there might be multiple '/'s
1214 // in a row. Use a better mechanism to indicate whether we have emitted an
1215 // absolute or relative path.
1216 ++Pos;
1217 }
1218
1219 return Filename + Pos;
1220}
1221
1222std::pair<ASTFileSignature, ASTFileSignature>
1223ASTWriter::createSignature() const {
1224 StringRef AllBytes(Buffer.data(), Buffer.size());
1225
1226 llvm::SHA1 Hasher;
1227 Hasher.update(AllBytes.slice(ASTBlockRange.first, ASTBlockRange.second));
1228 ASTFileSignature ASTBlockHash = ASTFileSignature::create(Hasher.result());
1229
1230 // Add the remaining bytes:
1231 // 1. Before the unhashed control block.
1232 Hasher.update(AllBytes.slice(0, UnhashedControlBlockRange.first));
1233 // 2. Between the unhashed control block and the AST block.
1234 Hasher.update(
1235 AllBytes.slice(UnhashedControlBlockRange.second, ASTBlockRange.first));
1236 // 3. After the AST block.
1237 Hasher.update(AllBytes.slice(ASTBlockRange.second, StringRef::npos));
1238 ASTFileSignature Signature = ASTFileSignature::create(Hasher.result());
1239
1240 return std::make_pair(ASTBlockHash, Signature);
1241}
1242
1243ASTFileSignature ASTWriter::createSignatureForNamedModule() const {
1244 llvm::SHA1 Hasher;
1245 Hasher.update(StringRef(Buffer.data(), Buffer.size()));
1246
1247 assert(WritingModule);
1248 assert(WritingModule->isNamedModule());
1249
1250 // We need to combine all the export imported modules no matter
1251 // we used it or not.
1252 for (auto [ExportImported, _] : WritingModule->Exports)
1253 Hasher.update(ExportImported->Signature);
1254
1255 // We combine all the used modules to make sure the signature is precise.
1256 // Consider the case like:
1257 //
1258 // // a.cppm
1259 // export module a;
1260 // export inline int a() { ... }
1261 //
1262 // // b.cppm
1263 // export module b;
1264 // import a;
1265 // export inline int b() { return a(); }
1266 //
1267 // Since both `a()` and `b()` are inline, we need to make sure the BMI of
1268 // `b.pcm` will change after the implementation of `a()` changes. We can't
1269 // get that naturally since we won't record the body of `a()` during the
1270 // writing process. We can't reuse ODRHash here since ODRHash won't calculate
1271 // the called function recursively. So ODRHash will be problematic if `a()`
1272 // calls other inline functions.
1273 //
1274 // Probably we can solve this by a new hash mechanism. But the safety and
1275 // efficiency may a problem too. Here we just combine the hash value of the
1276 // used modules conservatively.
1277 for (Module *M : TouchedTopLevelModules)
1278 Hasher.update(M->Signature);
1279
1280 return ASTFileSignature::create(Hasher.result());
1281}
1282
1283static void BackpatchSignatureAt(llvm::BitstreamWriter &Stream,
1284 const ASTFileSignature &S, uint64_t BitNo) {
1285 for (uint8_t Byte : S) {
1286 Stream.BackpatchByte(BitNo, Byte);
1287 BitNo += 8;
1288 }
1289}
1290
1291ASTFileSignature ASTWriter::backpatchSignature() {
1293 ASTFileSignature Signature = createSignatureForNamedModule();
1294 BackpatchSignatureAt(Stream, Signature, SignatureOffset);
1295 return Signature;
1296 }
1297
1298 if (!WritingModule ||
1300 return {};
1301
1302 // For implicit modules, write the hash of the PCM as its signature.
1303 ASTFileSignature ASTBlockHash;
1304 ASTFileSignature Signature;
1305 std::tie(ASTBlockHash, Signature) = createSignature();
1306
1307 BackpatchSignatureAt(Stream, ASTBlockHash, ASTBlockHashOffset);
1308 BackpatchSignatureAt(Stream, Signature, SignatureOffset);
1309
1310 return Signature;
1311}
1312
1313void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP) {
1314 using namespace llvm;
1315
1316 // Flush first to prepare the PCM hash (signature).
1317 Stream.FlushToWord();
1318 UnhashedControlBlockRange.first = Stream.GetCurrentBitNo() >> 3;
1319
1320 // Enter the block and prepare to write records.
1322 Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5);
1323
1324 // For implicit modules and C++20 named modules, write the hash of the PCM as
1325 // its signature.
1327 (WritingModule &&
1329 // At this point, we don't know the actual signature of the file or the AST
1330 // block - we're only able to compute those at the end of the serialization
1331 // process. Let's store dummy signatures for now, and replace them with the
1332 // real ones later on.
1333 // The bitstream VBR-encodes record elements, which makes backpatching them
1334 // really difficult. Let's store the signatures as blobs instead - they are
1335 // guaranteed to be word-aligned, and we control their format/encoding.
1336 auto Dummy = ASTFileSignature::createDummy();
1337 SmallString<128> Blob{Dummy.begin(), Dummy.end()};
1338
1339 // We don't need AST Block hash in named modules.
1341 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1342 Abbrev->Add(BitCodeAbbrevOp(AST_BLOCK_HASH));
1343 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
1344 unsigned ASTBlockHashAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
1345
1346 Record.push_back(AST_BLOCK_HASH);
1347 Stream.EmitRecordWithBlob(ASTBlockHashAbbrev, Record, Blob);
1348 ASTBlockHashOffset = Stream.GetCurrentBitNo() - Blob.size() * 8;
1349 Record.clear();
1350 }
1351
1352 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1353 Abbrev->Add(BitCodeAbbrevOp(SIGNATURE));
1354 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
1355 unsigned SignatureAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
1356
1357 Record.push_back(SIGNATURE);
1358 Stream.EmitRecordWithBlob(SignatureAbbrev, Record, Blob);
1359 SignatureOffset = Stream.GetCurrentBitNo() - Blob.size() * 8;
1360 Record.clear();
1361 }
1362
1363 const auto &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
1364
1365 // Diagnostic options.
1366 const auto &Diags = PP.getDiagnostics();
1367 const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions();
1368 if (!HSOpts.ModulesSkipDiagnosticOptions) {
1369#define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name);
1370#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
1371 Record.push_back(static_cast<unsigned>(DiagOpts.get##Name()));
1372#include "clang/Basic/DiagnosticOptions.def"
1373 Record.push_back(DiagOpts.Warnings.size());
1374 for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I)
1375 AddString(DiagOpts.Warnings[I], Record);
1376 Record.push_back(DiagOpts.Remarks.size());
1377 for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I)
1378 AddString(DiagOpts.Remarks[I], Record);
1379 // Note: we don't serialize the log or serialization file names, because
1380 // they are generally transient files and will almost always be overridden.
1381 Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record);
1382 Record.clear();
1383 }
1384
1385 // Header search paths.
1386 if (!HSOpts.ModulesSkipHeaderSearchPaths) {
1387 // Include entries.
1388 Record.push_back(HSOpts.UserEntries.size());
1389 for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) {
1390 const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I];
1391 AddString(Entry.Path, Record);
1392 Record.push_back(static_cast<unsigned>(Entry.Group));
1393 Record.push_back(Entry.IsFramework);
1394 Record.push_back(Entry.IgnoreSysRoot);
1395 }
1396
1397 // System header prefixes.
1398 Record.push_back(HSOpts.SystemHeaderPrefixes.size());
1399 for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) {
1400 AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record);
1401 Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader);
1402 }
1403
1404 // VFS overlay files.
1405 Record.push_back(HSOpts.VFSOverlayFiles.size());
1406 for (StringRef VFSOverlayFile : HSOpts.VFSOverlayFiles)
1407 AddString(VFSOverlayFile, Record);
1408
1409 Stream.EmitRecord(HEADER_SEARCH_PATHS, Record);
1410 }
1411
1412 if (!HSOpts.ModulesSkipPragmaDiagnosticMappings)
1413 WritePragmaDiagnosticMappings(Diags, /* isModule = */ WritingModule);
1414
1415 // Header search entry usage.
1416 {
1417 auto HSEntryUsage = PP.getHeaderSearchInfo().computeUserEntryUsage();
1418 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1419 Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_ENTRY_USAGE));
1420 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Number of bits.
1421 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Bit vector.
1422 unsigned HSUsageAbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1423 RecordData::value_type Record[] = {HEADER_SEARCH_ENTRY_USAGE,
1424 HSEntryUsage.size()};
1425 Stream.EmitRecordWithBlob(HSUsageAbbrevCode, Record, bytes(HSEntryUsage));
1426 }
1427
1428 // VFS usage.
1429 {
1430 auto VFSUsage = PP.getHeaderSearchInfo().collectVFSUsageAndClear();
1431 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1432 Abbrev->Add(BitCodeAbbrevOp(VFS_USAGE));
1433 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Number of bits.
1434 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Bit vector.
1435 unsigned VFSUsageAbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1436 RecordData::value_type Record[] = {VFS_USAGE, VFSUsage.size()};
1437 Stream.EmitRecordWithBlob(VFSUsageAbbrevCode, Record, bytes(VFSUsage));
1438 }
1439
1440 // Leave the options block.
1441 Stream.ExitBlock();
1442 UnhashedControlBlockRange.second = Stream.GetCurrentBitNo() >> 3;
1443}
1444
1445/// Write the control block.
1446void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
1447 using namespace llvm;
1448
1449 SourceManager &SourceMgr = PP.getSourceManager();
1450 FileManager &FileMgr = PP.getFileManager();
1451
1452 Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
1454
1455 // Metadata
1456 auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>();
1457 MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA));
1458 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major
1459 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor
1460 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj.
1461 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min.
1462 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable
1463 // Standard C++ module
1464 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1465 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps
1466 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors
1467 MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag
1468 unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev));
1469 assert((!WritingModule || isysroot.empty()) &&
1470 "writing module as a relocatable PCH?");
1471 {
1472 RecordData::value_type Record[] = {METADATA,
1475 CLANG_VERSION_MAJOR,
1476 CLANG_VERSION_MINOR,
1477 !isysroot.empty(),
1479 IncludeTimestamps,
1480 ASTHasCompilerErrors};
1481 Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record,
1483 }
1484
1485 if (WritingModule) {
1486 // Module name
1487 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1488 Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME));
1489 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
1490 unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1491 RecordData::value_type Record[] = {MODULE_NAME};
1492 Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name);
1493 }
1494
1495 if (WritingModule && WritingModule->Directory) {
1496 SmallString<128> BaseDir;
1498 // Use the current working directory as the base path for all inputs.
1499 auto CWD = FileMgr.getOptionalDirectoryRef(".");
1500 BaseDir.assign(CWD->getName());
1501 } else {
1502 BaseDir.assign(WritingModule->Directory->getName());
1503 }
1504 cleanPathForOutput(FileMgr, BaseDir);
1505
1506 // If the home of the module is the current working directory, then we
1507 // want to pick up the cwd of the build process loading the module, not
1508 // our cwd, when we load this module.
1510 (!PP.getHeaderSearchInfo()
1513 WritingModule->Directory->getName() != ".")) {
1514 // Module directory.
1515 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1516 Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
1517 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
1518 unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1519
1520 RecordData::value_type Record[] = {MODULE_DIRECTORY};
1521 Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
1522 }
1523
1524 // Write out all other paths relative to the base directory if possible.
1525 BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
1526 } else if (!isysroot.empty()) {
1527 // Write out paths relative to the sysroot if possible.
1528 BaseDirectory = std::string(isysroot);
1529 }
1530
1531 // Module map file
1532 if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) {
1533 Record.clear();
1534
1535 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
1536 AddPath(WritingModule->PresumedModuleMapFile.empty()
1537 ? Map.getModuleMapFileForUniquing(WritingModule)
1538 ->getNameAsRequested()
1539 : StringRef(WritingModule->PresumedModuleMapFile),
1540 Record);
1541
1542 // Additional module map files.
1543 if (auto *AdditionalModMaps =
1544 Map.getAdditionalModuleMapFiles(WritingModule)) {
1545 Record.push_back(AdditionalModMaps->size());
1546 SmallVector<FileEntryRef, 1> ModMaps(AdditionalModMaps->begin(),
1547 AdditionalModMaps->end());
1548 llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) {
1549 return A.getName() < B.getName();
1550 });
1551 for (FileEntryRef F : ModMaps)
1552 AddPath(F.getName(), Record);
1553 } else {
1554 Record.push_back(0);
1555 }
1556
1557 Stream.EmitRecord(MODULE_MAP_FILE, Record);
1558 }
1559
1560 // Imports
1561 if (Chain) {
1562 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1563 Abbrev->Add(BitCodeAbbrevOp(IMPORT));
1564 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Kind
1565 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ImportLoc
1566 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Module name len
1567 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Standard C++ mod
1568 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File size
1569 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File timestamp
1570 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File name len
1571 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Strings
1572 unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1573
1574 SmallString<128> Blob;
1575
1576 for (ModuleFile &M : Chain->getModuleManager()) {
1577 // Skip modules that weren't directly imported.
1578 if (!M.isDirectlyImported())
1579 continue;
1580
1581 Record.clear();
1582 Blob.clear();
1583
1584 Record.push_back(IMPORT);
1585 Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding
1586 AddSourceLocation(M.ImportLoc, Record);
1587 AddStringBlob(M.ModuleName, Record, Blob);
1588 Record.push_back(M.StandardCXXModule);
1589
1590 // We don't want to hard code the information about imported modules
1591 // in the C++20 named modules.
1592 if (M.StandardCXXModule) {
1593 Record.push_back(0);
1594 Record.push_back(0);
1595 Record.push_back(0);
1596 } else {
1597 // If we have calculated signature, there is no need to store
1598 // the size or timestamp.
1599 Record.push_back(M.Signature ? 0 : M.File.getSize());
1600 Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File));
1601
1602 llvm::append_range(Blob, M.Signature);
1603
1604 AddPathBlob(M.FileName, Record, Blob);
1605 }
1606
1607 Stream.EmitRecordWithBlob(AbbrevCode, Record, Blob);
1608 }
1609 }
1610
1611 // Write the options block.
1612 Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4);
1613
1614 // Language options.
1615 Record.clear();
1616 const LangOptions &LangOpts = PP.getLangOpts();
1617#define LANGOPT(Name, Bits, Default, Description) \
1618 Record.push_back(LangOpts.Name);
1619#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
1620 Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
1621#include "clang/Basic/LangOptions.def"
1622#define SANITIZER(NAME, ID) \
1623 Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID));
1624#include "clang/Basic/Sanitizers.def"
1625
1626 Record.push_back(LangOpts.ModuleFeatures.size());
1627 for (StringRef Feature : LangOpts.ModuleFeatures)
1628 AddString(Feature, Record);
1629
1630 Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind());
1632
1633 AddString(LangOpts.CurrentModule, Record);
1634
1635 // Comment options.
1636 Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size());
1637 for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) {
1638 AddString(I, Record);
1639 }
1640 Record.push_back(LangOpts.CommentOpts.ParseAllComments);
1641
1642 // OpenMP offloading options.
1643 Record.push_back(LangOpts.OMPTargetTriples.size());
1644 for (auto &T : LangOpts.OMPTargetTriples)
1645 AddString(T.getTriple(), Record);
1646
1647 AddString(LangOpts.OMPHostIRFile, Record);
1648
1649 Stream.EmitRecord(LANGUAGE_OPTIONS, Record);
1650
1651 // Target options.
1652 Record.clear();
1653 const TargetInfo &Target = PP.getTargetInfo();
1654 const TargetOptions &TargetOpts = Target.getTargetOpts();
1655 AddString(TargetOpts.Triple, Record);
1656 AddString(TargetOpts.CPU, Record);
1657 AddString(TargetOpts.TuneCPU, Record);
1658 AddString(TargetOpts.ABI, Record);
1659 Record.push_back(TargetOpts.FeaturesAsWritten.size());
1660 for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) {
1661 AddString(TargetOpts.FeaturesAsWritten[I], Record);
1662 }
1663 Record.push_back(TargetOpts.Features.size());
1664 for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) {
1665 AddString(TargetOpts.Features[I], Record);
1666 }
1667 Stream.EmitRecord(TARGET_OPTIONS, Record);
1668
1669 // File system options.
1670 Record.clear();
1671 const FileSystemOptions &FSOpts = FileMgr.getFileSystemOpts();
1672 AddString(FSOpts.WorkingDir, Record);
1673 Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
1674
1675 // Header search options.
1676 Record.clear();
1677 const HeaderSearchOptions &HSOpts =
1679
1680 AddString(HSOpts.Sysroot, Record);
1681 AddString(HSOpts.ResourceDir, Record);
1684 Record.push_back(HSOpts.DisableModuleHash);
1685 Record.push_back(HSOpts.ImplicitModuleMaps);
1686 Record.push_back(HSOpts.ModuleMapFileHomeIsCwd);
1687 Record.push_back(HSOpts.EnablePrebuiltImplicitModules);
1688 Record.push_back(HSOpts.UseBuiltinIncludes);
1689 Record.push_back(HSOpts.UseStandardSystemIncludes);
1690 Record.push_back(HSOpts.UseStandardCXXIncludes);
1691 Record.push_back(HSOpts.UseLibcxx);
1692 // Write out the specific module cache path that contains the module files.
1694 Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record);
1695
1696 // Preprocessor options.
1697 Record.clear();
1698 const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts();
1699
1700 // If we're building an implicit module with a context hash, the importer is
1701 // guaranteed to have the same macros defined on the command line. Skip
1702 // writing them.
1703 bool SkipMacros = BuildingImplicitModule && !HSOpts.DisableModuleHash;
1704 bool WriteMacros = !SkipMacros;
1705 Record.push_back(WriteMacros);
1706 if (WriteMacros) {
1707 // Macro definitions.
1708 Record.push_back(PPOpts.Macros.size());
1709 for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) {
1710 AddString(PPOpts.Macros[I].first, Record);
1711 Record.push_back(PPOpts.Macros[I].second);
1712 }
1713 }
1714
1715 // Includes
1716 Record.push_back(PPOpts.Includes.size());
1717 for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I)
1718 AddString(PPOpts.Includes[I], Record);
1719
1720 // Macro includes
1721 Record.push_back(PPOpts.MacroIncludes.size());
1722 for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I)
1723 AddString(PPOpts.MacroIncludes[I], Record);
1724
1725 Record.push_back(PPOpts.UsePredefines);
1726 // Detailed record is important since it is used for the module cache hash.
1727 Record.push_back(PPOpts.DetailedRecord);
1729 Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary));
1730 Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record);
1731
1732 // Leave the options block.
1733 Stream.ExitBlock();
1734
1735 // Original file name and file ID
1736 if (auto MainFile =
1737 SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())) {
1738 auto FileAbbrev = std::make_shared<BitCodeAbbrev>();
1739 FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE));
1740 FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID
1741 FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
1742 unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev));
1743
1744 Record.clear();
1745 Record.push_back(ORIGINAL_FILE);
1746 AddFileID(SourceMgr.getMainFileID(), Record);
1747 EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName());
1748 }
1749
1750 Record.clear();
1751 AddFileID(SourceMgr.getMainFileID(), Record);
1752 Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
1753
1754 WriteInputFiles(SourceMgr, PP.getHeaderSearchInfo().getHeaderSearchOpts());
1755 Stream.ExitBlock();
1756}
1757
1758namespace {
1759
1760/// An input file.
1761struct InputFileEntry {
1763 bool IsSystemFile;
1764 bool IsTransient;
1765 bool BufferOverridden;
1766 bool IsTopLevel;
1767 bool IsModuleMap;
1768 uint32_t ContentHash[2];
1769
1770 InputFileEntry(FileEntryRef File) : File(File) {}
1771};
1772
1773} // namespace
1774
1775SourceLocation ASTWriter::getAffectingIncludeLoc(const SourceManager &SourceMgr,
1776 const SrcMgr::FileInfo &File) {
1777 SourceLocation IncludeLoc = File.getIncludeLoc();
1778 if (IncludeLoc.isValid()) {
1779 FileID IncludeFID = SourceMgr.getFileID(IncludeLoc);
1780 assert(IncludeFID.isValid() && "IncludeLoc in invalid file");
1781 if (!IsSLocAffecting[IncludeFID.ID])
1782 IncludeLoc = SourceLocation();
1783 }
1784 return IncludeLoc;
1785}
1786
1787void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
1788 HeaderSearchOptions &HSOpts) {
1789 using namespace llvm;
1790
1791 Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
1792
1793 // Create input-file abbreviation.
1794 auto IFAbbrev = std::make_shared<BitCodeAbbrev>();
1795 IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE));
1796 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
1797 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size
1798 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time
1799 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden
1800 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient
1801 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Top-level
1802 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map
1803 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // Name as req. len
1804 IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name as req. + name
1805 unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev));
1806
1807 // Create input file hash abbreviation.
1808 auto IFHAbbrev = std::make_shared<BitCodeAbbrev>();
1809 IFHAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_HASH));
1810 IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
1811 IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
1812 unsigned IFHAbbrevCode = Stream.EmitAbbrev(std::move(IFHAbbrev));
1813
1814 uint64_t InputFilesOffsetBase = Stream.GetCurrentBitNo();
1815
1816 // Get all ContentCache objects for files.
1817 std::vector<InputFileEntry> UserFiles;
1818 std::vector<InputFileEntry> SystemFiles;
1819 for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) {
1820 // Get this source location entry.
1821 const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I);
1822 assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc);
1823
1824 // We only care about file entries that were not overridden.
1825 if (!SLoc->isFile())
1826 continue;
1827 const SrcMgr::FileInfo &File = SLoc->getFile();
1828 const SrcMgr::ContentCache *Cache = &File.getContentCache();
1829 if (!Cache->OrigEntry)
1830 continue;
1831
1832 // Do not emit input files that do not affect current module.
1833 if (!IsSLocFileEntryAffecting[I])
1834 continue;
1835
1836 InputFileEntry Entry(*Cache->OrigEntry);
1837 Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
1838 Entry.IsTransient = Cache->IsTransient;
1839 Entry.BufferOverridden = Cache->BufferOverridden;
1840
1841 FileID IncludeFileID = SourceMgr.getFileID(File.getIncludeLoc());
1842 Entry.IsTopLevel = IncludeFileID.isInvalid() || IncludeFileID.ID < 0 ||
1843 !IsSLocFileEntryAffecting[IncludeFileID.ID];
1844 Entry.IsModuleMap = isModuleMap(File.getFileCharacteristic());
1845
1846 uint64_t ContentHash = 0;
1847 if (PP->getHeaderSearchInfo()
1850 auto MemBuff = Cache->getBufferIfLoaded();
1851 if (MemBuff)
1852 ContentHash = xxh3_64bits(MemBuff->getBuffer());
1853 else
1854 PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content)
1855 << Entry.File.getName();
1856 }
1857 Entry.ContentHash[0] = uint32_t(ContentHash);
1858 Entry.ContentHash[1] = uint32_t(ContentHash >> 32);
1859 if (Entry.IsSystemFile)
1860 SystemFiles.push_back(Entry);
1861 else
1862 UserFiles.push_back(Entry);
1863 }
1864
1865 // User files go at the front, system files at the back.
1866 auto SortedFiles = llvm::concat<InputFileEntry>(std::move(UserFiles),
1867 std::move(SystemFiles));
1868
1869 unsigned UserFilesNum = 0;
1870 // Write out all of the input files.
1871 std::vector<uint64_t> InputFileOffsets;
1872 for (const auto &Entry : SortedFiles) {
1873 uint32_t &InputFileID = InputFileIDs[Entry.File];
1874 if (InputFileID != 0)
1875 continue; // already recorded this file.
1876
1877 // Record this entry's offset.
1878 InputFileOffsets.push_back(Stream.GetCurrentBitNo() - InputFilesOffsetBase);
1879
1880 InputFileID = InputFileOffsets.size();
1881
1882 if (!Entry.IsSystemFile)
1883 ++UserFilesNum;
1884
1885 // Emit size/modification time for this file.
1886 // And whether this file was overridden.
1887 {
1888 SmallString<128> NameAsRequested = Entry.File.getNameAsRequested();
1889 SmallString<128> Name = Entry.File.getName();
1890
1891 PreparePathForOutput(NameAsRequested);
1893
1894 if (Name == NameAsRequested)
1895 Name.clear();
1896
1897 RecordData::value_type Record[] = {
1898 INPUT_FILE,
1899 InputFileOffsets.size(),
1900 (uint64_t)Entry.File.getSize(),
1901 (uint64_t)getTimestampForOutput(Entry.File),
1902 Entry.BufferOverridden,
1903 Entry.IsTransient,
1904 Entry.IsTopLevel,
1905 Entry.IsModuleMap,
1906 NameAsRequested.size()};
1907
1908 Stream.EmitRecordWithBlob(IFAbbrevCode, Record,
1909 (NameAsRequested + Name).str());
1910 }
1911
1912 // Emit content hash for this file.
1913 {
1914 RecordData::value_type Record[] = {INPUT_FILE_HASH, Entry.ContentHash[0],
1915 Entry.ContentHash[1]};
1916 Stream.EmitRecordWithAbbrev(IFHAbbrevCode, Record);
1917 }
1918 }
1919
1920 Stream.ExitBlock();
1921
1922 // Create input file offsets abbreviation.
1923 auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>();
1924 OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS));
1925 OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files
1926 OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system
1927 // input files
1928 OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array
1929 unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev));
1930
1931 // Write input file offsets.
1932 RecordData::value_type Record[] = {INPUT_FILE_OFFSETS,
1933 InputFileOffsets.size(), UserFilesNum};
1934 Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets));
1935}
1936
1937//===----------------------------------------------------------------------===//
1938// Source Manager Serialization
1939//===----------------------------------------------------------------------===//
1940
1941/// Create an abbreviation for the SLocEntry that refers to a
1942/// file.
1943static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) {
1944 using namespace llvm;
1945
1946 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1947 Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY));
1948 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1949 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
1950 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic
1951 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
1952 // FileEntry fields.
1953 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID
1954 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs
1955 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex
1956 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls
1957 return Stream.EmitAbbrev(std::move(Abbrev));
1958}
1959
1960/// Create an abbreviation for the SLocEntry that refers to a
1961/// buffer.
1962static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) {
1963 using namespace llvm;
1964
1965 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1966 Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY));
1967 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1968 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
1969 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic
1970 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
1971 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob
1972 return Stream.EmitAbbrev(std::move(Abbrev));
1973}
1974
1975/// Create an abbreviation for the SLocEntry that refers to a
1976/// buffer's blob.
1977static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream,
1978 bool Compressed) {
1979 using namespace llvm;
1980
1981 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1982 Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED
1984 if (Compressed)
1985 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size
1986 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob
1987 return Stream.EmitAbbrev(std::move(Abbrev));
1988}
1989
1990/// Create an abbreviation for the SLocEntry that refers to a macro
1991/// expansion.
1992static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) {
1993 using namespace llvm;
1994
1995 auto Abbrev = std::make_shared<BitCodeAbbrev>();
1996 Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY));
1997 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1998 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location
1999 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Start location
2000 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // End location
2001 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is token range
2002 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length
2003 return Stream.EmitAbbrev(std::move(Abbrev));
2004}
2005
2006/// Emit key length and data length as ULEB-encoded data, and return them as a
2007/// pair.
2008static std::pair<unsigned, unsigned>
2009emitULEBKeyDataLength(unsigned KeyLen, unsigned DataLen, raw_ostream &Out) {
2010 llvm::encodeULEB128(KeyLen, Out);
2011 llvm::encodeULEB128(DataLen, Out);
2012 return std::make_pair(KeyLen, DataLen);
2013}
2014
2015namespace {
2016
2017 // Trait used for the on-disk hash table of header search information.
2018 class HeaderFileInfoTrait {
2019 ASTWriter &Writer;
2020
2021 public:
2022 HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {}
2023
2024 struct key_type {
2025 StringRef Filename;
2026 off_t Size;
2027 time_t ModTime;
2028 };
2029 using key_type_ref = const key_type &;
2030
2031 using UnresolvedModule =
2032 llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>;
2033
2034 struct data_type {
2035 data_type(const HeaderFileInfo &HFI, bool AlreadyIncluded,
2037 UnresolvedModule Unresolved)
2038 : HFI(HFI), AlreadyIncluded(AlreadyIncluded),
2039 KnownHeaders(KnownHeaders), Unresolved(Unresolved) {}
2040
2041 HeaderFileInfo HFI;
2042 bool AlreadyIncluded;
2044 UnresolvedModule Unresolved;
2045 };
2046 using data_type_ref = const data_type &;
2047
2048 using hash_value_type = unsigned;
2049 using offset_type = unsigned;
2050
2051 hash_value_type ComputeHash(key_type_ref key) {
2052 // The hash is based only on size/time of the file, so that the reader can
2053 // match even when symlinking or excess path elements ("foo/../", "../")
2054 // change the form of the name. However, complete path is still the key.
2055 uint8_t buf[sizeof(key.Size) + sizeof(key.ModTime)];
2056 memcpy(buf, &key.Size, sizeof(key.Size));
2057 memcpy(buf + sizeof(key.Size), &key.ModTime, sizeof(key.ModTime));
2058 return llvm::xxh3_64bits(buf);
2059 }
2060
2061 std::pair<unsigned, unsigned>
2062 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
2063 unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
2064 unsigned DataLen = 1 + sizeof(IdentifierID);
2065 for (auto ModInfo : Data.KnownHeaders)
2066 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
2067 DataLen += 4;
2068 if (Data.Unresolved.getPointer())
2069 DataLen += 4;
2070 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
2071 }
2072
2073 void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) {
2074 using namespace llvm::support;
2075
2076 endian::Writer LE(Out, llvm::endianness::little);
2077 LE.write<uint64_t>(key.Size);
2078 KeyLen -= 8;
2079 LE.write<uint64_t>(key.ModTime);
2080 KeyLen -= 8;
2081 Out.write(key.Filename.data(), KeyLen);
2082 }
2083
2084 void EmitData(raw_ostream &Out, key_type_ref key,
2085 data_type_ref Data, unsigned DataLen) {
2086 using namespace llvm::support;
2087
2088 endian::Writer LE(Out, llvm::endianness::little);
2089 uint64_t Start = Out.tell(); (void)Start;
2090
2091 unsigned char Flags = (Data.AlreadyIncluded << 6)
2092 | (Data.HFI.isImport << 5)
2093 | (Writer.isWritingStdCXXNamedModules() ? 0 :
2094 Data.HFI.isPragmaOnce << 4)
2095 | (Data.HFI.DirInfo << 1);
2096 LE.write<uint8_t>(Flags);
2097
2098 if (Data.HFI.LazyControllingMacro.isID())
2099 LE.write<IdentifierID>(Data.HFI.LazyControllingMacro.getID());
2100 else
2101 LE.write<IdentifierID>(
2102 Writer.getIdentifierRef(Data.HFI.LazyControllingMacro.getPtr()));
2103
2104 auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
2105 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
2106 uint32_t Value = (ModID << 3) | (unsigned)Role;
2107 assert((Value >> 3) == ModID && "overflow in header module info");
2108 LE.write<uint32_t>(Value);
2109 }
2110 };
2111
2112 for (auto ModInfo : Data.KnownHeaders)
2113 EmitModule(ModInfo.getModule(), ModInfo.getRole());
2114 if (Data.Unresolved.getPointer())
2115 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
2116
2117 assert(Out.tell() - Start == DataLen && "Wrong data length");
2118 }
2119 };
2120
2121} // namespace
2122
2123/// Write the header search block for the list of files that
2124///
2125/// \param HS The header search structure to save.
2126void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
2127 HeaderFileInfoTrait GeneratorTrait(*this);
2128 llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator;
2129 SmallVector<const char *, 4> SavedStrings;
2130 unsigned NumHeaderSearchEntries = 0;
2131
2132 // Find all unresolved headers for the current module. We generally will
2133 // have resolved them before we get here, but not necessarily: we might be
2134 // compiling a preprocessed module, where there is no requirement for the
2135 // original files to exist any more.
2136 const HeaderFileInfo Empty; // So we can take a reference.
2137 if (WritingModule) {
2138 llvm::SmallVector<Module *, 16> Worklist(1, WritingModule);
2139 while (!Worklist.empty()) {
2140 Module *M = Worklist.pop_back_val();
2141 // We don't care about headers in unimportable submodules.
2142 if (M->isUnimportable())
2143 continue;
2144
2145 // Map to disk files where possible, to pick up any missing stat
2146 // information. This also means we don't need to check the unresolved
2147 // headers list when emitting resolved headers in the first loop below.
2148 // FIXME: It'd be preferable to avoid doing this if we were given
2149 // sufficient stat information in the module map.
2150 HS.getModuleMap().resolveHeaderDirectives(M, /*File=*/std::nullopt);
2151
2152 // If the file didn't exist, we can still create a module if we were given
2153 // enough information in the module map.
2154 for (const auto &U : M->MissingHeaders) {
2155 // Check that we were given enough information to build a module
2156 // without this file existing on disk.
2157 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
2158 PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header)
2159 << WritingModule->getFullModuleName() << U.Size.has_value()
2160 << U.FileName;
2161 continue;
2162 }
2163
2164 // Form the effective relative pathname for the file.
2166 llvm::sys::path::append(Filename, U.FileName);
2168
2169 StringRef FilenameDup = strdup(Filename.c_str());
2170 SavedStrings.push_back(FilenameDup.data());
2171
2172 HeaderFileInfoTrait::key_type Key = {
2173 FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0};
2174 HeaderFileInfoTrait::data_type Data = {
2175 Empty, false, {}, {M, ModuleMap::headerKindToRole(U.Kind)}};
2176 // FIXME: Deal with cases where there are multiple unresolved header
2177 // directives in different submodules for the same header.
2178 Generator.insert(Key, Data, GeneratorTrait);
2179 ++NumHeaderSearchEntries;
2180 }
2181 auto SubmodulesRange = M->submodules();
2182 Worklist.append(SubmodulesRange.begin(), SubmodulesRange.end());
2183 }
2184 }
2185
2187 HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
2188
2189 if (FilesByUID.size() > HS.header_file_size())
2190 FilesByUID.resize(HS.header_file_size());
2191
2192 for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
2193 OptionalFileEntryRef File = FilesByUID[UID];
2194 if (!File)
2195 continue;
2196
2198 if (!HFI)
2199 continue; // We have no information on this being a header file.
2200 if (!HFI->isCompilingModuleHeader && HFI->isModuleHeader)
2201 continue; // Header file info is tracked by the owning module file.
2202 if (!HFI->isCompilingModuleHeader && !HFI->IsLocallyIncluded)
2203 continue; // Header file info is tracked by the including module file.
2204
2205 // Massage the file path into an appropriate form.
2206 StringRef Filename = File->getName();
2207 SmallString<128> FilenameTmp(Filename);
2208 if (PreparePathForOutput(FilenameTmp)) {
2209 // If we performed any translation on the file name at all, we need to
2210 // save this string, since the generator will refer to it later.
2211 Filename = StringRef(strdup(FilenameTmp.c_str()));
2212 SavedStrings.push_back(Filename.data());
2213 }
2214
2215 bool Included = HFI->IsLocallyIncluded || PP->alreadyIncluded(*File);
2216
2217 HeaderFileInfoTrait::key_type Key = {
2219 };
2220 HeaderFileInfoTrait::data_type Data = {
2221 *HFI, Included, HS.getModuleMap().findResolvedModulesForHeader(*File), {}
2222 };
2223 Generator.insert(Key, Data, GeneratorTrait);
2224 ++NumHeaderSearchEntries;
2225 }
2226
2227 // Create the on-disk hash table in a buffer.
2228 SmallString<4096> TableData;
2229 uint32_t BucketOffset;
2230 {
2231 using namespace llvm::support;
2232
2233 llvm::raw_svector_ostream Out(TableData);
2234 // Make sure that no bucket is at offset 0
2235 endian::write<uint32_t>(Out, 0, llvm::endianness::little);
2236 BucketOffset = Generator.Emit(Out, GeneratorTrait);
2237 }
2238
2239 // Create a blob abbreviation
2240 using namespace llvm;
2241
2242 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2243 Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE));
2244 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2245 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2246 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2247 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2248 unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2249
2250 // Write the header search table
2251 RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset,
2252 NumHeaderSearchEntries, TableData.size()};
2253 Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData);
2254
2255 // Free all of the strings we had to duplicate.
2256 for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I)
2257 free(const_cast<char *>(SavedStrings[I]));
2258}
2259
2260static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob,
2261 unsigned SLocBufferBlobCompressedAbbrv,
2262 unsigned SLocBufferBlobAbbrv) {
2263 using RecordDataType = ASTWriter::RecordData::value_type;
2264
2265 // Compress the buffer if possible. We expect that almost all PCM
2266 // consumers will not want its contents.
2267 SmallVector<uint8_t, 0> CompressedBuffer;
2268 if (llvm::compression::zstd::isAvailable()) {
2269 llvm::compression::zstd::compress(
2270 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer, 9);
2271 RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 1};
2272 Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
2273 llvm::toStringRef(CompressedBuffer));
2274 return;
2275 }
2276 if (llvm::compression::zlib::isAvailable()) {
2277 llvm::compression::zlib::compress(
2278 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
2279 RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 1};
2280 Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
2281 llvm::toStringRef(CompressedBuffer));
2282 return;
2283 }
2284
2285 RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB};
2286 Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob);
2287}
2288
2289/// Writes the block containing the serialized form of the
2290/// source manager.
2291///
2292/// TODO: We should probably use an on-disk hash table (stored in a
2293/// blob), indexed based on the file name, so that we only create
2294/// entries for files that we actually need. In the common case (no
2295/// errors), we probably won't have to create file entries for any of
2296/// the files in the AST.
2297void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr) {
2299
2300 // Enter the source manager block.
2301 Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4);
2302 const uint64_t SourceManagerBlockOffset = Stream.GetCurrentBitNo();
2303
2304 // Abbreviations for the various kinds of source-location entries.
2305 unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream);
2306 unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream);
2307 unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false);
2308 unsigned SLocBufferBlobCompressedAbbrv =
2309 CreateSLocBufferBlobAbbrev(Stream, true);
2310 unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream);
2311
2312 // Write out the source location entry table. We skip the first
2313 // entry, which is always the same dummy entry.
2314 std::vector<uint32_t> SLocEntryOffsets;
2315 uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo();
2316 SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
2317 for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
2318 I != N; ++I) {
2319 // Get this source location entry.
2320 const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I);
2321 FileID FID = FileID::get(I);
2322 assert(&SourceMgr.getSLocEntry(FID) == SLoc);
2323
2324 // Record the offset of this source-location entry.
2325 uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase;
2326 assert((Offset >> 32) == 0 && "SLocEntry offset too large");
2327
2328 // Figure out which record code to use.
2329 unsigned Code;
2330 if (SLoc->isFile()) {
2332 if (Cache->OrigEntry) {
2333 Code = SM_SLOC_FILE_ENTRY;
2334 } else
2335 Code = SM_SLOC_BUFFER_ENTRY;
2336 } else
2338 Record.clear();
2339 Record.push_back(Code);
2340
2341 if (SLoc->isFile()) {
2342 const SrcMgr::FileInfo &File = SLoc->getFile();
2343 const SrcMgr::ContentCache *Content = &File.getContentCache();
2344 // Do not emit files that were not listed as inputs.
2345 if (!IsSLocAffecting[I])
2346 continue;
2347 SLocEntryOffsets.push_back(Offset);
2348 // Starting offset of this entry within this module, so skip the dummy.
2349 Record.push_back(getAdjustedOffset(SLoc->getOffset()) - 2);
2350 AddSourceLocation(getAffectingIncludeLoc(SourceMgr, File), Record);
2351 Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
2352 Record.push_back(File.hasLineDirectives());
2353
2354 bool EmitBlob = false;
2355 if (Content->OrigEntry) {
2356 assert(Content->OrigEntry == Content->ContentsEntry &&
2357 "Writing to AST an overridden file is not supported");
2358
2359 // The source location entry is a file. Emit input file ID.
2360 assert(InputFileIDs[*Content->OrigEntry] != 0 && "Missed file entry");
2361 Record.push_back(InputFileIDs[*Content->OrigEntry]);
2362
2363 Record.push_back(getAdjustedNumCreatedFIDs(FID));
2364
2365 FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID);
2366 if (FDI != FileDeclIDs.end()) {
2367 Record.push_back(FDI->second->FirstDeclIndex);
2368 Record.push_back(FDI->second->DeclIDs.size());
2369 } else {
2370 Record.push_back(0);
2371 Record.push_back(0);
2372 }
2373
2374 Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record);
2375
2376 if (Content->BufferOverridden || Content->IsTransient)
2377 EmitBlob = true;
2378 } else {
2379 // The source location entry is a buffer. The blob associated
2380 // with this entry contains the contents of the buffer.
2381
2382 // We add one to the size so that we capture the trailing NULL
2383 // that is required by llvm::MemoryBuffer::getMemBuffer (on
2384 // the reader side).
2385 std::optional<llvm::MemoryBufferRef> Buffer = Content->getBufferOrNone(
2386 SourceMgr.getDiagnostics(), SourceMgr.getFileManager());
2387 StringRef Name = Buffer ? Buffer->getBufferIdentifier() : "";
2388 Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
2389 StringRef(Name.data(), Name.size() + 1));
2390 EmitBlob = true;
2391 }
2392
2393 if (EmitBlob) {
2394 // Include the implicit terminating null character in the on-disk buffer
2395 // if we're writing it uncompressed.
2396 std::optional<llvm::MemoryBufferRef> Buffer = Content->getBufferOrNone(
2397 SourceMgr.getDiagnostics(), SourceMgr.getFileManager());
2398 if (!Buffer)
2399 Buffer = llvm::MemoryBufferRef("<<<INVALID BUFFER>>>", "");
2400 StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1);
2401 emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv,
2402 SLocBufferBlobAbbrv);
2403 }
2404 } else {
2405 // The source location entry is a macro expansion.
2406 const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion();
2407 SLocEntryOffsets.push_back(Offset);
2408 // Starting offset of this entry within this module, so skip the dummy.
2409 Record.push_back(getAdjustedOffset(SLoc->getOffset()) - 2);
2410 LocSeq::State Seq;
2414 ? SourceLocation()
2415 : Expansion.getExpansionLocEnd(),
2416 Record, Seq);
2417 Record.push_back(Expansion.isExpansionTokenRange());
2418
2419 // Compute the token length for this macro expansion.
2420 SourceLocation::UIntTy NextOffset = SourceMgr.getNextLocalOffset();
2421 if (I + 1 != N)
2422 NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset();
2423 Record.push_back(getAdjustedOffset(NextOffset - SLoc->getOffset()) - 1);
2424 Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record);
2425 }
2426 }
2427
2428 Stream.ExitBlock();
2429
2430 if (SLocEntryOffsets.empty())
2431 return;
2432
2433 // Write the source-location offsets table into the AST block. This
2434 // table is used for lazily loading source-location information.
2435 using namespace llvm;
2436
2437 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2438 Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
2439 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
2440 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
2441 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
2442 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
2443 unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2444 {
2445 RecordData::value_type Record[] = {
2446 SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
2447 getAdjustedOffset(SourceMgr.getNextLocalOffset()) - 1 /* skip dummy */,
2448 SLocEntryOffsetsBase - SourceManagerBlockOffset};
2449 Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
2450 bytes(SLocEntryOffsets));
2451 }
2452
2453 // Write the line table. It depends on remapping working, so it must come
2454 // after the source location offsets.
2455 if (SourceMgr.hasLineTable()) {
2456 LineTableInfo &LineTable = SourceMgr.getLineTable();
2457
2458 Record.clear();
2459
2460 // Emit the needed file names.
2461 llvm::DenseMap<int, int> FilenameMap;
2462 FilenameMap[-1] = -1; // For unspecified filenames.
2463 for (const auto &L : LineTable) {
2464 if (L.first.ID < 0)
2465 continue;
2466 for (auto &LE : L.second) {
2467 if (FilenameMap.insert(std::make_pair(LE.FilenameID,
2468 FilenameMap.size() - 1)).second)
2469 AddPath(LineTable.getFilename(LE.FilenameID), Record);
2470 }
2471 }
2472 Record.push_back(0);
2473
2474 // Emit the line entries
2475 for (const auto &L : LineTable) {
2476 // Only emit entries for local files.
2477 if (L.first.ID < 0)
2478 continue;
2479
2480 AddFileID(L.first, Record);
2481
2482 // Emit the line entries
2483 Record.push_back(L.second.size());
2484 for (const auto &LE : L.second) {
2485 Record.push_back(LE.FileOffset);
2486 Record.push_back(LE.LineNo);
2487 Record.push_back(FilenameMap[LE.FilenameID]);
2488 Record.push_back((unsigned)LE.FileKind);
2489 Record.push_back(LE.IncludeOffset);
2490 }
2491 }
2492
2493 Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record);
2494 }
2495}
2496
2497//===----------------------------------------------------------------------===//
2498// Preprocessor Serialization
2499//===----------------------------------------------------------------------===//
2500
2501static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
2502 const Preprocessor &PP) {
2503 if (MacroInfo *MI = MD->getMacroInfo())
2504 if (MI->isBuiltinMacro())
2505 return true;
2506
2507 if (IsModule) {
2509 if (Loc.isInvalid())
2510 return true;
2512 return true;
2513 }
2514
2515 return false;
2516}
2517
2518/// Writes the block containing the serialized form of the
2519/// preprocessor.
2520void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2521 uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
2522
2524 if (PPRec)
2525 WritePreprocessorDetail(*PPRec, MacroOffsetsBase);
2526
2528 RecordData ModuleMacroRecord;
2529
2530 // If the preprocessor __COUNTER__ value has been bumped, remember it.
2531 if (PP.getCounterValue() != 0) {
2532 RecordData::value_type Record[] = {PP.getCounterValue()};
2533 Stream.EmitRecord(PP_COUNTER_VALUE, Record);
2534 }
2535
2536 // If we have a recorded #pragma assume_nonnull, remember it so it can be
2537 // replayed when the preamble terminates into the main file.
2538 SourceLocation AssumeNonNullLoc =
2540 if (AssumeNonNullLoc.isValid()) {
2541 assert(PP.isRecordingPreamble());
2542 AddSourceLocation(AssumeNonNullLoc, Record);
2543 Stream.EmitRecord(PP_ASSUME_NONNULL_LOC, Record);
2544 Record.clear();
2545 }
2546
2547 if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
2548 assert(!IsModule);
2549 auto SkipInfo = PP.getPreambleSkipInfo();
2550 if (SkipInfo) {
2551 Record.push_back(true);
2552 AddSourceLocation(SkipInfo->HashTokenLoc, Record);
2553 AddSourceLocation(SkipInfo->IfTokenLoc, Record);
2554 Record.push_back(SkipInfo->FoundNonSkipPortion);
2555 Record.push_back(SkipInfo->FoundElse);
2556 AddSourceLocation(SkipInfo->ElseLoc, Record);
2557 } else {
2558 Record.push_back(false);
2559 }
2560 for (const auto &Cond : PP.getPreambleConditionalStack()) {
2561 AddSourceLocation(Cond.IfLoc, Record);
2562 Record.push_back(Cond.WasSkipping);
2563 Record.push_back(Cond.FoundNonSkip);
2564 Record.push_back(Cond.FoundElse);
2565 }
2566 Stream.EmitRecord(PP_CONDITIONAL_STACK, Record);
2567 Record.clear();
2568 }
2569
2570 // Write the safe buffer opt-out region map in PP
2573 Stream.EmitRecord(PP_UNSAFE_BUFFER_USAGE, Record);
2574 Record.clear();
2575
2576 // Enter the preprocessor block.
2577 Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3);
2578
2579 // If the AST file contains __DATE__ or __TIME__ emit a warning about this.
2580 // FIXME: Include a location for the use, and say which one was used.
2581 if (PP.SawDateOrTime())
2582 PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule;
2583
2584 // Loop over all the macro directives that are live at the end of the file,
2585 // emitting each to the PP section.
2586
2587 // Construct the list of identifiers with macro directives that need to be
2588 // serialized.
2590 // It is meaningless to emit macros for named modules. It only wastes times
2591 // and spaces.
2593 for (auto &Id : PP.getIdentifierTable())
2594 if (Id.second->hadMacroDefinition() &&
2595 (!Id.second->isFromAST() ||
2596 Id.second->hasChangedSinceDeserialization()))
2597 MacroIdentifiers.push_back(Id.second);
2598 // Sort the set of macro definitions that need to be serialized by the
2599 // name of the macro, to provide a stable ordering.
2600 llvm::sort(MacroIdentifiers, llvm::deref<std::less<>>());
2601
2602 // Emit the macro directives as a list and associate the offset with the
2603 // identifier they belong to.
2604 for (const IdentifierInfo *Name : MacroIdentifiers) {
2606 uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2607 assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
2608
2609 // Write out any exported module macros.
2610 bool EmittedModuleMacros = false;
2611 // C+=20 Header Units are compiled module interfaces, but they preserve
2612 // macros that are live (i.e. have a defined value) at the end of the
2613 // compilation. So when writing a header unit, we preserve only the final
2614 // value of each macro (and discard any that are undefined). Header units
2615 // do not have sub-modules (although they might import other header units).
2616 // PCH files, conversely, retain the history of each macro's define/undef
2617 // and of leaf macros in sub modules.
2618 if (IsModule && WritingModule->isHeaderUnit()) {
2619 // This is for the main TU when it is a C++20 header unit.
2620 // We preserve the final state of defined macros, and we do not emit ones
2621 // that are undefined.
2622 if (!MD || shouldIgnoreMacro(MD, IsModule, PP) ||
2624 continue;
2626 Record.push_back(MD->getKind());
2627 if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) {
2628 Record.push_back(getMacroRef(DefMD->getInfo(), Name));
2629 } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
2630 Record.push_back(VisMD->isPublic());
2631 }
2632 ModuleMacroRecord.push_back(getSubmoduleID(WritingModule));
2633 ModuleMacroRecord.push_back(getMacroRef(MD->getMacroInfo(), Name));
2634 Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord);
2635 ModuleMacroRecord.clear();
2636 EmittedModuleMacros = true;
2637 } else {
2638 // Emit the macro directives in reverse source order.
2639 for (; MD; MD = MD->getPrevious()) {
2640 // Once we hit an ignored macro, we're done: the rest of the chain
2641 // will all be ignored macros.
2642 if (shouldIgnoreMacro(MD, IsModule, PP))
2643 break;
2645 Record.push_back(MD->getKind());
2646 if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) {
2647 Record.push_back(getMacroRef(DefMD->getInfo(), Name));
2648 } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
2649 Record.push_back(VisMD->isPublic());
2650 }
2651 }
2652
2653 // We write out exported module macros for PCH as well.
2654 auto Leafs = PP.getLeafModuleMacros(Name);
2655 SmallVector<ModuleMacro *, 8> Worklist(Leafs);
2656 llvm::DenseMap<ModuleMacro *, unsigned> Visits;
2657 while (!Worklist.empty()) {
2658 auto *Macro = Worklist.pop_back_val();
2659
2660 // Emit a record indicating this submodule exports this macro.
2661 ModuleMacroRecord.push_back(getSubmoduleID(Macro->getOwningModule()));
2662 ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name));
2663 for (auto *M : Macro->overrides())
2664 ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule()));
2665
2666 Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord);
2667 ModuleMacroRecord.clear();
2668
2669 // Enqueue overridden macros once we've visited all their ancestors.
2670 for (auto *M : Macro->overrides())
2671 if (++Visits[M] == M->getNumOverridingMacros())
2672 Worklist.push_back(M);
2673
2674 EmittedModuleMacros = true;
2675 }
2676 }
2677 if (Record.empty() && !EmittedModuleMacros)
2678 continue;
2679
2680 IdentMacroDirectivesOffsetMap[Name] = StartOffset;
2681 Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record);
2682 Record.clear();
2683 }
2684
2685 /// Offsets of each of the macros into the bitstream, indexed by
2686 /// the local macro ID
2687 ///
2688 /// For each identifier that is associated with a macro, this map
2689 /// provides the offset into the bitstream where that macro is
2690 /// defined.
2691 std::vector<uint32_t> MacroOffsets;
2692
2693 for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) {
2694 const IdentifierInfo *Name = MacroInfosToEmit[I].Name;
2695 MacroInfo *MI = MacroInfosToEmit[I].MI;
2696 MacroID ID = MacroInfosToEmit[I].ID;
2697
2698 if (ID < FirstMacroID) {
2699 assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?");
2700 continue;
2701 }
2702
2703 // Record the local offset of this macro.
2704 unsigned Index = ID - FirstMacroID;
2705 if (Index >= MacroOffsets.size())
2706 MacroOffsets.resize(Index + 1);
2707
2708 uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2709 assert((Offset >> 32) == 0 && "Macro offset too large");
2710 MacroOffsets[Index] = Offset;
2711
2712 AddIdentifierRef(Name, Record);
2715 Record.push_back(MI->isUsed());
2716 Record.push_back(MI->isUsedForHeaderGuard());
2717 Record.push_back(MI->getNumTokens());
2718 unsigned Code;
2719 if (MI->isObjectLike()) {
2720 Code = PP_MACRO_OBJECT_LIKE;
2721 } else {
2723
2724 Record.push_back(MI->isC99Varargs());
2725 Record.push_back(MI->isGNUVarargs());
2726 Record.push_back(MI->hasCommaPasting());
2727 Record.push_back(MI->getNumParams());
2728 for (const IdentifierInfo *Param : MI->params())
2729 AddIdentifierRef(Param, Record);
2730 }
2731
2732 // If we have a detailed preprocessing record, record the macro definition
2733 // ID that corresponds to this macro.
2734 if (PPRec)
2735 Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]);
2736
2737 Stream.EmitRecord(Code, Record);
2738 Record.clear();
2739
2740 // Emit the tokens array.
2741 for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
2742 // Note that we know that the preprocessor does not have any annotation
2743 // tokens in it because they are created by the parser, and thus can't
2744 // be in a macro definition.
2745 const Token &Tok = MI->getReplacementToken(TokNo);
2746 AddToken(Tok, Record);
2747 Stream.EmitRecord(PP_TOKEN, Record);
2748 Record.clear();
2749 }
2750 ++NumMacros;
2751 }
2752
2753 Stream.ExitBlock();
2754
2755 // Write the offsets table for macro IDs.
2756 using namespace llvm;
2757
2758 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2759 Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET));
2760 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros
2761 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
2762 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
2763 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2764
2765 unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2766 {
2767 RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(),
2768 FirstMacroID - NUM_PREDEF_MACRO_IDS,
2769 MacroOffsetsBase - ASTBlockStartOffset};
2770 Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
2771 }
2772}
2773
2774void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
2775 uint64_t MacroOffsetsBase) {
2776 if (PPRec.local_begin() == PPRec.local_end())
2777 return;
2778
2779 SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets;
2780
2781 // Enter the preprocessor block.
2782 Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3);
2783
2784 // If the preprocessor has a preprocessing record, emit it.
2785 unsigned NumPreprocessingRecords = 0;
2786 using namespace llvm;
2787
2788 // Set up the abbreviation for
2789 unsigned InclusionAbbrev = 0;
2790 {
2791 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2792 Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE));
2793 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length
2794 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes
2795 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind
2796 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module
2797 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2798 InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2799 }
2800
2801 unsigned FirstPreprocessorEntityID
2802 = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0)
2804 unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID;
2807 EEnd = PPRec.local_end();
2808 E != EEnd;
2809 (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
2810 Record.clear();
2811
2812 uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2813 assert((Offset >> 32) == 0 && "Preprocessed entity offset too large");
2814 SourceRange R = getAdjustedRange((*E)->getSourceRange());
2815 PreprocessedEntityOffsets.emplace_back(
2818
2819 if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
2820 // Record this macro definition's ID.
2821 MacroDefinitions[MD] = NextPreprocessorEntityID;
2822
2823 AddIdentifierRef(MD->getName(), Record);
2824 Stream.EmitRecord(PPD_MACRO_DEFINITION, Record);
2825 continue;
2826 }
2827
2828 if (auto *ME = dyn_cast<MacroExpansion>(*E)) {
2829 Record.push_back(ME->isBuiltinMacro());
2830 if (ME->isBuiltinMacro())
2831 AddIdentifierRef(ME->getName(), Record);
2832 else
2833 Record.push_back(MacroDefinitions[ME->getDefinition()]);
2834 Stream.EmitRecord(PPD_MACRO_EXPANSION, Record);
2835 continue;
2836 }
2837
2838 if (auto *ID = dyn_cast<InclusionDirective>(*E)) {
2840 Record.push_back(ID->getFileName().size());
2841 Record.push_back(ID->wasInQuotes());
2842 Record.push_back(static_cast<unsigned>(ID->getKind()));
2843 Record.push_back(ID->importedModule());
2844 SmallString<64> Buffer;
2845 Buffer += ID->getFileName();
2846 // Check that the FileEntry is not null because it was not resolved and
2847 // we create a PCH even with compiler errors.
2848 if (ID->getFile())
2849 Buffer += ID->getFile()->getName();
2850 Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer);
2851 continue;
2852 }
2853
2854 llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter");
2855 }
2856 Stream.ExitBlock();
2857
2858 // Write the offsets table for the preprocessing record.
2859 if (NumPreprocessingRecords > 0) {
2860 assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords);
2861
2862 // Write the offsets table for identifier IDs.
2863 using namespace llvm;
2864
2865 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2866 Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS));
2867 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity
2868 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2869 unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2870
2871 RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS,
2872 FirstPreprocessorEntityID -
2874 Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record,
2875 bytes(PreprocessedEntityOffsets));
2876 }
2877
2878 // Write the skipped region table for the preprocessing record.
2879 ArrayRef<SourceRange> SkippedRanges = PPRec.getSkippedRanges();
2880 if (SkippedRanges.size() > 0) {
2881 std::vector<PPSkippedRange> SerializedSkippedRanges;
2882 SerializedSkippedRanges.reserve(SkippedRanges.size());
2883 for (auto const& Range : SkippedRanges)
2884 SerializedSkippedRanges.emplace_back(
2887
2888 using namespace llvm;
2889 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2890 Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES));
2891 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2892 unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2893
2894 Record.clear();
2895 Record.push_back(PPD_SKIPPED_RANGES);
2896 Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record,
2897 bytes(SerializedSkippedRanges));
2898 }
2899}
2900
2902 if (!Mod)
2903 return 0;
2904
2905 auto Known = SubmoduleIDs.find(Mod);
2906 if (Known != SubmoduleIDs.end())
2907 return Known->second;
2908
2909 auto *Top = Mod->getTopLevelModule();
2910 if (Top != WritingModule &&
2911 (getLangOpts().CompilingPCH ||
2912 !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule))))
2913 return 0;
2914
2915 return SubmoduleIDs[Mod] = NextSubmoduleID++;
2916}
2917
2918unsigned ASTWriter::getSubmoduleID(Module *Mod) {
2919 unsigned ID = getLocalOrImportedSubmoduleID(Mod);
2920 // FIXME: This can easily happen, if we have a reference to a submodule that
2921 // did not result in us loading a module file for that submodule. For
2922 // instance, a cross-top-level-module 'conflict' declaration will hit this.
2923 // assert((ID || !Mod) &&
2924 // "asked for module ID for non-local, non-imported module");
2925 return ID;
2926}
2927
2928/// Compute the number of modules within the given tree (including the
2929/// given module).
2930static unsigned getNumberOfModules(Module *Mod) {
2931 unsigned ChildModules = 0;
2932 for (auto *Submodule : Mod->submodules())
2933 ChildModules += getNumberOfModules(Submodule);
2934
2935 return ChildModules + 1;
2936}
2937
2938void ASTWriter::WriteSubmodules(Module *WritingModule, ASTContext *Context) {
2939 // Enter the submodule description block.
2940 Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5);
2941
2942 // Write the abbreviations needed for the submodules block.
2943 using namespace llvm;
2944
2945 auto Abbrev = std::make_shared<BitCodeAbbrev>();
2946 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
2947 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
2948 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
2949 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // Kind
2950 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Definition location
2951 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // Inferred allowed by
2952 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
2953 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
2954 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
2955 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC
2956 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules...
2957 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit...
2958 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild...
2959 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh...
2960 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModuleMapIsPriv...
2961 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NamedModuleHasN...
2962 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2963 unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2964
2965 Abbrev = std::make_shared<BitCodeAbbrev>();
2966 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER));
2967 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2968 unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2969
2970 Abbrev = std::make_shared<BitCodeAbbrev>();
2971 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER));
2972 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2973 unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2974
2975 Abbrev = std::make_shared<BitCodeAbbrev>();
2976 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER));
2977 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2978 unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2979
2980 Abbrev = std::make_shared<BitCodeAbbrev>();
2981 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR));
2982 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2983 unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2984
2985 Abbrev = std::make_shared<BitCodeAbbrev>();
2986 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES));
2987 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State
2988 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature
2989 unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2990
2991 Abbrev = std::make_shared<BitCodeAbbrev>();
2992 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER));
2993 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2994 unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2995
2996 Abbrev = std::make_shared<BitCodeAbbrev>();
2997 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER));
2998 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2999 unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3000
3001 Abbrev = std::make_shared<BitCodeAbbrev>();
3002 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER));
3003 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
3004 unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3005
3006 Abbrev = std::make_shared<BitCodeAbbrev>();
3007 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER));
3008 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
3009 unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3010
3011 Abbrev = std::make_shared<BitCodeAbbrev>();
3012 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY));
3013 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
3014 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
3015 unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3016
3017 Abbrev = std::make_shared<BitCodeAbbrev>();
3018 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO));
3019 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name
3020 unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3021
3022 Abbrev = std::make_shared<BitCodeAbbrev>();
3023 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT));
3024 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module
3025 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message
3026 unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3027
3028 Abbrev = std::make_shared<BitCodeAbbrev>();
3029 Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXPORT_AS));
3030 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name
3031 unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3032
3033 // Write the submodule metadata block.
3034 RecordData::value_type Record[] = {
3035 getNumberOfModules(WritingModule),
3036 FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS};
3037 Stream.EmitRecord(SUBMODULE_METADATA, Record);
3038
3039 // Write all of the submodules.
3040 std::queue<Module *> Q;
3041 Q.push(WritingModule);
3042 while (!Q.empty()) {
3043 Module *Mod = Q.front();
3044 Q.pop();
3045 unsigned ID = getSubmoduleID(Mod);
3046
3047 uint64_t ParentID = 0;
3048 if (Mod->Parent) {
3049 assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?");
3050 ParentID = SubmoduleIDs[Mod->Parent];
3051 }
3052
3054 getRawSourceLocationEncoding(getAdjustedLocation(Mod->DefinitionLoc));
3055
3056 ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap();
3057 FileID UnadjustedInferredFID;
3058 if (Mod->IsInferred)
3059 UnadjustedInferredFID = ModMap.getModuleMapFileIDForUniquing(Mod);
3060 int InferredFID = getAdjustedFileID(UnadjustedInferredFID).getOpaqueValue();
3061
3062 // Emit the definition of the block.
3063 {
3064 RecordData::value_type Record[] = {SUBMODULE_DEFINITION,
3065 ID,
3066 ParentID,
3067 (RecordData::value_type)Mod->Kind,
3068 DefinitionLoc,
3069 (RecordData::value_type)InferredFID,
3070 Mod->IsFramework,
3071 Mod->IsExplicit,
3072 Mod->IsSystem,
3073 Mod->IsExternC,
3074 Mod->InferSubmodules,
3078 Mod->ModuleMapIsPrivate,
3079 Mod->NamedModuleHasInit};
3080 Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name);
3081 }
3082
3083 // Emit the requirements.
3084 for (const auto &R : Mod->Requirements) {
3085 RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.RequiredState};
3086 Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.FeatureName);
3087 }
3088
3089 // Emit the umbrella header, if there is one.
3090 if (std::optional<Module::Header> UmbrellaHeader =
3092 RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER};
3093 Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record,
3094 UmbrellaHeader->NameAsWritten);
3095 } else if (std::optional<Module::DirectoryName> UmbrellaDir =
3096 Mod->getUmbrellaDirAsWritten()) {
3097 RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR};
3098 Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record,
3099 UmbrellaDir->NameAsWritten);
3100 }
3101
3102 // Emit the headers.
3103 struct {
3104 unsigned RecordKind;
3105 unsigned Abbrev;
3106 Module::HeaderKind HeaderKind;
3107 } HeaderLists[] = {
3108 {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal},
3109 {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual},
3110 {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private},
3111 {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev,
3113 {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded}
3114 };
3115 for (const auto &HL : HeaderLists) {
3116 RecordData::value_type Record[] = {HL.RecordKind};
3117 for (const auto &H : Mod->getHeaders(HL.HeaderKind))
3118 Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten);
3119 }
3120
3121 // Emit the top headers.
3122 {
3123 RecordData::value_type Record[] = {SUBMODULE_TOPHEADER};
3124 for (FileEntryRef H : Mod->getTopHeaders(PP->getFileManager())) {
3125 SmallString<128> HeaderName(H.getName());
3126 PreparePathForOutput(HeaderName);
3127 Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, HeaderName);
3128 }
3129 }
3130
3131 // Emit the imports.
3132 if (!Mod->Imports.empty()) {
3134 for (auto *I : Mod->Imports)
3135 Record.push_back(getSubmoduleID(I));
3136 Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
3137 }
3138
3139 // Emit the modules affecting compilation that were not imported.
3140 if (!Mod->AffectingClangModules.empty()) {
3142 for (auto *I : Mod->AffectingClangModules)
3143 Record.push_back(getSubmoduleID(I));
3144 Stream.EmitRecord(SUBMODULE_AFFECTING_MODULES, Record);
3145 }
3146
3147 // Emit the exports.
3148 if (!Mod->Exports.empty()) {
3150 for (const auto &E : Mod->Exports) {
3151 // FIXME: This may fail; we don't require that all exported modules
3152 // are local or imported.
3153 Record.push_back(getSubmoduleID(E.getPointer()));
3154 Record.push_back(E.getInt());
3155 }
3156 Stream.EmitRecord(SUBMODULE_EXPORTS, Record);
3157 }
3158
3159 //FIXME: How do we emit the 'use'd modules? They may not be submodules.
3160 // Might be unnecessary as use declarations are only used to build the
3161 // module itself.
3162
3163 // TODO: Consider serializing undeclared uses of modules.
3164
3165 // Emit the link libraries.
3166 for (const auto &LL : Mod->LinkLibraries) {
3167 RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY,
3168 LL.IsFramework};
3169 Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library);
3170 }
3171
3172 // Emit the conflicts.
3173 for (const auto &C : Mod->Conflicts) {
3174 // FIXME: This may fail; we don't require that all conflicting modules
3175 // are local or imported.
3176 RecordData::value_type Record[] = {SUBMODULE_CONFLICT,
3177 getSubmoduleID(C.Other)};
3178 Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message);
3179 }
3180
3181 // Emit the configuration macros.
3182 for (const auto &CM : Mod->ConfigMacros) {
3183 RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO};
3184 Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM);
3185 }
3186
3187 // Emit the reachable initializers.
3188 // The initializer may only be unreachable in reduced BMI.
3189 if (Context) {
3190 RecordData Inits;
3191 for (Decl *D : Context->getModuleInitializers(Mod))
3192 if (wasDeclEmitted(D))
3193 AddDeclRef(D, Inits);
3194 if (!Inits.empty())
3195 Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits);
3196 }
3197
3198 // Emit the name of the re-exported module, if any.
3199 if (!Mod->ExportAsModule.empty()) {
3200 RecordData::value_type Record[] = {SUBMODULE_EXPORT_AS};
3201 Stream.EmitRecordWithBlob(ExportAsAbbrev, Record, Mod->ExportAsModule);
3202 }
3203
3204 // Queue up the submodules of this module.
3205 for (auto *M : Mod->submodules())
3206 Q.push(M);
3207 }
3208
3209 Stream.ExitBlock();
3210
3211 assert((NextSubmoduleID - FirstSubmoduleID ==
3212 getNumberOfModules(WritingModule)) &&
3213 "Wrong # of submodules; found a reference to a non-local, "
3214 "non-imported submodule?");
3215}
3216
3217void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
3218 bool isModule) {
3219 llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64>
3220 DiagStateIDMap;
3221 unsigned CurrID = 0;
3223
3224 auto EncodeDiagStateFlags =
3225 [](const DiagnosticsEngine::DiagState *DS) -> unsigned {
3226 unsigned Result = (unsigned)DS->ExtBehavior;
3227 for (unsigned Val :
3228 {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings,
3229 (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal,
3230 (unsigned)DS->SuppressSystemWarnings})
3231 Result = (Result << 1) | Val;
3232 return Result;
3233 };
3234
3235 unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState);
3236 Record.push_back(Flags);
3237
3238 auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State,
3239 bool IncludeNonPragmaStates) {
3240 // Ensure that the diagnostic state wasn't modified since it was created.
3241 // We will not correctly round-trip this information otherwise.
3242 assert(Flags == EncodeDiagStateFlags(State) &&
3243 "diag state flags vary in single AST file");
3244
3245 // If we ever serialize non-pragma mappings outside the initial state, the
3246 // code below will need to consider more than getDefaultMapping.
3247 assert(!IncludeNonPragmaStates ||
3248 State == Diag.DiagStatesByLoc.FirstDiagState);
3249
3250 unsigned &DiagStateID = DiagStateIDMap[State];
3251 Record.push_back(DiagStateID);
3252
3253 if (DiagStateID == 0) {
3254 DiagStateID = ++CurrID;
3256
3257 // Add a placeholder for the number of mappings.
3258 auto SizeIdx = Record.size();
3259 Record.emplace_back();
3260 for (const auto &I : *State) {
3261 // Maybe skip non-pragmas.
3262 if (!I.second.isPragma() && !IncludeNonPragmaStates)
3263 continue;
3264 // Skip default mappings. We have a mapping for every diagnostic ever
3265 // emitted, regardless of whether it was customized.
3266 if (!I.second.isPragma() &&
3267 I.second == DiagnosticIDs::getDefaultMapping(I.first))
3268 continue;
3269 Mappings.push_back(I);
3270 }
3271
3272 // Sort by diag::kind for deterministic output.
3273 llvm::sort(Mappings, llvm::less_first());
3274
3275 for (const auto &I : Mappings) {
3276 Record.push_back(I.first);
3277 Record.push_back(I.second.serialize());
3278 }
3279 // Update the placeholder.
3280 Record[SizeIdx] = (Record.size() - SizeIdx) / 2;
3281 }
3282 };
3283
3284 AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule);
3285
3286 // Reserve a spot for the number of locations with state transitions.
3287 auto NumLocationsIdx = Record.size();
3288 Record.emplace_back();
3289
3290 // Emit the state transitions.
3291 unsigned NumLocations = 0;
3292 for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) {
3293 if (!FileIDAndFile.first.isValid() ||
3294 !FileIDAndFile.second.HasLocalTransitions)
3295 continue;
3296 ++NumLocations;
3297
3298 AddFileID(FileIDAndFile.first, Record);
3299
3300 Record.push_back(FileIDAndFile.second.StateTransitions.size());
3301 for (auto &StatePoint : FileIDAndFile.second.StateTransitions) {
3302 Record.push_back(getAdjustedOffset(StatePoint.Offset));
3303 AddDiagState(StatePoint.State, false);
3304 }
3305 }
3306
3307 // Backpatch the number of locations.
3308 Record[NumLocationsIdx] = NumLocations;
3309
3310 // Emit CurDiagStateLoc. Do it last in order to match source order.
3311 //
3312 // This also protects against a hypothetical corner case with simulating
3313 // -Werror settings for implicit modules in the ASTReader, where reading
3314 // CurDiagState out of context could change whether warning pragmas are
3315 // treated as errors.
3316 AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record);
3317 AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false);
3318
3319 Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record);
3320}
3321
3322//===----------------------------------------------------------------------===//
3323// Type Serialization
3324//===----------------------------------------------------------------------===//
3325
3326/// Write the representation of a type to the AST stream.
3327void ASTWriter::WriteType(ASTContext &Context, QualType T) {
3328 TypeIdx &IdxRef = TypeIdxs[T];
3329 if (IdxRef.getValue() == 0) // we haven't seen this type before.
3330 IdxRef = TypeIdx(0, NextTypeID++);
3331 TypeIdx Idx = IdxRef;
3332
3333 assert(Idx.getModuleFileIndex() == 0 && "Re-writing a type from a prior AST");
3334 assert(Idx.getValue() >= FirstTypeID && "Writing predefined type");
3335
3336 // Emit the type's representation.
3337 uint64_t Offset =
3338 ASTTypeWriter(Context, *this).write(T) - DeclTypesBlockStartOffset;
3339
3340 // Record the offset for this type.
3341 uint64_t Index = Idx.getValue() - FirstTypeID;
3342 if (TypeOffsets.size() == Index)
3343 TypeOffsets.emplace_back(Offset);
3344 else if (TypeOffsets.size() < Index) {
3345 TypeOffsets.resize(Index + 1);
3346 TypeOffsets[Index].set(Offset);
3347 } else {
3348 llvm_unreachable("Types emitted in wrong order");
3349 }
3350}
3351
3352//===----------------------------------------------------------------------===//
3353// Declaration Serialization
3354//===----------------------------------------------------------------------===//
3355
3357 auto *ND = dyn_cast<NamedDecl>(D);
3358 if (!ND)
3359 return false;
3360
3362 return false;
3363
3364 return ND->getFormalLinkage() == Linkage::Internal;
3365}
3366
3367/// Write the block containing all of the declaration IDs
3368/// lexically declared within the given DeclContext.
3369///
3370/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the
3371/// bitstream, or 0 if no block was written.
3372uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
3373 const DeclContext *DC) {
3374 if (DC->decls_empty())
3375 return 0;
3376
3377 // In reduced BMI, we don't care the declarations in functions.
3378 if (GeneratingReducedBMI && DC->isFunctionOrMethod())
3379 return 0;
3380
3381 uint64_t Offset = Stream.GetCurrentBitNo();
3382 SmallVector<DeclID, 128> KindDeclPairs;
3383 for (const auto *D : DC->decls()) {
3384 if (DoneWritingDeclsAndTypes && !wasDeclEmitted(D))
3385 continue;
3386
3387 // We don't need to write decls with internal linkage into reduced BMI.
3388 // If such decls gets emitted due to it get used from inline functions,
3389 // the program illegal. However, there are too many use of static inline
3390 // functions in the global module fragment and it will be breaking change
3391 // to forbid that. So we have to allow to emit such declarations from GMF.
3392 if (GeneratingReducedBMI && !D->isFromExplicitGlobalModule() &&
3394 continue;
3395
3396 KindDeclPairs.push_back(D->getKind());
3397 KindDeclPairs.push_back(GetDeclRef(D).getRawValue());
3398 }
3399
3400 ++NumLexicalDeclContexts;
3401 RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL};
3402 Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record,
3403 bytes(KindDeclPairs));
3404 return Offset;
3405}
3406
3407void ASTWriter::WriteTypeDeclOffsets() {
3408 using namespace llvm;
3409
3410 // Write the type offsets array
3411 auto Abbrev = std::make_shared<BitCodeAbbrev>();
3412 Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET));
3413 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
3414 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
3415 unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3416 {
3417 RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size()};
3418 Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets));
3419 }
3420
3421 // Write the declaration offsets array
3422 Abbrev = std::make_shared<BitCodeAbbrev>();
3423 Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET));
3424 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
3425 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
3426 unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3427 {
3428 RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size()};
3429 Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets));
3430 }
3431}
3432
3433void ASTWriter::WriteFileDeclIDsMap() {
3434 using namespace llvm;
3435
3437 SortedFileDeclIDs.reserve(FileDeclIDs.size());
3438 for (const auto &P : FileDeclIDs)
3439 SortedFileDeclIDs.push_back(std::make_pair(P.first, P.second.get()));
3440 llvm::sort(SortedFileDeclIDs, llvm::less_first());
3441
3442 // Join the vectors of DeclIDs from all files.
3443 SmallVector<DeclID, 256> FileGroupedDeclIDs;
3444 for (auto &FileDeclEntry : SortedFileDeclIDs) {
3445 DeclIDInFileInfo &Info = *FileDeclEntry.second;
3446 Info.FirstDeclIndex = FileGroupedDeclIDs.size();
3447 llvm::stable_sort(Info.DeclIDs);
3448 for (auto &LocDeclEntry : Info.DeclIDs)
3449 FileGroupedDeclIDs.push_back(LocDeclEntry.second.getRawValue());
3450 }
3451
3452 auto Abbrev = std::make_shared<BitCodeAbbrev>();
3453 Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS));
3454 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3455 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3456 unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
3457 RecordData::value_type Record[] = {FILE_SORTED_DECLS,
3458 FileGroupedDeclIDs.size()};
3459 Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs));
3460}
3461
3462void ASTWriter::WriteComments(ASTContext &Context) {
3463 Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3);
3464 auto _ = llvm::make_scope_exit([this] { Stream.ExitBlock(); });
3466 return;
3467
3468 // Don't write comments to BMI to reduce the size of BMI.
3469 // If language services (e.g., clangd) want such abilities,
3470 // we can offer a special option then.
3472 return;
3473
3475 for (const auto &FO : Context.Comments.OrderedComments) {
3476 for (const auto &OC : FO.second) {
3477 const RawComment *I = OC.second;
3478 Record.clear();
3480 Record.push_back(I->getKind());
3481 Record.push_back(I->isTrailingComment());
3482 Record.push_back(I->isAlmostTrailingComment());
3483 Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record);
3484 }
3485 }
3486}
3487
3488//===----------------------------------------------------------------------===//
3489// Global Method Pool and Selector Serialization
3490//===----------------------------------------------------------------------===//
3491
3492namespace {
3493
3494// Trait used for the on-disk hash table used in the method pool.
3495class ASTMethodPoolTrait {
3496 ASTWriter &Writer;
3497
3498public:
3499 using key_type = Selector;
3500 using key_type_ref = key_type;
3501
3502 struct data_type {
3503 SelectorID ID;
3504 ObjCMethodList Instance, Factory;
3505 };
3506 using data_type_ref = const data_type &;
3507
3508 using hash_value_type = unsigned;
3509 using offset_type = unsigned;
3510
3511 explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) {}
3512
3513 static hash_value_type ComputeHash(Selector Sel) {
3514 return serialization::ComputeHash(Sel);
3515 }
3516
3517 std::pair<unsigned, unsigned>
3518 EmitKeyDataLength(raw_ostream& Out, Selector Sel,
3519 data_type_ref Methods) {
3520 unsigned KeyLen =
3521 2 + (Sel.getNumArgs() ? Sel.getNumArgs() * sizeof(IdentifierID)
3522 : sizeof(IdentifierID));
3523 unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts
3524 for (const ObjCMethodList *Method = &Methods.Instance; Method;
3525 Method = Method->getNext())
3526 if (ShouldWriteMethodListNode(Method))
3527 DataLen += sizeof(DeclID);
3528 for (const ObjCMethodList *Method = &Methods.Factory; Method;
3529 Method = Method->getNext())
3530 if (ShouldWriteMethodListNode(Method))
3531 DataLen += sizeof(DeclID);
3532 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
3533 }
3534
3535 void EmitKey(raw_ostream& Out, Selector Sel, unsigned) {
3536 using namespace llvm::support;
3537
3538 endian::Writer LE(Out, llvm::endianness::little);
3539 uint64_t Start = Out.tell();
3540 assert((Start >> 32) == 0 && "Selector key offset too large");
3541 Writer.SetSelectorOffset(Sel, Start);
3542 unsigned N = Sel.getNumArgs();
3543 LE.write<uint16_t>(N);
3544 if (N == 0)
3545 N = 1;
3546 for (unsigned I = 0; I != N; ++I)
3547 LE.write<IdentifierID>(
3549 }
3550
3551 void EmitData(raw_ostream& Out, key_type_ref,
3552 data_type_ref Methods, unsigned DataLen) {
3553 using namespace llvm::support;
3554
3555 endian::Writer LE(Out, llvm::endianness::little);
3556 uint64_t Start = Out.tell(); (void)Start;
3557 LE.write<uint32_t>(Methods.ID);
3558 unsigned NumInstanceMethods = 0;
3559 for (const ObjCMethodList *Method = &Methods.Instance; Method;
3560 Method = Method->getNext())
3561 if (ShouldWriteMethodListNode(Method))
3562 ++NumInstanceMethods;
3563
3564 unsigned NumFactoryMethods = 0;
3565 for (const ObjCMethodList *Method = &Methods.Factory; Method;
3566 Method = Method->getNext())
3567 if (ShouldWriteMethodListNode(Method))
3568 ++NumFactoryMethods;
3569
3570 unsigned InstanceBits = Methods.Instance.getBits();
3571 assert(InstanceBits < 4);
3572 unsigned InstanceHasMoreThanOneDeclBit =
3573 Methods.Instance.hasMoreThanOneDecl();
3574 unsigned FullInstanceBits = (NumInstanceMethods << 3) |
3575 (InstanceHasMoreThanOneDeclBit << 2) |
3576 InstanceBits;
3577 unsigned FactoryBits = Methods.Factory.getBits();
3578 assert(FactoryBits < 4);
3579 unsigned FactoryHasMoreThanOneDeclBit =
3580 Methods.Factory.hasMoreThanOneDecl();
3581 unsigned FullFactoryBits = (NumFactoryMethods << 3) |
3582 (FactoryHasMoreThanOneDeclBit << 2) |
3583 FactoryBits;
3584 LE.write<uint16_t>(FullInstanceBits);
3585 LE.write<uint16_t>(FullFactoryBits);
3586 for (const ObjCMethodList *Method = &Methods.Instance; Method;
3587 Method = Method->getNext())
3588 if (ShouldWriteMethodListNode(Method))
3589 LE.write<DeclID>((DeclID)Writer.getDeclID(Method->getMethod()));
3590 for (const ObjCMethodList *Method = &Methods.Factory; Method;
3591 Method = Method->getNext())
3592 if (ShouldWriteMethodListNode(Method))
3593 LE.write<DeclID>((DeclID)Writer.getDeclID(Method->getMethod()));
3594
3595 assert(Out.tell() - Start == DataLen && "Data length is wrong");
3596 }
3597
3598private:
3599 static bool ShouldWriteMethodListNode(const ObjCMethodList *Node) {
3600 return (Node->getMethod() && !Node->getMethod()->isFromASTFile());
3601 }
3602};
3603
3604} // namespace
3605
3606/// Write ObjC data: selectors and the method pool.
3607///
3608/// The method pool contains both instance and factory methods, stored
3609/// in an on-disk hash table indexed by the selector. The hash table also
3610/// contains an empty entry for every other selector known to Sema.
3611void ASTWriter::WriteSelectors(Sema &SemaRef) {
3612 using namespace llvm;
3613
3614 // Do we have to do anything at all?
3615 if (SemaRef.ObjC().MethodPool.empty() && SelectorIDs.empty())
3616 return;
3617 unsigned NumTableEntries = 0;
3618 // Create and write out the blob that contains selectors and the method pool.
3619 {
3620 llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator;
3621 ASTMethodPoolTrait Trait(*this);
3622
3623 // Create the on-disk hash table representation. We walk through every
3624 // selector we've seen and look it up in the method pool.
3625 SelectorOffsets.resize(NextSelectorID - FirstSelectorID);
3626 for (auto &SelectorAndID : SelectorIDs) {
3627 Selector S = SelectorAndID.first;
3628 SelectorID ID = SelectorAndID.second;
3629 SemaObjC::GlobalMethodPool::iterator F =
3630 SemaRef.ObjC().MethodPool.find(S);
3631 ASTMethodPoolTrait::data_type Data = {
3632 ID,
3635 };
3636 if (F != SemaRef.ObjC().MethodPool.end()) {
3637 Data.Instance = F->second.first;
3638 Data.Factory = F->second.second;
3639 }
3640 // Only write this selector if it's not in an existing AST or something
3641 // changed.
3642 if (Chain && ID < FirstSelectorID) {
3643 // Selector already exists. Did it change?
3644 bool changed = false;
3645 for (ObjCMethodList *M = &Data.Instance; M && M->getMethod();
3646 M = M->getNext()) {
3647 if (!M->getMethod()->isFromASTFile()) {
3648 changed = true;
3649 Data.Instance = *M;
3650 break;
3651 }
3652 }
3653 for (ObjCMethodList *M = &Data.Factory; M && M->getMethod();
3654 M = M->getNext()) {
3655 if (!M->getMethod()->isFromASTFile()) {
3656 changed = true;
3657 Data.Factory = *M;
3658 break;
3659 }
3660 }
3661 if (!changed)
3662 continue;
3663 } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) {
3664 // A new method pool entry.
3665 ++NumTableEntries;
3666 }
3667 Generator.insert(S, Data, Trait);
3668 }
3669
3670 // Create the on-disk hash table in a buffer.
3671 SmallString<4096> MethodPool;
3672 uint32_t BucketOffset;
3673 {
3674 using namespace llvm::support;
3675
3676 ASTMethodPoolTrait Trait(*this);
3677 llvm::raw_svector_ostream Out(MethodPool);
3678 // Make sure that no bucket is at offset 0
3679 endian::write<uint32_t>(Out, 0, llvm::endianness::little);
3680 BucketOffset = Generator.Emit(Out, Trait);
3681 }
3682
3683 // Create a blob abbreviation
3684 auto Abbrev = std::make_shared<BitCodeAbbrev>();
3685 Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL));
3686 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3687 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3688 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3689 unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3690
3691 // Write the method pool
3692 {
3693 RecordData::value_type Record[] = {METHOD_POOL, BucketOffset,
3694 NumTableEntries};
3695 Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool);
3696 }
3697
3698 // Create a blob abbreviation for the selector table offsets.
3699 Abbrev = std::make_shared<BitCodeAbbrev>();
3700 Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS));
3701 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size
3702 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
3703 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3704 unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3705
3706 // Write the selector offsets table.
3707 {
3708 RecordData::value_type Record[] = {
3709 SELECTOR_OFFSETS, SelectorOffsets.size(),
3710 FirstSelectorID - NUM_PREDEF_SELECTOR_IDS};
3711 Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record,
3712 bytes(SelectorOffsets));
3713 }
3714 }
3715}
3716
3717/// Write the selectors referenced in @selector expression into AST file.
3718void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) {
3719 using namespace llvm;
3720
3721 if (SemaRef.ObjC().ReferencedSelectors.empty())
3722 return;
3723
3725 ASTRecordWriter Writer(SemaRef.Context, *this, Record);
3726
3727 // Note: this writes out all references even for a dependent AST. But it is
3728 // very tricky to fix, and given that @selector shouldn't really appear in
3729 // headers, probably not worth it. It's not a correctness issue.
3730 for (auto &SelectorAndLocation : SemaRef.ObjC().ReferencedSelectors) {
3731 Selector Sel = SelectorAndLocation.first;
3732 SourceLocation Loc = SelectorAndLocation.second;
3733 Writer.AddSelectorRef(Sel);
3734 Writer.AddSourceLocation(Loc);
3735 }
3736 Writer.Emit(REFERENCED_SELECTOR_POOL);
3737}
3738
3739//===----------------------------------------------------------------------===//
3740// Identifier Table Serialization
3741//===----------------------------------------------------------------------===//
3742
3743/// Determine the declaration that should be put into the name lookup table to
3744/// represent the given declaration in this module. This is usually D itself,
3745/// but if D was imported and merged into a local declaration, we want the most
3746/// recent local declaration instead. The chosen declaration will be the most
3747/// recent declaration in any module that imports this one.
3749 NamedDecl *D) {
3750 if (!LangOpts.Modules || !D->isFromASTFile())
3751 return D;
3752
3753 if (Decl *Redecl = D->getPreviousDecl()) {
3754 // For Redeclarable decls, a prior declaration might be local.
3755 for (; Redecl; Redecl = Redecl->getPreviousDecl()) {
3756 // If we find a local decl, we're done.
3757 if (!Redecl->isFromASTFile()) {
3758 // Exception: in very rare cases (for injected-class-names), not all
3759 // redeclarations are in the same semantic context. Skip ones in a
3760 // different context. They don't go in this lookup table at all.
3761 if (!Redecl->getDeclContext()->getRedeclContext()->Equals(
3763 continue;
3764 return cast<NamedDecl>(Redecl);
3765 }
3766
3767 // If we find a decl from a (chained-)PCH stop since we won't find a
3768 // local one.
3769 if (Redecl->getOwningModuleID() == 0)
3770 break;
3771 }
3772 } else if (Decl *First = D->getCanonicalDecl()) {
3773 // For Mergeable decls, the first decl might be local.
3774 if (!First->isFromASTFile())
3775 return cast<NamedDecl>(First);
3776 }
3777
3778 // All declarations are imported. Our most recent declaration will also be
3779 // the most recent one in anyone who imports us.
3780 return D;
3781}
3782
3783namespace {
3784
3785bool IsInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset,
3786 bool IsModule, bool IsCPlusPlus) {
3787 bool NeedDecls = !IsModule || !IsCPlusPlus;
3788
3789 bool IsInteresting =
3790 II->getNotableIdentifierID() != tok::NotableIdentifierKind::not_notable ||
3792 II->getObjCKeywordID() != tok::ObjCKeywordKind::objc_not_keyword;
3793 if (MacroOffset || II->isPoisoned() || (!IsModule && IsInteresting) ||
3795 (NeedDecls && II->getFETokenInfo()))
3796 return true;
3797
3798 return false;
3799}
3800
3801bool IsInterestingNonMacroIdentifier(const IdentifierInfo *II,
3802 ASTWriter &Writer) {
3803 bool IsModule = Writer.isWritingModule();
3804 bool IsCPlusPlus = Writer.getLangOpts().CPlusPlus;
3805 return IsInterestingIdentifier(II, /*MacroOffset=*/0, IsModule, IsCPlusPlus);
3806}
3807
3808class ASTIdentifierTableTrait {
3809 ASTWriter &Writer;
3810 Preprocessor &PP;
3811 IdentifierResolver *IdResolver;
3812 bool IsModule;
3813 bool NeedDecls;
3814 ASTWriter::RecordData *InterestingIdentifierOffsets;
3815
3816 /// Determines whether this is an "interesting" identifier that needs a
3817 /// full IdentifierInfo structure written into the hash table. Notably, this
3818 /// doesn't check whether the name has macros defined; use PublicMacroIterator
3819 /// to check that.
3820 bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) {
3821 return IsInterestingIdentifier(II, MacroOffset, IsModule,
3822 Writer.getLangOpts().CPlusPlus);
3823 }
3824
3825public:
3826 using key_type = const IdentifierInfo *;
3827 using key_type_ref = key_type;
3828
3829 using data_type = IdentifierID;
3830 using data_type_ref = data_type;
3831
3832 using hash_value_type = unsigned;
3833 using offset_type = unsigned;
3834
3835 ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP,
3836 IdentifierResolver *IdResolver, bool IsModule,
3837 ASTWriter::RecordData *InterestingIdentifierOffsets)
3838 : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule),
3839 NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus),
3840 InterestingIdentifierOffsets(InterestingIdentifierOffsets) {}
3841
3842 bool needDecls() const { return NeedDecls; }
3843
3844 static hash_value_type ComputeHash(const IdentifierInfo* II) {
3845 return llvm::djbHash(II->getName());
3846 }
3847
3848 bool isInterestingIdentifier(const IdentifierInfo *II) {
3849 auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3850 return isInterestingIdentifier(II, MacroOffset);
3851 }
3852
3853 std::pair<unsigned, unsigned>
3854 EmitKeyDataLength(raw_ostream &Out, const IdentifierInfo *II, IdentifierID ID) {
3855 // Record the location of the identifier data. This is used when generating
3856 // the mapping from persistent IDs to strings.
3857 Writer.SetIdentifierOffset(II, Out.tell());
3858
3859 auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3860
3861 // Emit the offset of the key/data length information to the interesting
3862 // identifiers table if necessary.
3863 if (InterestingIdentifierOffsets &&
3864 isInterestingIdentifier(II, MacroOffset))
3865 InterestingIdentifierOffsets->push_back(Out.tell());
3866
3867 unsigned KeyLen = II->getLength() + 1;
3868 unsigned DataLen = sizeof(IdentifierID); // bytes for the persistent ID << 1
3869 if (isInterestingIdentifier(II, MacroOffset)) {
3870 DataLen += 2; // 2 bytes for builtin ID
3871 DataLen += 2; // 2 bytes for flags
3872 if (MacroOffset)
3873 DataLen += 4; // MacroDirectives offset.
3874
3875 if (NeedDecls && IdResolver)
3876 DataLen += std::distance(IdResolver->begin(II), IdResolver->end()) *
3877 sizeof(DeclID);
3878 }
3879 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
3880 }
3881
3882 void EmitKey(raw_ostream &Out, const IdentifierInfo *II, unsigned KeyLen) {
3883 Out.write(II->getNameStart(), KeyLen);
3884 }
3885
3886 void EmitData(raw_ostream &Out, const IdentifierInfo *II, IdentifierID ID,
3887 unsigned) {
3888 using namespace llvm::support;
3889
3890 endian::Writer LE(Out, llvm::endianness::little);
3891
3892 auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3893 if (!isInterestingIdentifier(II, MacroOffset)) {
3894 LE.write<IdentifierID>(ID << 1);
3895 return;
3896 }
3897
3898 LE.write<IdentifierID>((ID << 1) | 0x01);
3899 uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID();
3900 assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader.");
3901 LE.write<uint16_t>(Bits);
3902 Bits = 0;
3903 bool HadMacroDefinition = MacroOffset != 0;
3904 Bits = (Bits << 1) | unsigned(HadMacroDefinition);
3905 Bits = (Bits << 1) | unsigned(II->isExtensionToken());
3906 Bits = (Bits << 1) | unsigned(II->isPoisoned());
3907 Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier());
3908 Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword());
3909 LE.write<uint16_t>(Bits);
3910
3911 if (HadMacroDefinition)
3912 LE.write<uint32_t>(MacroOffset);
3913
3914 if (NeedDecls && IdResolver) {
3915 // Emit the declaration IDs in reverse order, because the
3916 // IdentifierResolver provides the declarations as they would be
3917 // visible (e.g., the function "stat" would come before the struct
3918 // "stat"), but the ASTReader adds declarations to the end of the list
3919 // (so we need to see the struct "stat" before the function "stat").
3920 // Only emit declarations that aren't from a chained PCH, though.
3921 SmallVector<NamedDecl *, 16> Decls(IdResolver->decls(II));
3922 for (NamedDecl *D : llvm::reverse(Decls))
3923 LE.write<DeclID>((DeclID)Writer.getDeclID(
3925 }
3926 }
3927};
3928
3929} // namespace
3930
3931/// If the \param IdentifierID ID is a local Identifier ID. If the higher
3932/// bits of ID is 0, it implies that the ID doesn't come from AST files.
3933static bool isLocalIdentifierID(IdentifierID ID) { return !(ID >> 32); }
3934
3935/// Write the identifier table into the AST file.
3936///
3937/// The identifier table consists of a blob containing string data
3938/// (the actual identifiers themselves) and a separate "offsets" index
3939/// that maps identifier IDs to locations within the blob.
3940void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
3941 IdentifierResolver *IdResolver,
3942 bool IsModule) {
3943 using namespace llvm;
3944
3945 RecordData InterestingIdents;
3946
3947 // Create and write out the blob that contains the identifier
3948 // strings.
3949 {
3950 llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator;
3951 ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule,
3952 IsModule ? &InterestingIdents : nullptr);
3953
3954 // Create the on-disk hash table representation. We only store offsets
3955 // for identifiers that appear here for the first time.
3956 IdentifierOffsets.resize(NextIdentID - FirstIdentID);
3957 for (auto IdentIDPair : IdentifierIDs) {
3958 const IdentifierInfo *II = IdentIDPair.first;
3959 IdentifierID ID = IdentIDPair.second;
3960 assert(II && "NULL identifier in identifier table");
3961
3962 // Write out identifiers if either the ID is local or the identifier has
3963 // changed since it was loaded.
3965 (Trait.needDecls() &&
3967 Generator.insert(II, ID, Trait);
3968 }
3969
3970 // Create the on-disk hash table in a buffer.
3972 uint32_t BucketOffset;
3973 {
3974 using namespace llvm::support;
3975
3976 llvm::raw_svector_ostream Out(IdentifierTable);
3977 // Make sure that no bucket is at offset 0
3978 endian::write<uint32_t>(Out, 0, llvm::endianness::little);
3979 BucketOffset = Generator.Emit(Out, Trait);
3980 }
3981
3982 // Create a blob abbreviation
3983 auto Abbrev = std::make_shared<BitCodeAbbrev>();
3984 Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE));
3985 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3986 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3987 unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3988
3989 // Write the identifier table
3990 RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset};
3991 Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable);
3992 }
3993
3994 // Write the offsets table for identifier IDs.
3995 auto Abbrev = std::make_shared<BitCodeAbbrev>();
3996 Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET));
3997 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers
3998 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3999 unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
4000
4001#ifndef NDEBUG
4002 for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I)
4003 assert(IdentifierOffsets[I] && "Missing identifier offset?");
4004#endif
4005
4006 RecordData::value_type Record[] = {IDENTIFIER_OFFSET,
4007 IdentifierOffsets.size()};
4008 Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record,
4009 bytes(IdentifierOffsets));
4010
4011 // In C++, write the list of interesting identifiers (those that are
4012 // defined as macros, poisoned, or similar unusual things).
4013 if (!InterestingIdents.empty())
4014 Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents);
4015}
4016
4018 if (!RD->isInNamedModule())
4019 return;
4020
4021 PendingEmittingVTables.push_back(RD);
4022}
4023
4024//===----------------------------------------------------------------------===//
4025// DeclContext's Name Lookup Table Serialization
4026//===----------------------------------------------------------------------===//
4027
4028namespace {
4029
4030class ASTDeclContextNameLookupTraitBase {
4031protected:
4032 ASTWriter &Writer;
4033 using DeclIDsTy = llvm::SmallVector<LocalDeclID, 64>;
4034 DeclIDsTy DeclIDs;
4035
4036public:
4037 /// A start and end index into DeclIDs, representing a sequence of decls.
4038 using data_type = std::pair<unsigned, unsigned>;
4039 using data_type_ref = const data_type &;
4040
4041 using hash_value_type = unsigned;
4042 using offset_type = unsigned;
4043
4044protected:
4045 explicit ASTDeclContextNameLookupTraitBase(ASTWriter &Writer)
4046 : Writer(Writer) {}
4047
4048public:
4049 data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) {
4050 unsigned Start = DeclIDs.size();
4051 DeclIDs.insert(
4052 DeclIDs.end(),
4055 return std::make_pair(Start, DeclIDs.size());
4056 }
4057
4058 void EmitFileRef(raw_ostream &Out, ModuleFile *F) const {
4059 assert(Writer.hasChain() &&
4060 "have reference to loaded module file but no chain?");
4061
4062 using namespace llvm::support;
4063
4064 endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F),
4065 llvm::endianness::little);
4066 }
4067
4068 std::pair<unsigned, unsigned> EmitKeyDataLengthBase(raw_ostream &Out,
4069 DeclarationNameKey Name,
4070 data_type_ref Lookup) {
4071 unsigned KeyLen = 1;
4072 switch (Name.getKind()) {
4076 KeyLen += sizeof(IdentifierID);
4077 break;
4081 KeyLen += 4;
4082 break;
4084 KeyLen += 1;
4085 break;
4090 break;
4091 }
4092
4093 // length of DeclIDs.
4094 unsigned DataLen = sizeof(DeclID) * (Lookup.second - Lookup.first);
4095
4096 return {KeyLen, DataLen};
4097 }
4098
4099 void EmitKeyBase(raw_ostream &Out, DeclarationNameKey Name) {
4100 using namespace llvm::support;
4101
4102 endian::Writer LE(Out, llvm::endianness::little);
4103 LE.write<uint8_t>(Name.getKind());
4104 switch (Name.getKind()) {
4108 LE.write<IdentifierID>(Writer.getIdentifierRef(Name.getIdentifier()));
4109 return;
4113 LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector()));
4114 return;
4116 assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS &&
4117 "Invalid operator?");
4118 LE.write<uint8_t>(Name.getOperatorKind());
4119 return;
4124 return;
4125 }
4126
4127 llvm_unreachable("Invalid name kind?");
4128 }
4129
4130 void EmitDataBase(raw_ostream &Out, data_type Lookup, unsigned DataLen) {
4131 using namespace llvm::support;
4132
4133 endian::Writer LE(Out, llvm::endianness::little);
4134 uint64_t Start = Out.tell(); (void)Start;
4135 for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I)
4136 LE.write<DeclID>((DeclID)DeclIDs[I]);
4137 assert(Out.tell() - Start == DataLen && "Data length is wrong");
4138 }
4139};
4140
4141class ModuleLocalNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
4142public:
4143 using primary_module_hash_type = unsigned;
4144
4145 using key_type = std::pair<DeclarationNameKey, primary_module_hash_type>;
4146 using key_type_ref = key_type;
4147
4148 explicit ModuleLocalNameLookupTrait(ASTWriter &Writer)
4149 : ASTDeclContextNameLookupTraitBase(Writer) {}
4150
4151 data_type getData(const DeclIDsTy &LocalIDs) {
4152 unsigned Start = DeclIDs.size();
4153 for (auto ID : LocalIDs)
4154 DeclIDs.push_back(ID);
4155 return std::make_pair(Start, DeclIDs.size());
4156 }
4157
4158 static bool EqualKey(key_type_ref a, key_type_ref b) { return a == b; }
4159
4160 hash_value_type ComputeHash(key_type Key) {
4161 llvm::FoldingSetNodeID ID;
4162 ID.AddInteger(Key.first.getHash());
4163 ID.AddInteger(Key.second);
4164 return ID.computeStableHash();
4165 }
4166
4167 std::pair<unsigned, unsigned>
4168 EmitKeyDataLength(raw_ostream &Out, key_type Key, data_type_ref Lookup) {
4169 auto [KeyLen, DataLen] = EmitKeyDataLengthBase(Out, Key.first, Lookup);
4170 KeyLen += sizeof(Key.second);
4171 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
4172 }
4173
4174 void EmitKey(raw_ostream &Out, key_type Key, unsigned) {
4175 EmitKeyBase(Out, Key.first);
4176 llvm::support::endian::Writer LE(Out, llvm::endianness::little);
4177 LE.write<primary_module_hash_type>(Key.second);
4178 }
4179
4180 void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
4181 unsigned DataLen) {
4182 EmitDataBase(Out, Lookup, DataLen);
4183 }
4184};
4185
4186static bool isModuleLocalDecl(NamedDecl *D) {
4187 // For decls not in a file context, they should have the same visibility
4188 // with their parent.
4189 if (auto *Parent = dyn_cast<NamedDecl>(D->getNonTransparentDeclContext());
4191 return isModuleLocalDecl(Parent);
4192
4193 // Deduction Guide are special here. Since their logical parent context are
4194 // not their actual parent.
4195 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
4196 if (auto *CDGD = dyn_cast<CXXDeductionGuideDecl>(FTD->getTemplatedDecl()))
4197 return isModuleLocalDecl(CDGD->getDeducedTemplate());
4198
4199 if (D->getFormalLinkage() == Linkage::Module)
4200 return true;
4201
4202 return false;
4203}
4204
4205// Trait used for the on-disk hash table used in the method pool.
4206class ASTDeclContextNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
4207public:
4208 using ModuleLocalDeclsMapTy =
4209 llvm::DenseMap<ModuleLocalNameLookupTrait::key_type, DeclIDsTy>;
4210
4211private:
4212 ModuleLocalDeclsMapTy ModuleLocalDeclsMap;
4213
4214public:
4215 using key_type = DeclarationNameKey;
4216 using key_type_ref = key_type;
4217
4218 explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer)
4219 : ASTDeclContextNameLookupTraitBase(Writer) {}
4220
4221 template <typename Coll> data_type getData(const Coll &Decls) {
4222 unsigned Start = DeclIDs.size();
4223 for (NamedDecl *D : Decls) {
4224 NamedDecl *DeclForLocalLookup =
4226
4227 if (Writer.getDoneWritingDeclsAndTypes() &&
4228 !Writer.wasDeclEmitted(DeclForLocalLookup))
4229 continue;
4230
4231 // Try to avoid writing internal decls to reduced BMI.
4232 // See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
4233 if (Writer.isGeneratingReducedBMI() &&
4234 !DeclForLocalLookup->isFromExplicitGlobalModule() &&
4235 IsInternalDeclFromFileContext(DeclForLocalLookup))
4236 continue;
4237
4238 auto ID = Writer.GetDeclRef(DeclForLocalLookup);
4239
4240 if (isModuleLocalDecl(D)) {
4241 if (std::optional<unsigned> PrimaryModuleHash =
4243 auto Key = std::make_pair(D->getDeclName(), *PrimaryModuleHash);
4244 auto Iter = ModuleLocalDeclsMap.find(Key);
4245 if (Iter == ModuleLocalDeclsMap.end())
4246 ModuleLocalDeclsMap.insert({Key, DeclIDsTy{ID}});
4247 else
4248 Iter->second.push_back(ID);
4249 continue;
4250 }
4251 }
4252
4253 DeclIDs.push_back(ID);
4254 }
4255 return std::make_pair(Start, DeclIDs.size());
4256 }
4257
4258 const ModuleLocalDeclsMapTy &getModuleLocalDecls() {
4259 return ModuleLocalDeclsMap;
4260 }
4261
4262 static bool EqualKey(key_type_ref a, key_type_ref b) { return a == b; }
4263
4264 hash_value_type ComputeHash(key_type Name) { return Name.getHash(); }
4265
4266 std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out,
4267 DeclarationNameKey Name,
4268 data_type_ref Lookup) {
4269 auto [KeyLen, DataLen] = EmitKeyDataLengthBase(Out, Name, Lookup);
4270 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
4271 }
4272
4273 void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) {
4274 return EmitKeyBase(Out, Name);
4275 }
4276
4277 void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
4278 unsigned DataLen) {
4279 EmitDataBase(Out, Lookup, DataLen);
4280 }
4281};
4282
4283} // namespace
4284
4285namespace {
4286class LazySpecializationInfoLookupTrait {
4287 ASTWriter &Writer;
4289
4290public:
4291 using key_type = unsigned;
4292 using key_type_ref = key_type;
4293
4294 /// A start and end index into Specs, representing a sequence of decls.
4295 using data_type = std::pair<unsigned, unsigned>;
4296 using data_type_ref = const data_type &;
4297
4298 using hash_value_type = unsigned;
4299 using offset_type = unsigned;
4300
4301 explicit LazySpecializationInfoLookupTrait(ASTWriter &Writer)
4302 : Writer(Writer) {}
4303
4304 template <typename Col, typename Col2>
4305 data_type getData(Col &&C, Col2 &ExistingInfo) {
4306 unsigned Start = Specs.size();
4307 for (auto *D : C) {
4309 const_cast<NamedDecl *>(D));
4310 Specs.push_back(GlobalDeclID(Writer.GetDeclRef(ND).getRawValue()));
4311 }
4313 ExistingInfo)
4314 Specs.push_back(Info);
4315 return std::make_pair(Start, Specs.size());
4316 }
4317
4318 data_type ImportData(
4320 unsigned Start = Specs.size();
4321 for (auto ID : FromReader)
4322 Specs.push_back(ID);
4323 return std::make_pair(Start, Specs.size());
4324 }
4325
4326 static bool EqualKey(key_type_ref a, key_type_ref b) { return a == b; }
4327
4328 hash_value_type ComputeHash(key_type Name) { return Name; }
4329
4330 void EmitFileRef(raw_ostream &Out, ModuleFile *F) const {
4331 assert(Writer.hasChain() &&
4332 "have reference to loaded module file but no chain?");
4333
4334 using namespace llvm::support;
4335 endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F),
4336 llvm::endianness::little);
4337 }
4338
4339 std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out,
4340 key_type HashValue,
4341 data_type_ref Lookup) {
4342 // 4 bytes for each slot.
4343 unsigned KeyLen = 4;
4344 unsigned DataLen = sizeof(serialization::reader::LazySpecializationInfo) *
4345 (Lookup.second - Lookup.first);
4346
4347 return emitULEBKeyDataLength(KeyLen, DataLen, Out);
4348 }
4349
4350 void EmitKey(raw_ostream &Out, key_type HashValue, unsigned) {
4351 using namespace llvm::support;
4352
4353 endian::Writer LE(Out, llvm::endianness::little);
4354 LE.write<uint32_t>(HashValue);
4355 }
4356
4357 void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
4358 unsigned DataLen) {
4359 using namespace llvm::support;
4360
4361 endian::Writer LE(Out, llvm::endianness::little);
4362 uint64_t Start = Out.tell();
4363 (void)Start;
4364 for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) {
4365 LE.write<DeclID>(Specs[I].getRawValue());
4366 }
4367 assert(Out.tell() - Start == DataLen && "Data length is wrong");
4368 }
4369};
4370
4371unsigned CalculateODRHashForSpecs(const Decl *Spec) {
4373 if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Spec))
4374 Args = CTSD->getTemplateArgs().asArray();
4375 else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Spec))
4376 Args = VTSD->getTemplateArgs().asArray();
4377 else if (auto *FD = dyn_cast<FunctionDecl>(Spec))
4378 Args = FD->getTemplateSpecializationArgs()->asArray();
4379 else
4380 llvm_unreachable("New Specialization Kind?");
4381
4382 return StableHashForTemplateArguments(Args);
4383}
4384} // namespace
4385
4386void ASTWriter::GenerateSpecializationInfoLookupTable(
4387 const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
4388 llvm::SmallVectorImpl<char> &LookupTable, bool IsPartial) {
4389 assert(D->isFirstDecl());
4390
4391 // Create the on-disk hash table representation.
4393 LazySpecializationInfoLookupTrait>
4394 Generator;
4395 LazySpecializationInfoLookupTrait Trait(*this);
4396
4397 llvm::DenseMap<unsigned, llvm::SmallVector<const NamedDecl *, 4>>
4398 SpecializationMaps;
4399
4400 for (auto *Specialization : Specializations) {
4401 unsigned HashedValue = CalculateODRHashForSpecs(Specialization);
4402
4403 auto Iter = SpecializationMaps.find(HashedValue);
4404 if (Iter == SpecializationMaps.end())
4405 Iter = SpecializationMaps
4406 .try_emplace(HashedValue,
4408 .first;
4409
4410 Iter->second.push_back(cast<NamedDecl>(Specialization));
4411 }
4412
4413 auto *Lookups =
4414 Chain ? Chain->getLoadedSpecializationsLookupTables(D, IsPartial)
4415 : nullptr;
4416
4417 for (auto &[HashValue, Specs] : SpecializationMaps) {
4419 ExisitingSpecs;
4420 // We have to merge the lookup table manually here. We can't depend on the
4421 // merge mechanism offered by
4422 // clang::serialization::MultiOnDiskHashTableGenerator since that generator
4423 // assumes the we'll get the same value with the same key.
4424 // And also underlying llvm::OnDiskChainedHashTableGenerator assumes that we
4425 // won't insert the values with the same key twice. So we have to merge the
4426 // lookup table here manually.
4427 if (Lookups)
4428 ExisitingSpecs = Lookups->Table.find(HashValue);
4429
4430 Generator.insert(HashValue, Trait.getData(Specs, ExisitingSpecs), Trait);
4431 }
4432
4433 Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr);
4434}
4435
4436uint64_t ASTWriter::WriteSpecializationInfoLookupTable(
4437 const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
4438 bool IsPartial) {
4439
4440 llvm::SmallString<4096> LookupTable;
4441 GenerateSpecializationInfoLookupTable(D, Specializations, LookupTable,
4442 IsPartial);
4443
4444 uint64_t Offset = Stream.GetCurrentBitNo();
4445 RecordData::value_type Record[] = {static_cast<RecordData::value_type>(
4447 Stream.EmitRecordWithBlob(IsPartial ? DeclPartialSpecializationsAbbrev
4448 : DeclSpecializationsAbbrev,
4449 Record, LookupTable);
4450
4451 return Offset;
4452}
4453
4454bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result,
4455 DeclContext *DC) {
4456 return Result.hasExternalDecls() &&
4457 DC->hasNeedToReconcileExternalVisibleStorage();
4458}
4459
4460/// Returns ture if all of the lookup result are either external, not emitted or
4461/// predefined. In such cases, the lookup result is not interesting and we don't
4462/// need to record the result in the current being written module. Return false
4463/// otherwise.
4466 for (auto *D : Result.getLookupResult()) {
4467 auto *LocalD = getDeclForLocalLookup(Writer.getLangOpts(), D);
4468 if (LocalD->isFromASTFile())
4469 continue;
4470
4471 // We can only be sure whether the local declaration is reachable
4472 // after we done writing the declarations and types.
4473 if (Writer.getDoneWritingDeclsAndTypes() && !Writer.wasDeclEmitted(LocalD))
4474 continue;
4475
4476 // We don't need to emit the predefined decls.
4477 if (Writer.isDeclPredefined(LocalD))
4478 continue;
4479
4480 return false;
4481 }
4482
4483 return true;
4484}
4485
4486void ASTWriter::GenerateNameLookupTable(
4487 ASTContext &Context, const DeclContext *ConstDC,
4488 llvm::SmallVectorImpl<char> &LookupTable,
4489 llvm::SmallVectorImpl<char> &ModuleLocalLookupTable) {
4490 assert(!ConstDC->hasLazyLocalLexicalLookups() &&
4491 !ConstDC->hasLazyExternalLexicalLookups() &&
4492 "must call buildLookups first");
4493
4494 // FIXME: We need to build the lookups table, which is logically const.
4495 auto *DC = const_cast<DeclContext*>(ConstDC);
4496 assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table");
4497
4498 // Create the on-disk hash table representation.
4500 ASTDeclContextNameLookupTrait> Generator;
4501 ASTDeclContextNameLookupTrait Trait(*this);
4502
4503 // The first step is to collect the declaration names which we need to
4504 // serialize into the name lookup table, and to collect them in a stable
4505 // order.
4507
4508 // We also build up small sets of the constructor and conversion function
4509 // names which are visible.
4510 llvm::SmallPtrSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet;
4511
4512 for (auto &Lookup : *DC->buildLookup()) {
4513 auto &Name = Lookup.first;
4514 auto &Result = Lookup.second;
4515
4516 // If there are no local declarations in our lookup result, we
4517 // don't need to write an entry for the name at all. If we can't
4518 // write out a lookup set without performing more deserialization,
4519 // just skip this entry.
4520 //
4521 // Also in reduced BMI, we'd like to avoid writing unreachable
4522 // declarations in GMF, so we need to avoid writing declarations
4523 // that entirely external or unreachable.
4524 //
4525 // FIMXE: It looks sufficient to test
4526 // isLookupResultNotInteresting here. But due to bug we have
4527 // to test isLookupResultExternal here. See
4528 // https://github.com/llvm/llvm-project/issues/61065 for details.
4529 if ((GeneratingReducedBMI || isLookupResultExternal(Result, DC)) &&
4531 continue;
4532
4533 // We also skip empty results. If any of the results could be external and
4534 // the currently available results are empty, then all of the results are
4535 // external and we skip it above. So the only way we get here with an empty
4536 // results is when no results could have been external *and* we have
4537 // external results.
4538 //
4539 // FIXME: While we might want to start emitting on-disk entries for negative
4540 // lookups into a decl context as an optimization, today we *have* to skip
4541 // them because there are names with empty lookup results in decl contexts
4542 // which we can't emit in any stable ordering: we lookup constructors and
4543 // conversion functions in the enclosing namespace scope creating empty
4544 // results for them. This in almost certainly a bug in Clang's name lookup,
4545 // but that is likely to be hard or impossible to fix and so we tolerate it
4546 // here by omitting lookups with empty results.
4547 if (Lookup.second.getLookupResult().empty())
4548 continue;
4549
4550 switch (Lookup.first.getNameKind()) {
4551 default:
4552 Names.push_back(Lookup.first);
4553 break;
4554
4556 assert(isa<CXXRecordDecl>(DC) &&
4557 "Cannot have a constructor name outside of a class!");
4558 ConstructorNameSet.insert(Name);
4559 break;
4560
4562 assert(isa<CXXRecordDecl>(DC) &&
4563 "Cannot have a conversion function name outside of a class!");
4564 ConversionNameSet.insert(Name);
4565 break;
4566 }
4567 }
4568
4569 // Sort the names into a stable order.
4570 llvm::sort(Names);
4571
4572 if (auto *D = dyn_cast<CXXRecordDecl>(DC)) {
4573 // We need to establish an ordering of constructor and conversion function
4574 // names, and they don't have an intrinsic ordering.
4575
4576 // First we try the easy case by forming the current context's constructor
4577 // name and adding that name first. This is a very useful optimization to
4578 // avoid walking the lexical declarations in many cases, and it also
4579 // handles the only case where a constructor name can come from some other
4580 // lexical context -- when that name is an implicit constructor merged from
4581 // another declaration in the redecl chain. Any non-implicit constructor or
4582 // conversion function which doesn't occur in all the lexical contexts
4583 // would be an ODR violation.
4584 auto ImplicitCtorName = Context.DeclarationNames.getCXXConstructorName(
4585 Context.getCanonicalType(Context.getRecordType(D)));
4586 if (ConstructorNameSet.erase(ImplicitCtorName))
4587 Names.push_back(ImplicitCtorName);
4588
4589 // If we still have constructors or conversion functions, we walk all the
4590 // names in the decl and add the constructors and conversion functions
4591 // which are visible in the order they lexically occur within the context.
4592 if (!ConstructorNameSet.empty() || !ConversionNameSet.empty())
4593 for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls())
4594 if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) {
4595 auto Name = ChildND->getDeclName();
4596 switch (Name.getNameKind()) {
4597 default:
4598 continue;
4599
4601 if (ConstructorNameSet.erase(Name))
4602 Names.push_back(Name);
4603 break;
4604
4606 if (ConversionNameSet.erase(Name))
4607 Names.push_back(Name);
4608 break;
4609 }
4610
4611 if (ConstructorNameSet.empty() && ConversionNameSet.empty())
4612 break;
4613 }
4614
4615 assert(ConstructorNameSet.empty() && "Failed to find all of the visible "
4616 "constructors by walking all the "
4617 "lexical members of the context.");
4618 assert(ConversionNameSet.empty() && "Failed to find all of the visible "
4619 "conversion functions by walking all "
4620 "the lexical members of the context.");
4621 }
4622
4623 // Next we need to do a lookup with each name into this decl context to fully
4624 // populate any results from external sources. We don't actually use the
4625 // results of these lookups because we only want to use the results after all
4626 // results have been loaded and the pointers into them will be stable.
4627 for (auto &Name : Names)
4628 DC->lookup(Name);
4629
4630 // Now we need to insert the results for each name into the hash table. For
4631 // constructor names and conversion function names, we actually need to merge
4632 // all of the results for them into one list of results each and insert
4633 // those.
4634 SmallVector<NamedDecl *, 8> ConstructorDecls;
4635 SmallVector<NamedDecl *, 8> ConversionDecls;
4636
4637 // Now loop over the names, either inserting them or appending for the two
4638 // special cases.
4639 for (auto &Name : Names) {
4641
4642 switch (Name.getNameKind()) {
4643 default:
4644 Generator.insert(Name, Trait.getData(Result), Trait);
4645 break;
4646
4648 ConstructorDecls.append(Result.begin(), Result.end());
4649 break;
4650
4652 ConversionDecls.append(Result.begin(), Result.end());
4653 break;
4654 }
4655 }
4656
4657 // Handle our two special cases if we ended up having any. We arbitrarily use
4658 // the first declaration's name here because the name itself isn't part of
4659 // the key, only the kind of name is used.
4660 if (!ConstructorDecls.empty())
4661 Generator.insert(ConstructorDecls.front()->getDeclName(),
4662 Trait.getData(ConstructorDecls), Trait);
4663 if (!ConversionDecls.empty())
4664 Generator.insert(ConversionDecls.front()->getDeclName(),
4665 Trait.getData(ConversionDecls), Trait);
4666
4667 // Create the on-disk hash table. Also emit the existing imported and
4668 // merged table if there is one.
4669 auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr;
4670 Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr);
4671
4672 const auto &ModuleLocalDecls = Trait.getModuleLocalDecls();
4673 if (ModuleLocalDecls.empty())
4674 return;
4675
4677 ModuleLocalNameLookupTrait>
4678 ModuleLocalLookupGenerator;
4679 ModuleLocalNameLookupTrait ModuleLocalTrait(*this);
4680
4681 for (const auto &ModuleLocalIter : ModuleLocalDecls) {
4682 const auto &Key = ModuleLocalIter.first;
4683 const auto &IDs = ModuleLocalIter.second;
4684 ModuleLocalLookupGenerator.insert(Key, ModuleLocalTrait.getData(IDs),
4685 ModuleLocalTrait);
4686 }
4687
4688 auto *ModuleLocalLookups =
4689 Chain ? Chain->getModuleLocalLookupTables(DC) : nullptr;
4690 ModuleLocalLookupGenerator.emit(
4691 ModuleLocalLookupTable, ModuleLocalTrait,
4692 ModuleLocalLookups ? &ModuleLocalLookups->Table : nullptr);
4693}
4694
4695/// Write the block containing all of the declaration IDs
4696/// visible from the given DeclContext.
4697///
4698/// \returns the offset of the DECL_CONTEXT_VISIBLE block within the
4699/// bitstream, or 0 if no block was written.
4700void ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
4701 DeclContext *DC,
4702 uint64_t &VisibleBlockOffset,
4703 uint64_t &ModuleLocalBlockOffset) {
4704 // If we imported a key declaration of this namespace, write the visible
4705 // lookup results as an update record for it rather than including them
4706 // on this declaration. We will only look at key declarations on reload.
4707 if (isa<NamespaceDecl>(DC) && Chain &&
4708 Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) {
4709 // Only do this once, for the first local declaration of the namespace.
4710 for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev;
4711 Prev = Prev->getPreviousDecl())
4712 if (!Prev->isFromASTFile())
4713 return;
4714
4715 // Note that we need to emit an update record for the primary context.
4716 UpdatedDeclContexts.insert(DC->getPrimaryContext());
4717
4718 // Make sure all visible decls are written. They will be recorded later. We
4719 // do this using a side data structure so we can sort the names into
4720 // a deterministic order.
4723 LookupResults;
4724 if (Map) {
4725 LookupResults.reserve(Map->size());
4726 for (auto &Entry : *Map)
4727 LookupResults.push_back(
4728 std::make_pair(Entry.first, Entry.second.getLookupResult()));
4729 }
4730
4731 llvm::sort(LookupResults, llvm::less_first());
4732 for (auto &NameAndResult : LookupResults) {
4733 DeclarationName Name = NameAndResult.first;
4734 DeclContext::lookup_result Result = NameAndResult.second;
4735 if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
4736 Name.getNameKind() == DeclarationName::CXXConversionFunctionName) {
4737 // We have to work around a name lookup bug here where negative lookup
4738 // results for these names get cached in namespace lookup tables (these
4739 // names should never be looked up in a namespace).
4740 assert(Result.empty() && "Cannot have a constructor or conversion "
4741 "function name in a namespace!");
4742 continue;
4743 }
4744
4745 for (NamedDecl *ND : Result) {
4746 if (ND->isFromASTFile())
4747 continue;
4748
4749 if (DoneWritingDeclsAndTypes && !wasDeclEmitted(ND))
4750 continue;
4751
4752 // We don't need to force emitting internal decls into reduced BMI.
4753 // See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
4754 if (GeneratingReducedBMI && !ND->isFromExplicitGlobalModule() &&
4756 continue;
4757
4758 GetDeclRef(ND);
4759 }
4760 }
4761
4762 return;
4763 }
4764
4765 if (DC->getPrimaryContext() != DC)
4766 return;
4767
4768 // Skip contexts which don't support name lookup.
4769 if (!DC->isLookupContext())
4770 return;
4771
4772 // If not in C++, we perform name lookup for the translation unit via the
4773 // IdentifierInfo chains, don't bother to build a visible-declarations table.
4774 if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus)
4775 return;
4776
4777 // Serialize the contents of the mapping used for lookup. Note that,
4778 // although we have two very different code paths, the serialized
4779 // representation is the same for both cases: a declaration name,
4780 // followed by a size, followed by references to the visible
4781 // declarations that have that name.
4782 StoredDeclsMap *Map = DC->buildLookup();
4783 if (!Map || Map->empty())
4784 return;
4785
4786 VisibleBlockOffset = Stream.GetCurrentBitNo();
4787 // Create the on-disk hash table in a buffer.
4788 SmallString<4096> LookupTable;
4789 SmallString<4096> ModuleLocalLookupTable;
4790 GenerateNameLookupTable(Context, DC, LookupTable, ModuleLocalLookupTable);
4791
4792 // Write the lookup table
4793 RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE};
4794 Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record,
4795 LookupTable);
4796 ++NumVisibleDeclContexts;
4797
4798 if (ModuleLocalLookupTable.empty())
4799 return;
4800
4801 ModuleLocalBlockOffset = Stream.GetCurrentBitNo();
4802 assert(ModuleLocalBlockOffset > VisibleBlockOffset);
4803 // Write the lookup table
4804 RecordData::value_type ModuleLocalRecord[] = {
4806 Stream.EmitRecordWithBlob(DeclModuleLocalVisibleLookupAbbrev,
4807 ModuleLocalRecord, ModuleLocalLookupTable);
4808 ++NumModuleLocalDeclContexts;
4809}
4810
4811/// Write an UPDATE_VISIBLE block for the given context.
4812///
4813/// UPDATE_VISIBLE blocks contain the declarations that are added to an existing
4814/// DeclContext in a dependent AST file. As such, they only exist for the TU
4815/// (in C++), for namespaces, and for classes with forward-declared unscoped
4816/// enumeration members (in C++11).
4817void ASTWriter::WriteDeclContextVisibleUpdate(ASTContext &Context,
4818 const DeclContext *DC) {
4819 StoredDeclsMap *Map = DC->getLookupPtr();
4820 if (!Map || Map->empty())
4821 return;
4822
4823 // Create the on-disk hash table in a buffer.
4824 SmallString<4096> LookupTable;
4825 SmallString<4096> ModuleLocalLookupTable;
4826 GenerateNameLookupTable(Context, DC, LookupTable, ModuleLocalLookupTable);
4827
4828 // If we're updating a namespace, select a key declaration as the key for the
4829 // update record; those are the only ones that will be checked on reload.
4830 if (isa<NamespaceDecl>(DC))
4831 DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC)));
4832
4833 // Write the lookup table
4834 RecordData::value_type Record[] = {UPDATE_VISIBLE,
4835 getDeclID(cast<Decl>(DC)).getRawValue()};
4836 Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable);
4837
4838 if (ModuleLocalLookupTable.empty())
4839 return;
4840
4841 // Write the module local lookup table
4842 RecordData::value_type ModuleLocalRecord[] = {
4844 Stream.EmitRecordWithBlob(ModuleLocalUpdateVisibleAbbrev, ModuleLocalRecord,
4845 ModuleLocalLookupTable);
4846}
4847
4848/// Write an FP_PRAGMA_OPTIONS block for the given FPOptions.
4849void ASTWriter::WriteFPPragmaOptions(const FPOptionsOverride &Opts) {
4850 RecordData::value_type Record[] = {Opts.getAsOpaqueInt()};
4851 Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record);
4852}
4853
4854/// Write an OPENCL_EXTENSIONS block for the given OpenCLOptions.
4855void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) {
4856 if (!SemaRef.Context.getLangOpts().OpenCL)
4857 return;
4858
4859 const OpenCLOptions &Opts = SemaRef.getOpenCLOptions();
4861 for (const auto &I:Opts.OptMap) {
4862 AddString(I.getKey(), Record);
4863 auto V = I.getValue();
4864 Record.push_back(V.Supported ? 1 : 0);
4865 Record.push_back(V.Enabled ? 1 : 0);
4866 Record.push_back(V.WithPragma ? 1 : 0);
4867 Record.push_back(V.Avail);
4868 Record.push_back(V.Core);
4869 Record.push_back(V.Opt);
4870 }
4871 Stream.EmitRecord(OPENCL_EXTENSIONS, Record);
4872}
4873void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) {
4874 if (SemaRef.CUDA().ForceHostDeviceDepth > 0) {
4875 RecordData::value_type Record[] = {SemaRef.CUDA().ForceHostDeviceDepth};
4876 Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record);
4877 }
4878}
4879
4880void ASTWriter::WriteObjCCategories() {
4882 RecordData Categories;
4883
4884 for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) {
4885 unsigned Size = 0;
4886 unsigned StartIndex = Categories.size();
4887
4888 ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I];
4889
4890 // Allocate space for the size.
4891 Categories.push_back(0);
4892
4893 // Add the categories.
4895 Cat = Class->known_categories_begin(),
4896 CatEnd = Class->known_categories_end();
4897 Cat != CatEnd; ++Cat, ++Size) {
4898 assert(getDeclID(*Cat).isValid() && "Bogus category");
4899 AddDeclRef(*Cat, Categories);
4900 }
4901
4902 // Update the size.
4903 Categories[StartIndex] = Size;
4904
4905 // Record this interface -> category map.
4906 ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex };
4907 CategoriesMap.push_back(CatInfo);
4908 }
4909
4910 // Sort the categories map by the definition ID, since the reader will be
4911 // performing binary searches on this information.
4912 llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end());
4913
4914 // Emit the categories map.
4915 using namespace llvm;
4916
4917 auto Abbrev = std::make_shared<BitCodeAbbrev>();
4918 Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP));
4919 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries
4920 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
4921 unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev));
4922
4923 RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()};
4924 Stream.EmitRecordWithBlob(AbbrevID, Record,
4925 reinterpret_cast<char *>(CategoriesMap.data()),
4926 CategoriesMap.size() * sizeof(ObjCCategoriesInfo));
4927
4928 // Emit the category lists.
4929 Stream.EmitRecord(OBJC_CATEGORIES, Categories);
4930}
4931
4932void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) {
4934
4935 if (LPTMap.empty())
4936 return;
4937
4939 for (auto &LPTMapEntry : LPTMap) {
4940 const FunctionDecl *FD = LPTMapEntry.first;
4941 LateParsedTemplate &LPT = *LPTMapEntry.second;
4942 AddDeclRef(FD, Record);
4943 AddDeclRef(LPT.D, Record);
4944 Record.push_back(LPT.FPO.getAsOpaqueInt());
4945 Record.push_back(LPT.Toks.size());
4946
4947 for (const auto &Tok : LPT.Toks) {
4948 AddToken(Tok, Record);
4949 }
4950 }
4951 Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record);
4952}
4953
4954/// Write the state of 'pragma clang optimize' at the end of the module.
4955void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) {
4957 SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation();
4958 AddSourceLocation(PragmaLoc, Record);
4959 Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record);
4960}
4961
4962/// Write the state of 'pragma ms_struct' at the end of the module.
4963void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) {
4965 Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF);
4966 Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record);
4967}
4968
4969/// Write the state of 'pragma pointers_to_members' at the end of the
4970//module.
4971void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) {
4975 Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record);
4976}
4977
4978/// Write the state of 'pragma align/pack' at the end of the module.
4979void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) {
4980 // Don't serialize pragma align/pack state for modules, since it should only
4981 // take effect on a per-submodule basis.
4982 if (WritingModule)
4983 return;
4984
4986 AddAlignPackInfo(SemaRef.AlignPackStack.CurrentValue, Record);
4987 AddSourceLocation(SemaRef.AlignPackStack.CurrentPragmaLocation, Record);
4988 Record.push_back(SemaRef.AlignPackStack.Stack.size());
4989 for (const auto &StackEntry : SemaRef.AlignPackStack.Stack) {
4990 AddAlignPackInfo(StackEntry.Value, Record);
4991 AddSourceLocation(StackEntry.PragmaLocation, Record);
4992 AddSourceLocation(StackEntry.PragmaPushLocation, Record);
4993 AddString(StackEntry.StackSlotLabel, Record);
4994 }
4995 Stream.EmitRecord(ALIGN_PACK_PRAGMA_OPTIONS, Record);
4996}
4997
4998/// Write the state of 'pragma float_control' at the end of the module.
4999void ASTWriter::WriteFloatControlPragmaOptions(Sema &SemaRef) {
5000 // Don't serialize pragma float_control state for modules,
5001 // since it should only take effect on a per-submodule basis.
5002 if (WritingModule)
5003 return;
5004
5006 Record.push_back(SemaRef.FpPragmaStack.CurrentValue.getAsOpaqueInt());
5007 AddSourceLocation(SemaRef.FpPragmaStack.CurrentPragmaLocation, Record);
5008 Record.push_back(SemaRef.FpPragmaStack.Stack.size());
5009 for (const auto &StackEntry : SemaRef.FpPragmaStack.Stack) {
5010 Record.push_back(StackEntry.Value.getAsOpaqueInt());
5011 AddSourceLocation(StackEntry.PragmaLocation, Record);
5012 AddSourceLocation(StackEntry.PragmaPushLocation, Record);
5013 AddString(StackEntry.StackSlotLabel, Record);
5014 }
5015 Stream.EmitRecord(FLOAT_CONTROL_PRAGMA_OPTIONS, Record);
5016}
5017
5018/// Write Sema's collected list of declarations with unverified effects.
5019void ASTWriter::WriteDeclsWithEffectsToVerify(Sema &SemaRef) {
5020 if (SemaRef.DeclsWithEffectsToVerify.empty())
5021 return;
5023 for (const auto *D : SemaRef.DeclsWithEffectsToVerify) {
5025 }
5026 Stream.EmitRecord(DECLS_WITH_EFFECTS_TO_VERIFY, Record);
5027}
5028
5029void ASTWriter::WriteModuleFileExtension(Sema &SemaRef,
5030 ModuleFileExtensionWriter &Writer) {
5031 // Enter the extension block.
5032 Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4);
5033
5034 // Emit the metadata record abbreviation.
5035 auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
5036 Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA));
5037 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
5038 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
5039 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
5040 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
5041 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
5042 unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv));
5043
5044 // Emit the metadata record.
5046 auto Metadata = Writer.getExtension()->getExtensionMetadata();
5047 Record.push_back(EXTENSION_METADATA);
5048 Record.push_back(Metadata.MajorVersion);
5049 Record.push_back(Metadata.MinorVersion);
5050 Record.push_back(Metadata.BlockName.size());
5051 Record.push_back(Metadata.UserInfo.size());
5052 SmallString<64> Buffer;
5053 Buffer += Metadata.BlockName;
5054 Buffer += Metadata.UserInfo;
5055 Stream.EmitRecordWithBlob(Abbrev, Record, Buffer);
5056
5057 // Emit the contents of the extension block.
5058 Writer.writeExtensionContents(SemaRef, Stream);
5059
5060 // Exit the extension block.
5061 Stream.ExitBlock();
5062}
5063
5064//===----------------------------------------------------------------------===//
5065// General Serialization Routines
5066//===----------------------------------------------------------------------===//
5067
5069 auto &Record = *this;
5070 // FIXME: Clang can't handle the serialization/deserialization of
5071 // preferred_name properly now. See
5072 // https://github.com/llvm/llvm-project/issues/56490 for example.
5073 if (!A || (isa<PreferredNameAttr>(A) &&
5074 Writer->isWritingStdCXXNamedModules()))
5075 return Record.push_back(0);
5076
5077 Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs
5078
5079 Record.AddIdentifierRef(A->getAttrName());
5080 Record.AddIdentifierRef(A->getScopeName());
5081 Record.AddSourceRange(A->getRange());
5082 Record.AddSourceLocation(A->getScopeLoc());
5083 Record.push_back(A->getParsedKind());
5084 Record.push_back(A->getSyntax());
5085 Record.push_back(A->getAttributeSpellingListIndexRaw());
5086 Record.push_back(A->isRegularKeywordAttribute());
5087
5088#include "clang/Serialization/AttrPCHWrite.inc"
5089}
5090
5091/// Emit the list of attributes to the specified record.
5093 push_back(Attrs.size());
5094 for (const auto *A : Attrs)
5095 AddAttr(A);
5096}
5097
5100 // FIXME: Should translate token kind to a stable encoding.
5101 Record.push_back(Tok.getKind());
5102 // FIXME: Should translate token flags to a stable encoding.
5103 Record.push_back(Tok.getFlags());
5104
5105 if (Tok.isAnnotation()) {
5107 switch (Tok.getKind()) {
5108 case tok::annot_pragma_loop_hint: {
5109 auto *Info = static_cast<PragmaLoopHintInfo *>(Tok.getAnnotationValue());
5110 AddToken(Info->PragmaName, Record);
5111 AddToken(Info->Option, Record);
5112 Record.push_back(Info->Toks.size());
5113 for (const auto &T : Info->Toks)
5114 AddToken(T, Record);
5115 break;
5116 }
5117 case tok::annot_pragma_pack: {
5118 auto *Info =
5119 static_cast<Sema::PragmaPackInfo *>(Tok.getAnnotationValue());
5120 Record.push_back(static_cast<unsigned>(Info->Action));
5121 AddString(Info->SlotLabel, Record);
5122 AddToken(Info->Alignment, Record);
5123 break;
5124 }
5125 // Some annotation tokens do not use the PtrData field.
5126 case tok::annot_pragma_openmp:
5127 case tok::annot_pragma_openmp_end:
5128 case tok::annot_pragma_unused:
5129 case tok::annot_pragma_openacc:
5130 case tok::annot_pragma_openacc_end:
5131 case tok::annot_repl_input_end:
5132 break;
5133 default:
5134 llvm_unreachable("missing serialization code for annotation token");
5135 }
5136 } else {
5137 Record.push_back(Tok.getLength());
5138 // FIXME: When reading literal tokens, reconstruct the literal pointer if it
5139 // is needed.
5141 }
5142}
5143
5145 Record.push_back(Str.size());
5146 Record.insert(Record.end(), Str.begin(), Str.end());
5147}
5148
5150 SmallVectorImpl<char> &Blob) {
5151 Record.push_back(Str.size());
5152 Blob.insert(Blob.end(), Str.begin(), Str.end());
5153}
5154
5156 assert(WritingAST && "can't prepare path for output when not writing AST");
5157
5158 // Leave special file names as they are.
5159 StringRef PathStr(Path.data(), Path.size());
5160 if (PathStr == "<built-in>" || PathStr == "<command line>")
5161 return false;
5162
5163 bool Changed = cleanPathForOutput(PP->getFileManager(), Path);
5164
5165 // Remove a prefix to make the path relative, if relevant.
5166 const char *PathBegin = Path.data();
5167 const char *PathPtr =
5168 adjustFilenameForRelocatableAST(PathBegin, BaseDirectory);
5169 if (PathPtr != PathBegin) {
5170 Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin));
5171 Changed = true;
5172 }
5173
5174 return Changed;
5175}
5176
5178 SmallString<128> FilePath(Path);
5179 PreparePathForOutput(FilePath);
5180 AddString(FilePath, Record);
5181}
5182
5184 SmallVectorImpl<char> &Blob) {
5185 SmallString<128> FilePath(Path);
5186 PreparePathForOutput(FilePath);
5187 AddStringBlob(FilePath, Record, Blob);
5188}
5189
5191 StringRef Path) {
5192 SmallString<128> FilePath(Path);
5193 PreparePathForOutput(FilePath);
5194 Stream.EmitRecordWithBlob(Abbrev, Record, FilePath);
5195}
5196
5197void ASTWriter::AddVersionTuple(const VersionTuple &Version,
5199 Record.push_back(Version.getMajor());
5200 if (std::optional<unsigned> Minor = Version.getMinor())
5201 Record.push_back(*Minor + 1);
5202 else
5203 Record.push_back(0);
5204 if (std::optional<unsigned> Subminor = Version.getSubminor())
5205 Record.push_back(*Subminor + 1);
5206 else
5207 Record.push_back(0);
5208}
5209
5210/// Note that the identifier II occurs at the given offset
5211/// within the identifier table.
5212void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) {
5213 IdentifierID ID = IdentifierIDs[II];
5214 // Only store offsets new to this AST file. Other identifier names are looked
5215 // up earlier in the chain and thus don't need an offset.
5216 if (!isLocalIdentifierID(ID))
5217 return;
5218
5219 // For local identifiers, the module file index must be 0.
5220
5221 assert(ID != 0);
5223 assert(ID < IdentifierOffsets.size());
5224 IdentifierOffsets[ID] = Offset;
5225}
5226
5227/// Note that the selector Sel occurs at the given offset
5228/// within the method pool/selector table.
5229void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
5230 unsigned ID = SelectorIDs[Sel];
5231 assert(ID && "Unknown selector");
5232 // Don't record offsets for selectors that are also available in a different
5233 // file.
5234 if (ID < FirstSelectorID)
5235 return;
5236 SelectorOffsets[ID - FirstSelectorID] = Offset;
5237}
5238
5239ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream,
5240 SmallVectorImpl<char> &Buffer,
5241 InMemoryModuleCache &ModuleCache,
5242 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
5243 bool IncludeTimestamps, bool BuildingImplicitModule,
5244 bool GeneratingReducedBMI)
5245 : Stream(Stream), Buffer(Buffer), ModuleCache(ModuleCache),
5246 IncludeTimestamps(IncludeTimestamps),
5247 BuildingImplicitModule(BuildingImplicitModule),
5248 GeneratingReducedBMI(GeneratingReducedBMI) {
5249 for (const auto &Ext : Extensions) {
5250 if (auto Writer = Ext->createExtensionWriter(*this))
5251 ModuleFileExtensionWriters.push_back(std::move(Writer));
5252 }
5253}
5254
5255ASTWriter::~ASTWriter() = default;
5256
5258 assert(WritingAST && "can't determine lang opts when not writing AST");
5259 return PP->getLangOpts();
5260}
5261
5263 return IncludeTimestamps ? E->getModificationTime() : 0;
5264}
5265
5267ASTWriter::WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
5268 StringRef OutputFile, Module *WritingModule,
5269 StringRef isysroot, bool ShouldCacheASTInMemory) {
5270 llvm::TimeTraceScope scope("WriteAST", OutputFile);
5271 WritingAST = true;
5272
5273 Sema *SemaPtr = Subject.dyn_cast<Sema *>();
5274 Preprocessor &PPRef =
5275 SemaPtr ? SemaPtr->getPreprocessor() : *cast<Preprocessor *>(Subject);
5276
5277 ASTHasCompilerErrors = PPRef.getDiagnostics().hasUncompilableErrorOccurred();
5278
5279 // Emit the file header.
5280 Stream.Emit((unsigned)'C', 8);
5281 Stream.Emit((unsigned)'P', 8);
5282 Stream.Emit((unsigned)'C', 8);
5283 Stream.Emit((unsigned)'H', 8);
5284
5285 WriteBlockInfoBlock();
5286
5287 PP = &PPRef;
5288 this->WritingModule = WritingModule;
5289 ASTFileSignature Signature = WriteASTCore(SemaPtr, isysroot, WritingModule);
5290 PP = nullptr;
5291 this->WritingModule = nullptr;
5292 this->BaseDirectory.clear();
5293
5294 WritingAST = false;
5295
5296 if (WritingModule && PPRef.getHeaderSearchInfo()
5297 .getHeaderSearchOpts()
5298 .ModulesValidateOncePerBuildSession)
5299 updateModuleTimestamp(OutputFile);
5300
5301 if (ShouldCacheASTInMemory) {
5302 // Construct MemoryBuffer and update buffer manager.
5303 ModuleCache.addBuiltPCM(OutputFile,
5304 llvm::MemoryBuffer::getMemBufferCopy(
5305 StringRef(Buffer.begin(), Buffer.size())));
5306 }
5307 return Signature;
5308}
5309
5310template<typename Vector>
5311static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec) {
5312 for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end();
5313 I != E; ++I) {
5314 Writer.GetDeclRef(*I);
5315 }
5316}
5317
5318template <typename Vector>
5321 for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end();
5322 I != E; ++I) {
5323 Writer.AddEmittedDeclRef(*I, Record);
5324 }
5325}
5326
5327void ASTWriter::computeNonAffectingInputFiles() {
5328 SourceManager &SrcMgr = PP->getSourceManager();
5329 unsigned N = SrcMgr.local_sloc_entry_size();
5330
5331 IsSLocAffecting.resize(N, true);
5332 IsSLocFileEntryAffecting.resize(N, true);
5333
5334 if (!WritingModule)
5335 return;
5336
5337 auto AffectingModuleMaps = GetAffectingModuleMaps(*PP, WritingModule);
5338
5339 unsigned FileIDAdjustment = 0;
5340 unsigned OffsetAdjustment = 0;
5341
5342 NonAffectingFileIDAdjustments.reserve(N);
5343 NonAffectingOffsetAdjustments.reserve(N);
5344
5345 NonAffectingFileIDAdjustments.push_back(FileIDAdjustment);
5346 NonAffectingOffsetAdjustments.push_back(OffsetAdjustment);
5347
5348 for (unsigned I = 1; I != N; ++I) {
5349 const SrcMgr::SLocEntry *SLoc = &SrcMgr.getLocalSLocEntry(I);
5350 FileID FID = FileID::get(I);
5351 assert(&SrcMgr.getSLocEntry(FID) == SLoc);
5352
5353 if (!SLoc->isFile())
5354 continue;
5355 const SrcMgr::FileInfo &File = SLoc->getFile();
5356 const SrcMgr::ContentCache *Cache = &File.getContentCache();
5357 if (!Cache->OrigEntry)
5358 continue;
5359
5360 // Don't prune anything other than module maps.
5361 if (!isModuleMap(File.getFileCharacteristic()))
5362 continue;
5363
5364 // Don't prune module maps if all are guaranteed to be affecting.
5365 if (!AffectingModuleMaps)
5366 continue;
5367
5368 // Don't prune module maps that are affecting.
5369 if (AffectingModuleMaps->DefinitionFileIDs.contains(FID))
5370 continue;
5371
5372 IsSLocAffecting[I] = false;
5373 IsSLocFileEntryAffecting[I] =
5374 AffectingModuleMaps->DefinitionFiles.contains(*Cache->OrigEntry);
5375
5376 FileIDAdjustment += 1;
5377 // Even empty files take up one element in the offset table.
5378 OffsetAdjustment += SrcMgr.getFileIDSize(FID) + 1;
5379
5380 // If the previous file was non-affecting as well, just extend its entry
5381 // with our information.
5382 if (!NonAffectingFileIDs.empty() &&
5383 NonAffectingFileIDs.back().ID == FID.ID - 1) {
5384 NonAffectingFileIDs.back() = FID;
5385 NonAffectingRanges.back().setEnd(SrcMgr.getLocForEndOfFile(FID));
5386 NonAffectingFileIDAdjustments.back() = FileIDAdjustment;
5387 NonAffectingOffsetAdjustments.back() = OffsetAdjustment;
5388 continue;
5389 }
5390
5391 NonAffectingFileIDs.push_back(FID);
5392 NonAffectingRanges.emplace_back(SrcMgr.getLocForStartOfFile(FID),
5393 SrcMgr.getLocForEndOfFile(FID));
5394 NonAffectingFileIDAdjustments.push_back(FileIDAdjustment);
5395 NonAffectingOffsetAdjustments.push_back(OffsetAdjustment);
5396 }
5397
5399 return;
5400
5401 FileManager &FileMgr = PP->getFileManager();
5402 FileMgr.trackVFSUsage(true);
5403 // Lookup the paths in the VFS to trigger `-ivfsoverlay` usage tracking.
5404 for (StringRef Path :
5406 FileMgr.getVirtualFileSystem().exists(Path);
5407 for (unsigned I = 1; I != N; ++I) {
5408 if (IsSLocAffecting[I]) {
5409 const SrcMgr::SLocEntry *SLoc = &SrcMgr.getLocalSLocEntry(I);
5410 if (!SLoc->isFile())
5411 continue;
5412 const SrcMgr::FileInfo &File = SLoc->getFile();
5413 const SrcMgr::ContentCache *Cache = &File.getContentCache();
5414 if (!Cache->OrigEntry)
5415 continue;
5416 FileMgr.getVirtualFileSystem().exists(
5417 Cache->OrigEntry->getNameAsRequested());
5418 }
5419 }
5420 FileMgr.trackVFSUsage(false);
5421}
5422
5423void ASTWriter::PrepareWritingSpecialDecls(Sema &SemaRef) {
5424 ASTContext &Context = SemaRef.Context;
5425
5426 bool isModule = WritingModule != nullptr;
5427
5428 // Set up predefined declaration IDs.
5429 auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) {
5430 if (D) {
5431 assert(D->isCanonicalDecl() && "predefined decl is not canonical");
5432 DeclIDs[D] = ID;
5433 PredefinedDecls.insert(D);
5434 }
5435 };
5436 RegisterPredefDecl(Context.getTranslationUnitDecl(),
5438 RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID);
5439 RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID);
5440 RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID);
5441 RegisterPredefDecl(Context.ObjCProtocolClassDecl,
5443 RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID);
5444 RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID);
5445 RegisterPredefDecl(Context.ObjCInstanceTypeDecl,
5447 RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID);
5448 RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG);
5449 RegisterPredefDecl(Context.BuiltinMSVaListDecl,
5451 RegisterPredefDecl(Context.MSGuidTagDecl,
5453 RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID);
5454 RegisterPredefDecl(Context.MakeIntegerSeqDecl,
5456 RegisterPredefDecl(Context.CFConstantStringTypeDecl,
5458 RegisterPredefDecl(Context.CFConstantStringTagDecl,
5460 RegisterPredefDecl(Context.TypePackElementDecl,
5462 RegisterPredefDecl(Context.BuiltinCommonTypeDecl, PREDEF_DECL_COMMON_TYPE_ID);
5463
5464 const TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
5465
5466 // Force all top level declarations to be emitted.
5467 //
5468 // We start emitting top level declarations from the module purview to
5469 // implement the eliding unreachable declaration feature.
5470 for (const auto *D : TU->noload_decls()) {
5471 if (D->isFromASTFile())
5472 continue;
5473
5474 if (GeneratingReducedBMI) {
5476 continue;
5477
5478 // Don't force emitting static entities.
5479 //
5480 // Technically, all static entities shouldn't be in reduced BMI. The
5481 // language also specifies that the program exposes TU-local entities
5482 // is ill-formed. However, in practice, there are a lot of projects
5483 // uses `static inline` in the headers. So we can't get rid of all
5484 // static entities in reduced BMI now.
5486 continue;
5487 }
5488
5489 // If we're writing C++ named modules, don't emit declarations which are
5490 // not from modules by default. They may be built in declarations (be
5491 // handled above) or implcit declarations (see the implementation of
5492 // `Sema::Initialize()` for example).
5494 D->isImplicit())
5495 continue;
5496
5497 GetDeclRef(D);
5498 }
5499
5500 if (GeneratingReducedBMI)
5501 return;
5502
5503 // Writing all of the tentative definitions in this file, in
5504 // TentativeDefinitions order. Generally, this record will be empty for
5505 // headers.
5506 RecordData TentativeDefinitions;
5508
5509 // Writing all of the file scoped decls in this file.
5510 if (!isModule)
5512
5513 // Writing all of the delegating constructors we still need
5514 // to resolve.
5515 if (!isModule)
5517
5518 // Writing all of the ext_vector declarations.
5519 AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls);
5520
5521 // Writing all of the VTable uses information.
5522 if (!SemaRef.VTableUses.empty())
5523 for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I)
5524 GetDeclRef(SemaRef.VTableUses[I].first);
5525
5526 // Writing all of the UnusedLocalTypedefNameCandidates.
5527 for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates)
5528 GetDeclRef(TD);
5529
5530 // Writing all of pending implicit instantiations.
5531 for (const auto &I : SemaRef.PendingInstantiations)
5532 GetDeclRef(I.first);
5533 assert(SemaRef.PendingLocalImplicitInstantiations.empty() &&
5534 "There are local ones at end of translation unit!");
5535
5536 // Writing some declaration references.
5537 if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) {
5538 GetDeclRef(SemaRef.getStdNamespace());
5539 GetDeclRef(SemaRef.getStdBadAlloc());
5540 GetDeclRef(SemaRef.getStdAlignValT());
5541 }
5542
5543 if (Context.getcudaConfigureCallDecl())
5545
5546 // Writing all of the known namespaces.
5547 for (const auto &I : SemaRef.KnownNamespaces)
5548 if (!I.second)
5549 GetDeclRef(I.first);
5550
5551 // Writing all used, undefined objects that require definitions.
5553 SemaRef.getUndefinedButUsed(Undefined);
5554 for (const auto &I : Undefined)
5555 GetDeclRef(I.first);
5556
5557 // Writing all delete-expressions that we would like to
5558 // analyze later in AST.
5559 if (!isModule)
5560 for (const auto &DeleteExprsInfo :
5562 GetDeclRef(DeleteExprsInfo.first);
5563
5564 // Make sure visible decls, added to DeclContexts previously loaded from
5565 // an AST file, are registered for serialization. Likewise for template
5566 // specializations added to imported templates.
5567 for (const auto *I : DeclsToEmitEvenIfUnreferenced)
5568 GetDeclRef(I);
5569 DeclsToEmitEvenIfUnreferenced.clear();
5570
5571 // Make sure all decls associated with an identifier are registered for
5572 // serialization, if we're storing decls with identifiers.
5573 if (!WritingModule || !getLangOpts().CPlusPlus) {
5575 for (const auto &ID : SemaRef.PP.getIdentifierTable()) {
5576 const IdentifierInfo *II = ID.second;
5577 if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization())
5578 IIs.push_back(II);
5579 }
5580 // Sort the identifiers to visit based on their name.
5581 llvm::sort(IIs, llvm::deref<std::less<>>());
5582 for (const IdentifierInfo *II : IIs)
5583 for (const Decl *D : SemaRef.IdResolver.decls(II))
5584 GetDeclRef(D);
5585 }
5586
5587 // Write all of the DeclsToCheckForDeferredDiags.
5588 for (auto *D : SemaRef.DeclsToCheckForDeferredDiags)
5589 GetDeclRef(D);
5590
5591 // Write all classes that need to emit the vtable definitions if required.
5593 for (CXXRecordDecl *RD : PendingEmittingVTables)
5594 GetDeclRef(RD);
5595 else
5596 PendingEmittingVTables.clear();
5597}
5598
5599void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
5600 ASTContext &Context = SemaRef.Context;
5601
5602 bool isModule = WritingModule != nullptr;
5603
5604 // Write the record containing external, unnamed definitions.
5605 if (!EagerlyDeserializedDecls.empty())
5606 Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls);
5607
5608 if (!ModularCodegenDecls.empty())
5609 Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls);
5610
5611 // Write the record containing tentative definitions.
5612 RecordData TentativeDefinitions;
5614 TentativeDefinitions);
5615 if (!TentativeDefinitions.empty())
5616 Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions);
5617
5618 // Write the record containing unused file scoped decls.
5619 RecordData UnusedFileScopedDecls;
5620 if (!isModule)
5622 UnusedFileScopedDecls);
5623 if (!UnusedFileScopedDecls.empty())
5624 Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls);
5625
5626 // Write the record containing ext_vector type names.
5627 RecordData ExtVectorDecls;
5628 AddLazyVectorEmiitedDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls);
5629 if (!ExtVectorDecls.empty())
5630 Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls);
5631
5632 // Write the record containing VTable uses information.
5633 RecordData VTableUses;
5634 if (!SemaRef.VTableUses.empty()) {
5635 for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) {
5636 CXXRecordDecl *D = SemaRef.VTableUses[I].first;
5637 if (!wasDeclEmitted(D))
5638 continue;
5639
5640 AddDeclRef(D, VTableUses);
5641 AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses);
5642 VTableUses.push_back(SemaRef.VTablesUsed[D]);
5643 }
5644 Stream.EmitRecord(VTABLE_USES, VTableUses);
5645 }
5646
5647 // Write the record containing potentially unused local typedefs.
5648 RecordData UnusedLocalTypedefNameCandidates;
5649 for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates)
5650 AddEmittedDeclRef(TD, UnusedLocalTypedefNameCandidates);
5651 if (!UnusedLocalTypedefNameCandidates.empty())
5652 Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES,
5653 UnusedLocalTypedefNameCandidates);
5654
5655 // Write the record containing pending implicit instantiations.
5656 RecordData PendingInstantiations;
5657 for (const auto &I : SemaRef.PendingInstantiations) {
5658 if (!wasDeclEmitted(I.first))
5659 continue;
5660
5661 AddDeclRef(I.first, PendingInstantiations);
5662 AddSourceLocation(I.second, PendingInstantiations);
5663 }
5664 if (!PendingInstantiations.empty())
5665 Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations);
5666
5667 // Write the record containing declaration references of Sema.
5668 RecordData SemaDeclRefs;
5669 if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) {
5670 auto AddEmittedDeclRefOrZero = [this, &SemaDeclRefs](Decl *D) {
5671 if (!D || !wasDeclEmitted(D))
5672 SemaDeclRefs.push_back(0);
5673 else
5674 AddDeclRef(D, SemaDeclRefs);
5675 };
5676
5677 AddEmittedDeclRefOrZero(SemaRef.getStdNamespace());
5678 AddEmittedDeclRefOrZero(SemaRef.getStdBadAlloc());
5679 AddEmittedDeclRefOrZero(SemaRef.getStdAlignValT());
5680 }
5681 if (!SemaDeclRefs.empty())
5682 Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs);
5683
5684 // Write the record containing decls to be checked for deferred diags.
5685 RecordData DeclsToCheckForDeferredDiags;
5686 for (auto *D : SemaRef.DeclsToCheckForDeferredDiags)
5687 if (wasDeclEmitted(D))
5688 AddDeclRef(D, DeclsToCheckForDeferredDiags);
5689 if (!DeclsToCheckForDeferredDiags.empty())
5690 Stream.EmitRecord(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS,
5691 DeclsToCheckForDeferredDiags);
5692
5693 // Write the record containing CUDA-specific declaration references.
5694 RecordData CUDASpecialDeclRefs;
5695 if (auto *CudaCallDecl = Context.getcudaConfigureCallDecl();
5696 CudaCallDecl && wasDeclEmitted(CudaCallDecl)) {
5697 AddDeclRef(CudaCallDecl, CUDASpecialDeclRefs);
5698 Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs);
5699 }
5700
5701 // Write the delegating constructors.
5702 RecordData DelegatingCtorDecls;
5703 if (!isModule)
5705 DelegatingCtorDecls);
5706 if (!DelegatingCtorDecls.empty())
5707 Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls);
5708
5709 // Write the known namespaces.
5710 RecordData KnownNamespaces;
5711 for (const auto &I : SemaRef.KnownNamespaces) {
5712 if (!I.second && wasDeclEmitted(I.first))
5713 AddDeclRef(I.first, KnownNamespaces);
5714 }
5715 if (!KnownNamespaces.empty())
5716 Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces);
5717
5718 // Write the undefined internal functions and variables, and inline functions.
5719 RecordData UndefinedButUsed;
5721 SemaRef.getUndefinedButUsed(Undefined);
5722 for (const auto &I : Undefined) {
5723 if (!wasDeclEmitted(I.first))
5724 continue;
5725
5726 AddDeclRef(I.first, UndefinedButUsed);
5727 AddSourceLocation(I.second, UndefinedButUsed);
5728 }
5729 if (!UndefinedButUsed.empty())
5730 Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed);
5731
5732 // Write all delete-expressions that we would like to
5733 // analyze later in AST.
5734 RecordData DeleteExprsToAnalyze;
5735 if (!isModule) {
5736 for (const auto &DeleteExprsInfo :
5738 if (!wasDeclEmitted(DeleteExprsInfo.first))
5739 continue;
5740
5741 AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze);
5742 DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size());
5743 for (const auto &DeleteLoc : DeleteExprsInfo.second) {
5744 AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze);
5745 DeleteExprsToAnalyze.push_back(DeleteLoc.second);
5746 }
5747 }
5748 }
5749 if (!DeleteExprsToAnalyze.empty())
5750 Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze);
5751
5752 RecordData VTablesToEmit;
5753 for (CXXRecordDecl *RD : PendingEmittingVTables) {
5754 if (!wasDeclEmitted(RD))
5755 continue;
5756
5757 AddDeclRef(RD, VTablesToEmit);
5758 }
5759
5760 if (!VTablesToEmit.empty())
5761 Stream.EmitRecord(VTABLES_TO_EMIT, VTablesToEmit);
5762}
5763
5764ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot,
5765 Module *WritingModule) {
5766 using namespace llvm;
5767
5768 bool isModule = WritingModule != nullptr;
5769
5770 // Make sure that the AST reader knows to finalize itself.
5771 if (Chain)
5772 Chain->finalizeForWriting();
5773
5774 // This needs to be done very early, since everything that writes
5775 // SourceLocations or FileIDs depends on it.
5776 computeNonAffectingInputFiles();
5777
5778 writeUnhashedControlBlock(*PP);
5779
5780 // Don't reuse type ID and Identifier ID from readers for C++ standard named
5781 // modules since we want to support no-transitive-change model for named
5782 // modules. The theory for no-transitive-change model is,
5783 // for a user of a named module, the user can only access the indirectly
5784 // imported decls via the directly imported module. So that it is possible to
5785 // control what matters to the users when writing the module. It would be
5786 // problematic if the users can reuse the type IDs and identifier IDs from
5787 // indirectly imported modules arbitrarily. So we choose to clear these ID
5788 // here.
5790 TypeIdxs.clear();
5791 IdentifierIDs.clear();
5792 }
5793
5794 // Look for any identifiers that were named while processing the
5795 // headers, but are otherwise not needed. We add these to the hash
5796 // table to enable checking of the predefines buffer in the case
5797 // where the user adds new macro definitions when building the AST
5798 // file.
5799 //
5800 // We do this before emitting any Decl and Types to make sure the
5801 // Identifier ID is stable.
5803 for (const auto &ID : PP->getIdentifierTable())
5804 if (IsInterestingNonMacroIdentifier(ID.second, *this))
5805 IIs.push_back(ID.second);
5806 // Sort the identifiers lexicographically before getting the references so
5807 // that their order is stable.
5808 llvm::sort(IIs, llvm::deref<std::less<>>());
5809 for (const IdentifierInfo *II : IIs)
5810 getIdentifierRef(II);
5811
5812 // Write the set of weak, undeclared identifiers. We always write the
5813 // entire table, since later PCH files in a PCH chain are only interested in
5814 // the results at the end of the chain.
5815 RecordData WeakUndeclaredIdentifiers;
5816 if (SemaPtr) {
5817 for (const auto &WeakUndeclaredIdentifierList :
5818 SemaPtr->WeakUndeclaredIdentifiers) {
5819 const IdentifierInfo *const II = WeakUndeclaredIdentifierList.first;
5820 for (const auto &WI : WeakUndeclaredIdentifierList.second) {
5821 AddIdentifierRef(II, WeakUndeclaredIdentifiers);
5822 AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
5823 AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
5824 }
5825 }
5826 }
5827
5828 // Form the record of special types.
5829 RecordData SpecialTypes;
5830 if (SemaPtr) {
5831 ASTContext &Context = SemaPtr->Context;
5832 AddTypeRef(Context, Context.getRawCFConstantStringType(), SpecialTypes);
5833 AddTypeRef(Context, Context.getFILEType(), SpecialTypes);
5834 AddTypeRef(Context, Context.getjmp_bufType(), SpecialTypes);
5835 AddTypeRef(Context, Context.getsigjmp_bufType(), SpecialTypes);
5836 AddTypeRef(Context, Context.ObjCIdRedefinitionType, SpecialTypes);
5837 AddTypeRef(Context, Context.ObjCClassRedefinitionType, SpecialTypes);
5838 AddTypeRef(Context, Context.ObjCSelRedefinitionType, SpecialTypes);
5839 AddTypeRef(Context, Context.getucontext_tType(), SpecialTypes);
5840 }
5841
5842 if (SemaPtr)
5843 PrepareWritingSpecialDecls(*SemaPtr);
5844
5845 // Write the control block
5846 WriteControlBlock(*PP, isysroot);
5847
5848 // Write the remaining AST contents.
5849 Stream.FlushToWord();
5850 ASTBlockRange.first = Stream.GetCurrentBitNo() >> 3;
5851 Stream.EnterSubblock(AST_BLOCK_ID, 5);
5852 ASTBlockStartOffset = Stream.GetCurrentBitNo();
5853
5854 // This is so that older clang versions, before the introduction
5855 // of the control block, can read and reject the newer PCH format.
5856 {
5858 Stream.EmitRecord(METADATA_OLD_FORMAT, Record);
5859 }
5860
5861 // For method pool in the module, if it contains an entry for a selector,
5862 // the entry should be complete, containing everything introduced by that
5863 // module and all modules it imports. It's possible that the entry is out of
5864 // date, so we need to pull in the new content here.
5865
5866 // It's possible that updateOutOfDateSelector can update SelectorIDs. To be
5867 // safe, we copy all selectors out.
5868 if (SemaPtr) {
5870 for (auto &SelectorAndID : SelectorIDs)
5871 AllSelectors.push_back(SelectorAndID.first);
5872 for (auto &Selector : AllSelectors)
5874 }
5875
5876 if (Chain) {
5877 // Write the mapping information describing our module dependencies and how
5878 // each of those modules were mapped into our own offset/ID space, so that
5879 // the reader can build the appropriate mapping to its own offset/ID space.
5880 // The map consists solely of a blob with the following format:
5881 // *(module-kind:i8
5882 // module-name-len:i16 module-name:len*i8
5883 // source-location-offset:i32
5884 // identifier-id:i32
5885 // preprocessed-entity-id:i32
5886 // macro-definition-id:i32
5887 // submodule-id:i32
5888 // selector-id:i32
5889 // declaration-id:i32
5890 // c++-base-specifiers-id:i32
5891 // type-id:i32)
5892 //
5893 // module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule,
5894 // MK_ExplicitModule or MK_ImplicitModule, then the module-name is the
5895 // module name. Otherwise, it is the module file name.
5896 auto Abbrev = std::make_shared<BitCodeAbbrev>();
5897 Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP));
5898 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
5899 unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
5900 SmallString<2048> Buffer;
5901 {
5902 llvm::raw_svector_ostream Out(Buffer);
5903 for (ModuleFile &M : Chain->ModuleMgr) {
5904 using namespace llvm::support;
5905
5906 endian::Writer LE(Out, llvm::endianness::little);
5907 LE.write<uint8_t>(static_cast<uint8_t>(M.Kind));
5908 StringRef Name = M.isModule() ? M.ModuleName : M.FileName;
5909 LE.write<uint16_t>(Name.size());
5910 Out.write(Name.data(), Name.size());
5911
5912 // Note: if a base ID was uint max, it would not be possible to load
5913 // another module after it or have more than one entity inside it.
5914 uint32_t None = std::numeric_limits<uint32_t>::max();
5915
5916 auto writeBaseIDOrNone = [&](auto BaseID, bool ShouldWrite) {
5917 assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high");
5918 if (ShouldWrite)
5919 LE.write<uint32_t>(BaseID);
5920 else
5921 LE.write<uint32_t>(None);
5922 };
5923
5924 // These values should be unique within a chain, since they will be read
5925 // as keys into ContinuousRangeMaps.
5926 writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros);
5927 writeBaseIDOrNone(M.BasePreprocessedEntityID,
5929 writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules);
5930 writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors);
5931 }
5932 }
5933 RecordData::value_type Record[] = {MODULE_OFFSET_MAP};
5934 Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
5935 Buffer.data(), Buffer.size());
5936 }
5937
5938 if (SemaPtr)
5939 WriteDeclAndTypes(SemaPtr->Context);
5940
5941 WriteFileDeclIDsMap();
5942 WriteSourceManagerBlock(PP->getSourceManager());
5943 if (SemaPtr)
5944 WriteComments(SemaPtr->Context);
5945 WritePreprocessor(*PP, isModule);
5946 WriteHeaderSearch(PP->getHeaderSearchInfo());
5947 if (SemaPtr) {
5948 WriteSelectors(*SemaPtr);
5949 WriteReferencedSelectorsPool(*SemaPtr);
5950 WriteLateParsedTemplates(*SemaPtr);
5951 }
5952 WriteIdentifierTable(*PP, SemaPtr ? &SemaPtr->IdResolver : nullptr, isModule);
5953 if (SemaPtr) {
5954 WriteFPPragmaOptions(SemaPtr->CurFPFeatureOverrides());
5955 WriteOpenCLExtensions(*SemaPtr);
5956 WriteCUDAPragmas(*SemaPtr);
5957 }
5958
5959 // If we're emitting a module, write out the submodule information.
5960 if (WritingModule)
5961 WriteSubmodules(WritingModule, SemaPtr ? &SemaPtr->Context : nullptr);
5962
5963 Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
5964
5965 if (SemaPtr)
5966 WriteSpecialDeclRecords(*SemaPtr);
5967
5968 // Write the record containing weak undeclared identifiers.
5969 if (!WeakUndeclaredIdentifiers.empty())
5970 Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS,
5971 WeakUndeclaredIdentifiers);
5972
5973 if (!WritingModule) {
5974 // Write the submodules that were imported, if any.
5975 struct ModuleInfo {
5976 uint64_t ID;
5977 Module *M;
5978 ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {}
5979 };
5981 if (SemaPtr) {
5982 for (const auto *I : SemaPtr->Context.local_imports()) {
5983 assert(SubmoduleIDs.contains(I->getImportedModule()));
5984 Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()],
5985 I->getImportedModule()));
5986 }
5987 }
5988
5989 if (!Imports.empty()) {
5990 auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) {
5991 return A.ID < B.ID;
5992 };
5993 auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) {
5994 return A.ID == B.ID;
5995 };
5996
5997 // Sort and deduplicate module IDs.
5998 llvm::sort(Imports, Cmp);
5999 Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq),
6000 Imports.end());
6001
6002 RecordData ImportedModules;
6003 for (const auto &Import : Imports) {
6004 ImportedModules.push_back(Import.ID);
6005 // FIXME: If the module has macros imported then later has declarations
6006 // imported, this location won't be the right one as a location for the
6007 // declaration imports.
6008 AddSourceLocation(PP->getModuleImportLoc(Import.M), ImportedModules);
6009 }
6010
6011 Stream.EmitRecord(IMPORTED_MODULES, ImportedModules);
6012 }
6013 }
6014
6015 WriteObjCCategories();
6016 if (SemaPtr) {
6017 if (!WritingModule) {
6018 WriteOptimizePragmaOptions(*SemaPtr);
6019 WriteMSStructPragmaOptions(*SemaPtr);
6020 WriteMSPointersToMembersPragmaOptions(*SemaPtr);
6021 }
6022 WritePackPragmaOptions(*SemaPtr);
6023 WriteFloatControlPragmaOptions(*SemaPtr);
6024 WriteDeclsWithEffectsToVerify(*SemaPtr);
6025 }
6026
6027 // Some simple statistics
6028 RecordData::value_type Record[] = {
6029 NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts,
6030 NumModuleLocalDeclContexts};
6031 Stream.EmitRecord(STATISTICS, Record);
6032 Stream.ExitBlock();
6033 Stream.FlushToWord();
6034 ASTBlockRange.second = Stream.GetCurrentBitNo() >> 3;
6035
6036 // Write the module file extension blocks.
6037 if (SemaPtr)
6038 for (const auto &ExtWriter : ModuleFileExtensionWriters)
6039 WriteModuleFileExtension(*SemaPtr, *ExtWriter);
6040
6041 return backpatchSignature();
6042}
6043
6044void ASTWriter::EnteringModulePurview() {
6045 // In C++20 named modules, all entities before entering the module purview
6046 // lives in the GMF.
6047 if (GeneratingReducedBMI)
6048 DeclUpdatesFromGMF.swap(DeclUpdates);
6049}
6050
6051// Add update records for all mangling numbers and static local numbers.
6052// These aren't really update records, but this is a convenient way of
6053// tagging this rare extra data onto the declarations.
6054void ASTWriter::AddedManglingNumber(const Decl *D, unsigned Number) {
6055 if (D->isFromASTFile())
6056 return;
6057
6058 DeclUpdates[D].push_back(DeclUpdate(UPD_MANGLING_NUMBER, Number));
6059}
6060void ASTWriter::AddedStaticLocalNumbers(const Decl *D, unsigned Number) {
6061 if (D->isFromASTFile())
6062 return;
6063
6064 DeclUpdates[D].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, Number));
6065}
6066
6067void ASTWriter::AddedAnonymousNamespace(const TranslationUnitDecl *TU,
6068 NamespaceDecl *AnonNamespace) {
6069 // If the translation unit has an anonymous namespace, and we don't already
6070 // have an update block for it, write it as an update block.
6071 // FIXME: Why do we not do this if there's already an update block?
6072 if (NamespaceDecl *NS = TU->getAnonymousNamespace()) {
6073 ASTWriter::UpdateRecord &Record = DeclUpdates[TU];
6074 if (Record.empty())
6075 Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS));
6076 }
6077}
6078
6079void ASTWriter::WriteDeclAndTypes(ASTContext &Context) {
6080 // Keep writing types, declarations, and declaration update records
6081 // until we've emitted all of them.
6082 RecordData DeclUpdatesOffsetsRecord;
6083 Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/ 6);
6084 DeclTypesBlockStartOffset = Stream.GetCurrentBitNo();
6085 WriteTypeAbbrevs();
6086 WriteDeclAbbrevs();
6087 do {
6088 WriteDeclUpdatesBlocks(Context, DeclUpdatesOffsetsRecord);
6089 while (!DeclTypesToEmit.empty()) {
6090 DeclOrType DOT = DeclTypesToEmit.front();
6091 DeclTypesToEmit.pop();
6092 if (DOT.isType())
6093 WriteType(Context, DOT.getType());
6094 else
6095 WriteDecl(Context, DOT.getDecl());
6096 }
6097 } while (!DeclUpdates.empty());
6098
6099 DoneWritingDeclsAndTypes = true;
6100
6101 // DelayedNamespace is only meaningful in reduced BMI.
6102 // See the comments of DelayedNamespace for details.
6103 assert(DelayedNamespace.empty() || GeneratingReducedBMI);
6104 RecordData DelayedNamespaceRecord;
6105 for (NamespaceDecl *NS : DelayedNamespace) {
6106 uint64_t LexicalOffset = WriteDeclContextLexicalBlock(Context, NS);
6107 uint64_t VisibleOffset = 0;
6108 uint64_t ModuleLocalOffset = 0;
6109 WriteDeclContextVisibleBlock(Context, NS, VisibleOffset, ModuleLocalOffset);
6110
6111 // Write the offset relative to current block.
6112 if (LexicalOffset)
6113 LexicalOffset -= DeclTypesBlockStartOffset;
6114
6115 if (VisibleOffset)
6116 VisibleOffset -= DeclTypesBlockStartOffset;
6117
6118 if (ModuleLocalOffset)
6119 ModuleLocalOffset -= DeclTypesBlockStartOffset;
6120
6121 AddDeclRef(NS, DelayedNamespaceRecord);
6122 DelayedNamespaceRecord.push_back(LexicalOffset);
6123 DelayedNamespaceRecord.push_back(VisibleOffset);
6124 DelayedNamespaceRecord.push_back(ModuleLocalOffset);
6125 }
6126
6127 // The process of writing lexical and visible block for delayed namespace
6128 // shouldn't introduce any new decls, types or update to emit.
6129 assert(DeclTypesToEmit.empty());
6130 assert(DeclUpdates.empty());
6131
6132 Stream.ExitBlock();
6133
6134 // These things can only be done once we've written out decls and types.
6135 WriteTypeDeclOffsets();
6136 if (!DeclUpdatesOffsetsRecord.empty())
6137 Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
6138
6139 if (!DelayedNamespaceRecord.empty())
6141 DelayedNamespaceRecord);
6142
6143 if (!RelatedDeclsMap.empty()) {
6144 // TODO: on disk hash table for related decls mapping might be more
6145 // efficent becuase it allows lazy deserialization.
6146 RecordData RelatedDeclsMapRecord;
6147 for (const auto &Pair : RelatedDeclsMap) {
6148 RelatedDeclsMapRecord.push_back(Pair.first.getRawValue());
6149 RelatedDeclsMapRecord.push_back(Pair.second.size());
6150 for (const auto &Lambda : Pair.second)
6151 RelatedDeclsMapRecord.push_back(Lambda.getRawValue());
6152 }
6153
6154 auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
6155 Abv->Add(llvm::BitCodeAbbrevOp(RELATED_DECLS_MAP));
6156 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array));
6157 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
6158 unsigned FunctionToLambdaMapAbbrev = Stream.EmitAbbrev(std::move(Abv));
6159 Stream.EmitRecord(RELATED_DECLS_MAP, RelatedDeclsMapRecord,
6160 FunctionToLambdaMapAbbrev);
6161 }
6162
6163 if (!SpecializationsUpdates.empty()) {
6164 WriteSpecializationsUpdates(/*IsPartial=*/false);
6165 SpecializationsUpdates.clear();
6166 }
6167
6168 if (!PartialSpecializationsUpdates.empty()) {
6169 WriteSpecializationsUpdates(/*IsPartial=*/true);
6170 PartialSpecializationsUpdates.clear();
6171 }
6172
6173 const TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
6174 // Create a lexical update block containing all of the declarations in the
6175 // translation unit that do not come from other AST files.
6176 SmallVector<DeclID, 128> NewGlobalKindDeclPairs;
6177 for (const auto *D : TU->noload_decls()) {
6178 if (D->isFromASTFile())
6179 continue;
6180
6181 // In reduced BMI, skip unreached declarations.
6182 if (!wasDeclEmitted(D))
6183 continue;
6184
6185 NewGlobalKindDeclPairs.push_back(D->getKind());
6186 NewGlobalKindDeclPairs.push_back(GetDeclRef(D).getRawValue());
6187 }
6188
6189 auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
6190 Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL));
6191 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
6192 unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
6193
6194 RecordData::value_type Record[] = {TU_UPDATE_LEXICAL};
6195 Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record,
6196 bytes(NewGlobalKindDeclPairs));
6197
6198 Abv = std::make_shared<llvm::BitCodeAbbrev>();
6199 Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE));
6200 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
6201 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
6202 UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
6203
6204 Abv = std::make_shared<llvm::BitCodeAbbrev>();
6205 Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_MODULE_LOCAL_VISIBLE));
6206 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
6207 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
6208 ModuleLocalUpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
6209
6210 // And a visible updates block for the translation unit.
6211 WriteDeclContextVisibleUpdate(Context, TU);
6212
6213 // If we have any extern "C" names, write out a visible update for them.
6214 if (Context.ExternCContext)
6215 WriteDeclContextVisibleUpdate(Context, Context.ExternCContext);
6216
6217 // Write the visible updates to DeclContexts.
6218 for (auto *DC : UpdatedDeclContexts)
6219 WriteDeclContextVisibleUpdate(Context, DC);
6220}
6221
6222void ASTWriter::WriteSpecializationsUpdates(bool IsPartial) {
6225
6226 auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
6227 Abv->Add(llvm::BitCodeAbbrevOp(RecordType));
6228 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
6229 Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
6230 auto UpdateSpecializationAbbrev = Stream.EmitAbbrev(std::move(Abv));
6231
6232 auto &SpecUpdates =
6233 IsPartial ? PartialSpecializationsUpdates : SpecializationsUpdates;
6234 for (auto &SpecializationUpdate : SpecUpdates) {
6235 const NamedDecl *D = SpecializationUpdate.first;
6236
6237 llvm::SmallString<4096> LookupTable;
6238 GenerateSpecializationInfoLookupTable(D, SpecializationUpdate.second,
6239 LookupTable, IsPartial);
6240
6241 // Write the lookup table
6242 RecordData::value_type Record[] = {
6243 static_cast<RecordData::value_type>(RecordType),
6245 Stream.EmitRecordWithBlob(UpdateSpecializationAbbrev, Record, LookupTable);
6246 }
6247}
6248
6249void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
6250 RecordDataImpl &OffsetsRecord) {
6251 if (DeclUpdates.empty())
6252 return;
6253
6254 DeclUpdateMap LocalUpdates;
6255 LocalUpdates.swap(DeclUpdates);
6256
6257 for (auto &DeclUpdate : LocalUpdates) {
6258 const Decl *D = DeclUpdate.first;
6259
6260 bool HasUpdatedBody = false;
6261 bool HasAddedVarDefinition = false;
6263 ASTRecordWriter Record(Context, *this, RecordData);
6264 for (auto &Update : DeclUpdate.second) {
6266
6267 // An updated body is emitted last, so that the reader doesn't need
6268 // to skip over the lazy body to reach statements for other records.
6270 HasUpdatedBody = true;
6271 else if (Kind == UPD_CXX_ADDED_VAR_DEFINITION)
6272 HasAddedVarDefinition = true;
6273 else
6274 Record.push_back(Kind);
6275
6276 switch (Kind) {
6279 assert(Update.getDecl() && "no decl to add?");
6280 Record.AddDeclRef(Update.getDecl());
6281 break;
6284 break;
6285
6287 // FIXME: Do we need to also save the template specialization kind here?
6288 Record.AddSourceLocation(Update.getLoc());
6289 break;
6290
6292 Record.writeStmtRef(
6293 cast<ParmVarDecl>(Update.getDecl())->getDefaultArg());
6294 break;
6295
6297 Record.AddStmt(
6298 cast<FieldDecl>(Update.getDecl())->getInClassInitializer());
6299 break;
6300
6302 auto *RD = cast<CXXRecordDecl>(D);
6303 UpdatedDeclContexts.insert(RD->getPrimaryContext());
6304 Record.push_back(RD->isParamDestroyedInCallee());
6305 Record.push_back(llvm::to_underlying(RD->getArgPassingRestrictions()));
6306 Record.AddCXXDefinitionData(RD);
6307 Record.AddOffset(WriteDeclContextLexicalBlock(Context, RD));
6308
6309 // This state is sometimes updated by template instantiation, when we
6310 // switch from the specialization referring to the template declaration
6311 // to it referring to the template definition.
6312 if (auto *MSInfo = RD->getMemberSpecializationInfo()) {
6313 Record.push_back(MSInfo->getTemplateSpecializationKind());
6314 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
6315 } else {
6316 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
6317 Record.push_back(Spec->getTemplateSpecializationKind());
6318 Record.AddSourceLocation(Spec->getPointOfInstantiation());
6319
6320 // The instantiation might have been resolved to a partial
6321 // specialization. If so, record which one.
6322 auto From = Spec->getInstantiatedFrom();
6323 if (auto PartialSpec =
6324 From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) {
6325 Record.push_back(true);
6326 Record.AddDeclRef(PartialSpec);
6327 Record.AddTemplateArgumentList(
6328 &Spec->getTemplateInstantiationArgs());
6329 } else {
6330 Record.push_back(false);
6331 }
6332 }
6333 Record.push_back(llvm::to_underlying(RD->getTagKind()));
6334 Record.AddSourceLocation(RD->getLocation());
6335 Record.AddSourceLocation(RD->getBeginLoc());
6336 Record.AddSourceRange(RD->getBraceRange());
6337
6338 // Instantiation may change attributes; write them all out afresh.
6339 Record.push_back(D->hasAttrs());
6340 if (D->hasAttrs())
6341 Record.AddAttributes(D->getAttrs());
6342
6343 // FIXME: Ensure we don't get here for explicit instantiations.
6344 break;
6345 }
6346
6348 Record.AddDeclRef(Update.getDecl());
6349 Record.AddStmt(cast<CXXDestructorDecl>(D)->getOperatorDeleteThisArg());
6350 break;
6351
6353 auto prototype =
6354 cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>();
6355 Record.writeExceptionSpecInfo(prototype->getExceptionSpecInfo());
6356 break;
6357 }
6358
6360 Record.push_back(GetOrCreateTypeID(Context, Update.getType()));
6361 break;
6362
6364 break;
6365
6368 Record.push_back(Update.getNumber());
6369 break;
6370
6372 Record.AddSourceRange(
6373 D->getAttr<OMPThreadPrivateDeclAttr>()->getRange());
6374 break;
6375
6377 auto *A = D->getAttr<OMPAllocateDeclAttr>();
6378 Record.push_back(A->getAllocatorType());
6379 Record.AddStmt(A->getAllocator());
6380 Record.AddStmt(A->getAlignment());
6381 Record.AddSourceRange(A->getRange());
6382 break;
6383 }
6384
6386 Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType());
6387 Record.AddSourceRange(
6388 D->getAttr<OMPDeclareTargetDeclAttr>()->getRange());
6389 break;
6390
6391 case UPD_DECL_EXPORTED:
6392 Record.push_back(getSubmoduleID(Update.getModule()));
6393 break;
6394
6396 Record.AddAttributes(llvm::ArrayRef(Update.getAttr()));
6397 break;
6398 }
6399 }
6400
6401 // Add a trailing update record, if any. These must go last because we
6402 // lazily load their attached statement.
6403 if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
6404 if (HasUpdatedBody) {
6405 const auto *Def = cast<FunctionDecl>(D);
6407 Record.push_back(Def->isInlined());
6408 Record.AddSourceLocation(Def->getInnerLocStart());
6409 Record.AddFunctionDefinition(Def);
6410 } else if (HasAddedVarDefinition) {
6411 const auto *VD = cast<VarDecl>(D);
6413 Record.push_back(VD->isInline());
6414 Record.push_back(VD->isInlineSpecified());
6415 Record.AddVarDeclInit(VD);
6416 }
6417 }
6418
6419 AddDeclRef(D, OffsetsRecord);
6420 OffsetsRecord.push_back(Record.Emit(DECL_UPDATES));
6421 }
6422}
6423
6426 uint32_t Raw = Sema::AlignPackInfo::getRawEncoding(Info);
6427 Record.push_back(Raw);
6428}
6429
6430FileID ASTWriter::getAdjustedFileID(FileID FID) const {
6431 if (FID.isInvalid() || PP->getSourceManager().isLoadedFileID(FID) ||
6432 NonAffectingFileIDs.empty())
6433 return FID;
6434 auto It = llvm::lower_bound(NonAffectingFileIDs, FID);
6435 unsigned Idx = std::distance(NonAffectingFileIDs.begin(), It);
6436 unsigned Offset = NonAffectingFileIDAdjustments[Idx];
6437 return FileID::get(FID.getOpaqueValue() - Offset);
6438}
6439
6440unsigned ASTWriter::getAdjustedNumCreatedFIDs(FileID FID) const {
6441 unsigned NumCreatedFIDs = PP->getSourceManager()
6442 .getLocalSLocEntry(FID.ID)
6443 .getFile()
6444 .NumCreatedFIDs;
6445
6446 unsigned AdjustedNumCreatedFIDs = 0;
6447 for (unsigned I = FID.ID, N = I + NumCreatedFIDs; I != N; ++I)
6448 if (IsSLocAffecting[I])
6449 ++AdjustedNumCreatedFIDs;
6450 return AdjustedNumCreatedFIDs;
6451}
6452
6453SourceLocation ASTWriter::getAdjustedLocation(SourceLocation Loc) const {
6454 if (Loc.isInvalid())
6455 return Loc;
6456 return Loc.getLocWithOffset(-getAdjustment(Loc.getOffset()));
6457}
6458
6459SourceRange ASTWriter::getAdjustedRange(SourceRange Range) const {
6460 return SourceRange(getAdjustedLocation(Range.getBegin()),
6461 getAdjustedLocation(Range.getEnd()));
6462}
6463
6465ASTWriter::getAdjustedOffset(SourceLocation::UIntTy Offset) const {
6466 return Offset - getAdjustment(Offset);
6467}
6468
6470ASTWriter::getAdjustment(SourceLocation::UIntTy Offset) const {
6471 if (NonAffectingRanges.empty())
6472 return 0;
6473
6474 if (PP->getSourceManager().isLoadedOffset(Offset))
6475 return 0;
6476
6477 if (Offset > NonAffectingRanges.back().getEnd().getOffset())
6478 return NonAffectingOffsetAdjustments.back();
6479
6480 if (Offset < NonAffectingRanges.front().getBegin().getOffset())
6481 return 0;
6482
6483 auto Contains = [](const SourceRange &Range, SourceLocation::UIntTy Offset) {
6484 return Range.getEnd().getOffset() < Offset;
6485 };
6486
6487 auto It = llvm::lower_bound(NonAffectingRanges, Offset, Contains);
6488 unsigned Idx = std::distance(NonAffectingRanges.begin(), It);
6489 return NonAffectingOffsetAdjustments[Idx];
6490}
6491
6493 Record.push_back(getAdjustedFileID(FID).getOpaqueValue());
6494}
6495
6498 unsigned BaseOffset = 0;
6499 unsigned ModuleFileIndex = 0;
6500
6501 // See SourceLocationEncoding.h for the encoding details.
6503 assert(getChain());
6504 auto SLocMapI = getChain()->GlobalSLocOffsetMap.find(
6505 SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
6506 assert(SLocMapI != getChain()->GlobalSLocOffsetMap.end() &&
6507 "Corrupted global sloc offset map");
6508 ModuleFile *F = SLocMapI->second;
6509 BaseOffset = F->SLocEntryBaseOffset - 2;
6510 // 0 means the location is not loaded. So we need to add 1 to the index to
6511 // make it clear.
6512 ModuleFileIndex = F->Index + 1;
6513 assert(&getChain()->getModuleManager()[F->Index] == F);
6514 }
6515
6516 return SourceLocationEncoding::encode(Loc, BaseOffset, ModuleFileIndex, Seq);
6517}
6518
6521 Loc = getAdjustedLocation(Loc);
6523}
6524
6529}
6530
6531void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) {
6532 AddAPInt(Value.bitcastToAPInt());
6533}
6534
6536 Record.push_back(getIdentifierRef(II));
6537}
6538
6540 if (!II)
6541 return 0;
6542
6543 IdentifierID &ID = IdentifierIDs[II];
6544 if (ID == 0)
6545 ID = NextIdentID++;
6546 return ID;
6547}
6548
6550 // Don't emit builtin macros like __LINE__ to the AST file unless they
6551 // have been redefined by the header (in which case they are not
6552 // isBuiltinMacro).
6553 if (!MI || MI->isBuiltinMacro())
6554 return 0;
6555
6556 MacroID &ID = MacroIDs[MI];
6557 if (ID == 0) {
6558 ID = NextMacroID++;
6559 MacroInfoToEmitData Info = { Name, MI, ID };
6560 MacroInfosToEmit.push_back(Info);
6561 }
6562 return ID;
6563}
6564
6566 if (!MI || MI->isBuiltinMacro())
6567 return 0;
6568
6569 assert(MacroIDs.contains(MI) && "Macro not emitted!");
6570 return MacroIDs[MI];
6571}
6572
6574 return IdentMacroDirectivesOffsetMap.lookup(Name);
6575}
6576
6578 Record->push_back(Writer->getSelectorRef(SelRef));
6579}
6580
6582 if (Sel.getAsOpaquePtr() == nullptr) {
6583 return 0;
6584 }
6585
6586 SelectorID SID = SelectorIDs[Sel];
6587 if (SID == 0 && Chain) {
6588 // This might trigger a ReadSelector callback, which will set the ID for
6589 // this selector.
6590 Chain->LoadSelector(Sel);
6591 SID = SelectorIDs[Sel];
6592 }
6593 if (SID == 0) {
6594 SID = NextSelectorID++;
6595 SelectorIDs[Sel] = SID;
6596 }
6597 return SID;
6598}
6599
6601 AddDeclRef(Temp->getDestructor());
6602}
6603
6606 switch (Kind) {
6608 AddStmt(Arg.getAsExpr());
6609 break;
6612 break;
6616 break;
6621 break;
6628 // FIXME: Is this right?
6629 break;
6630 }
6631}
6632
6635
6637 bool InfoHasSameExpr
6638 = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr();
6639 Record->push_back(InfoHasSameExpr);
6640 if (InfoHasSameExpr)
6641 return; // Avoid storing the same expr twice.
6642 }
6644}
6645
6647 if (!TInfo) {
6649 return;
6650 }
6651
6652 AddTypeRef(TInfo->getType());
6653 AddTypeLoc(TInfo->getTypeLoc());
6654}
6655
6657 LocSeq::State Seq(OuterSeq);
6658 TypeLocWriter TLW(*this, Seq);
6659 for (; !TL.isNull(); TL = TL.getNextTypeLoc())
6660 TLW.Visit(TL);
6661}
6662
6665 Record.push_back(GetOrCreateTypeID(Context, T));
6666}
6667
6668template <typename IdxForTypeTy>
6670 IdxForTypeTy IdxForType) {
6671 if (T.isNull())
6672 return PREDEF_TYPE_NULL_ID;
6673
6674 unsigned FastQuals = T.getLocalFastQualifiers();
6675 T.removeLocalFastQualifiers();
6676
6677 if (T.hasLocalNonFastQualifiers())
6678 return IdxForType(T).asTypeID(FastQuals);
6679
6680 assert(!T.hasLocalQualifiers());
6681
6682 if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
6683 return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
6684
6685 if (T == Context.AutoDeductTy)
6686 return TypeIdx(0, PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
6687 if (T == Context.AutoRRefDeductTy)
6688 return TypeIdx(0, PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
6689
6690 return IdxForType(T).asTypeID(FastQuals);
6691}
6692
6694 return MakeTypeID(Context, T, [&](QualType T) -> TypeIdx {
6695 if (T.isNull())
6696 return TypeIdx();
6697 assert(!T.getLocalFastQualifiers());
6698
6699 TypeIdx &Idx = TypeIdxs[T];
6700 if (Idx.getValue() == 0) {
6701 if (DoneWritingDeclsAndTypes) {
6702 assert(0 && "New type seen after serializing all the types to emit!");
6703 return TypeIdx();
6704 }
6705
6706 // We haven't seen this type before. Assign it a new ID and put it
6707 // into the queue of types to emit.
6708 Idx = TypeIdx(0, NextTypeID++);
6709 DeclTypesToEmit.push(T);
6710 }
6711 return Idx;
6712 });
6713}
6714
6716 if (!wasDeclEmitted(D))
6717 return;
6718
6720}
6721
6723 Record.push_back(GetDeclRef(D).getRawValue());
6724}
6725
6727 assert(WritingAST && "Cannot request a declaration ID before AST writing");
6728
6729 if (!D) {
6730 return LocalDeclID();
6731 }
6732
6733 // If the DeclUpdate from the GMF gets touched, emit it.
6734 if (auto *Iter = DeclUpdatesFromGMF.find(D);
6735 Iter != DeclUpdatesFromGMF.end()) {
6736 for (DeclUpdate &Update : Iter->second)
6737 DeclUpdates[D].push_back(Update);
6738 DeclUpdatesFromGMF.erase(Iter);
6739 }
6740
6741 // If D comes from an AST file, its declaration ID is already known and
6742 // fixed.
6743 if (D->isFromASTFile()) {
6745 TouchedTopLevelModules.insert(D->getOwningModule()->getTopLevelModule());
6746
6747 return LocalDeclID(D->getGlobalID());
6748 }
6749
6750 assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer");
6751 LocalDeclID &ID = DeclIDs[D];
6752 if (ID.isInvalid()) {
6753 if (DoneWritingDeclsAndTypes) {
6754 assert(0 && "New decl seen after serializing all the decls to emit!");
6755 return LocalDeclID();
6756 }
6757
6758 // We haven't seen this declaration before. Give it a new ID and
6759 // enqueue it in the list of declarations to emit.
6760 ID = NextDeclID++;
6761 DeclTypesToEmit.push(const_cast<Decl *>(D));
6762 }
6763
6764 return ID;
6765}
6766
6768 if (!D)
6769 return LocalDeclID();
6770
6771 // If D comes from an AST file, its declaration ID is already known and
6772 // fixed.
6773 if (D->isFromASTFile())
6774 return LocalDeclID(D->getGlobalID());
6775
6776 assert(DeclIDs.contains(D) && "Declaration not emitted!");
6777 return DeclIDs[D];
6778}
6779
6781 assert(D);
6782
6783 assert(DoneWritingDeclsAndTypes &&
6784 "wasDeclEmitted should only be called after writing declarations");
6785
6786 if (D->isFromASTFile())
6787 return true;
6788
6789 bool Emitted = DeclIDs.contains(D);
6790 assert((Emitted || (!D->getOwningModule() && isWritingStdCXXNamedModules()) ||
6791 GeneratingReducedBMI) &&
6792 "The declaration within modules can only be omitted in reduced BMI.");
6793 return Emitted;
6794}
6795
6796void ASTWriter::associateDeclWithFile(const Decl *D, LocalDeclID ID) {
6797 assert(ID.isValid());
6798 assert(D);
6799
6801 if (Loc.isInvalid())
6802 return;
6803
6804 // We only keep track of the file-level declarations of each file.
6806 return;
6807 // FIXME: ParmVarDecls that are part of a function type of a parameter of
6808 // a function/objc method, should not have TU as lexical context.
6809 // TemplateTemplateParmDecls that are part of an alias template, should not
6810 // have TU as lexical context.
6811 if (isa<ParmVarDecl, TemplateTemplateParmDecl>(D))
6812 return;
6813
6815 SourceLocation FileLoc = SM.getFileLoc(Loc);
6816 assert(SM.isLocalSourceLocation(FileLoc));
6817 FileID FID;
6818 unsigned Offset;
6819 std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc);
6820 if (FID.isInvalid())
6821 return;
6822 assert(SM.getSLocEntry(FID).isFile());
6823 assert(IsSLocAffecting[FID.ID]);
6824
6825 std::unique_ptr<DeclIDInFileInfo> &Info = FileDeclIDs[FID];
6826 if (!Info)
6827 Info = std::make_unique<DeclIDInFileInfo>();
6828
6829 std::pair<unsigned, LocalDeclID> LocDecl(Offset, ID);
6830 LocDeclIDsTy &Decls = Info->DeclIDs;
6831 Decls.push_back(LocDecl);
6832}
6833
6836 "expected an anonymous declaration");
6837
6838 // Number the anonymous declarations within this context, if we've not
6839 // already done so.
6840 auto It = AnonymousDeclarationNumbers.find(D);
6841 if (It == AnonymousDeclarationNumbers.end()) {
6842 auto *DC = D->getLexicalDeclContext();
6843 numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) {
6844 AnonymousDeclarationNumbers[ND] = Number;
6845 });
6846
6847 It = AnonymousDeclarationNumbers.find(D);
6848 assert(It != AnonymousDeclarationNumbers.end() &&
6849 "declaration not found within its lexical context");
6850 }
6851
6852 return It->second;
6853}
6854
6856 DeclarationName Name) {
6857 switch (Name.getNameKind()) {
6862 break;
6863
6866 break;
6867
6870 break;
6871
6878 break;
6879 }
6880}
6881
6883 const DeclarationNameInfo &NameInfo) {
6884 AddDeclarationName(NameInfo.getName());
6885 AddSourceLocation(NameInfo.getLoc());
6886 AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName());
6887}
6888
6891 Record->push_back(Info.NumTemplParamLists);
6892 for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i)
6894}
6895
6897 // Nested name specifiers usually aren't too long. I think that 8 would
6898 // typically accommodate the vast majority.
6900
6901 // Push each of the nested-name-specifiers's onto a stack for
6902 // serialization in reverse order.
6903 while (NNS) {
6904 NestedNames.push_back(NNS);
6905 NNS = NNS.getPrefix();
6906 }
6907
6908 Record->push_back(NestedNames.size());
6909 while(!NestedNames.empty()) {
6910 NNS = NestedNames.pop_back_val();
6913 Record->push_back(Kind);
6914 switch (Kind) {
6918 break;
6919
6923 break;
6924
6928 break;
6929
6933 AddTypeRef(NNS.getTypeLoc().getType());
6934 AddTypeLoc(NNS.getTypeLoc());
6936 break;
6937
6940 break;
6941
6945 break;
6946 }
6947 }
6948}
6949
6951 const TemplateParameterList *TemplateParams) {
6952 assert(TemplateParams && "No TemplateParams!");
6953 AddSourceLocation(TemplateParams->getTemplateLoc());
6954 AddSourceLocation(TemplateParams->getLAngleLoc());
6955 AddSourceLocation(TemplateParams->getRAngleLoc());
6956
6957 Record->push_back(TemplateParams->size());
6958 for (const auto &P : *TemplateParams)
6959 AddDeclRef(P);
6960 if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) {
6961 Record->push_back(true);
6962 writeStmtRef(RequiresClause);
6963 } else {
6964 Record->push_back(false);
6965 }
6966}
6967
6968/// Emit a template argument list.
6970 const TemplateArgumentList *TemplateArgs) {
6971 assert(TemplateArgs && "No TemplateArgs!");
6972 Record->push_back(TemplateArgs->size());
6973 for (int i = 0, e = TemplateArgs->size(); i != e; ++i)
6974 AddTemplateArgument(TemplateArgs->get(i));
6975}
6976
6978 const ASTTemplateArgumentListInfo *ASTTemplArgList) {
6979 assert(ASTTemplArgList && "No ASTTemplArgList!");
6980 AddSourceLocation(ASTTemplArgList->LAngleLoc);
6981 AddSourceLocation(ASTTemplArgList->RAngleLoc);
6982 Record->push_back(ASTTemplArgList->NumTemplateArgs);
6983 const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs();
6984 for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i)
6985 AddTemplateArgumentLoc(TemplArgs[i]);
6986}
6987
6989 Record->push_back(Set.size());
6991 I = Set.begin(), E = Set.end(); I != E; ++I) {
6992 AddDeclRef(I.getDecl());
6993 Record->push_back(I.getAccess());
6994 }
6995}
6996
6997// FIXME: Move this out of the main ASTRecordWriter interface.
6999 Record->push_back(Base.isVirtual());
7000 Record->push_back(Base.isBaseOfClass());
7001 Record->push_back(Base.getAccessSpecifierAsWritten());
7002 Record->push_back(Base.getInheritConstructors());
7003 AddTypeSourceInfo(Base.getTypeSourceInfo());
7004 AddSourceRange(Base.getSourceRange());
7005 AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc()
7006 : SourceLocation());
7007}
7008
7009static uint64_t EmitCXXBaseSpecifiers(ASTContext &Context, ASTWriter &W,
7012 ASTRecordWriter Writer(Context, W, Record);
7013 Writer.push_back(Bases.size());
7014
7015 for (auto &Base : Bases)
7016 Writer.AddCXXBaseSpecifier(Base);
7017
7019}
7020
7021// FIXME: Move this out of the main ASTRecordWriter interface.
7023 AddOffset(EmitCXXBaseSpecifiers(getASTContext(), *Writer, Bases));
7024}
7025
7026static uint64_t
7030 ASTRecordWriter Writer(Context, W, Record);
7031 Writer.push_back(CtorInits.size());
7032
7033 for (auto *Init : CtorInits) {
7034 if (Init->isBaseInitializer()) {
7036 Writer.AddTypeSourceInfo(Init->getTypeSourceInfo());
7037 Writer.push_back(Init->isBaseVirtual());
7038 } else if (Init->isDelegatingInitializer()) {
7040 Writer.AddTypeSourceInfo(Init->getTypeSourceInfo());
7041 } else if (Init->isMemberInitializer()){
7043 Writer.AddDeclRef(Init->getMember());
7044 } else {
7046 Writer.AddDeclRef(Init->getIndirectMember());
7047 }
7048
7049 Writer.AddSourceLocation(Init->getMemberLocation());
7050 Writer.AddStmt(Init->getInit());
7051 Writer.AddSourceLocation(Init->getLParenLoc());
7052 Writer.AddSourceLocation(Init->getRParenLoc());
7053 Writer.push_back(Init->isWritten());
7054 if (Init->isWritten())
7055 Writer.push_back(Init->getSourceOrder());
7056 }
7057
7059}
7060
7061// FIXME: Move this out of the main ASTRecordWriter interface.
7064 AddOffset(EmitCXXCtorInitializers(getASTContext(), *Writer, CtorInits));
7065}
7066
7068 auto &Data = D->data();
7069
7070 Record->push_back(Data.IsLambda);
7071
7072 BitsPacker DefinitionBits;
7073
7074#define FIELD(Name, Width, Merge) \
7075 if (!DefinitionBits.canWriteNextNBits(Width)) { \
7076 Record->push_back(DefinitionBits); \
7077 DefinitionBits.reset(0); \
7078 } \
7079 DefinitionBits.addBits(Data.Name, Width);
7080
7081#include "clang/AST/CXXRecordDeclDefinitionBits.def"
7082#undef FIELD
7083
7084 Record->push_back(DefinitionBits);
7085
7086 // getODRHash will compute the ODRHash if it has not been previously
7087 // computed.
7088 Record->push_back(D->getODRHash());
7089
7090 bool ModulesCodegen =
7091 !D->isDependentType() &&
7092 (Writer->getLangOpts().ModulesDebugInfo || D->isInNamedModule());
7093 Record->push_back(ModulesCodegen);
7094 if (ModulesCodegen)
7095 Writer->AddDeclRef(D, Writer->ModularCodegenDecls);
7096
7097 // IsLambda bit is already saved.
7098
7099 AddUnresolvedSet(Data.Conversions.get(getASTContext()));
7100 Record->push_back(Data.ComputedVisibleConversions);
7101 if (Data.ComputedVisibleConversions)
7102 AddUnresolvedSet(Data.VisibleConversions.get(getASTContext()));
7103 // Data.Definition is the owning decl, no need to write it.
7104
7105 if (!Data.IsLambda) {
7106 Record->push_back(Data.NumBases);
7107 if (Data.NumBases > 0)
7108 AddCXXBaseSpecifiers(Data.bases());
7109
7110 // FIXME: Make VBases lazily computed when needed to avoid storing them.
7111 Record->push_back(Data.NumVBases);
7112 if (Data.NumVBases > 0)
7113 AddCXXBaseSpecifiers(Data.vbases());
7114
7115 AddDeclRef(D->getFirstFriend());
7116 } else {
7117 auto &Lambda = D->getLambdaData();
7118
7119 BitsPacker LambdaBits;
7120 LambdaBits.addBits(Lambda.DependencyKind, /*Width=*/2);
7121 LambdaBits.addBit(Lambda.IsGenericLambda);
7122 LambdaBits.addBits(Lambda.CaptureDefault, /*Width=*/2);
7123 LambdaBits.addBits(Lambda.NumCaptures, /*Width=*/15);
7124 LambdaBits.addBit(Lambda.HasKnownInternalLinkage);
7125 Record->push_back(LambdaBits);
7126
7127 Record->push_back(Lambda.NumExplicitCaptures);
7128 Record->push_back(Lambda.ManglingNumber);
7129 Record->push_back(D->getDeviceLambdaManglingNumber());
7130 // The lambda context declaration and index within the context are provided
7131 // separately, so that they can be used for merging.
7132 AddTypeSourceInfo(Lambda.MethodTyInfo);
7133 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
7134 const LambdaCapture &Capture = Lambda.Captures.front()[I];
7136
7137 BitsPacker CaptureBits;
7138 CaptureBits.addBit(Capture.isImplicit());
7139 CaptureBits.addBits(Capture.getCaptureKind(), /*Width=*/3);
7140 Record->push_back(CaptureBits);
7141
7142 switch (Capture.getCaptureKind()) {
7143 case LCK_StarThis:
7144 case LCK_This:
7145 case LCK_VLAType:
7146 break;
7147 case LCK_ByCopy:
7148 case LCK_ByRef:
7149 ValueDecl *Var =
7150 Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr;
7151 AddDeclRef(Var);
7152 AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc()
7153 : SourceLocation());
7154 break;
7155 }
7156 }
7157 }
7158}
7159
7161 const Expr *Init = VD->getInit();
7162 if (!Init) {
7163 push_back(0);
7164 return;
7165 }
7166
7167 uint64_t Val = 1;
7168 if (EvaluatedStmt *ES = VD->getEvaluatedStmt()) {
7169 Val |= (ES->HasConstantInitialization ? 2 : 0);
7170 Val |= (ES->HasConstantDestruction ? 4 : 0);
7172 // If the evaluated result is constant, emit it.
7173 if (Evaluated && (Evaluated->isInt() || Evaluated->isFloat()))
7174 Val |= 8;
7175 }
7176 push_back(Val);
7177 if (Val & 8) {
7179 }
7180
7182}
7183
7184void ASTWriter::ReaderInitialized(ASTReader *Reader) {
7185 assert(Reader && "Cannot remove chain");
7186 assert((!Chain || Chain == Reader) && "Cannot replace chain");
7187 assert(FirstDeclID == NextDeclID &&
7188 FirstTypeID == NextTypeID &&
7189 FirstIdentID == NextIdentID &&
7190 FirstMacroID == NextMacroID &&
7191 FirstSubmoduleID == NextSubmoduleID &&
7192 FirstSelectorID == NextSelectorID &&
7193 "Setting chain after writing has started.");
7194
7195 Chain = Reader;
7196
7197 // Note, this will get called multiple times, once one the reader starts up
7198 // and again each time it's done reading a PCH or module.
7199 FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros();
7200 FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules();
7201 FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors();
7202 NextMacroID = FirstMacroID;
7203 NextSelectorID = FirstSelectorID;
7204 NextSubmoduleID = FirstSubmoduleID;
7205}
7206
7207void ASTWriter::IdentifierRead(IdentifierID ID, IdentifierInfo *II) {
7208 // Don't reuse Type ID from external modules for named modules. See the
7209 // comments in WriteASTCore for details.
7211 return;
7212
7213 IdentifierID &StoredID = IdentifierIDs[II];
7214 unsigned OriginalModuleFileIndex = StoredID >> 32;
7215
7216 // Always keep the local identifier ID. See \p TypeRead() for more
7217 // information.
7218 if (OriginalModuleFileIndex == 0 && StoredID)
7219 return;
7220
7221 // Otherwise, keep the highest ID since the module file comes later has
7222 // higher module file indexes.
7223 if (ID > StoredID)
7224 StoredID = ID;
7225}
7226
7227void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) {
7228 // Always keep the highest ID. See \p TypeRead() for more information.
7229 MacroID &StoredID = MacroIDs[MI];
7230 if (ID > StoredID)
7231 StoredID = ID;
7232}
7233
7234void ASTWriter::TypeRead(TypeIdx Idx, QualType T) {
7235 // Don't reuse Type ID from external modules for named modules. See the
7236 // comments in WriteASTCore for details.
7238 return;
7239
7240 // Always take the type index that comes in later module files.
7241 // This copes with an interesting
7242 // case for chained AST writing where we schedule writing the type and then,
7243 // later, deserialize the type from another AST. In this case, we want to
7244 // keep the entry from a later module so that we can properly write it out to
7245 // the AST file.
7246 TypeIdx &StoredIdx = TypeIdxs[T];
7247
7248 // Ignore it if the type comes from the current being written module file.
7249 // Since the current module file being written logically has the highest
7250 // index.
7251 unsigned ModuleFileIndex = StoredIdx.getModuleFileIndex();
7252 if (ModuleFileIndex == 0 && StoredIdx.getValue())
7253 return;
7254
7255 // Otherwise, keep the highest ID since the module file comes later has
7256 // higher module file indexes.
7257 if (Idx.getModuleFileIndex() >= StoredIdx.getModuleFileIndex())
7258 StoredIdx = Idx;
7259}
7260
7261void ASTWriter::PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) {
7262 assert(D->isCanonicalDecl() && "predefined decl is not canonical");
7263 DeclIDs[D] = LocalDeclID(ID);
7264 PredefinedDecls.insert(D);
7265}
7266
7267void ASTWriter::SelectorRead(SelectorID ID, Selector S) {
7268 // Always keep the highest ID. See \p TypeRead() for more information.
7269 SelectorID &StoredID = SelectorIDs[S];
7270 if (ID > StoredID)
7271 StoredID = ID;
7272}
7273
7274void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID,
7276 assert(!MacroDefinitions.contains(MD));
7277 MacroDefinitions[MD] = ID;
7278}
7279
7280void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) {
7281 assert(!SubmoduleIDs.contains(Mod));
7282 SubmoduleIDs[Mod] = ID;
7283}
7284
7285void ASTWriter::CompletedTagDefinition(const TagDecl *D) {
7286 if (Chain && Chain->isProcessingUpdateRecords()) return;
7287 assert(D->isCompleteDefinition());
7288 assert(!WritingAST && "Already writing the AST!");
7289 if (auto *RD = dyn_cast<CXXRecordDecl>(D)) {
7290 // We are interested when a PCH decl is modified.
7291 if (RD->isFromASTFile()) {
7292 // A forward reference was mutated into a definition. Rewrite it.
7293 // FIXME: This happens during template instantiation, should we
7294 // have created a new definition decl instead ?
7295 assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) &&
7296 "completed a tag from another module but not by instantiation?");
7297 DeclUpdates[RD].push_back(
7299 }
7300 }
7301}
7302
7303static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) {
7304 if (D->isFromASTFile())
7305 return true;
7306
7307 // The predefined __va_list_tag struct is imported if we imported any decls.
7308 // FIXME: This is a gross hack.
7309 return D == D->getASTContext().getVaListTagDecl();
7310}
7311
7312void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) {
7313 if (Chain && Chain->isProcessingUpdateRecords()) return;
7314 assert(DC->isLookupContext() &&
7315 "Should not add lookup results to non-lookup contexts!");
7316
7317 // TU is handled elsewhere.
7318 if (isa<TranslationUnitDecl>(DC))
7319 return;
7320
7321 // Namespaces are handled elsewhere, except for template instantiations of
7322 // FunctionTemplateDecls in namespaces. We are interested in cases where the
7323 // local instantiations are added to an imported context. Only happens when
7324 // adding ADL lookup candidates, for example templated friends.
7325 if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None &&
7326 !isa<FunctionTemplateDecl>(D))
7327 return;
7328
7329 // We're only interested in cases where a local declaration is added to an
7330 // imported context.
7331 if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC)))
7332 return;
7333
7334 assert(DC == DC->getPrimaryContext() && "added to non-primary context");
7335 assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!");
7336 assert(!WritingAST && "Already writing the AST!");
7337 if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) {
7338 // We're adding a visible declaration to a predefined decl context. Ensure
7339 // that we write out all of its lookup results so we don't get a nasty
7340 // surprise when we try to emit its lookup table.
7341 llvm::append_range(DeclsToEmitEvenIfUnreferenced, DC->decls());
7342 }
7343 DeclsToEmitEvenIfUnreferenced.push_back(D);
7344}
7345
7346void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) {
7347 if (Chain && Chain->isProcessingUpdateRecords()) return;
7348 assert(D->isImplicit());
7349
7350 // We're only interested in cases where a local declaration is added to an
7351 // imported context.
7352 if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD))
7353 return;
7354
7355 if (!isa<CXXMethodDecl>(D))
7356 return;
7357
7358 // A decl coming from PCH was modified.
7359 assert(RD->isCompleteDefinition());
7360 assert(!WritingAST && "Already writing the AST!");
7361 DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D));
7362}
7363
7364void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) {
7365 if (Chain && Chain->isProcessingUpdateRecords()) return;
7366 assert(!DoneWritingDeclsAndTypes && "Already done writing updates!");
7367 if (!Chain) return;
7368 Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) {
7369 // If we don't already know the exception specification for this redecl
7370 // chain, add an update record for it.
7371 if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D)
7372 ->getType()
7373 ->castAs<FunctionProtoType>()
7374 ->getExceptionSpecType()))
7375 DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC);
7376 });
7377}
7378
7379void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) {
7380 if (Chain && Chain->isProcessingUpdateRecords()) return;
7381 assert(!WritingAST && "Already writing the AST!");
7382 if (!Chain) return;
7383 Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) {
7384 DeclUpdates[D].push_back(
7385 DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType));
7386 });
7387}
7388
7389void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD,
7390 const FunctionDecl *Delete,
7391 Expr *ThisArg) {
7392 if (Chain && Chain->isProcessingUpdateRecords()) return;
7393 assert(!WritingAST && "Already writing the AST!");
7394 assert(Delete && "Not given an operator delete");
7395 if (!Chain) return;
7396 Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) {
7397 DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete));
7398 });
7399}
7400
7401void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) {
7402 if (Chain && Chain->isProcessingUpdateRecords()) return;
7403 assert(!WritingAST && "Already writing the AST!");
7404 if (!D->isFromASTFile())
7405 return; // Declaration not imported from PCH.
7406
7407 // The function definition may not have a body due to parsing errors.
7408 if (!D->doesThisDeclarationHaveABody())
7409 return;
7410
7411 // Implicit function decl from a PCH was defined.
7412 DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION));
7413}
7414
7415void ASTWriter::VariableDefinitionInstantiated(const VarDecl *D) {
7416 if (Chain && Chain->isProcessingUpdateRecords()) return;
7417 assert(!WritingAST && "Already writing the AST!");
7418 if (!D->isFromASTFile())
7419 return;
7420
7421 DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_VAR_DEFINITION));
7422}
7423
7424void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) {
7425 if (Chain && Chain->isProcessingUpdateRecords()) return;
7426 assert(!WritingAST && "Already writing the AST!");
7427 if (!D->isFromASTFile())
7428 return;
7429
7430 // The function definition may not have a body due to parsing errors.
7431 if (!D->doesThisDeclarationHaveABody())
7432 return;
7433
7434 DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION));
7435}
7436
7437void ASTWriter::InstantiationRequested(const ValueDecl *D) {
7438 if (Chain && Chain->isProcessingUpdateRecords()) return;
7439 assert(!WritingAST && "Already writing the AST!");
7440 if (!D->isFromASTFile())
7441 return;
7442
7443 // Since the actual instantiation is delayed, this really means that we need
7444 // to update the instantiation location.
7445 SourceLocation POI;
7446 if (auto *VD = dyn_cast<VarDecl>(D))
7447 POI = VD->getPointOfInstantiation();
7448 else
7449 POI = cast<FunctionDecl>(D)->getPointOfInstantiation();
7450 DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_POINT_OF_INSTANTIATION, POI));
7451}
7452
7453void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) {
7454 if (Chain && Chain->isProcessingUpdateRecords()) return;
7455 assert(!WritingAST && "Already writing the AST!");
7456 if (!D->isFromASTFile())
7457 return;
7458
7459 DeclUpdates[D].push_back(
7461}
7462
7463void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) {
7464 assert(!WritingAST && "Already writing the AST!");
7465 if (!D->isFromASTFile())
7466 return;
7467
7468 DeclUpdates[D].push_back(
7470}
7471
7472void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
7473 const ObjCInterfaceDecl *IFD) {
7474 if (Chain && Chain->isProcessingUpdateRecords()) return;
7475 assert(!WritingAST && "Already writing the AST!");
7476 if (!IFD->isFromASTFile())
7477 return; // Declaration not imported from PCH.
7478
7479 assert(IFD->getDefinition() && "Category on a class without a definition?");
7480 ObjCClassesWithCategories.insert(
7481 const_cast<ObjCInterfaceDecl *>(IFD->getDefinition()));
7482}
7483
7484void ASTWriter::DeclarationMarkedUsed(const Decl *D) {
7485 if (Chain && Chain->isProcessingUpdateRecords()) return;
7486 assert(!WritingAST && "Already writing the AST!");
7487
7488 // If there is *any* declaration of the entity that's not from an AST file,
7489 // we can skip writing the update record. We make sure that isUsed() triggers
7490 // completion of the redeclaration chain of the entity.
7491 for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl())
7492 if (IsLocalDecl(Prev))
7493 return;
7494
7495 DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED));
7496}
7497
7498void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {
7499 if (Chain && Chain->isProcessingUpdateRecords()) return;
7500 assert(!WritingAST && "Already writing the AST!");
7501 if (!D->isFromASTFile())
7502 return;
7503
7504 DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE));
7505}
7506
7507void ASTWriter::DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) {
7508 if (Chain && Chain->isProcessingUpdateRecords()) return;
7509 assert(!WritingAST && "Already writing the AST!");
7510 if (!D->isFromASTFile())
7511 return;
7512
7513 DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_ALLOCATE, A));
7514}
7515
7516void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
7517 const Attr *Attr) {
7518 if (Chain && Chain->isProcessingUpdateRecords()) return;
7519 assert(!WritingAST && "Already writing the AST!");
7520 if (!D->isFromASTFile())
7521 return;
7522
7523 DeclUpdates[D].push_back(
7525}
7526
7527void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) {
7528 if (Chain && Chain->isProcessingUpdateRecords()) return;
7529 assert(!WritingAST && "Already writing the AST!");
7530 assert(!D->isUnconditionallyVisible() && "expected a hidden declaration");
7531 DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M));
7532}
7533
7534void ASTWriter::AddedAttributeToRecord(const Attr *Attr,
7535 const RecordDecl *Record) {
7536 if (Chain && Chain->isProcessingUpdateRecords()) return;
7537 assert(!WritingAST && "Already writing the AST!");
7538 if (!Record->isFromASTFile())
7539 return;
7540 DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr));
7541}
7542
7543void ASTWriter::AddedCXXTemplateSpecialization(
7545 assert(!WritingAST && "Already writing the AST!");
7546
7547 if (!TD->getFirstDecl()->isFromASTFile())
7548 return;
7549 if (Chain && Chain->isProcessingUpdateRecords())
7550 return;
7551
7552 DeclsToEmitEvenIfUnreferenced.push_back(D);
7553}
7554
7555void ASTWriter::AddedCXXTemplateSpecialization(
7557 assert(!WritingAST && "Already writing the AST!");
7558
7559 if (!TD->getFirstDecl()->isFromASTFile())
7560 return;
7561 if (Chain && Chain->isProcessingUpdateRecords())
7562 return;
7563
7564 DeclsToEmitEvenIfUnreferenced.push_back(D);
7565}
7566
7567void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
7568 const FunctionDecl *D) {
7569 assert(!WritingAST && "Already writing the AST!");
7570
7571 if (!TD->getFirstDecl()->isFromASTFile())
7572 return;
7573 if (Chain && Chain->isProcessingUpdateRecords())
7574 return;
7575
7576 DeclsToEmitEvenIfUnreferenced.push_back(D);
7577}
7578
7579//===----------------------------------------------------------------------===//
7580//// OMPClause Serialization
7581////===----------------------------------------------------------------------===//
7582
7583namespace {
7584
7585class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
7587
7588public:
7589 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
7590#define GEN_CLANG_CLAUSE_CLASS
7591#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
7592#include "llvm/Frontend/OpenMP/OMP.inc"
7593 void writeClause(OMPClause *C);
7594 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
7595 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
7596};
7597
7598}
7599
7601 OMPClauseWriter(*this).writeClause(C);
7602}
7603
7604void OMPClauseWriter::writeClause(OMPClause *C) {
7605 Record.push_back(unsigned(C->getClauseKind()));
7606 Visit(C);
7607 Record.AddSourceLocation(C->getBeginLoc());
7608 Record.AddSourceLocation(C->getEndLoc());
7609}
7610
7611void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
7612 Record.push_back(uint64_t(C->getCaptureRegion()));
7613 Record.AddStmt(C->getPreInitStmt());
7614}
7615
7616void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
7617 VisitOMPClauseWithPreInit(C);
7618 Record.AddStmt(C->getPostUpdateExpr());
7619}
7620
7621void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
7622 VisitOMPClauseWithPreInit(C);
7623 Record.push_back(uint64_t(C->getNameModifier()));
7624 Record.AddSourceLocation(C->getNameModifierLoc());
7625 Record.AddSourceLocation(C->getColonLoc());
7626 Record.AddStmt(C->getCondition());
7627 Record.AddSourceLocation(C->getLParenLoc());
7628}
7629
7630void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
7631 VisitOMPClauseWithPreInit(C);
7632 Record.AddStmt(C->getCondition());
7633 Record.AddSourceLocation(C->getLParenLoc());
7634}
7635
7636void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
7637 VisitOMPClauseWithPreInit(C);
7638 Record.AddStmt(C->getNumThreads());
7639 Record.AddSourceLocation(C->getLParenLoc());
7640}
7641
7642void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
7643 Record.AddStmt(C->getSafelen());
7644 Record.AddSourceLocation(C->getLParenLoc());
7645}
7646
7647void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
7648 Record.AddStmt(C->getSimdlen());
7649 Record.AddSourceLocation(C->getLParenLoc());
7650}
7651
7652void OMPClauseWriter::VisitOMPSizesClause(OMPSizesClause *C) {
7653 Record.push_back(C->getNumSizes());
7654 for (Expr *Size : C->getSizesRefs())
7655 Record.AddStmt(Size);
7656 Record.AddSourceLocation(C->getLParenLoc());
7657}
7658
7659void OMPClauseWriter::VisitOMPPermutationClause(OMPPermutationClause *C) {
7660 Record.push_back(C->getNumLoops());
7661 for (Expr *Size : C->getArgsRefs())
7662 Record.AddStmt(Size);
7663 Record.AddSourceLocation(C->getLParenLoc());
7664}
7665
7666void OMPClauseWriter::VisitOMPFullClause(OMPFullClause *C) {}
7667
7668void OMPClauseWriter::VisitOMPPartialClause(OMPPartialClause *C) {
7669 Record.AddStmt(C->getFactor());
7670 Record.AddSourceLocation(C->getLParenLoc());
7671}
7672
7673void OMPClauseWriter::VisitOMPAllocatorClause(OMPAllocatorClause *C) {
7674 Record.AddStmt(C->getAllocator());
7675 Record.AddSourceLocation(C->getLParenLoc());
7676}
7677
7678void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
7679 Record.AddStmt(C->getNumForLoops());
7680 Record.AddSourceLocation(C->getLParenLoc());
7681}
7682
7683void OMPClauseWriter::VisitOMPDetachClause(OMPDetachClause *C) {
7684 Record.AddStmt(C->getEventHandler());
7685 Record.AddSourceLocation(C->getLParenLoc());
7686}
7687
7688void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
7689 Record.push_back(unsigned(C->getDefaultKind()));
7690 Record.AddSourceLocation(C->getLParenLoc());
7691 Record.AddSourceLocation(C->getDefaultKindKwLoc());
7692}
7693
7694void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
7695 Record.push_back(unsigned(C->getProcBindKind()));
7696 Record.AddSourceLocation(C->getLParenLoc());
7697 Record.AddSourceLocation(C->getProcBindKindKwLoc());
7698}
7699
7700void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
7701 VisitOMPClauseWithPreInit(C);
7702 Record.push_back(C->getScheduleKind());
7703 Record.push_back(C->getFirstScheduleModifier());
7704 Record.push_back(C->getSecondScheduleModifier());
7705 Record.AddStmt(C->getChunkSize());
7706 Record.AddSourceLocation(C->getLParenLoc());
7707 Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
7708 Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
7709 Record.AddSourceLocation(C->getScheduleKindLoc());
7710 Record.AddSourceLocation(C->getCommaLoc());
7711}
7712
7713void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
7714 Record.push_back(C->getLoopNumIterations().size());
7715 Record.AddStmt(C->getNumForLoops());
7716 for (Expr *NumIter : C->getLoopNumIterations())
7717 Record.AddStmt(NumIter);
7718 for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I)
7719 Record.AddStmt(C->getLoopCounter(I));
7720 Record.AddSourceLocation(C->getLParenLoc());
7721}
7722
7723void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
7724
7725void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
7726
7727void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
7728
7729void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
7730
7731void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
7732
7733void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *C) {
7734 Record.push_back(C->isExtended() ? 1 : 0);
7735 if (C->isExtended()) {
7736 Record.AddSourceLocation(C->getLParenLoc());
7737 Record.AddSourceLocation(C->getArgumentLoc());
7738 Record.writeEnum(C->getDependencyKind());
7739 }
7740}
7741
7742void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
7743
7744void OMPClauseWriter::VisitOMPCompareClause(OMPCompareClause *) {}
7745
7746// Save the parameter of fail clause.
7747void OMPClauseWriter::VisitOMPFailClause(OMPFailClause *C) {
7748 Record.AddSourceLocation(C->getLParenLoc());
7749 Record.AddSourceLocation(C->getFailParameterLoc());
7750 Record.writeEnum(C->getFailParameter());
7751}
7752
7753void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
7754
7755void OMPClauseWriter::VisitOMPAcqRelClause(OMPAcqRelClause *) {}
7756
7757void OMPClauseWriter::VisitOMPAbsentClause(OMPAbsentClause *C) {
7758 Record.push_back(static_cast<uint64_t>(C->getDirectiveKinds().size()));
7759 Record.AddSourceLocation(C->getLParenLoc());
7760 for (auto K : C->getDirectiveKinds()) {
7761 Record.writeEnum(K);
7762 }
7763}
7764
7765void OMPClauseWriter::VisitOMPHoldsClause(OMPHoldsClause *C) {
7766 Record.AddStmt(C->getExpr());
7767 Record.AddSourceLocation(C->getLParenLoc());
7768}
7769
7770void OMPClauseWriter::VisitOMPContainsClause(OMPContainsClause *C) {
7771 Record.push_back(static_cast<uint64_t>(C->getDirectiveKinds().size()));
7772 Record.AddSourceLocation(C->getLParenLoc());
7773 for (auto K : C->getDirectiveKinds()) {
7774 Record.writeEnum(K);
7775 }
7776}
7777
7778void OMPClauseWriter::VisitOMPNoOpenMPClause(OMPNoOpenMPClause *) {}
7779
7780void OMPClauseWriter::VisitOMPNoOpenMPRoutinesClause(
7782
7783void OMPClauseWriter::VisitOMPNoParallelismClause(OMPNoParallelismClause *) {}
7784
7785void OMPClauseWriter::VisitOMPAcquireClause(OMPAcquireClause *) {}
7786
7787void OMPClauseWriter::VisitOMPReleaseClause(OMPReleaseClause *) {}
7788
7789void OMPClauseWriter::VisitOMPRelaxedClause(OMPRelaxedClause *) {}
7790
7791void OMPClauseWriter::VisitOMPWeakClause(OMPWeakClause *) {}
7792
7793void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
7794
7795void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
7796
7797void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
7798
7799void OMPClauseWriter::VisitOMPInitClause(OMPInitClause *C) {
7800 Record.push_back(C->varlist_size());
7801 for (Expr *VE : C->varlist())
7802 Record.AddStmt(VE);
7803 Record.writeBool(C->getIsTarget());
7804 Record.writeBool(C->getIsTargetSync());
7805 Record.AddSourceLocation(C->getLParenLoc());
7806 Record.AddSourceLocation(C->getVarLoc());
7807}
7808
7809void OMPClauseWriter::VisitOMPUseClause(OMPUseClause *C) {
7810 Record.AddStmt(C->getInteropVar());
7811 Record.AddSourceLocation(C->getLParenLoc());
7812 Record.AddSourceLocation(C->getVarLoc());
7813}
7814
7815void OMPClauseWriter::VisitOMPDestroyClause(OMPDestroyClause *C) {
7816 Record.AddStmt(C->getInteropVar());
7817 Record.AddSourceLocation(C->getLParenLoc());
7818 Record.AddSourceLocation(C->getVarLoc());
7819}
7820
7821void OMPClauseWriter::VisitOMPNovariantsClause(OMPNovariantsClause *C) {
7822 VisitOMPClauseWithPreInit(C);
7823 Record.AddStmt(C->getCondition());
7824 Record.AddSourceLocation(C->getLParenLoc());
7825}
7826
7827void OMPClauseWriter::VisitOMPNocontextClause(OMPNocontextClause *C) {
7828 VisitOMPClauseWithPreInit(C);
7829 Record.AddStmt(C->getCondition());
7830 Record.AddSourceLocation(C->getLParenLoc());
7831}
7832
7833void OMPClauseWriter::VisitOMPFilterClause(OMPFilterClause *C) {
7834 VisitOMPClauseWithPreInit(C);
7835 Record.AddStmt(C->getThreadID());
7836 Record.AddSourceLocation(C->getLParenLoc());
7837}
7838
7839void OMPClauseWriter::VisitOMPAlignClause(OMPAlignClause *C) {
7840 Record.AddStmt(C->getAlignment());
7841 Record.AddSourceLocation(C->getLParenLoc());
7842}
7843
7844void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
7845 Record.push_back(C->varlist_size());
7846 Record.AddSourceLocation(C->getLParenLoc());
7847 for (auto *VE : C->varlist()) {
7848 Record.AddStmt(VE);
7849 }
7850 for (auto *VE : C->private_copies()) {
7851 Record.AddStmt(VE);
7852 }
7853}
7854
7855void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
7856 Record.push_back(C->varlist_size());
7857 VisitOMPClauseWithPreInit(C);
7858 Record.AddSourceLocation(C->getLParenLoc());
7859 for (auto *VE : C->varlist()) {
7860 Record.AddStmt(VE);
7861 }
7862 for (auto *VE : C->private_copies()) {
7863 Record.AddStmt(VE);
7864 }
7865 for (auto *VE : C->inits()) {
7866 Record.AddStmt(VE);
7867 }
7868}
7869
7870void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
7871 Record.push_back(C->varlist_size());
7872 VisitOMPClauseWithPostUpdate(C);
7873 Record.AddSourceLocation(C->getLParenLoc());
7874 Record.writeEnum(C->getKind());
7875 Record.AddSourceLocation(C->getKindLoc());
7876 Record.AddSourceLocation(C->getColonLoc());
7877 for (auto *VE : C->varlist())
7878 Record.AddStmt(VE);
7879 for (auto *E : C->private_copies())
7880 Record.AddStmt(E);
7881 for (auto *E : C->source_exprs())
7882 Record.AddStmt(E);
7883 for (auto *E : C->destination_exprs())
7884 Record.AddStmt(E);
7885 for (auto *E : C->assignment_ops())
7886 Record.AddStmt(E);
7887}
7888
7889void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
7890 Record.push_back(C->varlist_size());
7891 Record.AddSourceLocation(C->getLParenLoc());
7892 for (auto *VE : C->varlist())
7893 Record.AddStmt(VE);
7894}
7895
7896void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
7897 Record.push_back(C->varlist_size());
7898 Record.writeEnum(C->getModifier());
7899 VisitOMPClauseWithPostUpdate(C);
7900 Record.AddSourceLocation(C->getLParenLoc());
7901 Record.AddSourceLocation(C->getModifierLoc());
7902 Record.AddSourceLocation(C->getColonLoc());
7903 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
7904 Record.AddDeclarationNameInfo(C->getNameInfo());
7905 for (auto *VE : C->varlist())
7906 Record.AddStmt(VE);
7907 for (auto *VE : C->privates())
7908 Record.AddStmt(VE);
7909 for (auto *E : C->lhs_exprs())
7910 Record.AddStmt(E);
7911 for (auto *E : C->rhs_exprs())
7912 Record.AddStmt(E);
7913 for (auto *E : C->reduction_ops())
7914 Record.AddStmt(E);
7915 if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
7916 for (auto *E : C->copy_ops())
7917 Record.AddStmt(E);
7918 for (auto *E : C->copy_array_temps())
7919 Record.AddStmt(E);
7920 for (auto *E : C->copy_array_elems())
7921 Record.AddStmt(E);
7922 }
7923}
7924
7925void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
7926 Record.push_back(C->varlist_size());
7927 VisitOMPClauseWithPostUpdate(C);
7928 Record.AddSourceLocation(C->getLParenLoc());
7929 Record.AddSourceLocation(C->getColonLoc());
7930 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
7931 Record.AddDeclarationNameInfo(C->getNameInfo());
7932 for (auto *VE : C->varlist())
7933 Record.AddStmt(VE);
7934 for (auto *VE : C->privates())
7935 Record.AddStmt(VE);
7936 for (auto *E : C->lhs_exprs())
7937 Record.AddStmt(E);
7938 for (auto *E : C->rhs_exprs())
7939 Record.AddStmt(E);
7940 for (auto *E : C->reduction_ops())
7941 Record.AddStmt(E);
7942}
7943
7944void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) {
7945 Record.push_back(C->varlist_size());
7946 VisitOMPClauseWithPostUpdate(C);
7947 Record.AddSourceLocation(C->getLParenLoc());
7948 Record.AddSourceLocation(C->getColonLoc());
7949 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
7950 Record.AddDeclarationNameInfo(C->getNameInfo());
7951 for (auto *VE : C->varlist())
7952 Record.AddStmt(VE);
7953 for (auto *VE : C->privates())
7954 Record.AddStmt(VE);
7955 for (auto *E : C->lhs_exprs())
7956 Record.AddStmt(E);
7957 for (auto *E : C->rhs_exprs())
7958 Record.AddStmt(E);
7959 for (auto *E : C->reduction_ops())
7960 Record.AddStmt(E);
7961 for (auto *E : C->taskgroup_descriptors())
7962 Record.AddStmt(E);
7963}
7964
7965void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
7966 Record.push_back(C->varlist_size());
7967 VisitOMPClauseWithPostUpdate(C);
7968 Record.AddSourceLocation(C->getLParenLoc());
7969 Record.AddSourceLocation(C->getColonLoc());
7970 Record.push_back(C->getModifier());
7971 Record.AddSourceLocation(C->getModifierLoc());
7972 for (auto *VE : C->varlist()) {
7973 Record.AddStmt(VE);
7974 }
7975 for (auto *VE : C->privates()) {
7976 Record.AddStmt(VE);
7977 }
7978 for (auto *VE : C->inits()) {
7979 Record.AddStmt(VE);
7980 }
7981 for (auto *VE : C->updates()) {
7982 Record.AddStmt(VE);
7983 }
7984 for (auto *VE : C->finals()) {
7985 Record.AddStmt(VE);
7986 }
7987 Record.AddStmt(C->getStep());
7988 Record.AddStmt(C->getCalcStep());
7989 for (auto *VE : C->used_expressions())
7990 Record.AddStmt(VE);
7991}
7992
7993void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
7994 Record.push_back(C->varlist_size());
7995 Record.AddSourceLocation(C->getLParenLoc());
7996 Record.AddSourceLocation(C->getColonLoc());
7997 for (auto *VE : C->varlist())
7998 Record.AddStmt(VE);
7999 Record.AddStmt(C->getAlignment());
8000}
8001
8002void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
8003 Record.push_back(C->varlist_size());
8004 Record.AddSourceLocation(C->getLParenLoc());
8005 for (auto *VE : C->varlist())
8006 Record.AddStmt(VE);
8007 for (auto *E : C->source_exprs())
8008 Record.AddStmt(E);
8009 for (auto *E : C->destination_exprs())
8010 Record.AddStmt(E);
8011 for (auto *E : C->assignment_ops())
8012 Record.AddStmt(E);
8013}
8014
8015void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
8016 Record.push_back(C->varlist_size());
8017 Record.AddSourceLocation(C->getLParenLoc());
8018 for (auto *VE : C->varlist())
8019 Record.AddStmt(VE);
8020 for (auto *E : C->source_exprs())
8021 Record.AddStmt(E);
8022 for (auto *E : C->destination_exprs())
8023 Record.AddStmt(E);
8024 for (auto *E : C->assignment_ops())
8025 Record.AddStmt(E);
8026}
8027
8028void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
8029 Record.push_back(C->varlist_size());
8030 Record.AddSourceLocation(C->getLParenLoc());
8031 for (auto *VE : C->varlist())
8032 Record.AddStmt(VE);
8033}
8034
8035void OMPClauseWriter::VisitOMPDepobjClause(OMPDepobjClause *C) {
8036 Record.AddStmt(C->getDepobj());
8037 Record.AddSourceLocation(C->getLParenLoc());
8038}
8039
8040void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
8041 Record.push_back(C->varlist_size());
8042 Record.push_back(C->getNumLoops());
8043 Record.AddSourceLocation(C->getLParenLoc());
8044 Record.AddStmt(C->getModifier());
8045 Record.push_back(C->getDependencyKind());
8046 Record.AddSourceLocation(C->getDependencyLoc());
8047 Record.AddSourceLocation(C->getColonLoc());
8048 Record.AddSourceLocation(C->getOmpAllMemoryLoc());
8049 for (auto *VE : C->varlist())
8050 Record.AddStmt(VE);
8051 for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
8052 Record.AddStmt(C->getLoopData(I));
8053}
8054
8055void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
8056 VisitOMPClauseWithPreInit(C);
8057 Record.writeEnum(C->getModifier());
8058 Record.AddStmt(C->getDevice());
8059 Record.AddSourceLocation(C->getModifierLoc());
8060 Record.AddSourceLocation(C->getLParenLoc());
8061}
8062
8063void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
8064 Record.push_back(C->varlist_size());
8065 Record.push_back(C->getUniqueDeclarationsNum());
8066 Record.push_back(C->getTotalComponentListNum());
8067 Record.push_back(C->getTotalComponentsNum());
8068 Record.AddSourceLocation(C->getLParenLoc());
8069 bool HasIteratorModifier = false;
8070 for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
8071 Record.push_back(C->getMapTypeModifier(I));
8072 Record.AddSourceLocation(C->getMapTypeModifierLoc(I));
8073 if (C->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_iterator)
8074 HasIteratorModifier = true;
8075 }
8076 Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc());
8077 Record.AddDeclarationNameInfo(C->getMapperIdInfo());
8078 Record.push_back(C->getMapType());
8079 Record.AddSourceLocation(C->getMapLoc());
8080 Record.AddSourceLocation(C->getColonLoc());
8081 for (auto *E : C->varlist())
8082 Record.AddStmt(E);
8083 for (auto *E : C->mapperlists())
8084 Record.AddStmt(E);
8085 if (HasIteratorModifier)
8086 Record.AddStmt(C->getIteratorModifier());
8087 for (auto *D : C->all_decls())
8088 Record.AddDeclRef(D);
8089 for (auto N : C->all_num_lists())
8090 Record.push_back(N);
8091 for (auto N : C->all_lists_sizes())
8092 Record.push_back(N);
8093 for (auto &M : C->all_components()) {
8094 Record.AddStmt(M.getAssociatedExpression());
8095 Record.AddDeclRef(M.getAssociatedDeclaration());
8096 }
8097}
8098
8099void OMPClauseWriter::VisitOMPAllocateClause(OMPAllocateClause *C) {
8100 Record.push_back(C->varlist_size());
8101 Record.writeEnum(C->getFirstAllocateModifier());
8102 Record.writeEnum(C->getSecondAllocateModifier());
8103 Record.AddSourceLocation(C->getLParenLoc());
8104 Record.AddSourceLocation(C->getColonLoc());
8105 Record.AddStmt(C->getAllocator());
8106 Record.AddStmt(C->getAlignment());
8107 for (auto *VE : C->varlist())
8108 Record.AddStmt(VE);
8109}
8110
8111void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
8112 Record.push_back(C->varlist_size());
8113 VisitOMPClauseWithPreInit(C);
8114 Record.AddSourceLocation(C->getLParenLoc());
8115 for (auto *VE : C->varlist())
8116 Record.AddStmt(VE);
8117}
8118
8119void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
8120 Record.push_back(C->varlist_size());
8121 VisitOMPClauseWithPreInit(C);
8122 Record.AddSourceLocation(C->getLParenLoc());
8123 for (auto *VE : C->varlist())
8124 Record.AddStmt(VE);
8125}
8126
8127void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
8128 VisitOMPClauseWithPreInit(C);
8129 Record.AddStmt(C->getPriority());
8130 Record.AddSourceLocation(C->getLParenLoc());
8131}
8132
8133void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
8134 VisitOMPClauseWithPreInit(C);
8135 Record.writeEnum(C->getModifier());
8136 Record.AddStmt(C->getGrainsize());
8137 Record.AddSourceLocation(C->getModifierLoc());
8138 Record.AddSourceLocation(C->getLParenLoc());
8139}
8140
8141void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
8142 VisitOMPClauseWithPreInit(C);
8143 Record.writeEnum(C->getModifier());
8144 Record.AddStmt(C->getNumTasks());
8145 Record.AddSourceLocation(C->getModifierLoc());
8146 Record.AddSourceLocation(C->getLParenLoc());
8147}
8148
8149void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
8150 Record.AddStmt(C->getHint());
8151 Record.AddSourceLocation(C->getLParenLoc());
8152}
8153
8154void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
8155 VisitOMPClauseWithPreInit(C);
8156 Record.push_back(C->getDistScheduleKind());
8157 Record.AddStmt(C->getChunkSize());
8158 Record.AddSourceLocation(C->getLParenLoc());
8159 Record.AddSourceLocation(C->getDistScheduleKindLoc());
8160 Record.AddSourceLocation(C->getCommaLoc());
8161}
8162
8163void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
8164 Record.push_back(C->getDefaultmapKind());
8165 Record.push_back(C->getDefaultmapModifier());
8166 Record.AddSourceLocation(C->getLParenLoc());
8167 Record.AddSourceLocation(C->getDefaultmapModifierLoc());
8168 Record.AddSourceLocation(C->getDefaultmapKindLoc());
8169}
8170
8171void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
8172 Record.push_back(C->varlist_size());
8173 Record.push_back(C->getUniqueDeclarationsNum());
8174 Record.push_back(C->getTotalComponentListNum());
8175 Record.push_back(C->getTotalComponentsNum());
8176 Record.AddSourceLocation(C->getLParenLoc());
8177 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
8178 Record.push_back(C->getMotionModifier(I));
8179 Record.AddSourceLocation(C->getMotionModifierLoc(I));
8180 }
8181 Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc());
8182 Record.AddDeclarationNameInfo(C->getMapperIdInfo());
8183 Record.AddSourceLocation(C->getColonLoc());
8184 for (auto *E : C->varlist())
8185 Record.AddStmt(E);
8186 for (auto *E : C->mapperlists())
8187 Record.AddStmt(E);
8188 for (auto *D : C->all_decls())
8189 Record.AddDeclRef(D);
8190 for (auto N : C->all_num_lists())
8191 Record.push_back(N);
8192 for (auto N : C->all_lists_sizes())
8193 Record.push_back(N);
8194 for (auto &M : C->all_components()) {
8195 Record.AddStmt(M.getAssociatedExpression());
8196 Record.writeBool(M.isNonContiguous());
8197 Record.AddDeclRef(M.getAssociatedDeclaration());
8198 }
8199}
8200
8201void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
8202 Record.push_back(C->varlist_size());
8203 Record.push_back(C->getUniqueDeclarationsNum());
8204 Record.push_back(C->getTotalComponentListNum());
8205 Record.push_back(C->getTotalComponentsNum());
8206 Record.AddSourceLocation(C->getLParenLoc());
8207 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
8208 Record.push_back(C->getMotionModifier(I));
8209 Record.AddSourceLocation(C->getMotionModifierLoc(I));
8210 }
8211 Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc());
8212 Record.AddDeclarationNameInfo(C->getMapperIdInfo());
8213 Record.AddSourceLocation(C->getColonLoc());
8214 for (auto *E : C->varlist())
8215 Record.AddStmt(E);
8216 for (auto *E : C->mapperlists())
8217 Record.AddStmt(E);
8218 for (auto *D : C->all_decls())
8219 Record.AddDeclRef(D);
8220 for (auto N : C->all_num_lists())
8221 Record.push_back(N);
8222 for (auto N : C->all_lists_sizes())
8223 Record.push_back(N);
8224 for (auto &M : C->all_components()) {
8225 Record.AddStmt(M.getAssociatedExpression());
8226 Record.writeBool(M.isNonContiguous());
8227 Record.AddDeclRef(M.getAssociatedDeclaration());
8228 }
8229}
8230
8231void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
8232 Record.push_back(C->varlist_size());
8233 Record.push_back(C->getUniqueDeclarationsNum());
8234 Record.push_back(C->getTotalComponentListNum());
8235 Record.push_back(C->getTotalComponentsNum());
8236 Record.AddSourceLocation(C->getLParenLoc());
8237 for (auto *E : C->varlist())
8238 Record.AddStmt(E);
8239 for (auto *VE : C->private_copies())
8240 Record.AddStmt(VE);
8241 for (auto *VE : C->inits())
8242 Record.AddStmt(VE);
8243 for (auto *D : C->all_decls())
8244 Record.AddDeclRef(D);
8245 for (auto N : C->all_num_lists())
8246 Record.push_back(N);
8247 for (auto N : C->all_lists_sizes())
8248 Record.push_back(N);
8249 for (auto &M : C->all_components()) {
8250 Record.AddStmt(M.getAssociatedExpression());
8251 Record.AddDeclRef(M.getAssociatedDeclaration());
8252 }
8253}
8254
8255void OMPClauseWriter::VisitOMPUseDeviceAddrClause(OMPUseDeviceAddrClause *C) {
8256 Record.push_back(C->varlist_size());
8257 Record.push_back(C->getUniqueDeclarationsNum());
8258 Record.push_back(C->getTotalComponentListNum());
8259 Record.push_back(C->getTotalComponentsNum());
8260 Record.AddSourceLocation(C->getLParenLoc());
8261 for (auto *E : C->varlist())
8262 Record.AddStmt(E);
8263 for (auto *D : C->all_decls())
8264 Record.AddDeclRef(D);
8265 for (auto N : C->all_num_lists())
8266 Record.push_back(N);
8267 for (auto N : C->all_lists_sizes())
8268 Record.push_back(N);
8269 for (auto &M : C->all_components()) {
8270 Record.AddStmt(M.getAssociatedExpression());
8271 Record.AddDeclRef(M.getAssociatedDeclaration());
8272 }
8273}
8274
8275void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8276 Record.push_back(C->varlist_size());
8277 Record.push_back(C->getUniqueDeclarationsNum());
8278 Record.push_back(C->getTotalComponentListNum());
8279 Record.push_back(C->getTotalComponentsNum());
8280 Record.AddSourceLocation(C->getLParenLoc());
8281 for (auto *E : C->varlist())
8282 Record.AddStmt(E);
8283 for (auto *D : C->all_decls())
8284 Record.AddDeclRef(D);
8285 for (auto N : C->all_num_lists())
8286 Record.push_back(N);
8287 for (auto N : C->all_lists_sizes())
8288 Record.push_back(N);
8289 for (auto &M : C->all_components()) {
8290 Record.AddStmt(M.getAssociatedExpression());
8291 Record.AddDeclRef(M.getAssociatedDeclaration());
8292 }
8293}
8294
8295void OMPClauseWriter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause *C) {
8296 Record.push_back(C->varlist_size());
8297 Record.push_back(C->getUniqueDeclarationsNum());
8298 Record.push_back(C->getTotalComponentListNum());
8299 Record.push_back(C->getTotalComponentsNum());
8300 Record.AddSourceLocation(C->getLParenLoc());
8301 for (auto *E : C->varlist())
8302 Record.AddStmt(E);
8303 for (auto *D : C->all_decls())
8304 Record.AddDeclRef(D);
8305 for (auto N : C->all_num_lists())
8306 Record.push_back(N);
8307 for (auto N : C->all_lists_sizes())
8308 Record.push_back(N);
8309 for (auto &M : C->all_components()) {
8310 Record.AddStmt(M.getAssociatedExpression());
8311 Record.AddDeclRef(M.getAssociatedDeclaration());
8312 }
8313}
8314
8315void OMPClauseWriter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {}
8316
8317void OMPClauseWriter::VisitOMPUnifiedSharedMemoryClause(
8319
8320void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {}
8321
8322void
8323OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) {
8324}
8325
8326void OMPClauseWriter::VisitOMPAtomicDefaultMemOrderClause(
8328 Record.push_back(C->getAtomicDefaultMemOrderKind());
8329 Record.AddSourceLocation(C->getLParenLoc());
8330 Record.AddSourceLocation(C->getAtomicDefaultMemOrderKindKwLoc());
8331}
8332
8333void OMPClauseWriter::VisitOMPAtClause(OMPAtClause *C) {
8334 Record.push_back(C->getAtKind());
8335 Record.AddSourceLocation(C->getLParenLoc());
8336 Record.AddSourceLocation(C->getAtKindKwLoc());
8337}
8338
8339void OMPClauseWriter::VisitOMPSeverityClause(OMPSeverityClause *C) {
8340 Record.push_back(C->getSeverityKind());
8341 Record.AddSourceLocation(C->getLParenLoc());
8342 Record.AddSourceLocation(C->getSeverityKindKwLoc());
8343}
8344
8345void OMPClauseWriter::VisitOMPMessageClause(OMPMessageClause *C) {
8346 Record.AddStmt(C->getMessageString());
8347 Record.AddSourceLocation(C->getLParenLoc());
8348}
8349
8350void OMPClauseWriter::VisitOMPNontemporalClause(OMPNontemporalClause *C) {
8351 Record.push_back(C->varlist_size());
8352 Record.AddSourceLocation(C->getLParenLoc());
8353 for (auto *VE : C->varlist())
8354 Record.AddStmt(VE);
8355 for (auto *E : C->private_refs())
8356 Record.AddStmt(E);
8357}
8358
8359void OMPClauseWriter::VisitOMPInclusiveClause(OMPInclusiveClause *C) {
8360 Record.push_back(C->varlist_size());
8361 Record.AddSourceLocation(C->getLParenLoc());
8362 for (auto *VE : C->varlist())
8363 Record.AddStmt(VE);
8364}
8365
8366void OMPClauseWriter::VisitOMPExclusiveClause(OMPExclusiveClause *C) {
8367 Record.push_back(C->varlist_size());
8368 Record.AddSourceLocation(C->getLParenLoc());
8369 for (auto *VE : C->varlist())
8370 Record.AddStmt(VE);
8371}
8372
8373void OMPClauseWriter::VisitOMPOrderClause(OMPOrderClause *C) {
8374 Record.writeEnum(C->getKind());
8375 Record.writeEnum(C->getModifier());
8376 Record.AddSourceLocation(C->getLParenLoc());
8377 Record.AddSourceLocation(C->getKindKwLoc());
8378 Record.AddSourceLocation(C->getModifierKwLoc());
8379}
8380
8381void OMPClauseWriter::VisitOMPUsesAllocatorsClause(OMPUsesAllocatorsClause *C) {
8382 Record.push_back(C->getNumberOfAllocators());
8383 Record.AddSourceLocation(C->getLParenLoc());
8384 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
8385 OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I);
8386 Record.AddStmt(Data.Allocator);
8387 Record.AddStmt(Data.AllocatorTraits);
8388 Record.AddSourceLocation(Data.LParenLoc);
8389 Record.AddSourceLocation(Data.RParenLoc);
8390 }
8391}
8392
8393void OMPClauseWriter::VisitOMPAffinityClause(OMPAffinityClause *C) {
8394 Record.push_back(C->varlist_size());
8395 Record.AddSourceLocation(C->getLParenLoc());
8396 Record.AddStmt(C->getModifier());
8397 Record.AddSourceLocation(C->getColonLoc());
8398 for (Expr *E : C->varlist())
8399 Record.AddStmt(E);
8400}
8401
8402void OMPClauseWriter::VisitOMPBindClause(OMPBindClause *C) {
8403 Record.writeEnum(C->getBindKind());
8404 Record.AddSourceLocation(C->getLParenLoc());
8405 Record.AddSourceLocation(C->getBindKindLoc());
8406}
8407
8408void OMPClauseWriter::VisitOMPXDynCGroupMemClause(OMPXDynCGroupMemClause *C) {
8409 VisitOMPClauseWithPreInit(C);
8410 Record.AddStmt(C->getSize());
8411 Record.AddSourceLocation(C->getLParenLoc());
8412}
8413
8414void OMPClauseWriter::VisitOMPDoacrossClause(OMPDoacrossClause *C) {
8415 Record.push_back(C->varlist_size());
8416 Record.push_back(C->getNumLoops());
8417 Record.AddSourceLocation(C->getLParenLoc());
8418 Record.push_back(C->getDependenceType());
8419 Record.AddSourceLocation(C->getDependenceLoc());
8420 Record.AddSourceLocation(C->getColonLoc());
8421 for (auto *VE : C->varlist())
8422 Record.AddStmt(VE);
8423 for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
8424 Record.AddStmt(C->getLoopData(I));
8425}
8426
8427void OMPClauseWriter::VisitOMPXAttributeClause(OMPXAttributeClause *C) {
8428 Record.AddAttributes(C->getAttrs());
8429 Record.AddSourceLocation(C->getBeginLoc());
8430 Record.AddSourceLocation(C->getLParenLoc());
8431 Record.AddSourceLocation(C->getEndLoc());
8432}
8433
8434void OMPClauseWriter::VisitOMPXBareClause(OMPXBareClause *C) {}
8435
8437 writeUInt32(TI->Sets.size());
8438 for (const auto &Set : TI->Sets) {
8439 writeEnum(Set.Kind);
8440 writeUInt32(Set.Selectors.size());
8441 for (const auto &Selector : Set.Selectors) {
8442 writeEnum(Selector.Kind);
8443 writeBool(Selector.ScoreOrCondition);
8444 if (Selector.ScoreOrCondition)
8445 writeExprRef(Selector.ScoreOrCondition);
8446 writeUInt32(Selector.Properties.size());
8447 for (const auto &Property : Selector.Properties)
8448 writeEnum(Property.Kind);
8449 }
8450 }
8451}
8452
8454 if (!Data)
8455 return;
8456 writeUInt32(Data->getNumClauses());
8457 writeUInt32(Data->getNumChildren());
8458 writeBool(Data->hasAssociatedStmt());
8459 for (unsigned I = 0, E = Data->getNumClauses(); I < E; ++I)
8460 writeOMPClause(Data->getClauses()[I]);
8461 if (Data->hasAssociatedStmt())
8462 AddStmt(Data->getAssociatedStmt());
8463 for (unsigned I = 0, E = Data->getNumChildren(); I < E; ++I)
8464 AddStmt(Data->getChildren()[I]);
8465}
8466
8468 writeUInt32(C->getVarList().size());
8469 for (Expr *E : C->getVarList())
8470 AddStmt(E);
8471}
8472
8474 writeUInt32(Exprs.size());
8475 for (Expr *E : Exprs)
8476 AddStmt(E);
8477}
8478
8480 writeEnum(C->getClauseKind());
8481 writeSourceLocation(C->getBeginLoc());
8482 writeSourceLocation(C->getEndLoc());
8483
8484 switch (C->getClauseKind()) {
8486 const auto *DC = cast<OpenACCDefaultClause>(C);
8487 writeSourceLocation(DC->getLParenLoc());
8488 writeEnum(DC->getDefaultClauseKind());
8489 return;
8490 }
8491 case OpenACCClauseKind::If: {
8492 const auto *IC = cast<OpenACCIfClause>(C);
8493 writeSourceLocation(IC->getLParenLoc());
8494 AddStmt(const_cast<Expr*>(IC->getConditionExpr()));
8495 return;
8496 }
8498 const auto *SC = cast<OpenACCSelfClause>(C);
8499 writeSourceLocation(SC->getLParenLoc());
8500 writeBool(SC->isConditionExprClause());
8501 if (SC->isConditionExprClause()) {
8502 writeBool(SC->hasConditionExpr());
8503 if (SC->hasConditionExpr())
8504 AddStmt(const_cast<Expr *>(SC->getConditionExpr()));
8505 } else {
8506 writeUInt32(SC->getVarList().size());
8507 for (Expr *E : SC->getVarList())
8508 AddStmt(E);
8509 }
8510 return;
8511 }
8513 const auto *NGC = cast<OpenACCNumGangsClause>(C);
8514 writeSourceLocation(NGC->getLParenLoc());
8515 writeUInt32(NGC->getIntExprs().size());
8516 for (Expr *E : NGC->getIntExprs())
8517 AddStmt(E);
8518 return;
8519 }
8521 const auto *DNC = cast<OpenACCDeviceNumClause>(C);
8522 writeSourceLocation(DNC->getLParenLoc());
8523 AddStmt(const_cast<Expr*>(DNC->getIntExpr()));
8524 return;
8525 }
8527 const auto *DAC = cast<OpenACCDefaultAsyncClause>(C);
8528 writeSourceLocation(DAC->getLParenLoc());
8529 AddStmt(const_cast<Expr *>(DAC->getIntExpr()));
8530 return;
8531 }
8533 const auto *NWC = cast<OpenACCNumWorkersClause>(C);
8534 writeSourceLocation(NWC->getLParenLoc());
8535 AddStmt(const_cast<Expr*>(NWC->getIntExpr()));
8536 return;
8537 }
8539 const auto *NWC = cast<OpenACCVectorLengthClause>(C);
8540 writeSourceLocation(NWC->getLParenLoc());
8541 AddStmt(const_cast<Expr*>(NWC->getIntExpr()));
8542 return;
8543 }
8545 const auto *PC = cast<OpenACCPrivateClause>(C);
8546 writeSourceLocation(PC->getLParenLoc());
8548 return;
8549 }
8551 const auto *HC = cast<OpenACCHostClause>(C);
8552 writeSourceLocation(HC->getLParenLoc());
8554 return;
8555 }
8557 const auto *DC = cast<OpenACCDeviceClause>(C);
8558 writeSourceLocation(DC->getLParenLoc());
8560 return;
8561 }
8563 const auto *FPC = cast<OpenACCFirstPrivateClause>(C);
8564 writeSourceLocation(FPC->getLParenLoc());
8566 return;
8567 }
8569 const auto *AC = cast<OpenACCAttachClause>(C);
8570 writeSourceLocation(AC->getLParenLoc());
8572 return;
8573 }
8575 const auto *DC = cast<OpenACCDetachClause>(C);
8576 writeSourceLocation(DC->getLParenLoc());
8578 return;
8579 }
8581 const auto *DC = cast<OpenACCDeleteClause>(C);
8582 writeSourceLocation(DC->getLParenLoc());
8584 return;
8585 }
8587 const auto *UDC = cast<OpenACCUseDeviceClause>(C);
8588 writeSourceLocation(UDC->getLParenLoc());
8590 return;
8591 }
8593 const auto *DPC = cast<OpenACCDevicePtrClause>(C);
8594 writeSourceLocation(DPC->getLParenLoc());
8596 return;
8597 }
8599 const auto *NCC = cast<OpenACCNoCreateClause>(C);
8600 writeSourceLocation(NCC->getLParenLoc());
8602 return;
8603 }
8605 const auto *PC = cast<OpenACCPresentClause>(C);
8606 writeSourceLocation(PC->getLParenLoc());
8608 return;
8609 }
8613 const auto *CC = cast<OpenACCCopyClause>(C);
8614 writeSourceLocation(CC->getLParenLoc());
8616 return;
8617 }
8621 const auto *CIC = cast<OpenACCCopyInClause>(C);
8622 writeSourceLocation(CIC->getLParenLoc());
8623 writeBool(CIC->isReadOnly());
8625 return;
8626 }
8630 const auto *COC = cast<OpenACCCopyOutClause>(C);
8631 writeSourceLocation(COC->getLParenLoc());
8632 writeBool(COC->isZero());
8634 return;
8635 }
8639 const auto *CC = cast<OpenACCCreateClause>(C);
8640 writeSourceLocation(CC->getLParenLoc());
8641 writeBool(CC->isZero());
8643 return;
8644 }
8646 const auto *AC = cast<OpenACCAsyncClause>(C);
8647 writeSourceLocation(AC->getLParenLoc());
8648 writeBool(AC->hasIntExpr());
8649 if (AC->hasIntExpr())
8650 AddStmt(const_cast<Expr*>(AC->getIntExpr()));
8651 return;
8652 }
8654 const auto *WC = cast<OpenACCWaitClause>(C);
8655 writeSourceLocation(WC->getLParenLoc());
8656 writeBool(WC->getDevNumExpr());
8657 if (Expr *DNE = WC->getDevNumExpr())
8658 AddStmt(DNE);
8659 writeSourceLocation(WC->getQueuesLoc());
8660
8661 writeOpenACCIntExprList(WC->getQueueIdExprs());
8662 return;
8663 }
8666 const auto *DTC = cast<OpenACCDeviceTypeClause>(C);
8667 writeSourceLocation(DTC->getLParenLoc());
8668 writeUInt32(DTC->getArchitectures().size());
8669 for (const DeviceTypeArgument &Arg : DTC->getArchitectures()) {
8670 writeBool(Arg.first);
8671 if (Arg.first)
8672 AddIdentifierRef(Arg.first);
8673 writeSourceLocation(Arg.second);
8674 }
8675 return;
8676 }
8678 const auto *RC = cast<OpenACCReductionClause>(C);
8679 writeSourceLocation(RC->getLParenLoc());
8680 writeEnum(RC->getReductionOp());
8682 return;
8683 }
8689 // Nothing to do here, there is no additional information beyond the
8690 // begin/end loc and clause kind.
8691 return;
8693 const auto *CC = cast<OpenACCCollapseClause>(C);
8694 writeSourceLocation(CC->getLParenLoc());
8695 writeBool(CC->hasForce());
8696 AddStmt(const_cast<Expr *>(CC->getLoopCount()));
8697 return;
8698 }
8700 const auto *TC = cast<OpenACCTileClause>(C);
8701 writeSourceLocation(TC->getLParenLoc());
8702 writeUInt32(TC->getSizeExprs().size());
8703 for (Expr *E : TC->getSizeExprs())
8704 AddStmt(E);
8705 return;
8706 }
8708 const auto *GC = cast<OpenACCGangClause>(C);
8709 writeSourceLocation(GC->getLParenLoc());
8710 writeUInt32(GC->getNumExprs());
8711 for (unsigned I = 0; I < GC->getNumExprs(); ++I) {
8712 writeEnum(GC->getExpr(I).first);
8713 AddStmt(const_cast<Expr *>(GC->getExpr(I).second));
8714 }
8715 return;
8716 }
8718 const auto *WC = cast<OpenACCWorkerClause>(C);
8719 writeSourceLocation(WC->getLParenLoc());
8720 writeBool(WC->hasIntExpr());
8721 if (WC->hasIntExpr())
8722 AddStmt(const_cast<Expr *>(WC->getIntExpr()));
8723 return;
8724 }
8726 const auto *VC = cast<OpenACCVectorClause>(C);
8727 writeSourceLocation(VC->getLParenLoc());
8728 writeBool(VC->hasIntExpr());
8729 if (VC->hasIntExpr())
8730 AddStmt(const_cast<Expr *>(VC->getIntExpr()));
8731 return;
8732 }
8733
8739 llvm_unreachable("Clause serialization not yet implemented");
8740 }
8741 llvm_unreachable("Invalid Clause Kind");
8742}
8743
8746 for (const OpenACCClause *Clause : Clauses)
8747 writeOpenACCClause(Clause);
8748}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3453
NodeId Parent
Definition: ASTDiff.cpp:191
DynTypedNode Node
StringRef P
static bool isInterestingIdentifier(ASTReader &Reader, const IdentifierInfo &II, bool IsModule)
Whether the given identifier is "interesting".
Definition: ASTReader.cpp:1058
static NamedDecl * getDeclForLocalLookup(const LangOptions &LangOpts, NamedDecl *D)
Determine the declaration that should be put into the name lookup table to represent the given declar...
Definition: ASTWriter.cpp:3748
static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a buffer.
Definition: ASTWriter.cpp:1962
static bool isLookupResultNotInteresting(ASTWriter &Writer, StoredDeclsList &Result)
Returns ture if all of the lookup result are either external, not emitted or predefined.
Definition: ASTWriter.cpp:4464
static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec)
Definition: ASTWriter.cpp:5311
static bool IsInternalDeclFromFileContext(const Decl *D)
Definition: ASTWriter.cpp:3356
static TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType)
Definition: ASTWriter.cpp:6669
static void AddLazyVectorEmiitedDecls(ASTWriter &Writer, Vector &Vec, ASTWriter::RecordData &Record)
Definition: ASTWriter.cpp:5319
#define RECORD(X)
static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a macro expansion.
Definition: ASTWriter.cpp:1992
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:131
static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, bool Compressed)
Create an abbreviation for the SLocEntry that refers to a buffer's blob.
Definition: ASTWriter.cpp:1977
static void BackpatchSignatureAt(llvm::BitstreamWriter &Stream, const ASTFileSignature &S, uint64_t BitNo)
Definition: ASTWriter.cpp:1283
static const char * adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir)
Adjusts the given filename to only write out the portion of the filename that is not part of the syst...
Definition: ASTWriter.cpp:1186
static bool isLocalIdentifierID(IdentifierID ID)
If the.
Definition: ASTWriter.cpp:3933
static unsigned getNumberOfModules(Module *Mod)
Compute the number of modules within the given tree (including the given module).
Definition: ASTWriter.cpp:2930
static bool isImportedDeclContext(ASTReader *Chain, const Decl *D)
Definition: ASTWriter.cpp:7303
static TypeCode getTypeCodeForTypeClass(Type::TypeClass id)
Definition: ASTWriter.cpp:159
static void AddStmtsExprs(llvm::BitstreamWriter &Stream, ASTWriter::RecordDataImpl &Record)
Definition: ASTWriter.cpp:754
static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, unsigned SLocBufferBlobCompressedAbbrv, unsigned SLocBufferBlobAbbrv)
Definition: ASTWriter.cpp:2260
static uint64_t EmitCXXBaseSpecifiers(ASTContext &Context, ASTWriter &W, ArrayRef< CXXBaseSpecifier > Bases)
Definition: ASTWriter.cpp:7009
static std::pair< unsigned, unsigned > emitULEBKeyDataLength(unsigned KeyLen, unsigned DataLen, raw_ostream &Out)
Emit key length and data length as ULEB-encoded data, and return them as a pair.
Definition: ASTWriter.cpp:2009
static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, const Preprocessor &PP)
Definition: ASTWriter.cpp:2501
static bool cleanPathForOutput(FileManager &FileMgr, SmallVectorImpl< char > &Path)
Prepares a path for being written to an AST file by converting it to an absolute path and removing ne...
Definition: ASTWriter.cpp:1169
static uint64_t EmitCXXCtorInitializers(ASTContext &Context, ASTWriter &W, ArrayRef< CXXCtorInitializer * > CtorInits)
Definition: ASTWriter.cpp:7027
static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a file.
Definition: ASTWriter.cpp:1943
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:84
Defines the Diagnostic-related interfaces.
const Decl * D
IndirectLocalPath & Path
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Defines the clang::FileManager interface and associated types.
Defines the clang::FileSystemOptions interface.
StringRef Filename
Definition: Format.cpp:3051
unsigned Iter
Definition: HTMLLogger.cpp:153
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the clang::Module class, which describes a module in the source code.
Defines types useful for describing an Objective-C runtime.
Defines some OpenACC-specific enums and functions.
Defines the clang::OpenCLOptions class.
This file defines OpenMP AST classes for clauses.
Defines the clang::Preprocessor interface.
uint32_t Id
Definition: SemaARM.cpp:1134
This file declares semantic analysis for CUDA constructs.
SourceRange Range
Definition: SemaObjC.cpp:758
SourceLocation Loc
Definition: SemaObjC.cpp:759
This file declares semantic analysis for Objective-C.
static void EmitBlockID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, RecordDataImpl &Record)
Emits a block ID in the BLOCKINFO block.
static void EmitRecordID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, RecordDataImpl &Record)
Emits a record ID in the BLOCKINFO block.
Defines the clang::SourceLocation class and associated facilities.
Defines implementation details of the clang::SourceManager class.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
const char * Data
Defines the clang::TargetOptions class.
#define IMPORT(DERIVED, BASE)
Definition: Template.h:618
#define BLOCK(DERIVED, BASE)
Definition: Template.h:631
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Defines version macros and version-related utility functions for Clang.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
do v
Definition: arm_acle.h:91
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getRawCFConstantStringType() const
Get the structure type used to representation CFStrings, or NULL if it hasn't yet been built.
Definition: ASTContext.h:1966
QualType getucontext_tType() const
Retrieve the C ucontext_t type.
Definition: ASTContext.h:2125
QualType getRecordType(const RecordDecl *Decl) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2716
QualType getFILEType() const
Retrieve the C FILE type.
Definition: ASTContext.h:2089
ArrayRef< Decl * > getModuleInitializers(Module *M)
Get the initializations to perform when importing a module, if any.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
RawCommentList Comments
All comments in this translation unit.
Definition: ASTContext.h:867
QualType AutoDeductTy
Definition: ASTContext.h:1223
QualType getjmp_bufType() const
Retrieve the C jmp_buf type.
Definition: ASTContext.h:2101
QualType getsigjmp_bufType() const
Retrieve the C sigjmp_buf type.
Definition: ASTContext.h:2113
QualType AutoRRefDeductTy
Definition: ASTContext.h:1224
TagDecl * MSGuidTagDecl
Definition: ASTContext.h:1231
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
FunctionDecl * getcudaConfigureCallDecl()
Definition: ASTContext.h:1537
import_range local_imports() const
Definition: ASTContext.h:1093
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:384
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition: ASTReader.h:1909
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
Definition: ASTReader.cpp:8511
const serialization::reader::ModuleLocalLookupTable * getModuleLocalLookupTables(DeclContext *Primary) const
Definition: ASTReader.cpp:8517
unsigned getTotalNumSubmodules() const
Returns the number of submodules known.
Definition: ASTReader.h:2005
void finalizeForWriting()
Finalizes the AST reader's state before writing an AST file to disk.
Definition: ASTReader.cpp:5438
void forEachImportedKeyDecl(const Decl *D, Fn Visit)
Run a callback on each imported key declaration of D.
Definition: ASTReader.h:1448
unsigned getTotalNumSelectors() const
Returns the number of selectors found in the chain.
Definition: ASTReader.h:2010
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Definition: ASTReader.cpp:9566
Decl * getKeyDeclaration(Decl *D)
Returns the first key declaration for the given declaration.
Definition: ASTReader.h:1432
void LoadSelector(Selector Sel)
Load a selector from disk, registering its ID if it exists.
Definition: ASTReader.cpp:9346
bool isProcessingUpdateRecords()
Definition: ASTReader.h:2578
serialization::reader::LazySpecializationInfoLookupTable * getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial)
Get the loaded specializations lookup tables for D, if any.
Definition: ASTReader.cpp:8523
unsigned getTotalNumMacros() const
Returns the number of macros found in the chain.
Definition: ASTReader.h:1990
An object for streaming information to a record.
void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Definition: ASTWriter.cpp:6882
void AddCXXBaseSpecifiers(ArrayRef< CXXBaseSpecifier > Bases)
Emit a set of C++ base specifiers.
Definition: ASTWriter.cpp:7022
void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs)
Emit a template argument list.
Definition: ASTWriter.cpp:6969
uint64_t Emit(unsigned Code, unsigned Abbrev=0)
Emit the record to the stream, followed by its substatements, and return its offset.
void AddCXXTemporary(const CXXTemporary *Temp)
Emit a CXXTemporary.
Definition: ASTWriter.cpp:6600
void writeOMPTraitInfo(const OMPTraitInfo *TI)
Write an OMPTraitInfo object.
Definition: ASTWriter.cpp:8436
void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base)
Emit a C++ base specifier.
Definition: ASTWriter.cpp:6998
void writeOMPClause(OMPClause *C)
Definition: ASTWriter.cpp:7600
void writeBool(bool Value)
void AddAPValue(const APValue &Value)
Emit an APvalue.
void AddUnresolvedSet(const ASTUnresolvedSet &Set)
Emit a UnresolvedSet structure.
Definition: ASTWriter.cpp:6988
void AddIdentifierRef(const IdentifierInfo *II)
Emit a reference to an identifier.
void AddStmt(Stmt *S)
Add the given statement or expression to the queue of statements to emit.
void AddDeclarationName(DeclarationName Name)
Emit a declaration name.
void AddSelectorRef(Selector S)
Emit a Selector (which is a smart pointer reference).
Definition: ASTWriter.cpp:6577
void AddSourceRange(SourceRange Range, LocSeq *Seq=nullptr)
Emit a source range.
void writeSourceLocation(SourceLocation Loc)
void AddOffset(uint64_t BitOffset)
Add a bit offset into the record.
void AddTypeRef(QualType T)
Emit a reference to a type.
void writeQualType(QualType T)
void writeOpenACCClauseList(ArrayRef< const OpenACCClause * > Clauses)
Writes out a list of OpenACC clauses.
Definition: ASTWriter.cpp:8744
void AddSourceLocation(SourceLocation Loc, LocSeq *Seq=nullptr)
Emit a source location.
void push_back(uint64_t N)
Minimal vector-like interface.
void AddTypeLoc(TypeLoc TL, LocSeq *Seq=nullptr)
Emits source location information for a type. Does not emit the type.
Definition: ASTWriter.cpp:6656
void AddCXXCtorInitializers(ArrayRef< CXXCtorInitializer * > CtorInits)
Emit a CXXCtorInitializer array.
Definition: ASTWriter.cpp:7062
void AddTemplateParameterList(const TemplateParameterList *TemplateParams)
Emit a template parameter list.
Definition: ASTWriter.cpp:6950
void AddTemplateArgument(const TemplateArgument &Arg)
Emit a template argument.
void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, DeclarationName Name)
Definition: ASTWriter.cpp:6855
void writeOpenACCIntExprList(ArrayRef< Expr * > Exprs)
Definition: ASTWriter.cpp:8473
void AddAPFloat(const llvm::APFloat &Value)
Emit a floating-point value.
Definition: ASTWriter.cpp:6531
void AddTypeSourceInfo(TypeSourceInfo *TInfo)
Emits a reference to a declarator info.
Definition: ASTWriter.cpp:6646
void AddQualifierInfo(const QualifierInfo &Info)
Definition: ASTWriter.cpp:6889
void writeUInt32(uint32_t Value)
void AddDeclRef(const Decl *D)
Emit a reference to a declaration.
void writeOMPChildren(OMPChildren *Data)
Writes data related to the OpenMP directives.
Definition: ASTWriter.cpp:8453
void AddConceptReference(const ConceptReference *CR)
Definition: ASTWriter.cpp:549
void AddAPInt(const llvm::APInt &Value)
Emit an integral value.
void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg)
Emits a template argument location info.
Definition: ASTWriter.cpp:6604
void writeOpenACCVarList(const OpenACCClauseWithVarList *C)
Definition: ASTWriter.cpp:8467
void AddAttributes(ArrayRef< const Attr * > Attrs)
Emit a list of attributes.
Definition: ASTWriter.cpp:5092
void AddASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *ASTTemplArgList)
Emits an AST template argument list info.
Definition: ASTWriter.cpp:6977
void AddCXXDefinitionData(const CXXRecordDecl *D)
Definition: ASTWriter.cpp:7067
void AddVarDeclInit(const VarDecl *VD)
Emit information about the initializer of a VarDecl.
Definition: ASTWriter.cpp:7160
void writeStmtRef(const Stmt *S)
void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg)
Emits a template argument location.
Definition: ASTWriter.cpp:6633
void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Emit a nested name specifier with source-location information.
Definition: ASTWriter.cpp:6896
void writeOpenACCClause(const OpenACCClause *C)
Writes out a single OpenACC Clause.
Definition: ASTWriter.cpp:8479
void AddAttr(const Attr *A)
Definition: ASTWriter.cpp:5068
An UnresolvedSet-like class which uses the ASTContext's allocator.
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:89
serialization::MacroID getMacroID(MacroInfo *MI)
Determine the ID of an already-emitted macro.
Definition: ASTWriter.cpp:6565
void AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:6715
void AddSourceRange(SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source range.
Definition: ASTWriter.cpp:6525
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:890
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:5190
void AddFileID(FileID FID, RecordDataImpl &Record)
Emit a FileID.
Definition: ASTWriter.cpp:6492
bool isDeclPredefined(const Decl *D) const
Definition: ASTWriter.h:898
bool hasChain() const
Definition: ASTWriter.h:885
void AddPath(StringRef Path, RecordDataImpl &Record)
Add a path to the given record.
Definition: ASTWriter.cpp:5177
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:838
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:5197
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:894
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:6573
void AddAlignPackInfo(const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
Emit a AlignPackInfo.
Definition: ASTWriter.cpp:6424
void AddPathBlob(StringRef Str, RecordDataImpl &Record, SmallVectorImpl< char > &Blob)
Definition: ASTWriter.cpp:5183
bool IsLocalDecl(const Decl *D)
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for...
Definition: ASTWriter.h:765
void AddTypeRef(ASTContext &Context, QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:6663
bool wasDeclEmitted(const Decl *D) const
Whether or not the declaration got emitted.
Definition: ASTWriter.cpp:6780
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:5144
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:5262
~ASTWriter() override
bool isWritingModule() const
Definition: ASTWriter.h:888
LocalDeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its local ID to the module file been writing.
Definition: ASTWriter.cpp:6726
LocalDeclID getDeclID(const Decl *D)
Determine the local declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:6767
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:6535
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:6549
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source location.
Definition: ASTWriter.cpp:6519
ASTFileSignature WriteAST(llvm::PointerUnion< Sema *, Preprocessor * > Subject, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool ShouldCacheASTInMemory=false)
Write a precompiled header or a module with the AST produced by the Sema object, or a dependency scan...
Definition: ASTWriter.cpp:5267
ASTReader * getChain() const
Definition: ASTWriter.h:886
bool getDoneWritingDeclsAndTypes() const
Definition: ASTWriter.h:896
serialization::IdentifierID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:6539
void handleVTable(CXXRecordDecl *RD)
Definition: ASTWriter.cpp:4017
unsigned getLocalOrImportedSubmoduleID(const Module *Mod)
Retrieve or create a submodule ID for this module, or return 0 if the submodule is neither local (a s...
Definition: ASTWriter.cpp:2901
void AddToken(const Token &Tok, RecordDataImpl &Record)
Emit a token.
Definition: ASTWriter.cpp:5098
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:6581
SourceLocationEncoding::RawLocEncoding getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq=nullptr)
Return the raw encodings for source locations.
Definition: ASTWriter.cpp:6497
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl< char > &Buffer, InMemoryModuleCache &ModuleCache, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, bool IncludeTimestamps=true, bool BuildingImplicitModule=false, bool GeneratingReducedBMI=false)
Create a new precompiled header writer that outputs to the given bitstream.
Definition: ASTWriter.cpp:5239
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
serialization::TypeID GetOrCreateTypeID(ASTContext &Context, QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:6693
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6834
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:5257
void SetSelectorOffset(Selector Sel, uint32_t Offset)
Note that the selector Sel occurs at the given offset within the method pool/selector table.
Definition: ASTWriter.cpp:5229
bool PreparePathForOutput(SmallVectorImpl< char > &Path)
Convert a path from this build process into one that is appropriate for emission in the module file.
Definition: ASTWriter.cpp:5155
void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset)
Note that the identifier II occurs at the given offset within the identifier table.
Definition: ASTWriter.cpp:5212
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6722
void AddStringBlob(StringRef Str, RecordDataImpl &Record, SmallVectorImpl< char > &Blob)
Definition: ASTWriter.cpp:5149
Wrapper for source info for array parameter types.
Definition: TypeLoc.h:1648
Wrapper for source info for arrays.
Definition: TypeLoc.h:1592
SourceLocation getLBracketLoc() const
Definition: TypeLoc.h:1594
Expr * getSizeExpr() const
Definition: TypeLoc.h:1614
SourceLocation getRBracketLoc() const
Definition: TypeLoc.h:1602
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2665
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2649
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2657
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
SourceLocation getScopeLoc() const
const IdentifierInfo * getScopeName() const
const IdentifierInfo * getAttrName() const
Type source information for an attributed type.
Definition: TypeLoc.h:875
const Attr * getAttr() const
The type attribute.
Definition: TypeLoc.h:898
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2225
bool isDecltypeAuto() const
Definition: TypeLoc.h:2224
bool isConstrained() const
Definition: TypeLoc.h:2228
ConceptReference * getConceptReference() const
Definition: TypeLoc.h:2234
Type source information for an btf_tag attributed type.
Definition: TypeLoc.h:925
A simple helper class to pack several bits in order into (a) 32 bit integer(s).
Definition: ASTWriter.h:1042
void addBit(bool Value)
Definition: ASTWriter.h:1062
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1063
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1345
SourceLocation getCaretLoc() const
Definition: TypeLoc.h:1347
Wrapper for source info for builtin types.
Definition: TypeLoc.h:565
SourceLocation getBuiltinLoc() const
Definition: TypeLoc.h:567
TypeSpecifierType getWrittenTypeSpec() const
Definition: TypeLoc.cpp:332
TypeSpecifierWidth getWrittenWidthSpec() const
Definition: TypeLoc.h:629
bool needsExtraLocalData() const
Definition: TypeLoc.h:594
bool hasModeAttr() const
Definition: TypeLoc.h:656
TypeSpecifierSign getWrittenSignSpec() const
Definition: TypeLoc.h:613
This class is used for builtin types like 'int'.
Definition: Type.h:3034
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a C++ temporary.
Definition: ExprCXX.h:1457
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1468
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:163
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:195
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:167
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:199
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:203
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:173
Wrapper for source info for pointers decayed from arrays and functions.
Definition: TypeLoc.h:1293
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1372
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1439
bool isFileContext() const
Definition: DeclBase.h:2175
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1862
bool isLookupContext() const
Test whether the context supports looking up names.
Definition: DeclBase.h:2170
bool isTranslationUnit() const
Definition: DeclBase.h:2180
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2006
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1799
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1935
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:2372
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1432
bool decls_empty() const
Definition: DeclBase.cpp:1638
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2364
bool isFunctionOrMethod() const
Definition: DeclBase.h:2156
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2672
bool isValid() const
Definition: DeclID.h:124
DeclID getRawValue() const
Definition: DeclID.h:118
A helper iterator adaptor to convert the iterators to SmallVector<SomeDeclID> to the iterators to Sma...
Definition: DeclID.h:235
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1054
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1069
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1219
T * getAttr() const
Definition: DeclBase.h:576
bool hasAttrs() const
Definition: DeclBase.h:521
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:528
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
bool isInNamedModule() const
Whether this declaration comes from a named module.
Definition: DeclBase.cpp:1172
bool isUnconditionallyVisible() const
Determine whether this declaration is definitely visible to name lookup, independent of whether the o...
Definition: DeclBase.h:852
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1210
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:977
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:835
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: DeclBase.h:1063
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
Definition: DeclBase.cpp:1164
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:786
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Definition: DeclBase.cpp:1225
SourceLocation getLocation() const
Definition: DeclBase.h:442
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AttrVec & getAttrs()
Definition: DeclBase.h:527
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:911
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:971
Kind getKind() const
Definition: DeclBase.h:445
GlobalDeclID getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.cpp:110
DeclarationNameLoc - Additional source/type location info for a declaration name.
SourceLocation getCXXLiteralOperatorNameLoc() const
Return the location of the literal operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
Returns the source type info.
SourceRange getCXXOperatorNameRange() const
Return the range of the operator name (without the operator keyword).
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
The name of a declaration.
SourceLocation getDecltypeLoc() const
Definition: TypeLoc.h:2114
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2117
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2329
Expr * getAttrExprOperand() const
The attribute's expression operand, if it has one.
Definition: TypeLoc.h:1811
SourceRange getAttrOperandParensRange() const
The location of the parentheses around the operand, if there is an operand.
Definition: TypeLoc.h:1822
SourceLocation getAttrNameLoc() const
The location of the attribute name, i.e.
Definition: TypeLoc.h:1801
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2438
SourceLocation getNameLoc() const
Definition: TypeLoc.h:2450
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2430
SourceLocation getNameLoc() const
Definition: TypeLoc.h:1921
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2527
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2519
TemplateArgumentLoc getArgLoc(unsigned i) const
Definition: TypeLoc.h:2563
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2487
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2495
SourceLocation getNameLoc() const
Definition: TypeLoc.h:1893
static DiagnosticMapping getDefaultMapping(unsigned DiagID)
Get the default mapping for this diagnostic.
Options for controlling the compiler diagnostics engine.
std::vector< std::string > Remarks
The list of -R... options used to alter the diagnostic mappings, with the prefixes removed.
std::vector< std::string > Warnings
The list of -W... options used to alter the diagnostic mappings, with the prefixes removed.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
StringRef getName() const
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2350
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2362
Wrapper for source info for enum types.
Definition: TypeLoc.h:749
This represents one expression.
Definition: Expr.h:110
Represents difference between two FPOptions values.
Definition: LangOptions.h:978
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:1036
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:941
Represents a member of a struct/union/class.
Definition: Decl.h:3033
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:57
StringRef getName() const
The name of this FileEntry.
Definition: FileEntry.h:61
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:305
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
void trackVFSUsage(bool Active)
Enable or disable tracking of VFS usage.
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:256
void GetUniqueIDMapping(SmallVectorImpl< OptionalFileEntryRef > &UIDToFiles) const
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntryRef.
bool makeAbsolutePath(SmallVectorImpl< char > &Path) const
Makes Path absolute taking into account FileSystemOptions and the working directory option.
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Definition: FileManager.h:253
OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)
Get a DirectoryEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:175
Keeps track of options that affect how file operations are performed.
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
Represents a function declaration or definition.
Definition: Decl.h:1935
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5107
Declaration of a template function.
Definition: DeclTemplate.h:959
Wrapper for source info for functions.
Definition: TypeLoc.h:1459
unsigned getNumParams() const
Definition: TypeLoc.h:1531
ParmVarDecl * getParam(unsigned i) const
Definition: TypeLoc.h:1537
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1483
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1511
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1475
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1491
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1499
Type source information for HLSL attributed resource type.
Definition: TypeLoc.h:952
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
unsigned ModulesPruneNonAffectingModuleMaps
Whether to prune non-affecting module map files from PCM files.
unsigned ImplicitModuleMaps
Implicit module maps.
unsigned EnablePrebuiltImplicitModules
Also search for prebuilt implicit modules in the prebuilt module cache path.
unsigned ModuleMapFileHomeIsCwd
Set the 'home directory' of a module map file to the current working directory (or the home directory...
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
std::string ModuleCachePath
The directory used for the module cache.
std::string ModuleUserBuildPath
The directory used for a user build.
std::vector< std::string > VFSOverlayFiles
The set of user-provided virtual filesystem overlay files.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
unsigned ModuleFileHomeIsCwd
Set the base path of a built module file to be the current working directory.
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
unsigned ModulesIncludeVFSUsage
Whether to include ivfsoverlay usage information in written AST files.
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:237
std::vector< bool > collectVFSUsageAndClear() const
Collect which HeaderSearchOptions::VFSOverlayFiles have been meaningfully used so far and mark their ...
FileManager & getFileMgr() const
Definition: HeaderSearch.h:372
const HeaderFileInfo * getExistingLocalFileInfo(FileEntryRef FE) const
Return the headerFileInfo structure for the specified FileEntry, if it has ever been filled in locall...
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:434
std::vector< bool > computeUserEntryUsage() const
Determine which HeaderSearchOptions::UserEntries have been successfully used so far and mark their in...
ArrayRef< ModuleMap::KnownHeader > findResolvedModulesForHeader(FileEntryRef File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:821
HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized.
Definition: HeaderSearch.h:370
unsigned header_file_size() const
Definition: HeaderSearch.h:826
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
bool isCPlusPlusOperatorKeyword() const
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
bool isPoisoned() const
Return true if this token has been poisoned.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
tok::NotableIdentifierKind getNotableIdentifierID() const
unsigned getObjCOrBuiltinID() const
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
void * getFETokenInfo() const
Get and set FETokenInfo.
StringRef getName() const
Return the actual identifier string.
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension.
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
iterator begin(DeclarationName Name)
Returns an iterator over decls with the name 'Name'.
iterator end()
Returns the end iterator.
llvm::iterator_range< iterator > decls(DeclarationName Name)
Returns a range of decls with the name 'Name'.
Implements an efficient mapping from strings to IdentifierInfo nodes.
In-memory cache for modules.
llvm::MemoryBuffer & addBuiltPCM(llvm::StringRef Filename, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Store a just-built PCM under the Filename.
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:705
SourceLocation getAmpLoc() const
Definition: TypeLoc.h:1425
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:534
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:563
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:577
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
Definition: LangOptions.h:573
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:554
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:560
Used to hold and unique data used to represent #line information.
Record the location of a macro definition.
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:354
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:416
Kind getKind() const
Definition: MacroInfo.h:346
SourceLocation getLocation() const
Definition: MacroInfo.h:348
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
Definition: MacroInfo.h:224
bool isC99Varargs() const
Definition: MacroInfo.h:207
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
Definition: MacroInfo.h:131
ArrayRef< const IdentifierInfo * > params() const
Definition: MacroInfo.h:185
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Definition: MacroInfo.h:235
unsigned getNumParams() const
Definition: MacroInfo.h:184
const Token & getReplacementToken(unsigned Tok) const
Definition: MacroInfo.h:237
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:217
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:125
bool hasCommaPasting() const
Definition: MacroInfo.h:219
bool isObjectLike() const
Definition: MacroInfo.h:202
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Definition: MacroInfo.h:294
bool isGNUVarargs() const
Definition: MacroInfo.h:208
SourceLocation getExpansionLoc() const
Definition: TypeLoc.h:1198
Expr * getAttrColumnOperand() const
The attribute's column operand, if it has one.
Definition: TypeLoc.h:1963
SourceRange getAttrOperandParensRange() const
The location of the parentheses around the operand, if there is an operand.
Definition: TypeLoc.h:1970
SourceLocation getAttrNameLoc() const
The location of the attribute name, i.e.
Definition: TypeLoc.h:1951
Expr * getAttrRowOperand() const
The attribute's row operand, if it has one.
Definition: TypeLoc.h:1957
Wrapper for source info for member pointers.
Definition: TypeLoc.h:1363
TypeSourceInfo * getClassTInfo() const
Definition: TypeLoc.h:1377
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1365
Abstract base class that writes a module file extension block into a module file.
virtual void writeExtensionContents(Sema &SemaRef, llvm::BitstreamWriter &Stream)=0
Write the contents of the extension block into the given bitstream.
ModuleFileExtension * getExtension() const
Retrieve the module file extension with which this writer is associated.
virtual ModuleFileExtensionMetadata getExtensionMetadata() const =0
Retrieves the metadata for this module file extension.
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
Definition: ModuleMap.cpp:1264
ArrayRef< KnownHeader > findResolvedModulesForHeader(FileEntryRef File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...
Definition: ModuleMap.cpp:710
FileID getModuleMapFileIDForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
Definition: ModuleMap.cpp:1339
FileID getContainingModuleMapFileID(const Module *Module) const
Retrieve the module map file containing the definition of the given module.
Definition: ModuleMap.cpp:1327
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:130
static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
Definition: ModuleMap.cpp:91
Describes a module or submodule.
Definition: Module.h:115
unsigned IsExplicit
Whether this is an explicit submodule.
Definition: Module.h:355
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:442
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:377
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:499
SourceLocation DefinitionLoc
The location of the module definition.
Definition: Module.h:121
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
Definition: Module.h:312
Module * Parent
The parent of this module.
Definition: Module.h:164
ModuleKind Kind
The kind of this module.
Definition: Module.h:160
@ HK_PrivateTextual
Definition: Module.h:253
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition: Module.h:534
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition: Module.h:370
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:429
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition: Module.h:360
std::string Name
The name of this module.
Definition: Module.h:118
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:809
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition: Module.h:366
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition: Module.h:405
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
Definition: Module.h:491
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
Definition: Module.h:727
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:323
llvm::SmallSetVector< const Module *, 2 > UndeclaredUses
When NoUndeclaredIncludes is true, the set of modules this module tried to import but didn't because ...
Definition: Module.h:470
OptionalDirectoryEntryRef Directory
The build directory of this module.
Definition: Module.h:169
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
Definition: Module.h:410
llvm::SmallSetVector< Module *, 2 > AffectingClangModules
The set of top-level modules that affected the compilation of this module, but were not imported.
Definition: Module.h:433
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:395
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:173
ASTFileSignature Signature
The module signature.
Definition: Module.h:179
ArrayRef< Header > getHeaders(HeaderKind HK) const
Definition: Module.h:273
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition: Module.h:387
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition: Module.cpp:277
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
Definition: Module.h:719
bool isHeaderUnit() const
Is this module a header unit.
Definition: Module.h:640
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:129
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:351
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition: Module.h:189
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:240
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition: Module.h:195
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:382
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:693
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:524
This represents a decl that may have a name.
Definition: Decl.h:253
Represent a C++ namespace.
Definition: Decl.h:551
A C++ nested-name-specifier augmented with source location information.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier,...
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
This represents the 'absent' clause in the '#pragma omp assume' directive.
This represents 'acq_rel' clause in the '#pragma omp atomic|flush' directives.
This represents 'acquire' clause in the '#pragma omp atomic|flush' directives.
This represents clause 'affinity' in the '#pragma omp task'-based directives.
This represents the 'align' clause in the '#pragma omp allocate' directive.
Definition: OpenMPClause.h:448
This represents clause 'aligned' in the '#pragma omp ...' directives.
This represents clause 'allocate' in the '#pragma omp ...' directives.
Definition: OpenMPClause.h:493
This represents 'allocator' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:414
This represents 'at' clause in the '#pragma omp error' directive.
This represents 'atomic_default_mem_order' clause in the '#pragma omp requires' directive.
This represents 'bind' clause in the '#pragma omp ...' directives.
This represents 'capture' clause in the '#pragma omp atomic' directive.
Contains data for OpenMP directives: clauses, children expressions/statements (helpers for codegen) a...
Class that handles post-update expression for some clauses, like 'lastprivate', 'reduction' etc.
Definition: OpenMPClause.h:233
Class that handles pre-initialization statement for some clauses, like 'schedule',...
Definition: OpenMPClause.h:195
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:55
This represents 'collapse' clause in the '#pragma omp ...' directive.
This represents 'compare' clause in the '#pragma omp atomic' directive.
This represents the 'contains' clause in the '#pragma omp assume' directive.
This represents clause 'copyin' in the '#pragma omp ...' directives.
This represents clause 'copyprivate' in the '#pragma omp ...' directives.
This represents 'default' clause in the '#pragma omp ...' directive.
This represents 'defaultmap' clause in the '#pragma omp ...' directive.
This represents implicit clause 'depend' for the '#pragma omp task' directive.
This represents implicit clause 'depobj' for the '#pragma omp depobj' directive.
This represents 'destroy' clause in the '#pragma omp depobj' directive or the '#pragma omp interop' d...
This represents 'detach' clause in the '#pragma omp task' directive.
This represents 'device' clause in the '#pragma omp ...' directive.
This represents 'dist_schedule' clause in the '#pragma omp ...' directive.
This represents the 'doacross' clause for the '#pragma omp ordered' directive.
This represents 'dynamic_allocators' clause in the '#pragma omp requires' directive.
This represents clause 'exclusive' in the '#pragma omp scan' directive.
This represents 'fail' clause in the '#pragma omp atomic' directive.
This represents 'filter' clause in the '#pragma omp ...' directive.
This represents 'final' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:785
This represents clause 'firstprivate' in the '#pragma omp ...' directives.
This represents implicit clause 'flush' for the '#pragma omp flush' directive.
This represents clause 'from' in the '#pragma omp ...' directives.
Representation of the 'full' clause of the '#pragma omp unroll' directive.
This represents 'grainsize' clause in the '#pragma omp ...' directive.
This represents clause 'has_device_ptr' in the '#pragma omp ...' directives.
This represents 'hint' clause in the '#pragma omp ...' directive.
This represents the 'holds' clause in the '#pragma omp assume' directive.
This represents 'if' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:682
This represents clause 'in_reduction' in the '#pragma omp task' directives.
This represents clause 'inclusive' in the '#pragma omp scan' directive.
This represents the 'init' clause in '#pragma omp ...' directives.
This represents clause 'is_device_ptr' in the '#pragma omp ...' directives.
This represents clause 'lastprivate' in the '#pragma omp ...' directives.
This represents clause 'linear' in the '#pragma omp ...' directives.
This represents clause 'map' in the '#pragma omp ...' directives.
This represents 'mergeable' clause in the '#pragma omp ...' directive.
This represents 'message' clause in the '#pragma omp error' directive.
This represents the 'no_openmp' clause in the '#pragma omp assume' directive.
This represents the 'no_openmp_routines' clause in the '#pragma omp assume' directive.
This represents the 'no_parallelism' clause in the '#pragma omp assume' directive.
This represents 'nocontext' clause in the '#pragma omp ...' directive.
This represents 'nogroup' clause in the '#pragma omp ...' directive.
This represents clause 'nontemporal' in the '#pragma omp ...' directives.
This represents 'novariants' clause in the '#pragma omp ...' directive.
This represents 'nowait' clause in the '#pragma omp ...' directive.
This represents 'num_tasks' clause in the '#pragma omp ...' directive.
This represents 'num_teams' clause in the '#pragma omp ...' directive.
This represents 'num_threads' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:831
This represents 'order' clause in the '#pragma omp ...' directive.
This represents 'ordered' clause in the '#pragma omp ...' directive.
Representation of the 'partial' clause of the '#pragma omp unroll' directive.
This class represents the 'permutation' clause in the '#pragma omp interchange' directive.
This represents 'priority' clause in the '#pragma omp ...' directive.
This represents clause 'private' in the '#pragma omp ...' directives.
This represents 'proc_bind' clause in the '#pragma omp ...' directive.
This represents 'read' clause in the '#pragma omp atomic' directive.
This represents clause 'reduction' in the '#pragma omp ...' directives.
This represents 'relaxed' clause in the '#pragma omp atomic' directives.
This represents 'release' clause in the '#pragma omp atomic|flush' directives.
This represents 'reverse_offload' clause in the '#pragma omp requires' directive.
This represents 'simd' clause in the '#pragma omp ...' directive.
This represents 'safelen' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:876
This represents 'schedule' clause in the '#pragma omp ...' directive.
This represents 'seq_cst' clause in the '#pragma omp atomic|flush' directives.
This represents 'severity' clause in the '#pragma omp error' directive.
This represents clause 'shared' in the '#pragma omp ...' directives.
This represents 'simdlen' clause in the '#pragma omp ...' directive.
Definition: OpenMPClause.h:911
This represents the 'sizes' clause in the '#pragma omp tile' directive.
Definition: OpenMPClause.h:943
This represents clause 'task_reduction' in the '#pragma omp taskgroup' directives.
This represents 'thread_limit' clause in the '#pragma omp ...' directive.
This represents 'threads' clause in the '#pragma omp ...' directive.
This represents clause 'to' in the '#pragma omp ...' directives.
Helper data structure representing the traits in a match clause of an declare variant or metadirectiv...
llvm::SmallVector< OMPTraitSet, 2 > Sets
The outermost level of selector sets.
This represents 'unified_address' clause in the '#pragma omp requires' directive.
This represents 'unified_shared_memory' clause in the '#pragma omp requires' directive.
This represents 'untied' clause in the '#pragma omp ...' directive.
This represents 'update' clause in the '#pragma omp atomic' directive.
This represents the 'use' clause in '#pragma omp ...' directives.
This represents clause 'use_device_addr' in the '#pragma omp ...' directives.
This represents clause 'use_device_ptr' in the '#pragma omp ...' directives.
This represents clause 'uses_allocators' in the '#pragma omp target'-based directives.
This represents 'weak' clause in the '#pragma omp atomic' directives.
This represents 'write' clause in the '#pragma omp atomic' directive.
This represents 'ompx_attribute' clause in a directive that might generate an outlined function.
This represents 'ompx_bare' clause in the '#pragma omp target teams ...' directive.
This represents 'ompx_dyn_cgroup_mem' clause in the '#pragma omp target ...' directive.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
Iterator that walks over the list of categories, filtering out those that do not meet specific criter...
Definition: DeclObjC.h:1597
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
Wrapper for source info for ObjC interfaces.
Definition: TypeLoc.h:1122
SourceLocation getNameEndLoc() const
Definition: TypeLoc.h:1140
SourceLocation getNameLoc() const
Definition: TypeLoc.h:1128
Wraps an ObjCPointerType with source location information.
Definition: TypeLoc.h:1401
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1403
bool hasBaseTypeAsWritten() const
Definition: TypeLoc.h:1073
SourceLocation getTypeArgsLAngleLoc() const
Definition: TypeLoc.h:1003
unsigned getNumTypeArgs() const
Definition: TypeLoc.h:1019
unsigned getNumProtocols() const
Definition: TypeLoc.h:1049
TypeSourceInfo * getTypeArgTInfo(unsigned i) const
Definition: TypeLoc.h:1023
SourceLocation getProtocolRAngleLoc() const
Definition: TypeLoc.h:1041
SourceLocation getProtocolLoc(unsigned i) const
Definition: TypeLoc.h:1053
SourceLocation getProtocolLAngleLoc() const
Definition: TypeLoc.h:1033
SourceLocation getTypeArgsRAngleLoc() const
Definition: TypeLoc.h:1011
Kind getKind() const
Definition: ObjCRuntime.h:77
const VersionTuple & getVersion() const
Definition: ObjCRuntime.h:78
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition: TypeLoc.h:772
unsigned getNumProtocols() const
Definition: TypeLoc.h:809
SourceLocation getProtocolLoc(unsigned i) const
Definition: TypeLoc.h:813
SourceLocation getProtocolLAngleLoc() const
Definition: TypeLoc.h:789
SourceLocation getProtocolRAngleLoc() const
Definition: TypeLoc.h:799
Represents a clause with one or more 'var' objects, represented as an expr, as its arguments.
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
OpenCL supported extensions and optional core features.
Definition: OpenCLOptions.h:69
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2609
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2142
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1226
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1222
Represents a parameter to a function.
Definition: Decl.h:1725
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2704
Wrapper for source info for pointers.
Definition: TypeLoc.h:1332
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1334
Iteration over the preprocessed entities.
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)
Retrieve the macro definition that corresponds to the given MacroInfo.
const std::vector< SourceRange > & getSkippedRanges()
Retrieve all ranges that got skipped while preprocessing.
iterator local_begin()
Begin iterator for local, non-loaded, preprocessed entities.
iterator local_end()
End iterator for local, non-loaded, preprocessed entities.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
std::vector< std::string > MacroIncludes
std::vector< std::string > Includes
bool WriteCommentListToPCH
Whether to write comment locations into the PCH when building it.
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
std::vector< std::pair< std::string, bool > > Macros
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:138
ArrayRef< ModuleMacro * > getLeafModuleMacros(const IdentifierInfo *II) const
Get the list of leaf (non-overridden) module macros for a name.
ArrayRef< PPConditionalInfo > getPreambleConditionalStack() const
SourceLocation getModuleImportLoc(Module *M) const
bool isRecordingPreamble() const
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
bool SawDateOrTime() const
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
unsigned getCounterValue() const
SourceManager & getSourceManager() const
std::optional< PreambleSkipInfo > getPreambleSkipInfo() const
bool hasRecordedPreamble() const
const TargetInfo & getTargetInfo() const
FileManager & getFileManager() const
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
bool alreadyIncluded(FileEntryRef File) const
Return true if this header has already been included.
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
HeaderSearch & getHeaderSearchInfo() const
SmallVector< SourceLocation, 64 > serializeSafeBufferOptOutMap() const
IdentifierTable & getIdentifierTable()
const LangOptions & getLangOpts() const
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
DiagnosticsEngine & getDiagnostics() const
SourceLocation getPreambleRecordedPragmaAssumeNonNullLoc() const
Get the location of the recorded unterminated #pragma clang assume_nonnull begin in the preamble,...
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
A (possibly-)qualified type.
Definition: Type.h:929
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:324
SourceLocation getAmpAmpLoc() const
Definition: TypeLoc.h:1439
bool isTrailingComment() const LLVM_READONLY
Returns true if it is a comment that should be put after a member:
bool isAlmostTrailingComment() const LLVM_READONLY
Returns true if it is a probable typo:
CommentKind getKind() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
Represents a struct/union/class.
Definition: Decl.h:4162
Wrapper for source info for record types.
Definition: TypeLoc.h:741
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6077
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:215
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
void * getAsOpaquePtr() const
unsigned getNumArgs() const
void updateOutOfDateSelector(Selector Sel)
llvm::MapVector< Selector, SourceLocation > ReferencedSelectors
Method selectors used in a @selector expression.
Definition: SemaObjC.h:209
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Definition: SemaObjC.h:220
static uint32_t getRawEncoding(const AlignPackInfo &Info)
Definition: Sema.h:1478
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:464
llvm::SmallSetVector< const TypedefNameDecl *, 4 > UnusedLocalTypedefNameCandidates
Set containing all typedefs that are likely unused.
Definition: Sema.h:3084
DelegatingCtorDeclsType DelegatingCtorDecls
All the delegating constructors seen so far in the file, used for cycle detection at the end of the T...
Definition: Sema.h:6051
SemaCUDA & CUDA()
Definition: Sema.h:1071
Preprocessor & getPreprocessor() const
Definition: Sema.h:531
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:1664
ExtVectorDeclsType ExtVectorDecls
ExtVectorDecls - This is a list all the extended vector types.
Definition: Sema.h:4472
SourceLocation getOptimizeOffPragmaLocation() const
Get the location for the currently active "\#pragma clang optimize off". If this location is invalid,...
Definition: Sema.h:1735
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:1665
LateParsedTemplateMapT LateParsedTemplateMap
Definition: Sema.h:11061
ASTContext & Context
Definition: Sema.h:909
SemaObjC & ObjC()
Definition: Sema.h:1111
UnusedFileScopedDeclsType UnusedFileScopedDecls
The set of file scoped decls seen so far that have not been used and must warn if not used.
Definition: Sema.h:3092
SmallVector< const Decl * > DeclsWithEffectsToVerify
All functions/lambdas/blocks which have bodies and which have a non-empty FunctionEffectsRef to be ve...
Definition: Sema.h:15137
EnumDecl * getStdAlignValT() const
LazyDeclPtr StdBadAlloc
The C++ "std::bad_alloc" class, which is defined by the C++ standard library.
Definition: Sema.h:7962
SmallVector< VTableUse, 16 > VTableUses
The list of vtables that are required but have not yet been materialized.
Definition: Sema.h:5396
Preprocessor & PP
Definition: Sema.h:908
llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > LateParsedTemplateMapT
Definition: Sema.h:11060
CXXRecordDecl * getStdBadAlloc() const
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:1411
llvm::DenseMap< CXXRecordDecl *, bool > VTablesUsed
The set of classes whose vtables have been used within this translation unit, and a bit that will be ...
Definition: Sema.h:5402
PragmaStack< AlignPackInfo > AlignPackStack
Definition: Sema.h:1646
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
Definition: Sema.h:13543
bool MSStructPragmaOn
Definition: Sema.h:1408
void getUndefinedButUsed(SmallVectorImpl< std::pair< NamedDecl *, SourceLocation > > &Undefined)
Obtain a sorted list of functions that are undefined but ODR-used.
Definition: Sema.cpp:881
LazyDeclPtr StdNamespace
The C++ "std" namespace, where the standard library resides.
Definition: Sema.h:6054
std::deque< PendingImplicitInstantiation > PendingInstantiations
The queue of implicit template instantiations that are required but have not yet been performed.
Definition: Sema.h:13526
TentativeDefinitionsType TentativeDefinitions
All the tentative definitions encountered in the TU.
Definition: Sema.h:3099
const llvm::MapVector< FieldDecl *, DeleteLocs > & getMismatchingDeleteExpressions() const
Retrieves list of suspicious delete-expressions that will be checked at the end of translation unit.
Definition: Sema.cpp:2743
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:526
NamespaceDecl * getStdNamespace() const
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:1406
llvm::MapVector< IdentifierInfo *, llvm::SetVector< WeakInfo, llvm::SmallVector< WeakInfo, 1u >, llvm::SmallDenseSet< WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly > > > WeakUndeclaredIdentifiers
WeakUndeclaredIdentifiers - Identifiers contained in #pragma weak before declared.
Definition: Sema.h:3074
LazyDeclPtr StdAlignValT
The C++ "std::align_val_t" enum class, which is defined by the C++ standard library.
Definition: Sema.h:7966
IdentifierResolver IdResolver
Definition: Sema.h:3003
static RawLocEncoding encode(SourceLocation Loc, UIntTy BaseOffset, unsigned BaseModuleFileIndex, SourceLocationSequence *=nullptr)
This object establishes a SourceLocationSequence.
Serialized encoding of a sequence of SourceLocations.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
DiagnosticsEngine & getDiagnostics() const
SourceLocation::UIntTy getNextLocalOffset() const
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index) const
Get a local SLocEntry. This is exposed for indexing.
FileManager & getFileManager() const
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
bool hasLineTable() const
Determine if the source manager has a line table.
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
LineTableInfo & getLineTable()
Retrieve the stored line table.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
OptionalFileEntryRef ContentsEntry
References the file which the contents were actually loaded from.
unsigned IsTransient
True if this file may be transient, that is, if it might not exist at some later point in time when t...
std::optional< llvm::MemoryBufferRef > getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, SourceLocation Loc=SourceLocation()) const
Returns the memory buffer for the associated content.
unsigned BufferOverridden
Indicates whether the buffer itself was provided to override the actual file contents.
OptionalFileEntryRef OrigEntry
Reference to the file entry representing this ContentCache.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
Information about a FileID, basically just the logical file that it represents and include stack info...
const ContentCache & getContentCache() const
This is a discriminated union of FileInfo and ExpansionInfo.
SourceLocation::UIntTy getOffset() const
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
An array of decls optimized for the common case of only containing one entry.
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:857
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3578
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3681
Exposes information about the current target.
Definition: TargetInfo.h:220
Options for controlling the target.
Definition: TargetOptions.h:26
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:29
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings starting...
Definition: TargetOptions.h:58
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:45
std::string TuneCPU
If given, the name of the target CPU to tune code for.
Definition: TargetOptions.h:39
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:36
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line.
Definition: TargetOptions.h:54
A template argument list.
Definition: DeclTemplate.h:250
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:271
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
ArgKind
The kind of template argument we're storing.
Definition: TemplateBase.h:64
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:183
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:207
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:206
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:205
SourceLocation getLAngleLoc() const
Definition: TypeLoc.h:1698
TemplateArgumentLoc getArgLoc(unsigned i) const
Definition: TypeLoc.h:1726
SourceLocation getRAngleLoc() const
Definition: TypeLoc.h:1706
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1731
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:1690
Wrapper for template type parameters.
Definition: TypeLoc.h:758
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:187
unsigned getFlags() const
Return the internal represtation of the flags.
Definition: Token.h:262
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:132
unsigned getLength() const
Definition: Token.h:135
SourceLocation getAnnotationEndLoc() const
Definition: Token.h:146
void * getAnnotationValue() const
Definition: Token.h:234
tok::TokenKind getKind() const
Definition: Token.h:94
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:121
The top declaration context.
Definition: Decl.h:84
NamespaceDecl * getAnonymousNamespace() const
Definition: Decl.h:122
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:133
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
Definition: TypeLoc.h:170
bool isNull() const
Definition: TypeLoc.h:121
TypeSourceInfo * getUnmodifiedTInfo() const
Definition: TypeLoc.h:2088
The type-property cache.
Definition: Type.cpp:4501
A container of type source information.
Definition: Type.h:7907
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7918
SourceLocation getNameLoc() const
Definition: TypeLoc.h:535
The base class of the type hierarchy.
Definition: Type.h:1828
TypeClass getTypeClass() const
Definition: Type.h:2341
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3427
Wrapper for source info for typedefs.
Definition: TypeLoc.h:693
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2031
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2039
SourceLocation getTypeofLoc() const
Definition: TypeLoc.h:2023
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2170
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2176
TypeSourceInfo * getUnderlyingTInfo() const
Definition: TypeLoc.h:2179
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2173
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:35
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:716
Wrapper for source info for types used via transparent aliases.
Definition: TypeLoc.h:682
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
Represents a variable declaration or definition.
Definition: Decl.h:882
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2543
const Expr * getInit() const
Definition: Decl.h:1319
APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable's initializer, or NULL if the value is not yet kn...
Definition: Decl.cpp:2600
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getNameLoc() const
Definition: TypeLoc.h:1870
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Definition: ScopeInfo.h:686
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
Definition: ScopeInfo.h:690
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:2115
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:130
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
Definition: ModuleFile.h:373
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
Definition: ModuleFile.h:426
unsigned LocalNumSubmodules
The number of submodules in this module.
Definition: ModuleFile.h:406
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
Definition: ModuleFile.h:515
unsigned Index
The index of this module in the list of modules.
Definition: ModuleFile.h:139
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
Definition: ModuleFile.h:409
std::string FileName
The file name of the module file.
Definition: ModuleFile.h:145
SourceLocation::UIntTy SLocEntryBaseOffset
The base offset in the source manager's view of this module.
Definition: ModuleFile.h:294
unsigned LocalNumMacros
The number of macros in this AST file.
Definition: ModuleFile.h:340
unsigned LocalNumSelectors
The number of selectors new to this file.
Definition: ModuleFile.h:419
ModuleKind Kind
The type of this module.
Definition: ModuleFile.h:142
std::string ModuleName
The name of the module.
Definition: ModuleFile.h:148
serialization::MacroID BaseMacroID
Base macro ID for macros local to this module.
Definition: ModuleFile.h:354
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:99
uint32_t getModuleFileIndex() const
Definition: ASTBitCodes.h:109
TypeID asTypeID(unsigned FastQuals) const
Definition: ASTBitCodes.h:113
Class that performs name lookup into a DeclContext stored in an AST file.
Class that performs lookup to specialized decls.
const unsigned int LOCAL_REDECLARATIONS
Record code for a list of local redeclarations of a declaration.
Definition: ASTBitCodes.h:1221
TypeCode
Record codes for each kind of type.
Definition: ASTBitCodes.h:1172
const unsigned int DECL_UPDATES
Record of updates for a declaration that was modified after being deserialized.
Definition: ASTBitCodes.h:1217
@ PREDEF_TYPE_AUTO_RREF_DEDUCT
The "auto &&" deduction type.
Definition: ASTBitCodes.h:993
@ PREDEF_TYPE_NULL_ID
The NULL type.
Definition: ASTBitCodes.h:897
@ PREDEF_TYPE_AUTO_DEDUCT
The "auto" deduction type.
Definition: ASTBitCodes.h:990
@ DECL_EMPTY
An EmptyDecl record.
Definition: ASTBitCodes.h:1481
@ DECL_CXX_BASE_SPECIFIERS
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1452
@ DECL_CXX_RECORD
A CXXRecordDecl record.
Definition: ASTBitCodes.h:1383
@ DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION
A VarTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1425
@ DECL_OMP_ALLOCATE
An OMPAllocateDcl record.
Definition: ASTBitCodes.h:1478
@ DECL_MS_PROPERTY
A MSPropertyDecl record.
Definition: ASTBitCodes.h:1285
@ DECL_REQUIRES_EXPR_BODY
A RequiresExprBodyDecl record.
Definition: ASTBitCodes.h:1487
@ DECL_STATIC_ASSERT
A StaticAssertDecl record.
Definition: ASTBitCodes.h:1449
@ DECL_INDIRECTFIELD
A IndirectFieldDecl record.
Definition: ASTBitCodes.h:1458
@ DECL_TEMPLATE_TEMPLATE_PARM
A TemplateTemplateParmDecl record.
Definition: ASTBitCodes.h:1437
@ DECL_IMPORT
An ImportDecl recording a module import.
Definition: ASTBitCodes.h:1469
@ DECL_ACCESS_SPEC
An AccessSpecDecl record.
Definition: ASTBitCodes.h:1401
@ DECL_OBJC_TYPE_PARAM
An ObjCTypeParamDecl record.
Definition: ASTBitCodes.h:1490
@ DECL_OBJC_CATEGORY_IMPL
A ObjCCategoryImplDecl record.
Definition: ASTBitCodes.h:1267
@ DECL_ENUM_CONSTANT
An EnumConstantDecl record.
Definition: ASTBitCodes.h:1243
@ DECL_PARM_VAR
A ParmVarDecl record.
Definition: ASTBitCodes.h:1300
@ DECL_TYPEDEF
A TypedefDecl record.
Definition: ASTBitCodes.h:1231
@ DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK
A TemplateTemplateParmDecl record that stores an expanded template template parameter pack.
Definition: ASTBitCodes.h:1466
@ DECL_HLSL_BUFFER
A HLSLBufferDecl record.
Definition: ASTBitCodes.h:1511
@ DECL_NAMESPACE_ALIAS
A NamespaceAliasDecl record.
Definition: ASTBitCodes.h:1350
@ DECL_TYPEALIAS
A TypeAliasDecl record.
Definition: ASTBitCodes.h:1234
@ DECL_FUNCTION_TEMPLATE
A FunctionTemplateDecl record.
Definition: ASTBitCodes.h:1428
@ DECL_UNRESOLVED_USING_TYPENAME
An UnresolvedUsingTypenameDecl record.
Definition: ASTBitCodes.h:1374
@ DECL_CLASS_TEMPLATE_SPECIALIZATION
A ClassTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1413
@ DECL_FILE_SCOPE_ASM
A FileScopeAsmDecl record.
Definition: ASTBitCodes.h:1309
@ DECL_CXX_CONSTRUCTOR
A CXXConstructorDecl record.
Definition: ASTBitCodes.h:1392
@ DECL_CXX_CONVERSION
A CXXConversionDecl record.
Definition: ASTBitCodes.h:1398
@ DECL_FIELD
A FieldDecl record.
Definition: ASTBitCodes.h:1282
@ DECL_LINKAGE_SPEC
A LinkageSpecDecl record.
Definition: ASTBitCodes.h:1377
@ DECL_NAMESPACE
A NamespaceDecl record.
Definition: ASTBitCodes.h:1347
@ DECL_NON_TYPE_TEMPLATE_PARM
A NonTypeTemplateParmDecl record.
Definition: ASTBitCodes.h:1434
@ DECL_FUNCTION
A FunctionDecl record.
Definition: ASTBitCodes.h:1246
@ DECL_USING_DIRECTIVE
A UsingDirecitveDecl record.
Definition: ASTBitCodes.h:1368
@ DECL_RECORD
A RecordDecl record.
Definition: ASTBitCodes.h:1240
@ DECL_CONTEXT_LEXICAL
A record that stores the set of declarations that are lexically stored within a given DeclContext.
Definition: ASTBitCodes.h:1328
@ DECL_BLOCK
A BlockDecl record.
Definition: ASTBitCodes.h:1315
@ DECL_UNRESOLVED_USING_VALUE
An UnresolvedUsingValueDecl record.
Definition: ASTBitCodes.h:1371
@ DECL_TYPE_ALIAS_TEMPLATE
A TypeAliasTemplateDecl record.
Definition: ASTBitCodes.h:1440
@ DECL_CXX_CTOR_INITIALIZERS
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1455
@ DECL_OBJC_CATEGORY
A ObjCCategoryDecl record.
Definition: ASTBitCodes.h:1264
@ DECL_VAR
A VarDecl record.
Definition: ASTBitCodes.h:1294
@ DECL_USING
A UsingDecl record.
Definition: ASTBitCodes.h:1353
@ DECL_OBJC_PROTOCOL
A ObjCProtocolDecl record.
Definition: ASTBitCodes.h:1255
@ DECL_TEMPLATE_TYPE_PARM
A TemplateTypeParmDecl record.
Definition: ASTBitCodes.h:1431
@ DECL_VAR_TEMPLATE_SPECIALIZATION
A VarTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1422
@ DECL_OBJC_IMPLEMENTATION
A ObjCImplementationDecl record.
Definition: ASTBitCodes.h:1270
@ DECL_OBJC_COMPATIBLE_ALIAS
A ObjCCompatibleAliasDecl record.
Definition: ASTBitCodes.h:1273
@ DECL_FRIEND_TEMPLATE
A FriendTemplateDecl record.
Definition: ASTBitCodes.h:1407
@ DECL_PRAGMA_DETECT_MISMATCH
A PragmaDetectMismatchDecl record.
Definition: ASTBitCodes.h:1499
@ DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
A NonTypeTemplateParmDecl record that stores an expanded non-type template parameter pack.
Definition: ASTBitCodes.h:1462
@ DECL_OBJC_AT_DEFS_FIELD
A ObjCAtDefsFieldDecl record.
Definition: ASTBitCodes.h:1261
@ DECL_IMPLICIT_PARAM
An ImplicitParamDecl record.
Definition: ASTBitCodes.h:1297
@ DECL_FRIEND
A FriendDecl record.
Definition: ASTBitCodes.h:1404
@ DECL_CXX_METHOD
A CXXMethodDecl record.
Definition: ASTBitCodes.h:1389
@ DECL_EXPORT
An ExportDecl record.
Definition: ASTBitCodes.h:1380
@ DECL_PRAGMA_COMMENT
A PragmaCommentDecl record.
Definition: ASTBitCodes.h:1496
@ DECL_ENUM
An EnumDecl record.
Definition: ASTBitCodes.h:1237
@ DECL_CONTEXT_MODULE_LOCAL_VISIBLE
A record containing the set of declarations that are only visible from DeclContext in the same module...
Definition: ASTBitCodes.h:1341
@ DECL_OMP_DECLARE_REDUCTION
An OMPDeclareReductionDecl record.
Definition: ASTBitCodes.h:1505
@ DECL_OMP_THREADPRIVATE
An OMPThreadPrivateDecl record.
Definition: ASTBitCodes.h:1472
@ DECL_OBJC_METHOD
A ObjCMethodDecl record.
Definition: ASTBitCodes.h:1249
@ DECL_CXX_DESTRUCTOR
A CXXDestructorDecl record.
Definition: ASTBitCodes.h:1395
@ DECL_OMP_CAPTUREDEXPR
An OMPCapturedExprDecl record.
Definition: ASTBitCodes.h:1493
@ DECL_CLASS_TEMPLATE
A ClassTemplateDecl record.
Definition: ASTBitCodes.h:1410
@ DECL_USING_SHADOW
A UsingShadowDecl record.
Definition: ASTBitCodes.h:1362
@ DECL_CONCEPT
A ConceptDecl record.
Definition: ASTBitCodes.h:1443
@ DECL_OBJC_IVAR
A ObjCIvarDecl record.
Definition: ASTBitCodes.h:1258
@ DECL_OBJC_PROPERTY
A ObjCPropertyDecl record.
Definition: ASTBitCodes.h:1276
@ DECL_OBJC_INTERFACE
A ObjCInterfaceDecl record.
Definition: ASTBitCodes.h:1252
@ DECL_VAR_TEMPLATE
A VarTemplateDecl record.
Definition: ASTBitCodes.h:1419
@ DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
A ClassTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1416
@ DECL_CONTEXT_VISIBLE
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1337
@ DECL_OBJC_PROPERTY_IMPL
A ObjCPropertyImplDecl record.
Definition: ASTBitCodes.h:1279
@ TYPE_EXT_QUAL
An ExtQualType record.
Definition: ASTBitCodes.h:1178
@ EXPR_DESIGNATED_INIT
A DesignatedInitExpr record.
Definition: ASTBitCodes.h:1679
@ EXPR_COMPOUND_LITERAL
A CompoundLiteralExpr record.
Definition: ASTBitCodes.h:1670
@ EXPR_OBJC_IVAR_REF_EXPR
An ObjCIvarRefExpr record.
Definition: ASTBitCodes.h:1757
@ EXPR_MEMBER
A MemberExpr record.
Definition: ASTBitCodes.h:1652
@ EXPR_CXX_TEMPORARY_OBJECT
A CXXTemporaryObjectExpr record.
Definition: ASTBitCodes.h:1831
@ EXPR_COMPOUND_ASSIGN_OPERATOR
A CompoundAssignOperator record.
Definition: ASTBitCodes.h:1658
@ EXPR_CXX_STATIC_CAST
A CXXStaticCastExpr record.
Definition: ASTBitCodes.h:1834
@ EXPR_OBJC_STRING_LITERAL
An ObjCStringLiteral record.
Definition: ASTBitCodes.h:1741
@ EXPR_VA_ARG
A VAArgExpr record.
Definition: ASTBitCodes.h:1697
@ EXPR_CXX_OPERATOR_CALL
A CXXOperatorCallExpr record.
Definition: ASTBitCodes.h:1816
@ STMT_OBJC_AT_TRY
An ObjCAtTryStmt record.
Definition: ASTBitCodes.h:1787
@ STMT_DO
A DoStmt record.
Definition: ASTBitCodes.h:1571
@ STMT_OBJC_CATCH
An ObjCAtCatchStmt record.
Definition: ASTBitCodes.h:1781
@ STMT_IF
An IfStmt record.
Definition: ASTBitCodes.h:1562
@ EXPR_STRING_LITERAL
A StringLiteral record.
Definition: ASTBitCodes.h:1622
@ EXPR_IMPLICIT_CAST
An ImplicitCastExpr record.
Definition: ASTBitCodes.h:1664
@ STMT_GCCASM
A GCC-style AsmStmt record.
Definition: ASTBitCodes.h:1598
@ EXPR_IMAGINARY_LITERAL
An ImaginaryLiteral record.
Definition: ASTBitCodes.h:1619
@ STMT_WHILE
A WhileStmt record.
Definition: ASTBitCodes.h:1568
@ EXPR_STMT
A StmtExpr record.
Definition: ASTBitCodes.h:1703
@ EXPR_CXX_REINTERPRET_CAST
A CXXReinterpretCastExpr record.
Definition: ASTBitCodes.h:1840
@ EXPR_DESIGNATED_INIT_UPDATE
A DesignatedInitUpdateExpr record.
Definition: ASTBitCodes.h:1682
@ STMT_OBJC_AT_SYNCHRONIZED
An ObjCAtSynchronizedStmt record.
Definition: ASTBitCodes.h:1790
@ EXPR_CHARACTER_LITERAL
A CharacterLiteral record.
Definition: ASTBitCodes.h:1625
@ EXPR_OBJC_ENCODE
An ObjCEncodeExpr record.
Definition: ASTBitCodes.h:1748
@ EXPR_CSTYLE_CAST
A CStyleCastExpr record.
Definition: ASTBitCodes.h:1667
@ EXPR_OBJC_BOOL_LITERAL
An ObjCBoolLiteralExpr record.
Definition: ASTBitCodes.h:1799
@ EXPR_EXT_VECTOR_ELEMENT
An ExtVectorElementExpr record.
Definition: ASTBitCodes.h:1673
@ STMT_RETURN
A ReturnStmt record.
Definition: ASTBitCodes.h:1589
@ STMT_OBJC_FOR_COLLECTION
An ObjCForCollectionStmt record.
Definition: ASTBitCodes.h:1778
@ STMT_CONTINUE
A ContinueStmt record.
Definition: ASTBitCodes.h:1583
@ EXPR_PREDEFINED
A PredefinedExpr record.
Definition: ASTBitCodes.h:1607
@ EXPR_CXX_BOOL_LITERAL
A CXXBoolLiteralExpr record.
Definition: ASTBitCodes.h:1861
@ EXPR_PAREN_LIST
A ParenListExpr record.
Definition: ASTBitCodes.h:1631
@ EXPR_CXX_PAREN_LIST_INIT
A CXXParenListInitExpr record.
Definition: ASTBitCodes.h:1864
@ STMT_COMPOUND
A CompoundStmt record.
Definition: ASTBitCodes.h:1547
@ STMT_FOR
A ForStmt record.
Definition: ASTBitCodes.h:1574
@ STMT_ATTRIBUTED
An AttributedStmt record.
Definition: ASTBitCodes.h:1559
@ EXPR_CXX_REWRITTEN_BINARY_OPERATOR
A CXXRewrittenBinaryOperator record.
Definition: ASTBitCodes.h:1822
@ STMT_GOTO
A GotoStmt record.
Definition: ASTBitCodes.h:1577
@ EXPR_NO_INIT
An NoInitExpr record.
Definition: ASTBitCodes.h:1685
@ EXPR_OBJC_PROTOCOL_EXPR
An ObjCProtocolExpr record.
Definition: ASTBitCodes.h:1754
@ EXPR_CXX_CONSTRUCT
A CXXConstructExpr record.
Definition: ASTBitCodes.h:1825
@ EXPR_CXX_DYNAMIC_CAST
A CXXDynamicCastExpr record.
Definition: ASTBitCodes.h:1837
@ STMT_CXX_TRY
A CXXTryStmt record.
Definition: ASTBitCodes.h:1810
@ EXPR_GENERIC_SELECTION
A GenericSelectionExpr record.
Definition: ASTBitCodes.h:1727
@ EXPR_CALL
A CallExpr record.
Definition: ASTBitCodes.h:1649
@ EXPR_GNU_NULL
A GNUNullExpr record.
Definition: ASTBitCodes.h:1709
@ EXPR_OBJC_PROPERTY_REF_EXPR
An ObjCPropertyRefExpr record.
Definition: ASTBitCodes.h:1760
@ EXPR_CXX_CONST_CAST
A CXXConstCastExpr record.
Definition: ASTBitCodes.h:1843
@ STMT_REF_PTR
A reference to a previously [de]serialized Stmt record.
Definition: ASTBitCodes.h:1541
@ EXPR_OBJC_MESSAGE_EXPR
An ObjCMessageExpr record.
Definition: ASTBitCodes.h:1769
@ STMT_CASE
A CaseStmt record.
Definition: ASTBitCodes.h:1550
@ STMT_STOP
A marker record that indicates that we are at the end of an expression.
Definition: ASTBitCodes.h:1535
@ STMT_MSASM
A MS-style AsmStmt record.
Definition: ASTBitCodes.h:1601
@ EXPR_CONDITIONAL_OPERATOR
A ConditionOperator record.
Definition: ASTBitCodes.h:1661
@ EXPR_BINARY_OPERATOR
A BinaryOperator record.
Definition: ASTBitCodes.h:1655
@ EXPR_CXX_STD_INITIALIZER_LIST
A CXXStdInitializerListExpr record.
Definition: ASTBitCodes.h:1858
@ EXPR_SHUFFLE_VECTOR
A ShuffleVectorExpr record.
Definition: ASTBitCodes.h:1718
@ STMT_OBJC_FINALLY
An ObjCAtFinallyStmt record.
Definition: ASTBitCodes.h:1784
@ EXPR_OBJC_SELECTOR_EXPR
An ObjCSelectorExpr record.
Definition: ASTBitCodes.h:1751
@ EXPR_FLOATING_LITERAL
A FloatingLiteral record.
Definition: ASTBitCodes.h:1616
@ STMT_NULL_PTR
A NULL expression.
Definition: ASTBitCodes.h:1538
@ STMT_DEFAULT
A DefaultStmt record.
Definition: ASTBitCodes.h:1553
@ EXPR_CHOOSE
A ChooseExpr record.
Definition: ASTBitCodes.h:1706
@ STMT_NULL
A NullStmt record.
Definition: ASTBitCodes.h:1544
@ EXPR_BLOCK
BlockExpr.
Definition: ASTBitCodes.h:1724
@ EXPR_DECL_REF
A DeclRefExpr record.
Definition: ASTBitCodes.h:1610
@ EXPR_INIT_LIST
An InitListExpr record.
Definition: ASTBitCodes.h:1676
@ EXPR_IMPLICIT_VALUE_INIT
An ImplicitValueInitExpr record.
Definition: ASTBitCodes.h:1694
@ EXPR_PAREN
A ParenExpr record.
Definition: ASTBitCodes.h:1628
@ STMT_LABEL
A LabelStmt record.
Definition: ASTBitCodes.h:1556
@ EXPR_CXX_FUNCTIONAL_CAST
A CXXFunctionalCastExpr record.
Definition: ASTBitCodes.h:1849
@ EXPR_USER_DEFINED_LITERAL
A UserDefinedLiteral record.
Definition: ASTBitCodes.h:1855
@ EXPR_INTEGER_LITERAL
An IntegerLiteral record.
Definition: ASTBitCodes.h:1613
@ EXPR_CXX_MEMBER_CALL
A CXXMemberCallExpr record.
Definition: ASTBitCodes.h:1819
@ STMT_SWITCH
A SwitchStmt record.
Definition: ASTBitCodes.h:1565
@ STMT_DECL
A DeclStmt record.
Definition: ASTBitCodes.h:1592
@ EXPR_OBJC_KVC_REF_EXPR
UNUSED.
Definition: ASTBitCodes.h:1766
@ EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK
Definition: ASTBitCodes.h:1900
@ EXPR_SIZEOF_ALIGN_OF
A SizefAlignOfExpr record.
Definition: ASTBitCodes.h:1640
@ STMT_BREAK
A BreakStmt record.
Definition: ASTBitCodes.h:1586
@ STMT_OBJC_AT_THROW
An ObjCAtThrowStmt record.
Definition: ASTBitCodes.h:1793
@ EXPR_ADDR_LABEL
An AddrLabelExpr record.
Definition: ASTBitCodes.h:1700
@ STMT_CXX_FOR_RANGE
A CXXForRangeStmt record.
Definition: ASTBitCodes.h:1813
@ EXPR_CXX_ADDRSPACE_CAST
A CXXAddrspaceCastExpr record.
Definition: ASTBitCodes.h:1846
@ EXPR_ARRAY_SUBSCRIPT
An ArraySubscriptExpr record.
Definition: ASTBitCodes.h:1643
@ EXPR_UNARY_OPERATOR
A UnaryOperator record.
Definition: ASTBitCodes.h:1634
@ STMT_CXX_CATCH
A CXXCatchStmt record.
Definition: ASTBitCodes.h:1807
@ STMT_INDIRECT_GOTO
An IndirectGotoStmt record.
Definition: ASTBitCodes.h:1580
Defines the clang::TargetInfo interface.
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:90
bool isModuleMap(CharacteristicKind CK)
Determine whether a file characteristic is for a module map.
Definition: SourceManager.h:95
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1171
uint64_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:88
@ EXTENSION_METADATA
Metadata describing this particular extension.
Definition: ASTBitCodes.h:431
@ SUBMODULE_EXCLUDED_HEADER
Specifies a header that has been explicitly excluded from this submodule.
Definition: ASTBitCodes.h:844
@ SUBMODULE_TOPHEADER
Specifies a top-level header that falls into this (sub)module.
Definition: ASTBitCodes.h:826
@ SUBMODULE_PRIVATE_TEXTUAL_HEADER
Specifies a header that is private to this submodule but must be textually included.
Definition: ASTBitCodes.h:864
@ SUBMODULE_HEADER
Specifies a header that falls into this (sub)module.
Definition: ASTBitCodes.h:823
@ SUBMODULE_EXPORT_AS
Specifies the name of the module that will eventually re-export the entities in this module.
Definition: ASTBitCodes.h:872
@ SUBMODULE_UMBRELLA_DIR
Specifies an umbrella directory.
Definition: ASTBitCodes.h:829
@ SUBMODULE_UMBRELLA_HEADER
Specifies the umbrella header used to create this module, if any.
Definition: ASTBitCodes.h:820
@ SUBMODULE_METADATA
Metadata for submodules as a whole.
Definition: ASTBitCodes.h:812
@ SUBMODULE_REQUIRES
Specifies a required feature.
Definition: ASTBitCodes.h:840
@ SUBMODULE_PRIVATE_HEADER
Specifies a header that is private to this submodule.
Definition: ASTBitCodes.h:856
@ SUBMODULE_IMPORTS
Specifies the submodules that are imported by this submodule.
Definition: ASTBitCodes.h:833
@ SUBMODULE_CONFLICT
Specifies a conflict with another module.
Definition: ASTBitCodes.h:853
@ SUBMODULE_INITIALIZERS
Specifies some declarations with initializers that must be emitted to initialize the module.
Definition: ASTBitCodes.h:868
@ SUBMODULE_DEFINITION
Defines the major attributes of a submodule, including its name and parent.
Definition: ASTBitCodes.h:816
@ SUBMODULE_LINK_LIBRARY
Specifies a library or framework to link against.
Definition: ASTBitCodes.h:847
@ SUBMODULE_CONFIG_MACRO
Specifies a configuration macro for this module.
Definition: ASTBitCodes.h:850
@ SUBMODULE_EXPORTS
Specifies the submodules that are re-exported from this submodule.
Definition: ASTBitCodes.h:837
@ SUBMODULE_TEXTUAL_HEADER
Specifies a header that is part of the module but must be textually included.
Definition: ASTBitCodes.h:860
@ SUBMODULE_AFFECTING_MODULES
Specifies affecting modules that were not imported.
Definition: ASTBitCodes.h:875
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT)
Definition: ASTCommon.cpp:29
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:66
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:185
@ FILE_SYSTEM_OPTIONS
Record code for the filesystem options table.
Definition: ASTBitCodes.h:395
@ TARGET_OPTIONS
Record code for the target options table.
Definition: ASTBitCodes.h:392
@ PREPROCESSOR_OPTIONS
Record code for the preprocessor options table.
Definition: ASTBitCodes.h:401
@ HEADER_SEARCH_OPTIONS
Record code for the headers search options table.
Definition: ASTBitCodes.h:398
@ LANGUAGE_OPTIONS
Record code for the language options table.
Definition: ASTBitCodes.h:389
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:167
const unsigned int NUM_PREDEF_PP_ENTITY_IDS
The number of predefined preprocessed entity IDs.
Definition: ASTBitCodes.h:289
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:182
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:188
@ SUBMODULE_BLOCK_ID
The block containing the submodule structure.
Definition: ASTBitCodes.h:314
@ PREPROCESSOR_DETAIL_BLOCK_ID
The block containing the detailed preprocessing record.
Definition: ASTBitCodes.h:311
@ AST_BLOCK_ID
The AST block, which acts as a container around the full AST block.
Definition: ASTBitCodes.h:296
@ SOURCE_MANAGER_BLOCK_ID
The block containing information about the source manager.
Definition: ASTBitCodes.h:300
@ CONTROL_BLOCK_ID
The control block, which contains all of the information that needs to be validated prior to committi...
Definition: ASTBitCodes.h:322
@ DECLTYPES_BLOCK_ID
The block containing the definitions of all of the types and decls used within the AST file.
Definition: ASTBitCodes.h:308
@ PREPROCESSOR_BLOCK_ID
The block containing information about the preprocessor.
Definition: ASTBitCodes.h:304
@ COMMENTS_BLOCK_ID
The block containing comments.
Definition: ASTBitCodes.h:317
@ UNHASHED_CONTROL_BLOCK_ID
A block with unhashed content.
Definition: ASTBitCodes.h:344
@ EXTENSION_BLOCK_ID
A block containing a module file extension.
Definition: ASTBitCodes.h:338
@ OPTIONS_BLOCK_ID
The block of configuration options, used to check that a module is being used in a configuration comp...
Definition: ASTBitCodes.h:335
@ INPUT_FILES_BLOCK_ID
The block of input files, which were used as inputs to create this AST file.
Definition: ASTBitCodes.h:328
unsigned StableHashForTemplateArguments(llvm::ArrayRef< TemplateArgument > Args)
Calculate a stable hash value for template arguments.
const unsigned VERSION_MINOR
AST file minor version number supported by this version of Clang.
Definition: ASTBitCodes.h:57
@ SM_SLOC_FILE_ENTRY
Describes a source location entry (SLocEntry) for a file.
Definition: ASTBitCodes.h:749
@ SM_SLOC_BUFFER_BLOB_COMPRESSED
Describes a zlib-compressed blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:763
@ SM_SLOC_BUFFER_ENTRY
Describes a source location entry (SLocEntry) for a buffer.
Definition: ASTBitCodes.h:753
@ SM_SLOC_BUFFER_BLOB
Describes a blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:759
@ SM_SLOC_EXPANSION_ENTRY
Describes a source location entry (SLocEntry) for a macro expansion.
Definition: ASTBitCodes.h:767
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:170
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:472
const unsigned VERSION_MAJOR
AST file major version number supported by this version of Clang.
Definition: ASTBitCodes.h:47
DeclIDBase::DeclID DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:70
@ PP_TOKEN
Describes one token.
Definition: ASTBitCodes.h:786
@ PP_MACRO_FUNCTION_LIKE
A function-like macro definition.
Definition: ASTBitCodes.h:782
@ PP_MACRO_OBJECT_LIKE
An object-like macro definition.
Definition: ASTBitCodes.h:777
@ PP_MACRO_DIRECTIVE_HISTORY
The macro directives history for a particular identifier.
Definition: ASTBitCodes.h:789
@ PP_MODULE_MACRO
A macro directive exported by a module.
Definition: ASTBitCodes.h:793
void numberAnonymousDeclsWithin(const DeclContext *DC, Fn Visit)
Visit each declaration within DC that needs an anonymous declaration number and call Visit with the d...
Definition: ASTCommon.h:72
@ MODULE_MAP_FILE
Record code for the module map file that was used to build this AST file.
Definition: ASTBitCodes.h:374
@ MODULE_DIRECTORY
Record code for the module build directory.
Definition: ASTBitCodes.h:377
@ ORIGINAL_FILE_ID
Record code for file ID of the file or buffer that was used to generate the AST file.
Definition: ASTBitCodes.h:363
@ MODULE_NAME
Record code for the module name.
Definition: ASTBitCodes.h:370
@ ORIGINAL_FILE
Record code for the original file that was used to generate the AST file, including both its file ID ...
Definition: ASTBitCodes.h:359
@ INPUT_FILE_OFFSETS
Offsets into the input-files block where input files reside.
Definition: ASTBitCodes.h:367
@ METADATA
AST file metadata, including the AST file version number and information about the compiler used to b...
Definition: ASTBitCodes.h:351
@ DIAGNOSTIC_OPTIONS
Record code for the diagnostic options table.
Definition: ASTBitCodes.h:413
@ HEADER_SEARCH_ENTRY_USAGE
Record code for the indices of used header search entries.
Definition: ASTBitCodes.h:422
@ AST_BLOCK_HASH
Record code for the content hash of the AST block.
Definition: ASTBitCodes.h:410
@ DIAG_PRAGMA_MAPPINGS
Record code for #pragma diagnostic mappings.
Definition: ASTBitCodes.h:419
@ SIGNATURE
Record code for the signature that identifiers this AST file.
Definition: ASTBitCodes.h:407
@ HEADER_SEARCH_PATHS
Record code for the headers search paths.
Definition: ASTBitCodes.h:416
@ VFS_USAGE
Record code for the indices of used VFSs.
Definition: ASTBitCodes.h:425
@ INPUT_FILE_HASH
The input file content hash.
Definition: ASTBitCodes.h:444
@ INPUT_FILE
An input file.
Definition: ASTBitCodes.h:441
const DeclContext * getDefinitiveDeclContext(const DeclContext *DC)
Retrieve the "definitive" declaration that provides all of the visible entries for the given declarat...
Definition: ASTCommon.cpp:309
void updateModuleTimestamp(StringRef ModuleFilename)
Definition: ASTCommon.cpp:510
@ PPD_INCLUSION_DIRECTIVE
Describes an inclusion directive within the preprocessing record.
Definition: ASTBitCodes.h:806
@ PPD_MACRO_EXPANSION
Describes a macro expansion within the preprocessing record.
Definition: ASTBitCodes.h:799
@ PPD_MACRO_DEFINITION
Describes a macro definition within the preprocessing record.
Definition: ASTBitCodes.h:802
uint64_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:63
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:164
@ DECL_UPDATE_OFFSETS
Record for offsets of DECL_UPDATES records for declarations that were modified after being deserializ...
Definition: ASTBitCodes.h:589
@ STATISTICS
Record code for the extra statistics we gather while generating an AST file.
Definition: ASTBitCodes.h:523
@ FLOAT_CONTROL_PRAGMA_OPTIONS
Record code for #pragma float_control options.
Definition: ASTBitCodes.h:709
@ KNOWN_NAMESPACES
Record code for the set of known namespaces, which are used for typo correction.
Definition: ASTBitCodes.h:615
@ SPECIAL_TYPES
Record code for the set of non-builtin, special types.
Definition: ASTBitCodes.h:519
@ PENDING_IMPLICIT_INSTANTIATIONS
Record code for pending implicit instantiations.
Definition: ASTBitCodes.h:578
@ TYPE_OFFSET
Record code for the offsets of each type.
Definition: ASTBitCodes.h:461
@ DELEGATING_CTORS
The list of delegating constructor declarations.
Definition: ASTBitCodes.h:611
@ PP_ASSUME_NONNULL_LOC
ID 66 used to be the list of included files.
Definition: ASTBitCodes.h:715
@ EXT_VECTOR_DECLS
Record code for the set of ext_vector type names.
Definition: ASTBitCodes.h:548
@ OPENCL_EXTENSIONS
Record code for enabled OpenCL extensions.
Definition: ASTBitCodes.h:608
@ FP_PRAGMA_OPTIONS
Record code for floating point #pragma options.
Definition: ASTBitCodes.h:605
@ PP_UNSAFE_BUFFER_USAGE
Record code for #pragma clang unsafe_buffer_usage begin/end.
Definition: ASTBitCodes.h:722
@ CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION
Definition: ASTBitCodes.h:740
@ DECLS_WITH_EFFECTS_TO_VERIFY
Record code for Sema's vector of functions/blocks with effects to be verified.
Definition: ASTBitCodes.h:733
@ VTABLE_USES
Record code for the array of VTable uses.
Definition: ASTBitCodes.h:558
@ LATE_PARSED_TEMPLATE
Record code for late parsed template functions.
Definition: ASTBitCodes.h:665
@ DECLS_TO_CHECK_FOR_DEFERRED_DIAGS
Record code for the Decls to be checked for deferred diags.
Definition: ASTBitCodes.h:706
@ DECL_OFFSET
Record code for the offsets of each decl.
Definition: ASTBitCodes.h:473
@ SOURCE_MANAGER_LINE_TABLE
Record code for the source manager line table information, which stores information about #line direc...
Definition: ASTBitCodes.h:625
@ PP_COUNTER_VALUE
The value of the next COUNTER to dispense.
Definition: ASTBitCodes.h:539
@ DELETE_EXPRS_TO_ANALYZE
Delete expressions that will be analyzed later.
Definition: ASTBitCodes.h:676
@ RELATED_DECLS_MAP
Record code for related declarations that have to be deserialized together from the same module.
Definition: ASTBitCodes.h:729
@ UPDATE_VISIBLE
Record code for an update to a decl context's lookup table.
Definition: ASTBitCodes.h:585
@ CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH
Number of unmatched #pragma clang cuda_force_host_device begin directives we've seen.
Definition: ASTBitCodes.h:686
@ MACRO_OFFSET
Record code for the table of offsets of each macro ID.
Definition: ASTBitCodes.h:653
@ PPD_ENTITIES_OFFSETS
Record code for the table of offsets to entries in the preprocessing record.
Definition: ASTBitCodes.h:555
@ OPENCL_EXTENSION_DECLS
Record code for declarations associated with OpenCL extensions.
Definition: ASTBitCodes.h:692
@ VTABLES_TO_EMIT
Record code for vtables to emit.
Definition: ASTBitCodes.h:725
@ IDENTIFIER_OFFSET
Record code for the table of offsets of each identifier ID.
Definition: ASTBitCodes.h:481
@ OBJC_CATEGORIES
Record code for the array of Objective-C categories (including extensions).
Definition: ASTBitCodes.h:646
@ METHOD_POOL
Record code for the Objective-C method pool,.
Definition: ASTBitCodes.h:535
@ DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD
Record code for lexical and visible block for delayed namespace in reduced BMI.
Definition: ASTBitCodes.h:719
@ PP_CONDITIONAL_STACK
The stack of open #ifs/#ifdefs recorded in a preamble.
Definition: ASTBitCodes.h:700
@ REFERENCED_SELECTOR_POOL
Record code for referenced selector pool.
Definition: ASTBitCodes.h:563
@ SOURCE_LOCATION_OFFSETS
Record code for the table of offsets into the block of source-location information.
Definition: ASTBitCodes.h:543
@ WEAK_UNDECLARED_IDENTIFIERS
Record code for weak undeclared identifiers.
Definition: ASTBitCodes.h:575
@ UNDEFINED_BUT_USED
Record code for undefined but used functions and variables that need a definition in this TU.
Definition: ASTBitCodes.h:662
@ FILE_SORTED_DECLS
Record code for a file sorted array of DeclIDs in a module.
Definition: ASTBitCodes.h:632
@ MSSTRUCT_PRAGMA_OPTIONS
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:679
@ TENTATIVE_DEFINITIONS
Record code for the array of tentative definitions.
Definition: ASTBitCodes.h:526
@ UNUSED_FILESCOPED_DECLS
Record code for the array of unused file scoped decls.
Definition: ASTBitCodes.h:551
@ ALIGN_PACK_PRAGMA_OPTIONS
Record code for #pragma align/pack options.
Definition: ASTBitCodes.h:697
@ IMPORTED_MODULES
Record code for an array of all of the (sub)modules that were imported by the AST file.
Definition: ASTBitCodes.h:636
@ SELECTOR_OFFSETS
Record code for the table of offsets into the Objective-C method pool.
Definition: ASTBitCodes.h:532
@ UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES
Record code for potentially unused local typedef names.
Definition: ASTBitCodes.h:671
@ OPENCL_EXTENSION_TYPES
Record code for types associated with OpenCL extensions.
Definition: ASTBitCodes.h:689
@ EAGERLY_DESERIALIZED_DECLS
Record code for the array of eagerly deserialized decls.
Definition: ASTBitCodes.h:510
@ INTERESTING_IDENTIFIERS
A list of "interesting" identifiers.
Definition: ASTBitCodes.h:658
@ HEADER_SEARCH_TABLE
Record code for header search information.
Definition: ASTBitCodes.h:602
@ OBJC_CATEGORIES_MAP
Record code for map of Objective-C class definition IDs to the ObjC categories in a module that are a...
Definition: ASTBitCodes.h:629
@ METADATA_OLD_FORMAT
This is so that older clang versions, before the introduction of the control block,...
Definition: ASTBitCodes.h:486
@ CUDA_SPECIAL_DECL_REFS
Record code for special CUDA declarations.
Definition: ASTBitCodes.h:599
@ TU_UPDATE_LEXICAL
Record code for an update to the TU's lexically contained declarations.
Definition: ASTBitCodes.h:567
@ PPD_SKIPPED_RANGES
A table of skipped ranges within the preprocessing record.
Definition: ASTBitCodes.h:703
@ IDENTIFIER_TABLE
Record code for the identifier table.
Definition: ASTBitCodes.h:500
@ SEMA_DECL_REFS
Record code for declarations that Sema keeps references of.
Definition: ASTBitCodes.h:572
@ OPTIMIZE_PRAGMA_OPTIONS
Record code for #pragma optimize options.
Definition: ASTBitCodes.h:668
@ MODULE_OFFSET_MAP
Record code for the remapping information used to relate loaded modules to the various offsets and ID...
Definition: ASTBitCodes.h:621
@ POINTERS_TO_MEMBERS_PRAGMA_OPTIONS
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:682
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:154
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:297
@ UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER
Definition: ASTCommon.h:33
@ UPD_DECL_MARKED_OPENMP_DECLARETARGET
Definition: ASTCommon.h:42
@ UPD_CXX_POINT_OF_INSTANTIATION
Definition: ASTCommon.h:30
@ UPD_CXX_RESOLVED_EXCEPTION_SPEC
Definition: ASTCommon.h:35
@ UPD_CXX_ADDED_FUNCTION_DEFINITION
Definition: ASTCommon.h:28
@ UPD_DECL_MARKED_OPENMP_THREADPRIVATE
Definition: ASTCommon.h:40
@ UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT
Definition: ASTCommon.h:32
@ UPD_DECL_MARKED_OPENMP_ALLOCATE
Definition: ASTCommon.h:41
@ UPD_CXX_ADDED_ANONYMOUS_NAMESPACE
Definition: ASTCommon.h:27
@ UPD_CXX_INSTANTIATED_CLASS_DEFINITION
Definition: ASTCommon.h:31
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
Definition: RangeSelector.h:41
std::shared_ptr< MatchComputation< T > > Generator
Definition: RewriteRule.h:65
The JSON file list parser is used to communicate input to InstallAPI.
@ NUM_OVERLOADED_OPERATORS
Definition: OperatorKinds.h:26
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:212
@ CPlusPlus
Definition: LangStandard.h:55
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_VLAType
Capturing variable-length array type.
Definition: Lambda.h:38
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
@ Auto
'auto' clause, allowed on 'loop' directives.
@ Bind
'bind' clause, allowed on routine constructs.
@ Gang
'gang' clause, allowed on 'loop' and Combined constructs.
@ Wait
'wait' clause, allowed on Compute, Data, 'update', and Combined constructs.
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ PCopyOut
'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
@ VectorLength
'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', and 'kernels loop' constru...
@ Async
'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined constructs.
@ PresentOrCreate
'create' clause alias 'present_or_create'.
@ Collapse
'collapse' clause, allowed on 'loop' and Combined constructs.
@ NoHost
'nohost' clause, allowed on 'routine' directives.
@ PresentOrCopy
'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.
@ DeviceNum
'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Copy
'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Worker
'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ DeviceType
'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown', 'set', update',...
@ DefaultAsync
'default_async' clause, allowed on 'set' construct.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ NumGangs
'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs.
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
@ Default
'default' clause, allowed on parallel, serial, kernel (and compound) constructs.
@ UseDevice
'use_device' clause, allowed on 'host_data' construct.
@ NoCreate
'no_create' clause, allowed on allowed on Compute and Combined constructs, plus 'data'.
@ PresentOrCopyOut
'copyout' clause alias 'present_or_copyout'.
@ Link
'link' clause, allowed on 'declare' construct.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ CopyOut
'copyout' clause, allowed on Compute and Combined constructs, plus 'data', 'exit data',...
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
@ FirstPrivate
'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...
@ Host
'host' clause, allowed on 'update' construct.
@ PCopy
'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.
@ Tile
'tile' clause, allowed on 'loop' and Combined constructs.
@ PCopyIn
'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
@ DeviceResident
'device_resident' clause, allowed on the 'declare' construct.
@ PCreate
'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
@ Present
'present' clause, allowed on Compute and Combined constructs, plus 'data' and 'declare'.
@ DType
'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.
@ CopyIn
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Device
'device' clause, allowed on the 'update' construct.
@ Independent
'independent' clause, allowed on 'loop' directives.
@ NumWorkers
'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs...
@ IfPresent
'if_present' clause, allowed on 'host_data' and 'update' directives.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
@ Delete
'delete' clause, allowed on the 'exit data' construct.
@ PresentOrCopyIn
'copyin' clause alias 'present_or_copyin'.
@ Finalize
'finalize' clause, allowed on 'exit data' directive.
static constexpr unsigned NumberOfOMPMapClauseModifiers
Number of allowed map-type-modifiers.
Definition: OpenMPKinds.h:88
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
PredefinedDeclIDs
Predefined declaration IDs.
Definition: DeclID.h:31
@ PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID
The internal '__NSConstantString' tag type.
Definition: DeclID.h:81
@ PREDEF_DECL_COMMON_TYPE_ID
The internal '__builtin_common_type' template.
Definition: DeclID.h:87
@ PREDEF_DECL_TRANSLATION_UNIT_ID
The translation unit.
Definition: DeclID.h:36
@ PREDEF_DECL_TYPE_PACK_ELEMENT_ID
The internal '__type_pack_element' template.
Definition: DeclID.h:84
@ PREDEF_DECL_OBJC_CLASS_ID
The Objective-C 'Class' type.
Definition: DeclID.h:45
@ PREDEF_DECL_BUILTIN_MS_GUID_ID
The predeclared '_GUID' struct.
Definition: DeclID.h:69
@ PREDEF_DECL_OBJC_INSTANCETYPE_ID
The internal 'instancetype' typedef.
Definition: DeclID.h:57
@ PREDEF_DECL_OBJC_PROTOCOL_ID
The Objective-C 'Protocol' type.
Definition: DeclID.h:48
@ PREDEF_DECL_UNSIGNED_INT_128_ID
The unsigned 128-bit integer type.
Definition: DeclID.h:54
@ PREDEF_DECL_OBJC_SEL_ID
The Objective-C 'SEL' type.
Definition: DeclID.h:42
@ PREDEF_DECL_INT_128_ID
The signed 128-bit integer type.
Definition: DeclID.h:51
@ PREDEF_DECL_VA_LIST_TAG
The internal '__va_list_tag' struct, if any.
Definition: DeclID.h:63
@ PREDEF_DECL_BUILTIN_MS_VA_LIST_ID
The internal '__builtin_ms_va_list' typedef.
Definition: DeclID.h:66
@ PREDEF_DECL_CF_CONSTANT_STRING_ID
The internal '__NSConstantString' typedef.
Definition: DeclID.h:78
@ PREDEF_DECL_BUILTIN_VA_LIST_ID
The internal '__builtin_va_list' typedef.
Definition: DeclID.h:60
@ PREDEF_DECL_EXTERN_C_CONTEXT_ID
The extern "C" context.
Definition: DeclID.h:72
@ PREDEF_DECL_OBJC_ID_ID
The Objective-C 'id' type.
Definition: DeclID.h:39
@ PREDEF_DECL_MAKE_INTEGER_SEQ_ID
The internal '__make_integer_seq' template.
Definition: DeclID.h:75
@ Property
The type of a property.
@ Result
The result type of a method or function.
bool CanElideDeclDef(const Decl *D)
If we can elide the definition of.
std::pair< IdentifierInfo *, SourceLocation > DeviceTypeArgument
static constexpr unsigned NumberOfOMPMotionModifiers
Number of allowed motion-modifiers.
Definition: OpenMPKinds.h:100
std::optional< unsigned > getPrimaryModuleHash(const Module *M)
Calculate a hash value for the primary module name of the given module.
@ PMSST_ON
Definition: PragmaKinds.h:25
@ PMSST_OFF
Definition: PragmaKinds.h:24
for(const auto &A :T->param_types())
const FunctionProtoType * T
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:68
@ None
The alignment was not explicit in code.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
unsigned long uint64_t
unsigned int uint32_t
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
The signature of a module, which is a hash of the AST content.
Definition: Module.h:58
static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)
Definition: Module.h:76
static ASTFileSignature createDummy()
Definition: Module.h:86
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:691
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:700
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:688
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:694
bool ParseAllComments
Treat ordinary comments as documentation comments.
BlockCommandNamesTy BlockCommandNames
Command names to treat as block commands in comments.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
const DeclarationNameLoc & getInfo() const
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition: Decl.h:847
The preprocessor keeps track of this information for each file that is #included.
Definition: HeaderSearch.h:59
unsigned isModuleHeader
Whether this header is part of and built with a module.
Definition: HeaderSearch.h:92
unsigned isCompilingModuleHeader
Whether this header is part of the module that we are building, even if it doesn't build with the mod...
Definition: HeaderSearch.h:104
unsigned IsLocallyIncluded
True if this file has been included (or imported) locally.
Definition: HeaderSearch.h:64
frontend::IncludeDirGroup Group
unsigned IgnoreSysRoot
IgnoreSysRoot - This is false if an absolute path should be treated relative to the sysroot,...
Contains a late templated function.
Definition: Sema.h:15183
CachedTokens Toks
Definition: Sema.h:15184
FPOptions FPO
Floating-point options in the point of definition.
Definition: Sema.h:15188
Decl * D
The template function declaration to be late parsed.
Definition: Sema.h:15186
Data for list of allocators.
a linked list of methods with the same selector name but different signatures.
ObjCMethodList * getNext() const
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:708
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition: Decl.h:722
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:709
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition: Decl.h:715
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:2071