clang  8.0.0
ASTWriter.cpp
Go to the documentation of this file.
1 //===- ASTWriter.cpp - AST File Writer ------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ASTWriter class, which writes AST files.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "ASTCommon.h"
16 #include "ASTReaderInternals.h"
17 #include "MultiOnDiskHashTable.h"
18 #include "clang/AST/ASTContext.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"
25 #include "clang/AST/DeclFriend.h"
26 #include "clang/AST/DeclObjC.h"
27 #include "clang/AST/DeclTemplate.h"
29 #include "clang/AST/Expr.h"
30 #include "clang/AST/ExprCXX.h"
34 #include "clang/AST/TemplateName.h"
35 #include "clang/AST/Type.h"
37 #include "clang/Basic/Diagnostic.h"
42 #include "clang/Basic/LLVM.h"
43 #include "clang/Basic/Lambda.h"
46 #include "clang/Basic/Module.h"
52 #include "clang/Basic/Specifiers.h"
53 #include "clang/Basic/TargetInfo.h"
55 #include "clang/Basic/Version.h"
56 #include "clang/Lex/HeaderSearch.h"
58 #include "clang/Lex/MacroInfo.h"
59 #include "clang/Lex/ModuleMap.h"
61 #include "clang/Lex/Preprocessor.h"
63 #include "clang/Lex/Token.h"
66 #include "clang/Sema/Sema.h"
67 #include "clang/Sema/Weak.h"
72 #include "llvm/ADT/APFloat.h"
73 #include "llvm/ADT/APInt.h"
74 #include "llvm/ADT/APSInt.h"
75 #include "llvm/ADT/ArrayRef.h"
76 #include "llvm/ADT/DenseMap.h"
77 #include "llvm/ADT/Hashing.h"
78 #include "llvm/ADT/Optional.h"
79 #include "llvm/ADT/PointerIntPair.h"
80 #include "llvm/ADT/STLExtras.h"
81 #include "llvm/ADT/ScopeExit.h"
82 #include "llvm/ADT/SmallSet.h"
83 #include "llvm/ADT/SmallString.h"
84 #include "llvm/ADT/SmallVector.h"
85 #include "llvm/ADT/StringMap.h"
86 #include "llvm/ADT/StringRef.h"
87 #include "llvm/Bitcode/BitCodes.h"
88 #include "llvm/Bitcode/BitstreamWriter.h"
89 #include "llvm/Support/Casting.h"
90 #include "llvm/Support/Compression.h"
91 #include "llvm/Support/DJB.h"
92 #include "llvm/Support/Endian.h"
93 #include "llvm/Support/EndianStream.h"
94 #include "llvm/Support/Error.h"
95 #include "llvm/Support/ErrorHandling.h"
96 #include "llvm/Support/MemoryBuffer.h"
97 #include "llvm/Support/OnDiskHashTable.h"
98 #include "llvm/Support/Path.h"
99 #include "llvm/Support/SHA1.h"
100 #include "llvm/Support/VersionTuple.h"
101 #include "llvm/Support/raw_ostream.h"
102 #include <algorithm>
103 #include <cassert>
104 #include <cstdint>
105 #include <cstdlib>
106 #include <cstring>
107 #include <ctime>
108 #include <deque>
109 #include <limits>
110 #include <memory>
111 #include <queue>
112 #include <tuple>
113 #include <utility>
114 #include <vector>
115 
116 using namespace clang;
117 using namespace clang::serialization;
118 
119 template <typename T, typename Allocator>
120 static StringRef bytes(const std::vector<T, Allocator> &v) {
121  if (v.empty()) return StringRef();
122  return StringRef(reinterpret_cast<const char*>(&v[0]),
123  sizeof(T) * v.size());
124 }
125 
126 template <typename T>
127 static StringRef bytes(const SmallVectorImpl<T> &v) {
128  return StringRef(reinterpret_cast<const char*>(v.data()),
129  sizeof(T) * v.size());
130 }
131 
132 //===----------------------------------------------------------------------===//
133 // Type serialization
134 //===----------------------------------------------------------------------===//
135 
136 namespace clang {
137 
139  ASTWriter &Writer;
140  ASTRecordWriter Record;
141 
142  /// Type code that corresponds to the record generated.
143  TypeCode Code = static_cast<TypeCode>(0);
144 
145  /// Abbreviation to use for the record, if any.
146  unsigned AbbrevToUse = 0;
147 
148  public:
150  : Writer(Writer), Record(Writer, Record) {}
151 
152  uint64_t Emit() {
153  return Record.Emit(Code, AbbrevToUse);
154  }
155 
156  void Visit(QualType T) {
157  if (T.hasLocalNonFastQualifiers()) {
160  Record.push_back(Qs.getAsOpaqueValue());
161  Code = TYPE_EXT_QUAL;
162  AbbrevToUse = Writer.TypeExtQualAbbrev;
163  } else {
164  switch (T->getTypeClass()) {
165  // For all of the concrete, non-dependent types, call the
166  // appropriate visitor function.
167 #define TYPE(Class, Base) \
168  case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break;
169 #define ABSTRACT_TYPE(Class, Base)
170 #include "clang/AST/TypeNodes.def"
171  }
172  }
173  }
174 
175  void VisitArrayType(const ArrayType *T);
176  void VisitFunctionType(const FunctionType *T);
177  void VisitTagType(const TagType *T);
178 
179 #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T);
180 #define ABSTRACT_TYPE(Class, Base)
181 #include "clang/AST/TypeNodes.def"
182  };
183 
184 } // namespace clang
185 
186 void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) {
187  llvm_unreachable("Built-in types are never serialized");
188 }
189 
190 void ASTTypeWriter::VisitComplexType(const ComplexType *T) {
191  Record.AddTypeRef(T->getElementType());
192  Code = TYPE_COMPLEX;
193 }
194 
195 void ASTTypeWriter::VisitPointerType(const PointerType *T) {
196  Record.AddTypeRef(T->getPointeeType());
197  Code = TYPE_POINTER;
198 }
199 
200 void ASTTypeWriter::VisitDecayedType(const DecayedType *T) {
201  Record.AddTypeRef(T->getOriginalType());
202  Code = TYPE_DECAYED;
203 }
204 
205 void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) {
206  Record.AddTypeRef(T->getOriginalType());
207  Record.AddTypeRef(T->getAdjustedType());
208  Code = TYPE_ADJUSTED;
209 }
210 
211 void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) {
212  Record.AddTypeRef(T->getPointeeType());
213  Code = TYPE_BLOCK_POINTER;
214 }
215 
216 void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) {
217  Record.AddTypeRef(T->getPointeeTypeAsWritten());
218  Record.push_back(T->isSpelledAsLValue());
219  Code = TYPE_LVALUE_REFERENCE;
220 }
221 
222 void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) {
223  Record.AddTypeRef(T->getPointeeTypeAsWritten());
224  Code = TYPE_RVALUE_REFERENCE;
225 }
226 
227 void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) {
228  Record.AddTypeRef(T->getPointeeType());
229  Record.AddTypeRef(QualType(T->getClass(), 0));
230  Code = TYPE_MEMBER_POINTER;
231 }
232 
234  Record.AddTypeRef(T->getElementType());
235  Record.push_back(T->getSizeModifier()); // FIXME: stable values
236  Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values
237 }
238 
239 void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) {
240  VisitArrayType(T);
241  Record.AddAPInt(T->getSize());
242  Code = TYPE_CONSTANT_ARRAY;
243 }
244 
245 void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
246  VisitArrayType(T);
247  Code = TYPE_INCOMPLETE_ARRAY;
248 }
249 
250 void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) {
251  VisitArrayType(T);
252  Record.AddSourceLocation(T->getLBracketLoc());
253  Record.AddSourceLocation(T->getRBracketLoc());
254  Record.AddStmt(T->getSizeExpr());
255  Code = TYPE_VARIABLE_ARRAY;
256 }
257 
258 void ASTTypeWriter::VisitVectorType(const VectorType *T) {
259  Record.AddTypeRef(T->getElementType());
260  Record.push_back(T->getNumElements());
261  Record.push_back(T->getVectorKind());
262  Code = TYPE_VECTOR;
263 }
264 
265 void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) {
266  VisitVectorType(T);
267  Code = TYPE_EXT_VECTOR;
268 }
269 
271  Record.AddTypeRef(T->getReturnType());
273  Record.push_back(C.getNoReturn());
274  Record.push_back(C.getHasRegParm());
275  Record.push_back(C.getRegParm());
276  // FIXME: need to stabilize encoding of calling convention...
277  Record.push_back(C.getCC());
278  Record.push_back(C.getProducesResult());
279  Record.push_back(C.getNoCallerSavedRegs());
280  Record.push_back(C.getNoCfCheck());
281 
282  if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult())
283  AbbrevToUse = 0;
284 }
285 
286 void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
287  VisitFunctionType(T);
288  Code = TYPE_FUNCTION_NO_PROTO;
289 }
290 
291 static void addExceptionSpec(const FunctionProtoType *T,
292  ASTRecordWriter &Record) {
293  Record.push_back(T->getExceptionSpecType());
294  if (T->getExceptionSpecType() == EST_Dynamic) {
295  Record.push_back(T->getNumExceptions());
296  for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I)
297  Record.AddTypeRef(T->getExceptionType(I));
298  } else if (isComputedNoexcept(T->getExceptionSpecType())) {
299  Record.AddStmt(T->getNoexceptExpr());
300  } else if (T->getExceptionSpecType() == EST_Uninstantiated) {
301  Record.AddDeclRef(T->getExceptionSpecDecl());
303  } else if (T->getExceptionSpecType() == EST_Unevaluated) {
304  Record.AddDeclRef(T->getExceptionSpecDecl());
305  }
306 }
307 
308 void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) {
309  VisitFunctionType(T);
310 
311  Record.push_back(T->isVariadic());
312  Record.push_back(T->hasTrailingReturn());
313  Record.push_back(T->getTypeQuals().getAsOpaqueValue());
314  Record.push_back(static_cast<unsigned>(T->getRefQualifier()));
315  addExceptionSpec(T, Record);
316 
317  Record.push_back(T->getNumParams());
318  for (unsigned I = 0, N = T->getNumParams(); I != N; ++I)
319  Record.AddTypeRef(T->getParamType(I));
320 
321  if (T->hasExtParameterInfos()) {
322  for (unsigned I = 0, N = T->getNumParams(); I != N; ++I)
323  Record.push_back(T->getExtParameterInfo(I).getOpaqueValue());
324  }
325 
326  if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() ||
329  AbbrevToUse = 0;
330 
331  Code = TYPE_FUNCTION_PROTO;
332 }
333 
334 void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
335  Record.AddDeclRef(T->getDecl());
336  Code = TYPE_UNRESOLVED_USING;
337 }
338 
339 void ASTTypeWriter::VisitTypedefType(const TypedefType *T) {
340  Record.AddDeclRef(T->getDecl());
341  assert(!T->isCanonicalUnqualified() && "Invalid typedef ?");
342  Record.AddTypeRef(T->getCanonicalTypeInternal());
343  Code = TYPE_TYPEDEF;
344 }
345 
346 void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) {
347  Record.AddStmt(T->getUnderlyingExpr());
348  Code = TYPE_TYPEOF_EXPR;
349 }
350 
351 void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) {
352  Record.AddTypeRef(T->getUnderlyingType());
353  Code = TYPE_TYPEOF;
354 }
355 
356 void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) {
357  Record.AddTypeRef(T->getUnderlyingType());
358  Record.AddStmt(T->getUnderlyingExpr());
359  Code = TYPE_DECLTYPE;
360 }
361 
362 void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) {
363  Record.AddTypeRef(T->getBaseType());
364  Record.AddTypeRef(T->getUnderlyingType());
365  Record.push_back(T->getUTTKind());
366  Code = TYPE_UNARY_TRANSFORM;
367 }
368 
369 void ASTTypeWriter::VisitAutoType(const AutoType *T) {
370  Record.AddTypeRef(T->getDeducedType());
371  Record.push_back((unsigned)T->getKeyword());
372  if (T->getDeducedType().isNull())
373  Record.push_back(T->isDependentType());
374  Code = TYPE_AUTO;
375 }
376 
377 void ASTTypeWriter::VisitDeducedTemplateSpecializationType(
379  Record.AddTemplateName(T->getTemplateName());
380  Record.AddTypeRef(T->getDeducedType());
381  if (T->getDeducedType().isNull())
382  Record.push_back(T->isDependentType());
384 }
385 
387  Record.push_back(T->isDependentType());
388  Record.AddDeclRef(T->getDecl()->getCanonicalDecl());
389  assert(!T->isBeingDefined() &&
390  "Cannot serialize in the middle of a type definition");
391 }
392 
393 void ASTTypeWriter::VisitRecordType(const RecordType *T) {
394  VisitTagType(T);
395  Code = TYPE_RECORD;
396 }
397 
398 void ASTTypeWriter::VisitEnumType(const EnumType *T) {
399  VisitTagType(T);
400  Code = TYPE_ENUM;
401 }
402 
403 void ASTTypeWriter::VisitAttributedType(const AttributedType *T) {
404  Record.AddTypeRef(T->getModifiedType());
405  Record.AddTypeRef(T->getEquivalentType());
406  Record.push_back(T->getAttrKind());
407  Code = TYPE_ATTRIBUTED;
408 }
409 
410 void
411 ASTTypeWriter::VisitSubstTemplateTypeParmType(
412  const SubstTemplateTypeParmType *T) {
413  Record.AddTypeRef(QualType(T->getReplacedParameter(), 0));
414  Record.AddTypeRef(T->getReplacementType());
416 }
417 
418 void
419 ASTTypeWriter::VisitSubstTemplateTypeParmPackType(
421  Record.AddTypeRef(QualType(T->getReplacedParameter(), 0));
422  Record.AddTemplateArgument(T->getArgumentPack());
424 }
425 
426 void
427 ASTTypeWriter::VisitTemplateSpecializationType(
428  const TemplateSpecializationType *T) {
429  Record.push_back(T->isDependentType());
430  Record.AddTemplateName(T->getTemplateName());
431  Record.push_back(T->getNumArgs());
432  for (const auto &ArgI : *T)
433  Record.AddTemplateArgument(ArgI);
434  Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType()
435  : T->isCanonicalUnqualified()
436  ? QualType()
437  : T->getCanonicalTypeInternal());
439 }
440 
441 void
442 ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
443  VisitArrayType(T);
444  Record.AddStmt(T->getSizeExpr());
445  Record.AddSourceRange(T->getBracketsRange());
447 }
448 
449 void
450 ASTTypeWriter::VisitDependentSizedExtVectorType(
451  const DependentSizedExtVectorType *T) {
452  Record.AddTypeRef(T->getElementType());
453  Record.AddStmt(T->getSizeExpr());
454  Record.AddSourceLocation(T->getAttributeLoc());
456 }
457 
458 void ASTTypeWriter::VisitDependentVectorType(const DependentVectorType *T) {
459  Record.AddTypeRef(T->getElementType());
460  Record.AddStmt(const_cast<Expr*>(T->getSizeExpr()));
461  Record.AddSourceLocation(T->getAttributeLoc());
462  Record.push_back(T->getVectorKind());
464 }
465 
466 void
467 ASTTypeWriter::VisitDependentAddressSpaceType(
468  const DependentAddressSpaceType *T) {
469  Record.AddTypeRef(T->getPointeeType());
470  Record.AddStmt(T->getAddrSpaceExpr());
471  Record.AddSourceLocation(T->getAttributeLoc());
473 }
474 
475 void
476 ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
477  Record.push_back(T->getDepth());
478  Record.push_back(T->getIndex());
479  Record.push_back(T->isParameterPack());
480  Record.AddDeclRef(T->getDecl());
482 }
483 
484 void
485 ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) {
486  Record.push_back(T->getKeyword());
487  Record.AddNestedNameSpecifier(T->getQualifier());
488  Record.AddIdentifierRef(T->getIdentifier());
489  Record.AddTypeRef(
491  Code = TYPE_DEPENDENT_NAME;
492 }
493 
494 void
495 ASTTypeWriter::VisitDependentTemplateSpecializationType(
497  Record.push_back(T->getKeyword());
498  Record.AddNestedNameSpecifier(T->getQualifier());
499  Record.AddIdentifierRef(T->getIdentifier());
500  Record.push_back(T->getNumArgs());
501  for (const auto &I : *T)
502  Record.AddTemplateArgument(I);
504 }
505 
506 void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) {
507  Record.AddTypeRef(T->getPattern());
508  if (Optional<unsigned> NumExpansions = T->getNumExpansions())
509  Record.push_back(*NumExpansions + 1);
510  else
511  Record.push_back(0);
512  Code = TYPE_PACK_EXPANSION;
513 }
514 
515 void ASTTypeWriter::VisitParenType(const ParenType *T) {
516  Record.AddTypeRef(T->getInnerType());
517  Code = TYPE_PAREN;
518 }
519 
520 void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) {
521  Record.push_back(T->getKeyword());
522  Record.AddNestedNameSpecifier(T->getQualifier());
523  Record.AddTypeRef(T->getNamedType());
524  Record.AddDeclRef(T->getOwnedTagDecl());
525  Code = TYPE_ELABORATED;
526 }
527 
528 void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
529  Record.AddDeclRef(T->getDecl()->getCanonicalDecl());
530  Record.AddTypeRef(T->getInjectedSpecializationType());
532 }
533 
534 void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
535  Record.AddDeclRef(T->getDecl()->getCanonicalDecl());
536  Code = TYPE_OBJC_INTERFACE;
537 }
538 
539 void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) {
540  Record.AddDeclRef(T->getDecl());
541  Record.push_back(T->getNumProtocols());
542  for (const auto *I : T->quals())
543  Record.AddDeclRef(I);
544  Code = TYPE_OBJC_TYPE_PARAM;
545 }
546 
547 void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) {
548  Record.AddTypeRef(T->getBaseType());
549  Record.push_back(T->getTypeArgsAsWritten().size());
550  for (auto TypeArg : T->getTypeArgsAsWritten())
551  Record.AddTypeRef(TypeArg);
552  Record.push_back(T->getNumProtocols());
553  for (const auto *I : T->quals())
554  Record.AddDeclRef(I);
555  Record.push_back(T->isKindOfTypeAsWritten());
556  Code = TYPE_OBJC_OBJECT;
557 }
558 
559 void
560 ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
561  Record.AddTypeRef(T->getPointeeType());
563 }
564 
565 void
566 ASTTypeWriter::VisitAtomicType(const AtomicType *T) {
567  Record.AddTypeRef(T->getValueType());
568  Code = TYPE_ATOMIC;
569 }
570 
571 void
572 ASTTypeWriter::VisitPipeType(const PipeType *T) {
573  Record.AddTypeRef(T->getElementType());
574  Record.push_back(T->isReadOnly());
575  Code = TYPE_PIPE;
576 }
577 
578 namespace {
579 
580 class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> {
581  ASTRecordWriter &Record;
582 
583 public:
584  TypeLocWriter(ASTRecordWriter &Record) : Record(Record) {}
585 
586 #define ABSTRACT_TYPELOC(CLASS, PARENT)
587 #define TYPELOC(CLASS, PARENT) \
588  void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
589 #include "clang/AST/TypeLocNodes.def"
590 
591  void VisitArrayTypeLoc(ArrayTypeLoc TyLoc);
592  void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc);
593 };
594 
595 } // namespace
596 
597 void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
598  // nothing to do
599 }
600 
601 void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
602  Record.AddSourceLocation(TL.getBuiltinLoc());
603  if (TL.needsExtraLocalData()) {
604  Record.push_back(TL.getWrittenTypeSpec());
605  Record.push_back(TL.getWrittenSignSpec());
606  Record.push_back(TL.getWrittenWidthSpec());
607  Record.push_back(TL.hasModeAttr());
608  }
609 }
610 
611 void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) {
612  Record.AddSourceLocation(TL.getNameLoc());
613 }
614 
615 void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
616  Record.AddSourceLocation(TL.getStarLoc());
617 }
618 
619 void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
620  // nothing to do
621 }
622 
623 void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
624  // nothing to do
625 }
626 
627 void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
628  Record.AddSourceLocation(TL.getCaretLoc());
629 }
630 
631 void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
632  Record.AddSourceLocation(TL.getAmpLoc());
633 }
634 
635 void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
636  Record.AddSourceLocation(TL.getAmpAmpLoc());
637 }
638 
639 void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
640  Record.AddSourceLocation(TL.getStarLoc());
641  Record.AddTypeSourceInfo(TL.getClassTInfo());
642 }
643 
644 void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) {
645  Record.AddSourceLocation(TL.getLBracketLoc());
646  Record.AddSourceLocation(TL.getRBracketLoc());
647  Record.push_back(TL.getSizeExpr() ? 1 : 0);
648  if (TL.getSizeExpr())
649  Record.AddStmt(TL.getSizeExpr());
650 }
651 
652 void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
653  VisitArrayTypeLoc(TL);
654 }
655 
656 void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
657  VisitArrayTypeLoc(TL);
658 }
659 
660 void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
661  VisitArrayTypeLoc(TL);
662 }
663 
664 void TypeLocWriter::VisitDependentSizedArrayTypeLoc(
666  VisitArrayTypeLoc(TL);
667 }
668 
669 void TypeLocWriter::VisitDependentAddressSpaceTypeLoc(
671  Record.AddSourceLocation(TL.getAttrNameLoc());
673  Record.AddSourceLocation(range.getBegin());
674  Record.AddSourceLocation(range.getEnd());
675  Record.AddStmt(TL.getAttrExprOperand());
676 }
677 
678 void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
680  Record.AddSourceLocation(TL.getNameLoc());
681 }
682 
683 void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
684  Record.AddSourceLocation(TL.getNameLoc());
685 }
686 
687 void TypeLocWriter::VisitDependentVectorTypeLoc(
689  Record.AddSourceLocation(TL.getNameLoc());
690 }
691 
692 void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
693  Record.AddSourceLocation(TL.getNameLoc());
694 }
695 
696 void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
697  Record.AddSourceLocation(TL.getLocalRangeBegin());
698  Record.AddSourceLocation(TL.getLParenLoc());
699  Record.AddSourceLocation(TL.getRParenLoc());
700  Record.AddSourceRange(TL.getExceptionSpecRange());
701  Record.AddSourceLocation(TL.getLocalRangeEnd());
702  for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i)
703  Record.AddDeclRef(TL.getParam(i));
704 }
705 
706 void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
707  VisitFunctionTypeLoc(TL);
708 }
709 
710 void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
711  VisitFunctionTypeLoc(TL);
712 }
713 
714 void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
715  Record.AddSourceLocation(TL.getNameLoc());
716 }
717 
718 void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
719  Record.AddSourceLocation(TL.getNameLoc());
720 }
721 
722 void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
723  if (TL.getNumProtocols()) {
724  Record.AddSourceLocation(TL.getProtocolLAngleLoc());
725  Record.AddSourceLocation(TL.getProtocolRAngleLoc());
726  }
727  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
728  Record.AddSourceLocation(TL.getProtocolLoc(i));
729 }
730 
731 void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
732  Record.AddSourceLocation(TL.getTypeofLoc());
733  Record.AddSourceLocation(TL.getLParenLoc());
734  Record.AddSourceLocation(TL.getRParenLoc());
735 }
736 
737 void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
738  Record.AddSourceLocation(TL.getTypeofLoc());
739  Record.AddSourceLocation(TL.getLParenLoc());
740  Record.AddSourceLocation(TL.getRParenLoc());
741  Record.AddTypeSourceInfo(TL.getUnderlyingTInfo());
742 }
743 
744 void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
745  Record.AddSourceLocation(TL.getNameLoc());
746 }
747 
748 void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
749  Record.AddSourceLocation(TL.getKWLoc());
750  Record.AddSourceLocation(TL.getLParenLoc());
751  Record.AddSourceLocation(TL.getRParenLoc());
752  Record.AddTypeSourceInfo(TL.getUnderlyingTInfo());
753 }
754 
755 void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) {
756  Record.AddSourceLocation(TL.getNameLoc());
757 }
758 
759 void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
761  Record.AddSourceLocation(TL.getTemplateNameLoc());
762 }
763 
764 void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) {
765  Record.AddSourceLocation(TL.getNameLoc());
766 }
767 
768 void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) {
769  Record.AddSourceLocation(TL.getNameLoc());
770 }
771 
772 void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
773  Record.AddAttr(TL.getAttr());
774 }
775 
776 void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
777  Record.AddSourceLocation(TL.getNameLoc());
778 }
779 
780 void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc(
782  Record.AddSourceLocation(TL.getNameLoc());
783 }
784 
785 void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc(
787  Record.AddSourceLocation(TL.getNameLoc());
788 }
789 
790 void TypeLocWriter::VisitTemplateSpecializationTypeLoc(
792  Record.AddSourceLocation(TL.getTemplateKeywordLoc());
793  Record.AddSourceLocation(TL.getTemplateNameLoc());
794  Record.AddSourceLocation(TL.getLAngleLoc());
795  Record.AddSourceLocation(TL.getRAngleLoc());
796  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
797  Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(),
798  TL.getArgLoc(i).getLocInfo());
799 }
800 
801 void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) {
802  Record.AddSourceLocation(TL.getLParenLoc());
803  Record.AddSourceLocation(TL.getRParenLoc());
804 }
805 
806 void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
807  Record.AddSourceLocation(TL.getElaboratedKeywordLoc());
808  Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
809 }
810 
811 void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
812  Record.AddSourceLocation(TL.getNameLoc());
813 }
814 
815 void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
816  Record.AddSourceLocation(TL.getElaboratedKeywordLoc());
817  Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
818  Record.AddSourceLocation(TL.getNameLoc());
819 }
820 
821 void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc(
823  Record.AddSourceLocation(TL.getElaboratedKeywordLoc());
824  Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());
825  Record.AddSourceLocation(TL.getTemplateKeywordLoc());
826  Record.AddSourceLocation(TL.getTemplateNameLoc());
827  Record.AddSourceLocation(TL.getLAngleLoc());
828  Record.AddSourceLocation(TL.getRAngleLoc());
829  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
830  Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(),
831  TL.getArgLoc(I).getLocInfo());
832 }
833 
834 void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
835  Record.AddSourceLocation(TL.getEllipsisLoc());
836 }
837 
838 void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
839  Record.AddSourceLocation(TL.getNameLoc());
840 }
841 
842 void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
843  Record.push_back(TL.hasBaseTypeAsWritten());
844  Record.AddSourceLocation(TL.getTypeArgsLAngleLoc());
845  Record.AddSourceLocation(TL.getTypeArgsRAngleLoc());
846  for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i)
847  Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i));
848  Record.AddSourceLocation(TL.getProtocolLAngleLoc());
849  Record.AddSourceLocation(TL.getProtocolRAngleLoc());
850  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
851  Record.AddSourceLocation(TL.getProtocolLoc(i));
852 }
853 
854 void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
855  Record.AddSourceLocation(TL.getStarLoc());
856 }
857 
858 void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
859  Record.AddSourceLocation(TL.getKWLoc());
860  Record.AddSourceLocation(TL.getLParenLoc());
861  Record.AddSourceLocation(TL.getRParenLoc());
862 }
863 
864 void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) {
865  Record.AddSourceLocation(TL.getKWLoc());
866 }
867 
868 void ASTWriter::WriteTypeAbbrevs() {
869  using namespace llvm;
870 
871  std::shared_ptr<BitCodeAbbrev> Abv;
872 
873  // Abbreviation for TYPE_EXT_QUAL
874  Abv = std::make_shared<BitCodeAbbrev>();
875  Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL));
876  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
877  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals
878  TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv));
879 
880  // Abbreviation for TYPE_FUNCTION_PROTO
881  Abv = std::make_shared<BitCodeAbbrev>();
882  Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO));
883  // FunctionType
884  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType
885  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn
886  Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm
887  Abv->Add(BitCodeAbbrevOp(0)); // RegParm
888  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC
889  Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult
890  Abv->Add(BitCodeAbbrevOp(0)); // NoCallerSavedRegs
891  Abv->Add(BitCodeAbbrevOp(0)); // NoCfCheck
892  // FunctionProtoType
893  Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic
894  Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn
895  Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals
896  Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier
897  Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec
898  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams
899  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
900  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params
901  TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv));
902 }
903 
904 //===----------------------------------------------------------------------===//
905 // ASTWriter Implementation
906 //===----------------------------------------------------------------------===//
907 
908 static void EmitBlockID(unsigned ID, const char *Name,
909  llvm::BitstreamWriter &Stream,
910  ASTWriter::RecordDataImpl &Record) {
911  Record.clear();
912  Record.push_back(ID);
913  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
914 
915  // Emit the block name if present.
916  if (!Name || Name[0] == 0)
917  return;
918  Record.clear();
919  while (*Name)
920  Record.push_back(*Name++);
921  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
922 }
923 
924 static void EmitRecordID(unsigned ID, const char *Name,
925  llvm::BitstreamWriter &Stream,
926  ASTWriter::RecordDataImpl &Record) {
927  Record.clear();
928  Record.push_back(ID);
929  while (*Name)
930  Record.push_back(*Name++);
931  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
932 }
933 
934 static void AddStmtsExprs(llvm::BitstreamWriter &Stream,
935  ASTWriter::RecordDataImpl &Record) {
936 #define RECORD(X) EmitRecordID(X, #X, Stream, Record)
937  RECORD(STMT_STOP);
940  RECORD(STMT_NULL);
942  RECORD(STMT_CASE);
946  RECORD(STMT_IF);
949  RECORD(STMT_DO);
950  RECORD(STMT_FOR);
951  RECORD(STMT_GOTO);
956  RECORD(STMT_DECL);
971  RECORD(EXPR_CALL);
987  RECORD(EXPR_STMT);
1060 #undef RECORD
1061 }
1062 
1063 void ASTWriter::WriteBlockInfoBlock() {
1064  RecordData Record;
1065  Stream.EnterBlockInfoBlock();
1066 
1067 #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record)
1068 #define RECORD(X) EmitRecordID(X, #X, Stream, Record)
1069 
1070  // Control Block.
1071  BLOCK(CONTROL_BLOCK);
1072  RECORD(METADATA);
1076  RECORD(IMPORTS);
1081 
1082  BLOCK(OPTIONS_BLOCK);
1088 
1089  BLOCK(INPUT_FILES_BLOCK);
1090  RECORD(INPUT_FILE);
1091 
1092  // AST Top-Level Block.
1093  BLOCK(AST_BLOCK);
1101  RECORD(STATISTICS);
1146 
1147  // SourceManager Block.
1148  BLOCK(SOURCE_MANAGER_BLOCK);
1154 
1155  // Preprocessor Block.
1156  BLOCK(PREPROCESSOR_BLOCK);
1161  RECORD(PP_TOKEN);
1162 
1163  // Submodule Block.
1164  BLOCK(SUBMODULE_BLOCK);
1183 
1184  // Comments Block.
1185  BLOCK(COMMENTS_BLOCK);
1187 
1188  // Decls and Types block.
1189  BLOCK(DECLTYPES_BLOCK);
1208  RECORD(TYPE_ENUM);
1222  RECORD(TYPE_PAREN);
1226  RECORD(TYPE_AUTO);
1235  RECORD(DECL_ENUM);
1250  RECORD(DECL_FIELD);
1252  RECORD(DECL_VAR);
1256  RECORD(DECL_BLOCK);
1261  RECORD(DECL_USING);
1296  RECORD(DECL_EMPTY);
1302 
1303  // Statements and Exprs can occur in the Decls and Types block.
1304  AddStmtsExprs(Stream, Record);
1305 
1306  BLOCK(PREPROCESSOR_DETAIL_BLOCK);
1310 
1311  // Decls and Types block.
1312  BLOCK(EXTENSION_BLOCK);
1314 
1315  BLOCK(UNHASHED_CONTROL_BLOCK);
1316  RECORD(SIGNATURE);
1319 
1320 #undef RECORD
1321 #undef BLOCK
1322  Stream.ExitBlock();
1323 }
1324 
1325 /// Prepares a path for being written to an AST file by converting it
1326 /// to an absolute path and removing nested './'s.
1327 ///
1328 /// \return \c true if the path was changed.
1329 static bool cleanPathForOutput(FileManager &FileMgr,
1330  SmallVectorImpl<char> &Path) {
1331  bool Changed = FileMgr.makeAbsolutePath(Path);
1332  return Changed | llvm::sys::path::remove_dots(Path);
1333 }
1334 
1335 /// Adjusts the given filename to only write out the portion of the
1336 /// filename that is not part of the system root directory.
1337 ///
1338 /// \param Filename the file name to adjust.
1339 ///
1340 /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and
1341 /// the returned filename will be adjusted by this root directory.
1342 ///
1343 /// \returns either the original filename (if it needs no adjustment) or the
1344 /// adjusted filename (which points into the @p Filename parameter).
1345 static const char *
1346 adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) {
1347  assert(Filename && "No file name to adjust?");
1348 
1349  if (BaseDir.empty())
1350  return Filename;
1351 
1352  // Verify that the filename and the system root have the same prefix.
1353  unsigned Pos = 0;
1354  for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos)
1355  if (Filename[Pos] != BaseDir[Pos])
1356  return Filename; // Prefixes don't match.
1357 
1358  // We hit the end of the filename before we hit the end of the system root.
1359  if (!Filename[Pos])
1360  return Filename;
1361 
1362  // If there's not a path separator at the end of the base directory nor
1363  // immediately after it, then this isn't within the base directory.
1364  if (!llvm::sys::path::is_separator(Filename[Pos])) {
1365  if (!llvm::sys::path::is_separator(BaseDir.back()))
1366  return Filename;
1367  } else {
1368  // If the file name has a '/' at the current position, skip over the '/'.
1369  // We distinguish relative paths from absolute paths by the
1370  // absence of '/' at the beginning of relative paths.
1371  //
1372  // FIXME: This is wrong. We distinguish them by asking if the path is
1373  // absolute, which isn't the same thing. And there might be multiple '/'s
1374  // in a row. Use a better mechanism to indicate whether we have emitted an
1375  // absolute or relative path.
1376  ++Pos;
1377  }
1378 
1379  return Filename + Pos;
1380 }
1381 
1382 ASTFileSignature ASTWriter::createSignature(StringRef Bytes) {
1383  // Calculate the hash till start of UNHASHED_CONTROL_BLOCK.
1384  llvm::SHA1 Hasher;
1385  Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size()));
1386  auto Hash = Hasher.result();
1387 
1388  // Convert to an array [5*i32].
1389  ASTFileSignature Signature;
1390  auto LShift = [&](unsigned char Val, unsigned Shift) {
1391  return (uint32_t)Val << Shift;
1392  };
1393  for (int I = 0; I != 5; ++I)
1394  Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
1395  LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
1396 
1397  return Signature;
1398 }
1399 
1400 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
1401  ASTContext &Context) {
1402  // Flush first to prepare the PCM hash (signature).
1403  Stream.FlushToWord();
1404  auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3;
1405 
1406  // Enter the block and prepare to write records.
1407  RecordData Record;
1408  Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5);
1409 
1410  // For implicit modules, write the hash of the PCM as its signature.
1411  ASTFileSignature Signature;
1412  if (WritingModule &&
1414  Signature = createSignature(StringRef(Buffer.begin(), StartOfUnhashedControl));
1415  Record.append(Signature.begin(), Signature.end());
1416  Stream.EmitRecord(SIGNATURE, Record);
1417  Record.clear();
1418  }
1419 
1420  // Diagnostic options.
1421  const auto &Diags = Context.getDiagnostics();
1422  const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions();
1423 #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name);
1424 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
1425  Record.push_back(static_cast<unsigned>(DiagOpts.get##Name()));
1426 #include "clang/Basic/DiagnosticOptions.def"
1427  Record.push_back(DiagOpts.Warnings.size());
1428  for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I)
1429  AddString(DiagOpts.Warnings[I], Record);
1430  Record.push_back(DiagOpts.Remarks.size());
1431  for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I)
1432  AddString(DiagOpts.Remarks[I], Record);
1433  // Note: we don't serialize the log or serialization file names, because they
1434  // are generally transient files and will almost always be overridden.
1435  Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record);
1436 
1437  // Write out the diagnostic/pragma mappings.
1438  WritePragmaDiagnosticMappings(Diags, /* IsModule = */ WritingModule);
1439 
1440  // Leave the options block.
1441  Stream.ExitBlock();
1442  return Signature;
1443 }
1444 
1445 /// Write the control block.
1446 void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
1447  StringRef isysroot,
1448  const std::string &OutputFile) {
1449  using namespace llvm;
1450 
1451  Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
1452  RecordData Record;
1453 
1454  // Metadata
1455  auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>();
1456  MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA));
1457  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major
1458  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor
1459  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj.
1460  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min.
1461  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable
1462  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps
1463  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PCHHasObjectFile
1464  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors
1465  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag
1466  unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev));
1467  assert((!WritingModule || isysroot.empty()) &&
1468  "writing module as a relocatable PCH?");
1469  {
1470  RecordData::value_type Record[] = {
1471  METADATA,
1472  VERSION_MAJOR,
1473  VERSION_MINOR,
1474  CLANG_VERSION_MAJOR,
1475  CLANG_VERSION_MINOR,
1476  !isysroot.empty(),
1477  IncludeTimestamps,
1478  Context.getLangOpts().BuildingPCHWithObjectFile,
1479  ASTHasCompilerErrors};
1480  Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record,
1482  }
1483 
1484  if (WritingModule) {
1485  // Module name
1486  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1487  Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME));
1488  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
1489  unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1490  RecordData::value_type Record[] = {MODULE_NAME};
1491  Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name);
1492  }
1493 
1494  if (WritingModule && WritingModule->Directory) {
1495  SmallString<128> BaseDir(WritingModule->Directory->getName());
1496  cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
1497 
1498  // If the home of the module is the current working directory, then we
1499  // want to pick up the cwd of the build process loading the module, not
1500  // our cwd, when we load this module.
1501  if (!PP.getHeaderSearchInfo()
1504  WritingModule->Directory->getName() != StringRef(".")) {
1505  // Module directory.
1506  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1507  Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
1508  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
1509  unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1510 
1511  RecordData::value_type Record[] = {MODULE_DIRECTORY};
1512  Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
1513  }
1514 
1515  // Write out all other paths relative to the base directory if possible.
1516  BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
1517  } else if (!isysroot.empty()) {
1518  // Write out paths relative to the sysroot if possible.
1519  BaseDirectory = isysroot;
1520  }
1521 
1522  // Module map file
1523  if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) {
1524  Record.clear();
1525 
1526  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
1527  AddPath(WritingModule->PresumedModuleMapFile.empty()
1528  ? Map.getModuleMapFileForUniquing(WritingModule)->getName()
1529  : StringRef(WritingModule->PresumedModuleMapFile),
1530  Record);
1531 
1532  // Additional module map files.
1533  if (auto *AdditionalModMaps =
1534  Map.getAdditionalModuleMapFiles(WritingModule)) {
1535  Record.push_back(AdditionalModMaps->size());
1536  for (const FileEntry *F : *AdditionalModMaps)
1537  AddPath(F->getName(), Record);
1538  } else {
1539  Record.push_back(0);
1540  }
1541 
1542  Stream.EmitRecord(MODULE_MAP_FILE, Record);
1543  }
1544 
1545  // Imports
1546  if (Chain) {
1547  serialization::ModuleManager &Mgr = Chain->getModuleManager();
1548  Record.clear();
1549 
1550  for (ModuleFile &M : Mgr) {
1551  // Skip modules that weren't directly imported.
1552  if (!M.isDirectlyImported())
1553  continue;
1554 
1555  Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding
1556  AddSourceLocation(M.ImportLoc, Record);
1557 
1558  // If we have calculated signature, there is no need to store
1559  // the size or timestamp.
1560  Record.push_back(M.Signature ? 0 : M.File->getSize());
1561  Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File));
1562 
1563  for (auto I : M.Signature)
1564  Record.push_back(I);
1565 
1566  AddString(M.ModuleName, Record);
1567  AddPath(M.FileName, Record);
1568  }
1569  Stream.EmitRecord(IMPORTS, Record);
1570  }
1571 
1572  // Write the options block.
1573  Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4);
1574 
1575  // Language options.
1576  Record.clear();
1577  const LangOptions &LangOpts = Context.getLangOpts();
1578 #define LANGOPT(Name, Bits, Default, Description) \
1579  Record.push_back(LangOpts.Name);
1580 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
1581  Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
1582 #include "clang/Basic/LangOptions.def"
1583 #define SANITIZER(NAME, ID) \
1584  Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID));
1585 #include "clang/Basic/Sanitizers.def"
1586 
1587  Record.push_back(LangOpts.ModuleFeatures.size());
1588  for (StringRef Feature : LangOpts.ModuleFeatures)
1589  AddString(Feature, Record);
1590 
1591  Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind());
1592  AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record);
1593 
1594  AddString(LangOpts.CurrentModule, Record);
1595 
1596  // Comment options.
1597  Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size());
1598  for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) {
1599  AddString(I, Record);
1600  }
1601  Record.push_back(LangOpts.CommentOpts.ParseAllComments);
1602 
1603  // OpenMP offloading options.
1604  Record.push_back(LangOpts.OMPTargetTriples.size());
1605  for (auto &T : LangOpts.OMPTargetTriples)
1606  AddString(T.getTriple(), Record);
1607 
1608  AddString(LangOpts.OMPHostIRFile, Record);
1609 
1610  Stream.EmitRecord(LANGUAGE_OPTIONS, Record);
1611 
1612  // Target options.
1613  Record.clear();
1614  const TargetInfo &Target = Context.getTargetInfo();
1615  const TargetOptions &TargetOpts = Target.getTargetOpts();
1616  AddString(TargetOpts.Triple, Record);
1617  AddString(TargetOpts.CPU, Record);
1618  AddString(TargetOpts.ABI, Record);
1619  Record.push_back(TargetOpts.FeaturesAsWritten.size());
1620  for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) {
1621  AddString(TargetOpts.FeaturesAsWritten[I], Record);
1622  }
1623  Record.push_back(TargetOpts.Features.size());
1624  for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) {
1625  AddString(TargetOpts.Features[I], Record);
1626  }
1627  Stream.EmitRecord(TARGET_OPTIONS, Record);
1628 
1629  // File system options.
1630  Record.clear();
1631  const FileSystemOptions &FSOpts =
1633  AddString(FSOpts.WorkingDir, Record);
1634  Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
1635 
1636  // Header search options.
1637  Record.clear();
1638  const HeaderSearchOptions &HSOpts
1640  AddString(HSOpts.Sysroot, Record);
1641 
1642  // Include entries.
1643  Record.push_back(HSOpts.UserEntries.size());
1644  for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) {
1645  const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I];
1646  AddString(Entry.Path, Record);
1647  Record.push_back(static_cast<unsigned>(Entry.Group));
1648  Record.push_back(Entry.IsFramework);
1649  Record.push_back(Entry.IgnoreSysRoot);
1650  }
1651 
1652  // System header prefixes.
1653  Record.push_back(HSOpts.SystemHeaderPrefixes.size());
1654  for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) {
1655  AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record);
1656  Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader);
1657  }
1658 
1659  AddString(HSOpts.ResourceDir, Record);
1660  AddString(HSOpts.ModuleCachePath, Record);
1661  AddString(HSOpts.ModuleUserBuildPath, Record);
1662  Record.push_back(HSOpts.DisableModuleHash);
1663  Record.push_back(HSOpts.ImplicitModuleMaps);
1664  Record.push_back(HSOpts.ModuleMapFileHomeIsCwd);
1665  Record.push_back(HSOpts.UseBuiltinIncludes);
1666  Record.push_back(HSOpts.UseStandardSystemIncludes);
1667  Record.push_back(HSOpts.UseStandardCXXIncludes);
1668  Record.push_back(HSOpts.UseLibcxx);
1669  // Write out the specific module cache path that contains the module files.
1670  AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record);
1671  Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record);
1672 
1673  // Preprocessor options.
1674  Record.clear();
1675  const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts();
1676 
1677  // Macro definitions.
1678  Record.push_back(PPOpts.Macros.size());
1679  for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) {
1680  AddString(PPOpts.Macros[I].first, Record);
1681  Record.push_back(PPOpts.Macros[I].second);
1682  }
1683 
1684  // Includes
1685  Record.push_back(PPOpts.Includes.size());
1686  for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I)
1687  AddString(PPOpts.Includes[I], Record);
1688 
1689  // Macro includes
1690  Record.push_back(PPOpts.MacroIncludes.size());
1691  for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I)
1692  AddString(PPOpts.MacroIncludes[I], Record);
1693 
1694  Record.push_back(PPOpts.UsePredefines);
1695  // Detailed record is important since it is used for the module cache hash.
1696  Record.push_back(PPOpts.DetailedRecord);
1697  AddString(PPOpts.ImplicitPCHInclude, Record);
1698  Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary));
1699  Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record);
1700 
1701  // Leave the options block.
1702  Stream.ExitBlock();
1703 
1704  // Original file name and file ID
1705  SourceManager &SM = Context.getSourceManager();
1706  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
1707  auto FileAbbrev = std::make_shared<BitCodeAbbrev>();
1708  FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE));
1709  FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID
1710  FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
1711  unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev));
1712 
1713  Record.clear();
1714  Record.push_back(ORIGINAL_FILE);
1715  Record.push_back(SM.getMainFileID().getOpaqueValue());
1716  EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName());
1717  }
1718 
1719  Record.clear();
1720  Record.push_back(SM.getMainFileID().getOpaqueValue());
1721  Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
1722 
1723  // Original PCH directory
1724  if (!OutputFile.empty() && OutputFile != "-") {
1725  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1726  Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR));
1727  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
1728  unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1729 
1730  SmallString<128> OutputPath(OutputFile);
1731 
1732  SM.getFileManager().makeAbsolutePath(OutputPath);
1733  StringRef origDir = llvm::sys::path::parent_path(OutputPath);
1734 
1735  RecordData::value_type Record[] = {ORIGINAL_PCH_DIR};
1736  Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
1737  }
1738 
1739  WriteInputFiles(Context.SourceMgr,
1741  PP.getLangOpts().Modules);
1742  Stream.ExitBlock();
1743 }
1744 
1745 namespace {
1746 
1747 /// An input file.
1748 struct InputFileEntry {
1749  const FileEntry *File;
1750  bool IsSystemFile;
1751  bool IsTransient;
1752  bool BufferOverridden;
1753  bool IsTopLevelModuleMap;
1754 };
1755 
1756 } // namespace
1757 
1758 void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
1759  HeaderSearchOptions &HSOpts,
1760  bool Modules) {
1761  using namespace llvm;
1762 
1763  Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
1764 
1765  // Create input-file abbreviation.
1766  auto IFAbbrev = std::make_shared<BitCodeAbbrev>();
1767  IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE));
1768  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
1769  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size
1770  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time
1771  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden
1772  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient
1773  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map
1774  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
1775  unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev));
1776 
1777  // Get all ContentCache objects for files, sorted by whether the file is a
1778  // system one or not. System files go at the back, users files at the front.
1779  std::deque<InputFileEntry> SortedFiles;
1780  for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) {
1781  // Get this source location entry.
1782  const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I);
1783  assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc);
1784 
1785  // We only care about file entries that were not overridden.
1786  if (!SLoc->isFile())
1787  continue;
1788  const SrcMgr::FileInfo &File = SLoc->getFile();
1789  const SrcMgr::ContentCache *Cache = File.getContentCache();
1790  if (!Cache->OrigEntry)
1791  continue;
1792 
1793  InputFileEntry Entry;
1794  Entry.File = Cache->OrigEntry;
1795  Entry.IsSystemFile = Cache->IsSystemFile;
1796  Entry.IsTransient = Cache->IsTransient;
1797  Entry.BufferOverridden = Cache->BufferOverridden;
1798  Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) &&
1799  File.getIncludeLoc().isInvalid();
1800  if (Cache->IsSystemFile)
1801  SortedFiles.push_back(Entry);
1802  else
1803  SortedFiles.push_front(Entry);
1804  }
1805 
1806  unsigned UserFilesNum = 0;
1807  // Write out all of the input files.
1808  std::vector<uint64_t> InputFileOffsets;
1809  for (const auto &Entry : SortedFiles) {
1810  uint32_t &InputFileID = InputFileIDs[Entry.File];
1811  if (InputFileID != 0)
1812  continue; // already recorded this file.
1813 
1814  // Record this entry's offset.
1815  InputFileOffsets.push_back(Stream.GetCurrentBitNo());
1816 
1817  InputFileID = InputFileOffsets.size();
1818 
1819  if (!Entry.IsSystemFile)
1820  ++UserFilesNum;
1821 
1822  // Emit size/modification time for this file.
1823  // And whether this file was overridden.
1824  RecordData::value_type Record[] = {
1825  INPUT_FILE,
1826  InputFileOffsets.size(),
1827  (uint64_t)Entry.File->getSize(),
1828  (uint64_t)getTimestampForOutput(Entry.File),
1829  Entry.BufferOverridden,
1830  Entry.IsTransient,
1831  Entry.IsTopLevelModuleMap};
1832 
1833  EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName());
1834  }
1835 
1836  Stream.ExitBlock();
1837 
1838  // Create input file offsets abbreviation.
1839  auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>();
1840  OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS));
1841  OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files
1842  OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system
1843  // input files
1844  OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array
1845  unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev));
1846 
1847  // Write input file offsets.
1848  RecordData::value_type Record[] = {INPUT_FILE_OFFSETS,
1849  InputFileOffsets.size(), UserFilesNum};
1850  Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets));
1851 }
1852 
1853 //===----------------------------------------------------------------------===//
1854 // Source Manager Serialization
1855 //===----------------------------------------------------------------------===//
1856 
1857 /// Create an abbreviation for the SLocEntry that refers to a
1858 /// file.
1859 static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) {
1860  using namespace llvm;
1861 
1862  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1863  Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY));
1864  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1865  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
1866  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic
1867  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
1868  // FileEntry fields.
1869  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID
1870  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs
1871  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex
1872  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls
1873  return Stream.EmitAbbrev(std::move(Abbrev));
1874 }
1875 
1876 /// Create an abbreviation for the SLocEntry that refers to a
1877 /// buffer.
1878 static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) {
1879  using namespace llvm;
1880 
1881  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1882  Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY));
1883  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1884  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
1885  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic
1886  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
1887  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob
1888  return Stream.EmitAbbrev(std::move(Abbrev));
1889 }
1890 
1891 /// Create an abbreviation for the SLocEntry that refers to a
1892 /// buffer's blob.
1893 static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream,
1894  bool Compressed) {
1895  using namespace llvm;
1896 
1897  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1898  Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED
1899  : SM_SLOC_BUFFER_BLOB));
1900  if (Compressed)
1901  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size
1902  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob
1903  return Stream.EmitAbbrev(std::move(Abbrev));
1904 }
1905 
1906 /// Create an abbreviation for the SLocEntry that refers to a macro
1907 /// expansion.
1908 static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) {
1909  using namespace llvm;
1910 
1911  auto Abbrev = std::make_shared<BitCodeAbbrev>();
1912  Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY));
1913  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
1914  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location
1915  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location
1916  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location
1917  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is token range
1918  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length
1919  return Stream.EmitAbbrev(std::move(Abbrev));
1920 }
1921 
1922 namespace {
1923 
1924  // Trait used for the on-disk hash table of header search information.
1925  class HeaderFileInfoTrait {
1926  ASTWriter &Writer;
1927 
1928  // Keep track of the framework names we've used during serialization.
1929  SmallVector<char, 128> FrameworkStringData;
1930  llvm::StringMap<unsigned> FrameworkNameOffset;
1931 
1932  public:
1933  HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {}
1934 
1935  struct key_type {
1936  StringRef Filename;
1937  off_t Size;
1938  time_t ModTime;
1939  };
1940  using key_type_ref = const key_type &;
1941 
1942  using UnresolvedModule =
1943  llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>;
1944 
1945  struct data_type {
1946  const HeaderFileInfo &HFI;
1947  ArrayRef<ModuleMap::KnownHeader> KnownHeaders;
1948  UnresolvedModule Unresolved;
1949  };
1950  using data_type_ref = const data_type &;
1951 
1952  using hash_value_type = unsigned;
1953  using offset_type = unsigned;
1954 
1955  hash_value_type ComputeHash(key_type_ref key) {
1956  // The hash is based only on size/time of the file, so that the reader can
1957  // match even when symlinking or excess path elements ("foo/../", "../")
1958  // change the form of the name. However, complete path is still the key.
1959  return llvm::hash_combine(key.Size, key.ModTime);
1960  }
1961 
1962  std::pair<unsigned, unsigned>
1963  EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
1964  using namespace llvm::support;
1965 
1966  endian::Writer LE(Out, little);
1967  unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
1968  LE.write<uint16_t>(KeyLen);
1969  unsigned DataLen = 1 + 2 + 4 + 4;
1970  for (auto ModInfo : Data.KnownHeaders)
1971  if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
1972  DataLen += 4;
1973  if (Data.Unresolved.getPointer())
1974  DataLen += 4;
1975  LE.write<uint8_t>(DataLen);
1976  return std::make_pair(KeyLen, DataLen);
1977  }
1978 
1979  void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) {
1980  using namespace llvm::support;
1981 
1982  endian::Writer LE(Out, little);
1983  LE.write<uint64_t>(key.Size);
1984  KeyLen -= 8;
1985  LE.write<uint64_t>(key.ModTime);
1986  KeyLen -= 8;
1987  Out.write(key.Filename.data(), KeyLen);
1988  }
1989 
1990  void EmitData(raw_ostream &Out, key_type_ref key,
1991  data_type_ref Data, unsigned DataLen) {
1992  using namespace llvm::support;
1993 
1994  endian::Writer LE(Out, little);
1995  uint64_t Start = Out.tell(); (void)Start;
1996 
1997  unsigned char Flags = (Data.HFI.isImport << 5)
1998  | (Data.HFI.isPragmaOnce << 4)
1999  | (Data.HFI.DirInfo << 1)
2000  | Data.HFI.IndexHeaderMapHeader;
2001  LE.write<uint8_t>(Flags);
2002  LE.write<uint16_t>(Data.HFI.NumIncludes);
2003 
2004  if (!Data.HFI.ControllingMacro)
2005  LE.write<uint32_t>(Data.HFI.ControllingMacroID);
2006  else
2007  LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro));
2008 
2009  unsigned Offset = 0;
2010  if (!Data.HFI.Framework.empty()) {
2011  // If this header refers into a framework, save the framework name.
2012  llvm::StringMap<unsigned>::iterator Pos
2013  = FrameworkNameOffset.find(Data.HFI.Framework);
2014  if (Pos == FrameworkNameOffset.end()) {
2015  Offset = FrameworkStringData.size() + 1;
2016  FrameworkStringData.append(Data.HFI.Framework.begin(),
2017  Data.HFI.Framework.end());
2018  FrameworkStringData.push_back(0);
2019 
2020  FrameworkNameOffset[Data.HFI.Framework] = Offset;
2021  } else
2022  Offset = Pos->second;
2023  }
2024  LE.write<uint32_t>(Offset);
2025 
2026  auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
2027  if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
2028  uint32_t Value = (ModID << 2) | (unsigned)Role;
2029  assert((Value >> 2) == ModID && "overflow in header module info");
2030  LE.write<uint32_t>(Value);
2031  }
2032  };
2033 
2034  // FIXME: If the header is excluded, we should write out some
2035  // record of that fact.
2036  for (auto ModInfo : Data.KnownHeaders)
2037  EmitModule(ModInfo.getModule(), ModInfo.getRole());
2038  if (Data.Unresolved.getPointer())
2039  EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
2040 
2041  assert(Out.tell() - Start == DataLen && "Wrong data length");
2042  }
2043 
2044  const char *strings_begin() const { return FrameworkStringData.begin(); }
2045  const char *strings_end() const { return FrameworkStringData.end(); }
2046  };
2047 
2048 } // namespace
2049 
2050 /// Write the header search block for the list of files that
2051 ///
2052 /// \param HS The header search structure to save.
2053 void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
2054  HeaderFileInfoTrait GeneratorTrait(*this);
2055  llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator;
2056  SmallVector<const char *, 4> SavedStrings;
2057  unsigned NumHeaderSearchEntries = 0;
2058 
2059  // Find all unresolved headers for the current module. We generally will
2060  // have resolved them before we get here, but not necessarily: we might be
2061  // compiling a preprocessed module, where there is no requirement for the
2062  // original files to exist any more.
2063  const HeaderFileInfo Empty; // So we can take a reference.
2064  if (WritingModule) {
2065  llvm::SmallVector<Module *, 16> Worklist(1, WritingModule);
2066  while (!Worklist.empty()) {
2067  Module *M = Worklist.pop_back_val();
2068  if (!M->isAvailable())
2069  continue;
2070 
2071  // Map to disk files where possible, to pick up any missing stat
2072  // information. This also means we don't need to check the unresolved
2073  // headers list when emitting resolved headers in the first loop below.
2074  // FIXME: It'd be preferable to avoid doing this if we were given
2075  // sufficient stat information in the module map.
2077 
2078  // If the file didn't exist, we can still create a module if we were given
2079  // enough information in the module map.
2080  for (auto U : M->MissingHeaders) {
2081  // Check that we were given enough information to build a module
2082  // without this file existing on disk.
2083  if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
2084  PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header)
2085  << WritingModule->getFullModuleName() << U.Size.hasValue()
2086  << U.FileName;
2087  continue;
2088  }
2089 
2090  // Form the effective relative pathname for the file.
2092  llvm::sys::path::append(Filename, U.FileName);
2093  PreparePathForOutput(Filename);
2094 
2095  StringRef FilenameDup = strdup(Filename.c_str());
2096  SavedStrings.push_back(FilenameDup.data());
2097 
2098  HeaderFileInfoTrait::key_type Key = {
2099  FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0
2100  };
2101  HeaderFileInfoTrait::data_type Data = {
2102  Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)}
2103  };
2104  // FIXME: Deal with cases where there are multiple unresolved header
2105  // directives in different submodules for the same header.
2106  Generator.insert(Key, Data, GeneratorTrait);
2107  ++NumHeaderSearchEntries;
2108  }
2109 
2110  Worklist.append(M->submodule_begin(), M->submodule_end());
2111  }
2112  }
2113 
2115  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
2116 
2117  if (FilesByUID.size() > HS.header_file_size())
2118  FilesByUID.resize(HS.header_file_size());
2119 
2120  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
2121  const FileEntry *File = FilesByUID[UID];
2122  if (!File)
2123  continue;
2124 
2125  // Get the file info. This will load info from the external source if
2126  // necessary. Skip emitting this file if we have no information on it
2127  // as a header file (in which case HFI will be null) or if it hasn't
2128  // changed since it was loaded. Also skip it if it's for a modular header
2129  // from a different module; in that case, we rely on the module(s)
2130  // containing the header to provide this information.
2131  const HeaderFileInfo *HFI =
2132  HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
2133  if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
2134  continue;
2135 
2136  // Massage the file path into an appropriate form.
2137  StringRef Filename = File->getName();
2138  SmallString<128> FilenameTmp(Filename);
2139  if (PreparePathForOutput(FilenameTmp)) {
2140  // If we performed any translation on the file name at all, we need to
2141  // save this string, since the generator will refer to it later.
2142  Filename = StringRef(strdup(FilenameTmp.c_str()));
2143  SavedStrings.push_back(Filename.data());
2144  }
2145 
2146  HeaderFileInfoTrait::key_type Key = {
2147  Filename, File->getSize(), getTimestampForOutput(File)
2148  };
2149  HeaderFileInfoTrait::data_type Data = {
2150  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
2151  };
2152  Generator.insert(Key, Data, GeneratorTrait);
2153  ++NumHeaderSearchEntries;
2154  }
2155 
2156  // Create the on-disk hash table in a buffer.
2157  SmallString<4096> TableData;
2158  uint32_t BucketOffset;
2159  {
2160  using namespace llvm::support;
2161 
2162  llvm::raw_svector_ostream Out(TableData);
2163  // Make sure that no bucket is at offset 0
2164  endian::write<uint32_t>(Out, 0, little);
2165  BucketOffset = Generator.Emit(Out, GeneratorTrait);
2166  }
2167 
2168  // Create a blob abbreviation
2169  using namespace llvm;
2170 
2171  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2172  Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE));
2173  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2174  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2175  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2176  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2177  unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2178 
2179  // Write the header search table
2180  RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset,
2181  NumHeaderSearchEntries, TableData.size()};
2182  TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end());
2183  Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData);
2184 
2185  // Free all of the strings we had to duplicate.
2186  for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I)
2187  free(const_cast<char *>(SavedStrings[I]));
2188 }
2189 
2190 static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob,
2191  unsigned SLocBufferBlobCompressedAbbrv,
2192  unsigned SLocBufferBlobAbbrv) {
2193  using RecordDataType = ASTWriter::RecordData::value_type;
2194 
2195  // Compress the buffer if possible. We expect that almost all PCM
2196  // consumers will not want its contents.
2197  SmallString<0> CompressedBuffer;
2198  if (llvm::zlib::isAvailable()) {
2199  llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
2200  if (!E) {
2201  RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
2202  Blob.size() - 1};
2203  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
2204  CompressedBuffer);
2205  return;
2206  }
2207  llvm::consumeError(std::move(E));
2208  }
2209 
2210  RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB};
2211  Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob);
2212 }
2213 
2214 /// Writes the block containing the serialized form of the
2215 /// source manager.
2216 ///
2217 /// TODO: We should probably use an on-disk hash table (stored in a
2218 /// blob), indexed based on the file name, so that we only create
2219 /// entries for files that we actually need. In the common case (no
2220 /// errors), we probably won't have to create file entries for any of
2221 /// the files in the AST.
2222 void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
2223  const Preprocessor &PP) {
2224  RecordData Record;
2225 
2226  // Enter the source manager block.
2227  Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4);
2228 
2229  // Abbreviations for the various kinds of source-location entries.
2230  unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream);
2231  unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream);
2232  unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false);
2233  unsigned SLocBufferBlobCompressedAbbrv =
2234  CreateSLocBufferBlobAbbrev(Stream, true);
2235  unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream);
2236 
2237  // Write out the source location entry table. We skip the first
2238  // entry, which is always the same dummy entry.
2239  std::vector<uint32_t> SLocEntryOffsets;
2240  RecordData PreloadSLocs;
2241  SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
2242  for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
2243  I != N; ++I) {
2244  // Get this source location entry.
2245  const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I);
2246  FileID FID = FileID::get(I);
2247  assert(&SourceMgr.getSLocEntry(FID) == SLoc);
2248 
2249  // Record the offset of this source-location entry.
2250  SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
2251 
2252  // Figure out which record code to use.
2253  unsigned Code;
2254  if (SLoc->isFile()) {
2256  if (Cache->OrigEntry) {
2257  Code = SM_SLOC_FILE_ENTRY;
2258  } else
2259  Code = SM_SLOC_BUFFER_ENTRY;
2260  } else
2261  Code = SM_SLOC_EXPANSION_ENTRY;
2262  Record.clear();
2263  Record.push_back(Code);
2264 
2265  // Starting offset of this entry within this module, so skip the dummy.
2266  Record.push_back(SLoc->getOffset() - 2);
2267  if (SLoc->isFile()) {
2268  const SrcMgr::FileInfo &File = SLoc->getFile();
2269  AddSourceLocation(File.getIncludeLoc(), Record);
2270  Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
2271  Record.push_back(File.hasLineDirectives());
2272 
2273  const SrcMgr::ContentCache *Content = File.getContentCache();
2274  bool EmitBlob = false;
2275  if (Content->OrigEntry) {
2276  assert(Content->OrigEntry == Content->ContentsEntry &&
2277  "Writing to AST an overridden file is not supported");
2278 
2279  // The source location entry is a file. Emit input file ID.
2280  assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry");
2281  Record.push_back(InputFileIDs[Content->OrigEntry]);
2282 
2283  Record.push_back(File.NumCreatedFIDs);
2284 
2285  FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID);
2286  if (FDI != FileDeclIDs.end()) {
2287  Record.push_back(FDI->second->FirstDeclIndex);
2288  Record.push_back(FDI->second->DeclIDs.size());
2289  } else {
2290  Record.push_back(0);
2291  Record.push_back(0);
2292  }
2293 
2294  Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record);
2295 
2296  if (Content->BufferOverridden || Content->IsTransient)
2297  EmitBlob = true;
2298  } else {
2299  // The source location entry is a buffer. The blob associated
2300  // with this entry contains the contents of the buffer.
2301 
2302  // We add one to the size so that we capture the trailing NULL
2303  // that is required by llvm::MemoryBuffer::getMemBuffer (on
2304  // the reader side).
2305  const llvm::MemoryBuffer *Buffer
2306  = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
2307  StringRef Name = Buffer->getBufferIdentifier();
2308  Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
2309  StringRef(Name.data(), Name.size() + 1));
2310  EmitBlob = true;
2311 
2312  if (Name == "<built-in>")
2313  PreloadSLocs.push_back(SLocEntryOffsets.size());
2314  }
2315 
2316  if (EmitBlob) {
2317  // Include the implicit terminating null character in the on-disk buffer
2318  // if we're writing it uncompressed.
2319  const llvm::MemoryBuffer *Buffer =
2320  Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
2321  StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1);
2322  emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv,
2323  SLocBufferBlobAbbrv);
2324  }
2325  } else {
2326  // The source location entry is a macro expansion.
2327  const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion();
2328  AddSourceLocation(Expansion.getSpellingLoc(), Record);
2329  AddSourceLocation(Expansion.getExpansionLocStart(), Record);
2330  AddSourceLocation(Expansion.isMacroArgExpansion()
2331  ? SourceLocation()
2332  : Expansion.getExpansionLocEnd(),
2333  Record);
2334  Record.push_back(Expansion.isExpansionTokenRange());
2335 
2336  // Compute the token length for this macro expansion.
2337  unsigned NextOffset = SourceMgr.getNextLocalOffset();
2338  if (I + 1 != N)
2339  NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset();
2340  Record.push_back(NextOffset - SLoc->getOffset() - 1);
2341  Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record);
2342  }
2343  }
2344 
2345  Stream.ExitBlock();
2346 
2347  if (SLocEntryOffsets.empty())
2348  return;
2349 
2350  // Write the source-location offsets table into the AST block. This
2351  // table is used for lazily loading source-location information.
2352  using namespace llvm;
2353 
2354  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2355  Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
2356  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
2357  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
2358  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
2359  unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2360  {
2361  RecordData::value_type Record[] = {
2362  SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
2363  SourceMgr.getNextLocalOffset() - 1 /* skip dummy */};
2364  Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
2365  bytes(SLocEntryOffsets));
2366  }
2367  // Write the source location entry preloads array, telling the AST
2368  // reader which source locations entries it should load eagerly.
2369  Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs);
2370 
2371  // Write the line table. It depends on remapping working, so it must come
2372  // after the source location offsets.
2373  if (SourceMgr.hasLineTable()) {
2374  LineTableInfo &LineTable = SourceMgr.getLineTable();
2375 
2376  Record.clear();
2377 
2378  // Emit the needed file names.
2379  llvm::DenseMap<int, int> FilenameMap;
2380  FilenameMap[-1] = -1; // For unspecified filenames.
2381  for (const auto &L : LineTable) {
2382  if (L.first.ID < 0)
2383  continue;
2384  for (auto &LE : L.second) {
2385  if (FilenameMap.insert(std::make_pair(LE.FilenameID,
2386  FilenameMap.size() - 1)).second)
2387  AddPath(LineTable.getFilename(LE.FilenameID), Record);
2388  }
2389  }
2390  Record.push_back(0);
2391 
2392  // Emit the line entries
2393  for (const auto &L : LineTable) {
2394  // Only emit entries for local files.
2395  if (L.first.ID < 0)
2396  continue;
2397 
2398  // Emit the file ID
2399  Record.push_back(L.first.ID);
2400 
2401  // Emit the line entries
2402  Record.push_back(L.second.size());
2403  for (const auto &LE : L.second) {
2404  Record.push_back(LE.FileOffset);
2405  Record.push_back(LE.LineNo);
2406  Record.push_back(FilenameMap[LE.FilenameID]);
2407  Record.push_back((unsigned)LE.FileKind);
2408  Record.push_back(LE.IncludeOffset);
2409  }
2410  }
2411 
2412  Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record);
2413  }
2414 }
2415 
2416 //===----------------------------------------------------------------------===//
2417 // Preprocessor Serialization
2418 //===----------------------------------------------------------------------===//
2419 
2420 static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
2421  const Preprocessor &PP) {
2422  if (MacroInfo *MI = MD->getMacroInfo())
2423  if (MI->isBuiltinMacro())
2424  return true;
2425 
2426  if (IsModule) {
2427  SourceLocation Loc = MD->getLocation();
2428  if (Loc.isInvalid())
2429  return true;
2430  if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID())
2431  return true;
2432  }
2433 
2434  return false;
2435 }
2436 
2437 /// Writes the block containing the serialized form of the
2438 /// preprocessor.
2439 void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2441  if (PPRec)
2442  WritePreprocessorDetail(*PPRec);
2443 
2444  RecordData Record;
2445  RecordData ModuleMacroRecord;
2446 
2447  // If the preprocessor __COUNTER__ value has been bumped, remember it.
2448  if (PP.getCounterValue() != 0) {
2449  RecordData::value_type Record[] = {PP.getCounterValue()};
2450  Stream.EmitRecord(PP_COUNTER_VALUE, Record);
2451  }
2452 
2453  if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
2454  assert(!IsModule);
2455  auto SkipInfo = PP.getPreambleSkipInfo();
2456  if (SkipInfo.hasValue()) {
2457  Record.push_back(true);
2458  AddSourceLocation(SkipInfo->HashTokenLoc, Record);
2459  AddSourceLocation(SkipInfo->IfTokenLoc, Record);
2460  Record.push_back(SkipInfo->FoundNonSkipPortion);
2461  Record.push_back(SkipInfo->FoundElse);
2462  AddSourceLocation(SkipInfo->ElseLoc, Record);
2463  } else {
2464  Record.push_back(false);
2465  }
2466  for (const auto &Cond : PP.getPreambleConditionalStack()) {
2467  AddSourceLocation(Cond.IfLoc, Record);
2468  Record.push_back(Cond.WasSkipping);
2469  Record.push_back(Cond.FoundNonSkip);
2470  Record.push_back(Cond.FoundElse);
2471  }
2472  Stream.EmitRecord(PP_CONDITIONAL_STACK, Record);
2473  Record.clear();
2474  }
2475 
2476  // Enter the preprocessor block.
2477  Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3);
2478 
2479  // If the AST file contains __DATE__ or __TIME__ emit a warning about this.
2480  // FIXME: Include a location for the use, and say which one was used.
2481  if (PP.SawDateOrTime())
2482  PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule;
2483 
2484  // Loop over all the macro directives that are live at the end of the file,
2485  // emitting each to the PP section.
2486 
2487  // Construct the list of identifiers with macro directives that need to be
2488  // serialized.
2490  for (auto &Id : PP.getIdentifierTable())
2491  if (Id.second->hadMacroDefinition() &&
2492  (!Id.second->isFromAST() ||
2493  Id.second->hasChangedSinceDeserialization()))
2494  MacroIdentifiers.push_back(Id.second);
2495  // Sort the set of macro definitions that need to be serialized by the
2496  // name of the macro, to provide a stable ordering.
2497  llvm::sort(MacroIdentifiers, llvm::less_ptr<IdentifierInfo>());
2498 
2499  // Emit the macro directives as a list and associate the offset with the
2500  // identifier they belong to.
2501  for (const IdentifierInfo *Name : MacroIdentifiers) {
2503  auto StartOffset = Stream.GetCurrentBitNo();
2504 
2505  // Emit the macro directives in reverse source order.
2506  for (; MD; MD = MD->getPrevious()) {
2507  // Once we hit an ignored macro, we're done: the rest of the chain
2508  // will all be ignored macros.
2509  if (shouldIgnoreMacro(MD, IsModule, PP))
2510  break;
2511 
2512  AddSourceLocation(MD->getLocation(), Record);
2513  Record.push_back(MD->getKind());
2514  if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) {
2515  Record.push_back(getMacroRef(DefMD->getInfo(), Name));
2516  } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
2517  Record.push_back(VisMD->isPublic());
2518  }
2519  }
2520 
2521  // Write out any exported module macros.
2522  bool EmittedModuleMacros = false;
2523  // We write out exported module macros for PCH as well.
2524  auto Leafs = PP.getLeafModuleMacros(Name);
2525  SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end());
2526  llvm::DenseMap<ModuleMacro*, unsigned> Visits;
2527  while (!Worklist.empty()) {
2528  auto *Macro = Worklist.pop_back_val();
2529 
2530  // Emit a record indicating this submodule exports this macro.
2531  ModuleMacroRecord.push_back(
2532  getSubmoduleID(Macro->getOwningModule()));
2533  ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name));
2534  for (auto *M : Macro->overrides())
2535  ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule()));
2536 
2537  Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord);
2538  ModuleMacroRecord.clear();
2539 
2540  // Enqueue overridden macros once we've visited all their ancestors.
2541  for (auto *M : Macro->overrides())
2542  if (++Visits[M] == M->getNumOverridingMacros())
2543  Worklist.push_back(M);
2544 
2545  EmittedModuleMacros = true;
2546  }
2547 
2548  if (Record.empty() && !EmittedModuleMacros)
2549  continue;
2550 
2551  IdentMacroDirectivesOffsetMap[Name] = StartOffset;
2552  Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record);
2553  Record.clear();
2554  }
2555 
2556  /// Offsets of each of the macros into the bitstream, indexed by
2557  /// the local macro ID
2558  ///
2559  /// For each identifier that is associated with a macro, this map
2560  /// provides the offset into the bitstream where that macro is
2561  /// defined.
2562  std::vector<uint32_t> MacroOffsets;
2563 
2564  for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) {
2565  const IdentifierInfo *Name = MacroInfosToEmit[I].Name;
2566  MacroInfo *MI = MacroInfosToEmit[I].MI;
2567  MacroID ID = MacroInfosToEmit[I].ID;
2568 
2569  if (ID < FirstMacroID) {
2570  assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?");
2571  continue;
2572  }
2573 
2574  // Record the local offset of this macro.
2575  unsigned Index = ID - FirstMacroID;
2576  if (Index == MacroOffsets.size())
2577  MacroOffsets.push_back(Stream.GetCurrentBitNo());
2578  else {
2579  if (Index > MacroOffsets.size())
2580  MacroOffsets.resize(Index + 1);
2581 
2582  MacroOffsets[Index] = Stream.GetCurrentBitNo();
2583  }
2584 
2585  AddIdentifierRef(Name, Record);
2586  AddSourceLocation(MI->getDefinitionLoc(), Record);
2587  AddSourceLocation(MI->getDefinitionEndLoc(), Record);
2588  Record.push_back(MI->isUsed());
2589  Record.push_back(MI->isUsedForHeaderGuard());
2590  unsigned Code;
2591  if (MI->isObjectLike()) {
2592  Code = PP_MACRO_OBJECT_LIKE;
2593  } else {
2594  Code = PP_MACRO_FUNCTION_LIKE;
2595 
2596  Record.push_back(MI->isC99Varargs());
2597  Record.push_back(MI->isGNUVarargs());
2598  Record.push_back(MI->hasCommaPasting());
2599  Record.push_back(MI->getNumParams());
2600  for (const IdentifierInfo *Param : MI->params())
2601  AddIdentifierRef(Param, Record);
2602  }
2603 
2604  // If we have a detailed preprocessing record, record the macro definition
2605  // ID that corresponds to this macro.
2606  if (PPRec)
2607  Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]);
2608 
2609  Stream.EmitRecord(Code, Record);
2610  Record.clear();
2611 
2612  // Emit the tokens array.
2613  for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
2614  // Note that we know that the preprocessor does not have any annotation
2615  // tokens in it because they are created by the parser, and thus can't
2616  // be in a macro definition.
2617  const Token &Tok = MI->getReplacementToken(TokNo);
2618  AddToken(Tok, Record);
2619  Stream.EmitRecord(PP_TOKEN, Record);
2620  Record.clear();
2621  }
2622  ++NumMacros;
2623  }
2624 
2625  Stream.ExitBlock();
2626 
2627  // Write the offsets table for macro IDs.
2628  using namespace llvm;
2629 
2630  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2631  Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET));
2632  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros
2633  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
2634  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2635 
2636  unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2637  {
2638  RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(),
2639  FirstMacroID - NUM_PREDEF_MACRO_IDS};
2640  Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
2641  }
2642 }
2643 
2644 void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
2645  if (PPRec.local_begin() == PPRec.local_end())
2646  return;
2647 
2648  SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets;
2649 
2650  // Enter the preprocessor block.
2651  Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3);
2652 
2653  // If the preprocessor has a preprocessing record, emit it.
2654  unsigned NumPreprocessingRecords = 0;
2655  using namespace llvm;
2656 
2657  // Set up the abbreviation for
2658  unsigned InclusionAbbrev = 0;
2659  {
2660  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2661  Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE));
2662  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length
2663  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes
2664  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind
2665  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module
2666  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2667  InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2668  }
2669 
2670  unsigned FirstPreprocessorEntityID
2671  = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0)
2673  unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID;
2674  RecordData Record;
2675  for (PreprocessingRecord::iterator E = PPRec.local_begin(),
2676  EEnd = PPRec.local_end();
2677  E != EEnd;
2678  (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
2679  Record.clear();
2680 
2681  PreprocessedEntityOffsets.push_back(
2682  PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo()));
2683 
2684  if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
2685  // Record this macro definition's ID.
2686  MacroDefinitions[MD] = NextPreprocessorEntityID;
2687 
2688  AddIdentifierRef(MD->getName(), Record);
2689  Stream.EmitRecord(PPD_MACRO_DEFINITION, Record);
2690  continue;
2691  }
2692 
2693  if (auto *ME = dyn_cast<MacroExpansion>(*E)) {
2694  Record.push_back(ME->isBuiltinMacro());
2695  if (ME->isBuiltinMacro())
2696  AddIdentifierRef(ME->getName(), Record);
2697  else
2698  Record.push_back(MacroDefinitions[ME->getDefinition()]);
2699  Stream.EmitRecord(PPD_MACRO_EXPANSION, Record);
2700  continue;
2701  }
2702 
2703  if (auto *ID = dyn_cast<InclusionDirective>(*E)) {
2704  Record.push_back(PPD_INCLUSION_DIRECTIVE);
2705  Record.push_back(ID->getFileName().size());
2706  Record.push_back(ID->wasInQuotes());
2707  Record.push_back(static_cast<unsigned>(ID->getKind()));
2708  Record.push_back(ID->importedModule());
2709  SmallString<64> Buffer;
2710  Buffer += ID->getFileName();
2711  // Check that the FileEntry is not null because it was not resolved and
2712  // we create a PCH even with compiler errors.
2713  if (ID->getFile())
2714  Buffer += ID->getFile()->getName();
2715  Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer);
2716  continue;
2717  }
2718 
2719  llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter");
2720  }
2721  Stream.ExitBlock();
2722 
2723  // Write the offsets table for the preprocessing record.
2724  if (NumPreprocessingRecords > 0) {
2725  assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords);
2726 
2727  // Write the offsets table for identifier IDs.
2728  using namespace llvm;
2729 
2730  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2731  Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS));
2732  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity
2733  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2734  unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2735 
2736  RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS,
2737  FirstPreprocessorEntityID -
2739  Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record,
2740  bytes(PreprocessedEntityOffsets));
2741  }
2742 
2743  // Write the skipped region table for the preprocessing record.
2744  ArrayRef<SourceRange> SkippedRanges = PPRec.getSkippedRanges();
2745  if (SkippedRanges.size() > 0) {
2746  std::vector<PPSkippedRange> SerializedSkippedRanges;
2747  SerializedSkippedRanges.reserve(SkippedRanges.size());
2748  for (auto const& Range : SkippedRanges)
2749  SerializedSkippedRanges.emplace_back(Range);
2750 
2751  using namespace llvm;
2752  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2753  Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES));
2754  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2755  unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2756 
2757  Record.clear();
2758  Record.push_back(PPD_SKIPPED_RANGES);
2759  Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record,
2760  bytes(SerializedSkippedRanges));
2761  }
2762 }
2763 
2765  if (!Mod)
2766  return 0;
2767 
2768  llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod);
2769  if (Known != SubmoduleIDs.end())
2770  return Known->second;
2771 
2772  auto *Top = Mod->getTopLevelModule();
2773  if (Top != WritingModule &&
2774  (getLangOpts().CompilingPCH ||
2775  !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule))))
2776  return 0;
2777 
2778  return SubmoduleIDs[Mod] = NextSubmoduleID++;
2779 }
2780 
2781 unsigned ASTWriter::getSubmoduleID(Module *Mod) {
2782  // FIXME: This can easily happen, if we have a reference to a submodule that
2783  // did not result in us loading a module file for that submodule. For
2784  // instance, a cross-top-level-module 'conflict' declaration will hit this.
2785  unsigned ID = getLocalOrImportedSubmoduleID(Mod);
2786  assert((ID || !Mod) &&
2787  "asked for module ID for non-local, non-imported module");
2788  return ID;
2789 }
2790 
2791 /// Compute the number of modules within the given tree (including the
2792 /// given module).
2793 static unsigned getNumberOfModules(Module *Mod) {
2794  unsigned ChildModules = 0;
2795  for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end();
2796  Sub != SubEnd; ++Sub)
2797  ChildModules += getNumberOfModules(*Sub);
2798 
2799  return ChildModules + 1;
2800 }
2801 
2802 void ASTWriter::WriteSubmodules(Module *WritingModule) {
2803  // Enter the submodule description block.
2804  Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5);
2805 
2806  // Write the abbreviations needed for the submodules block.
2807  using namespace llvm;
2808 
2809  auto Abbrev = std::make_shared<BitCodeAbbrev>();
2810  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
2811  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
2812  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
2813  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind
2814  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
2815  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
2816  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
2817  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC
2818  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules...
2819  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit...
2820  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild...
2821  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh...
2822  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModuleMapIsPriv...
2823  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2824  unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2825 
2826  Abbrev = std::make_shared<BitCodeAbbrev>();
2827  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER));
2828  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2829  unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2830 
2831  Abbrev = std::make_shared<BitCodeAbbrev>();
2832  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER));
2833  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2834  unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2835 
2836  Abbrev = std::make_shared<BitCodeAbbrev>();
2837  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER));
2838  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2839  unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2840 
2841  Abbrev = std::make_shared<BitCodeAbbrev>();
2842  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR));
2843  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2844  unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2845 
2846  Abbrev = std::make_shared<BitCodeAbbrev>();
2847  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES));
2848  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State
2849  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature
2850  unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2851 
2852  Abbrev = std::make_shared<BitCodeAbbrev>();
2853  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER));
2854  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2855  unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2856 
2857  Abbrev = std::make_shared<BitCodeAbbrev>();
2858  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER));
2859  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2860  unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2861 
2862  Abbrev = std::make_shared<BitCodeAbbrev>();
2863  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER));
2864  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2865  unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2866 
2867  Abbrev = std::make_shared<BitCodeAbbrev>();
2868  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER));
2869  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2870  unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2871 
2872  Abbrev = std::make_shared<BitCodeAbbrev>();
2873  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY));
2874  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
2875  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
2876  unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2877 
2878  Abbrev = std::make_shared<BitCodeAbbrev>();
2879  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO));
2880  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name
2881  unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2882 
2883  Abbrev = std::make_shared<BitCodeAbbrev>();
2884  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT));
2885  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module
2886  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message
2887  unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2888 
2889  Abbrev = std::make_shared<BitCodeAbbrev>();
2890  Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXPORT_AS));
2891  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name
2892  unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2893 
2894  // Write the submodule metadata block.
2895  RecordData::value_type Record[] = {
2896  getNumberOfModules(WritingModule),
2897  FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS};
2898  Stream.EmitRecord(SUBMODULE_METADATA, Record);
2899 
2900  // Write all of the submodules.
2901  std::queue<Module *> Q;
2902  Q.push(WritingModule);
2903  while (!Q.empty()) {
2904  Module *Mod = Q.front();
2905  Q.pop();
2906  unsigned ID = getSubmoduleID(Mod);
2907 
2908  uint64_t ParentID = 0;
2909  if (Mod->Parent) {
2910  assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?");
2911  ParentID = SubmoduleIDs[Mod->Parent];
2912  }
2913 
2914  // Emit the definition of the block.
2915  {
2916  RecordData::value_type Record[] = {SUBMODULE_DEFINITION,
2917  ID,
2918  ParentID,
2919  (RecordData::value_type)Mod->Kind,
2920  Mod->IsFramework,
2921  Mod->IsExplicit,
2922  Mod->IsSystem,
2923  Mod->IsExternC,
2924  Mod->InferSubmodules,
2926  Mod->InferExportWildcard,
2928  Mod->ModuleMapIsPrivate};
2929  Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name);
2930  }
2931 
2932  // Emit the requirements.
2933  for (const auto &R : Mod->Requirements) {
2934  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second};
2935  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first);
2936  }
2937 
2938  // Emit the umbrella header, if there is one.
2939  if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) {
2940  RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER};
2941  Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record,
2942  UmbrellaHeader.NameAsWritten);
2943  } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) {
2944  RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR};
2945  Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record,
2946  UmbrellaDir.NameAsWritten);
2947  }
2948 
2949  // Emit the headers.
2950  struct {
2951  unsigned RecordKind;
2952  unsigned Abbrev;
2953  Module::HeaderKind HeaderKind;
2954  } HeaderLists[] = {
2955  {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal},
2956  {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual},
2957  {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private},
2958  {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev,
2960  {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded}
2961  };
2962  for (auto &HL : HeaderLists) {
2963  RecordData::value_type Record[] = {HL.RecordKind};
2964  for (auto &H : Mod->Headers[HL.HeaderKind])
2965  Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten);
2966  }
2967 
2968  // Emit the top headers.
2969  {
2970  auto TopHeaders = Mod->getTopHeaders(PP->getFileManager());
2971  RecordData::value_type Record[] = {SUBMODULE_TOPHEADER};
2972  for (auto *H : TopHeaders)
2973  Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName());
2974  }
2975 
2976  // Emit the imports.
2977  if (!Mod->Imports.empty()) {
2978  RecordData Record;
2979  for (auto *I : Mod->Imports)
2980  Record.push_back(getSubmoduleID(I));
2981  Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
2982  }
2983 
2984  // Emit the exports.
2985  if (!Mod->Exports.empty()) {
2986  RecordData Record;
2987  for (const auto &E : Mod->Exports) {
2988  // FIXME: This may fail; we don't require that all exported modules
2989  // are local or imported.
2990  Record.push_back(getSubmoduleID(E.getPointer()));
2991  Record.push_back(E.getInt());
2992  }
2993  Stream.EmitRecord(SUBMODULE_EXPORTS, Record);
2994  }
2995 
2996  //FIXME: How do we emit the 'use'd modules? They may not be submodules.
2997  // Might be unnecessary as use declarations are only used to build the
2998  // module itself.
2999 
3000  // Emit the link libraries.
3001  for (const auto &LL : Mod->LinkLibraries) {
3002  RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY,
3003  LL.IsFramework};
3004  Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library);
3005  }
3006 
3007  // Emit the conflicts.
3008  for (const auto &C : Mod->Conflicts) {
3009  // FIXME: This may fail; we don't require that all conflicting modules
3010  // are local or imported.
3011  RecordData::value_type Record[] = {SUBMODULE_CONFLICT,
3012  getSubmoduleID(C.Other)};
3013  Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message);
3014  }
3015 
3016  // Emit the configuration macros.
3017  for (const auto &CM : Mod->ConfigMacros) {
3018  RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO};
3019  Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM);
3020  }
3021 
3022  // Emit the initializers, if any.
3023  RecordData Inits;
3024  for (Decl *D : Context->getModuleInitializers(Mod))
3025  Inits.push_back(GetDeclRef(D));
3026  if (!Inits.empty())
3027  Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits);
3028 
3029  // Emit the name of the re-exported module, if any.
3030  if (!Mod->ExportAsModule.empty()) {
3031  RecordData::value_type Record[] = {SUBMODULE_EXPORT_AS};
3032  Stream.EmitRecordWithBlob(ExportAsAbbrev, Record, Mod->ExportAsModule);
3033  }
3034 
3035  // Queue up the submodules of this module.
3036  for (auto *M : Mod->submodules())
3037  Q.push(M);
3038  }
3039 
3040  Stream.ExitBlock();
3041 
3042  assert((NextSubmoduleID - FirstSubmoduleID ==
3043  getNumberOfModules(WritingModule)) &&
3044  "Wrong # of submodules; found a reference to a non-local, "
3045  "non-imported submodule?");
3046 }
3047 
3048 void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
3049  bool isModule) {
3050  llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64>
3051  DiagStateIDMap;
3052  unsigned CurrID = 0;
3053  RecordData Record;
3054 
3055  auto EncodeDiagStateFlags =
3056  [](const DiagnosticsEngine::DiagState *DS) -> unsigned {
3057  unsigned Result = (unsigned)DS->ExtBehavior;
3058  for (unsigned Val :
3059  {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings,
3060  (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal,
3061  (unsigned)DS->SuppressSystemWarnings})
3062  Result = (Result << 1) | Val;
3063  return Result;
3064  };
3065 
3066  unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState);
3067  Record.push_back(Flags);
3068 
3069  auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State,
3070  bool IncludeNonPragmaStates) {
3071  // Ensure that the diagnostic state wasn't modified since it was created.
3072  // We will not correctly round-trip this information otherwise.
3073  assert(Flags == EncodeDiagStateFlags(State) &&
3074  "diag state flags vary in single AST file");
3075 
3076  unsigned &DiagStateID = DiagStateIDMap[State];
3077  Record.push_back(DiagStateID);
3078 
3079  if (DiagStateID == 0) {
3080  DiagStateID = ++CurrID;
3081 
3082  // Add a placeholder for the number of mappings.
3083  auto SizeIdx = Record.size();
3084  Record.emplace_back();
3085  for (const auto &I : *State) {
3086  if (I.second.isPragma() || IncludeNonPragmaStates) {
3087  Record.push_back(I.first);
3088  Record.push_back(I.second.serialize());
3089  }
3090  }
3091  // Update the placeholder.
3092  Record[SizeIdx] = (Record.size() - SizeIdx) / 2;
3093  }
3094  };
3095 
3096  AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule);
3097 
3098  // Reserve a spot for the number of locations with state transitions.
3099  auto NumLocationsIdx = Record.size();
3100  Record.emplace_back();
3101 
3102  // Emit the state transitions.
3103  unsigned NumLocations = 0;
3104  for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) {
3105  if (!FileIDAndFile.first.isValid() ||
3106  !FileIDAndFile.second.HasLocalTransitions)
3107  continue;
3108  ++NumLocations;
3109 
3110  SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0);
3111  assert(!Loc.isInvalid() && "start loc for valid FileID is invalid");
3112  AddSourceLocation(Loc, Record);
3113 
3114  Record.push_back(FileIDAndFile.second.StateTransitions.size());
3115  for (auto &StatePoint : FileIDAndFile.second.StateTransitions) {
3116  Record.push_back(StatePoint.Offset);
3117  AddDiagState(StatePoint.State, false);
3118  }
3119  }
3120 
3121  // Backpatch the number of locations.
3122  Record[NumLocationsIdx] = NumLocations;
3123 
3124  // Emit CurDiagStateLoc. Do it last in order to match source order.
3125  //
3126  // This also protects against a hypothetical corner case with simulating
3127  // -Werror settings for implicit modules in the ASTReader, where reading
3128  // CurDiagState out of context could change whether warning pragmas are
3129  // treated as errors.
3130  AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record);
3131  AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false);
3132 
3133  Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record);
3134 }
3135 
3136 //===----------------------------------------------------------------------===//
3137 // Type Serialization
3138 //===----------------------------------------------------------------------===//
3139 
3140 /// Write the representation of a type to the AST stream.
3141 void ASTWriter::WriteType(QualType T) {
3142  TypeIdx &IdxRef = TypeIdxs[T];
3143  if (IdxRef.getIndex() == 0) // we haven't seen this type before.
3144  IdxRef = TypeIdx(NextTypeID++);
3145  TypeIdx Idx = IdxRef;
3146 
3147  assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST");
3148 
3149  RecordData Record;
3150 
3151  // Emit the type's representation.
3152  ASTTypeWriter W(*this, Record);
3153  W.Visit(T);
3154  uint64_t Offset = W.Emit();
3155 
3156  // Record the offset for this type.
3157  unsigned Index = Idx.getIndex() - FirstTypeID;
3158  if (TypeOffsets.size() == Index)
3159  TypeOffsets.push_back(Offset);
3160  else if (TypeOffsets.size() < Index) {
3161  TypeOffsets.resize(Index + 1);
3162  TypeOffsets[Index] = Offset;
3163  } else {
3164  llvm_unreachable("Types emitted in wrong order");
3165  }
3166 }
3167 
3168 //===----------------------------------------------------------------------===//
3169 // Declaration Serialization
3170 //===----------------------------------------------------------------------===//
3171 
3172 /// Write the block containing all of the declaration IDs
3173 /// lexically declared within the given DeclContext.
3174 ///
3175 /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the
3176 /// bitstream, or 0 if no block was written.
3177 uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
3178  DeclContext *DC) {
3179  if (DC->decls_empty())
3180  return 0;
3181 
3182  uint64_t Offset = Stream.GetCurrentBitNo();
3183  SmallVector<uint32_t, 128> KindDeclPairs;
3184  for (const auto *D : DC->decls()) {
3185  KindDeclPairs.push_back(D->getKind());
3186  KindDeclPairs.push_back(GetDeclRef(D));
3187  }
3188 
3189  ++NumLexicalDeclContexts;
3190  RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL};
3191  Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record,
3192  bytes(KindDeclPairs));
3193  return Offset;
3194 }
3195 
3196 void ASTWriter::WriteTypeDeclOffsets() {
3197  using namespace llvm;
3198 
3199  // Write the type offsets array
3200  auto Abbrev = std::make_shared<BitCodeAbbrev>();
3201  Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET));
3202  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
3203  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index
3204  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
3205  unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3206  {
3207  RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(),
3208  FirstTypeID - NUM_PREDEF_TYPE_IDS};
3209  Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets));
3210  }
3211 
3212  // Write the declaration offsets array
3213  Abbrev = std::make_shared<BitCodeAbbrev>();
3214  Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET));
3215  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
3216  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID
3217  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
3218  unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3219  {
3220  RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(),
3221  FirstDeclID - NUM_PREDEF_DECL_IDS};
3222  Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets));
3223  }
3224 }
3225 
3226 void ASTWriter::WriteFileDeclIDsMap() {
3227  using namespace llvm;
3228 
3230  FileDeclIDs.begin(), FileDeclIDs.end());
3231  llvm::sort(SortedFileDeclIDs, llvm::less_first());
3232 
3233  // Join the vectors of DeclIDs from all files.
3234  SmallVector<DeclID, 256> FileGroupedDeclIDs;
3235  for (auto &FileDeclEntry : SortedFileDeclIDs) {
3236  DeclIDInFileInfo &Info = *FileDeclEntry.second;
3237  Info.FirstDeclIndex = FileGroupedDeclIDs.size();
3238  for (auto &LocDeclEntry : Info.DeclIDs)
3239  FileGroupedDeclIDs.push_back(LocDeclEntry.second);
3240  }
3241 
3242  auto Abbrev = std::make_shared<BitCodeAbbrev>();
3243  Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS));
3244  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3245  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3246  unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
3247  RecordData::value_type Record[] = {FILE_SORTED_DECLS,
3248  FileGroupedDeclIDs.size()};
3249  Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs));
3250 }
3251 
3252 void ASTWriter::WriteComments() {
3253  Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3);
3254  auto _ = llvm::make_scope_exit([this] { Stream.ExitBlock(); });
3256  return;
3257  ArrayRef<RawComment *> RawComments = Context->Comments.getComments();
3258  RecordData Record;
3259  for (const auto *I : RawComments) {
3260  Record.clear();
3261  AddSourceRange(I->getSourceRange(), Record);
3262  Record.push_back(I->getKind());
3263  Record.push_back(I->isTrailingComment());
3264  Record.push_back(I->isAlmostTrailingComment());
3265  Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record);
3266  }
3267 }
3268 
3269 //===----------------------------------------------------------------------===//
3270 // Global Method Pool and Selector Serialization
3271 //===----------------------------------------------------------------------===//
3272 
3273 namespace {
3274 
3275 // Trait used for the on-disk hash table used in the method pool.
3276 class ASTMethodPoolTrait {
3277  ASTWriter &Writer;
3278 
3279 public:
3280  using key_type = Selector;
3281  using key_type_ref = key_type;
3282 
3283  struct data_type {
3284  SelectorID ID;
3285  ObjCMethodList Instance, Factory;
3286  };
3287  using data_type_ref = const data_type &;
3288 
3289  using hash_value_type = unsigned;
3290  using offset_type = unsigned;
3291 
3292  explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) {}
3293 
3294  static hash_value_type ComputeHash(Selector Sel) {
3295  return serialization::ComputeHash(Sel);
3296  }
3297 
3298  std::pair<unsigned, unsigned>
3299  EmitKeyDataLength(raw_ostream& Out, Selector Sel,
3300  data_type_ref Methods) {
3301  using namespace llvm::support;
3302 
3303  endian::Writer LE(Out, little);
3304  unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4);
3305  LE.write<uint16_t>(KeyLen);
3306  unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts
3307  for (const ObjCMethodList *Method = &Methods.Instance; Method;
3308  Method = Method->getNext())
3309  if (Method->getMethod())
3310  DataLen += 4;
3311  for (const ObjCMethodList *Method = &Methods.Factory; Method;
3312  Method = Method->getNext())
3313  if (Method->getMethod())
3314  DataLen += 4;
3315  LE.write<uint16_t>(DataLen);
3316  return std::make_pair(KeyLen, DataLen);
3317  }
3318 
3319  void EmitKey(raw_ostream& Out, Selector Sel, unsigned) {
3320  using namespace llvm::support;
3321 
3322  endian::Writer LE(Out, little);
3323  uint64_t Start = Out.tell();
3324  assert((Start >> 32) == 0 && "Selector key offset too large");
3325  Writer.SetSelectorOffset(Sel, Start);
3326  unsigned N = Sel.getNumArgs();
3327  LE.write<uint16_t>(N);
3328  if (N == 0)
3329  N = 1;
3330  for (unsigned I = 0; I != N; ++I)
3331  LE.write<uint32_t>(
3333  }
3334 
3335  void EmitData(raw_ostream& Out, key_type_ref,
3336  data_type_ref Methods, unsigned DataLen) {
3337  using namespace llvm::support;
3338 
3339  endian::Writer LE(Out, little);
3340  uint64_t Start = Out.tell(); (void)Start;
3341  LE.write<uint32_t>(Methods.ID);
3342  unsigned NumInstanceMethods = 0;
3343  for (const ObjCMethodList *Method = &Methods.Instance; Method;
3344  Method = Method->getNext())
3345  if (Method->getMethod())
3346  ++NumInstanceMethods;
3347 
3348  unsigned NumFactoryMethods = 0;
3349  for (const ObjCMethodList *Method = &Methods.Factory; Method;
3350  Method = Method->getNext())
3351  if (Method->getMethod())
3352  ++NumFactoryMethods;
3353 
3354  unsigned InstanceBits = Methods.Instance.getBits();
3355  assert(InstanceBits < 4);
3356  unsigned InstanceHasMoreThanOneDeclBit =
3357  Methods.Instance.hasMoreThanOneDecl();
3358  unsigned FullInstanceBits = (NumInstanceMethods << 3) |
3359  (InstanceHasMoreThanOneDeclBit << 2) |
3360  InstanceBits;
3361  unsigned FactoryBits = Methods.Factory.getBits();
3362  assert(FactoryBits < 4);
3363  unsigned FactoryHasMoreThanOneDeclBit =
3364  Methods.Factory.hasMoreThanOneDecl();
3365  unsigned FullFactoryBits = (NumFactoryMethods << 3) |
3366  (FactoryHasMoreThanOneDeclBit << 2) |
3367  FactoryBits;
3368  LE.write<uint16_t>(FullInstanceBits);
3369  LE.write<uint16_t>(FullFactoryBits);
3370  for (const ObjCMethodList *Method = &Methods.Instance; Method;
3371  Method = Method->getNext())
3372  if (Method->getMethod())
3373  LE.write<uint32_t>(Writer.getDeclID(Method->getMethod()));
3374  for (const ObjCMethodList *Method = &Methods.Factory; Method;
3375  Method = Method->getNext())
3376  if (Method->getMethod())
3377  LE.write<uint32_t>(Writer.getDeclID(Method->getMethod()));
3378 
3379  assert(Out.tell() - Start == DataLen && "Data length is wrong");
3380  }
3381 };
3382 
3383 } // namespace
3384 
3385 /// Write ObjC data: selectors and the method pool.
3386 ///
3387 /// The method pool contains both instance and factory methods, stored
3388 /// in an on-disk hash table indexed by the selector. The hash table also
3389 /// contains an empty entry for every other selector known to Sema.
3390 void ASTWriter::WriteSelectors(Sema &SemaRef) {
3391  using namespace llvm;
3392 
3393  // Do we have to do anything at all?
3394  if (SemaRef.MethodPool.empty() && SelectorIDs.empty())
3395  return;
3396  unsigned NumTableEntries = 0;
3397  // Create and write out the blob that contains selectors and the method pool.
3398  {
3399  llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator;
3400  ASTMethodPoolTrait Trait(*this);
3401 
3402  // Create the on-disk hash table representation. We walk through every
3403  // selector we've seen and look it up in the method pool.
3404  SelectorOffsets.resize(NextSelectorID - FirstSelectorID);
3405  for (auto &SelectorAndID : SelectorIDs) {
3406  Selector S = SelectorAndID.first;
3407  SelectorID ID = SelectorAndID.second;
3408  Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S);
3409  ASTMethodPoolTrait::data_type Data = {
3410  ID,
3411  ObjCMethodList(),
3412  ObjCMethodList()
3413  };
3414  if (F != SemaRef.MethodPool.end()) {
3415  Data.Instance = F->second.first;
3416  Data.Factory = F->second.second;
3417  }
3418  // Only write this selector if it's not in an existing AST or something
3419  // changed.
3420  if (Chain && ID < FirstSelectorID) {
3421  // Selector already exists. Did it change?
3422  bool changed = false;
3423  for (ObjCMethodList *M = &Data.Instance;
3424  !changed && M && M->getMethod(); M = M->getNext()) {
3425  if (!M->getMethod()->isFromASTFile())
3426  changed = true;
3427  }
3428  for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod();
3429  M = M->getNext()) {
3430  if (!M->getMethod()->isFromASTFile())
3431  changed = true;
3432  }
3433  if (!changed)
3434  continue;
3435  } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) {
3436  // A new method pool entry.
3437  ++NumTableEntries;
3438  }
3439  Generator.insert(S, Data, Trait);
3440  }
3441 
3442  // Create the on-disk hash table in a buffer.
3443  SmallString<4096> MethodPool;
3444  uint32_t BucketOffset;
3445  {
3446  using namespace llvm::support;
3447 
3448  ASTMethodPoolTrait Trait(*this);
3449  llvm::raw_svector_ostream Out(MethodPool);
3450  // Make sure that no bucket is at offset 0
3451  endian::write<uint32_t>(Out, 0, little);
3452  BucketOffset = Generator.Emit(Out, Trait);
3453  }
3454 
3455  // Create a blob abbreviation
3456  auto Abbrev = std::make_shared<BitCodeAbbrev>();
3457  Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL));
3458  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3459  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3460  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3461  unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3462 
3463  // Write the method pool
3464  {
3465  RecordData::value_type Record[] = {METHOD_POOL, BucketOffset,
3466  NumTableEntries};
3467  Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool);
3468  }
3469 
3470  // Create a blob abbreviation for the selector table offsets.
3471  Abbrev = std::make_shared<BitCodeAbbrev>();
3472  Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS));
3473  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size
3474  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
3475  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3476  unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3477 
3478  // Write the selector offsets table.
3479  {
3480  RecordData::value_type Record[] = {
3481  SELECTOR_OFFSETS, SelectorOffsets.size(),
3482  FirstSelectorID - NUM_PREDEF_SELECTOR_IDS};
3483  Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record,
3484  bytes(SelectorOffsets));
3485  }
3486  }
3487 }
3488 
3489 /// Write the selectors referenced in @selector expression into AST file.
3490 void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) {
3491  using namespace llvm;
3492 
3493  if (SemaRef.ReferencedSelectors.empty())
3494  return;
3495 
3496  RecordData Record;
3497  ASTRecordWriter Writer(*this, Record);
3498 
3499  // Note: this writes out all references even for a dependent AST. But it is
3500  // very tricky to fix, and given that @selector shouldn't really appear in
3501  // headers, probably not worth it. It's not a correctness issue.
3502  for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) {
3503  Selector Sel = SelectorAndLocation.first;
3504  SourceLocation Loc = SelectorAndLocation.second;
3505  Writer.AddSelectorRef(Sel);
3506  Writer.AddSourceLocation(Loc);
3507  }
3509 }
3510 
3511 //===----------------------------------------------------------------------===//
3512 // Identifier Table Serialization
3513 //===----------------------------------------------------------------------===//
3514 
3515 /// Determine the declaration that should be put into the name lookup table to
3516 /// represent the given declaration in this module. This is usually D itself,
3517 /// but if D was imported and merged into a local declaration, we want the most
3518 /// recent local declaration instead. The chosen declaration will be the most
3519 /// recent declaration in any module that imports this one.
3521  NamedDecl *D) {
3522  if (!LangOpts.Modules || !D->isFromASTFile())
3523  return D;
3524 
3525  if (Decl *Redecl = D->getPreviousDecl()) {
3526  // For Redeclarable decls, a prior declaration might be local.
3527  for (; Redecl; Redecl = Redecl->getPreviousDecl()) {
3528  // If we find a local decl, we're done.
3529  if (!Redecl->isFromASTFile()) {
3530  // Exception: in very rare cases (for injected-class-names), not all
3531  // redeclarations are in the same semantic context. Skip ones in a
3532  // different context. They don't go in this lookup table at all.
3533  if (!Redecl->getDeclContext()->getRedeclContext()->Equals(
3535  continue;
3536  return cast<NamedDecl>(Redecl);
3537  }
3538 
3539  // If we find a decl from a (chained-)PCH stop since we won't find a
3540  // local one.
3541  if (Redecl->getOwningModuleID() == 0)
3542  break;
3543  }
3544  } else if (Decl *First = D->getCanonicalDecl()) {
3545  // For Mergeable decls, the first decl might be local.
3546  if (!First->isFromASTFile())
3547  return cast<NamedDecl>(First);
3548  }
3549 
3550  // All declarations are imported. Our most recent declaration will also be
3551  // the most recent one in anyone who imports us.
3552  return D;
3553 }
3554 
3555 namespace {
3556 
3557 class ASTIdentifierTableTrait {
3558  ASTWriter &Writer;
3559  Preprocessor &PP;
3560  IdentifierResolver &IdResolver;
3561  bool IsModule;
3562  bool NeedDecls;
3563  ASTWriter::RecordData *InterestingIdentifierOffsets;
3564 
3565  /// Determines whether this is an "interesting" identifier that needs a
3566  /// full IdentifierInfo structure written into the hash table. Notably, this
3567  /// doesn't check whether the name has macros defined; use PublicMacroIterator
3568  /// to check that.
3569  bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) {
3570  if (MacroOffset ||
3571  II->isPoisoned() ||
3572  (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) ||
3574  (NeedDecls && II->getFETokenInfo()))
3575  return true;
3576 
3577  return false;
3578  }
3579 
3580 public:
3581  using key_type = IdentifierInfo *;
3582  using key_type_ref = key_type;
3583 
3584  using data_type = IdentID;
3585  using data_type_ref = data_type;
3586 
3587  using hash_value_type = unsigned;
3588  using offset_type = unsigned;
3589 
3590  ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP,
3591  IdentifierResolver &IdResolver, bool IsModule,
3592  ASTWriter::RecordData *InterestingIdentifierOffsets)
3593  : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule),
3594  NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus),
3595  InterestingIdentifierOffsets(InterestingIdentifierOffsets) {}
3596 
3597  bool needDecls() const { return NeedDecls; }
3598 
3599  static hash_value_type ComputeHash(const IdentifierInfo* II) {
3600  return llvm::djbHash(II->getName());
3601  }
3602 
3603  bool isInterestingIdentifier(const IdentifierInfo *II) {
3604  auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3605  return isInterestingIdentifier(II, MacroOffset);
3606  }
3607 
3608  bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) {
3609  return isInterestingIdentifier(II, 0);
3610  }
3611 
3612  std::pair<unsigned, unsigned>
3613  EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) {
3614  unsigned KeyLen = II->getLength() + 1;
3615  unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
3616  auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3617  if (isInterestingIdentifier(II, MacroOffset)) {
3618  DataLen += 2; // 2 bytes for builtin ID
3619  DataLen += 2; // 2 bytes for flags
3620  if (MacroOffset)
3621  DataLen += 4; // MacroDirectives offset.
3622 
3623  if (NeedDecls) {
3624  for (IdentifierResolver::iterator D = IdResolver.begin(II),
3625  DEnd = IdResolver.end();
3626  D != DEnd; ++D)
3627  DataLen += 4;
3628  }
3629  }
3630 
3631  using namespace llvm::support;
3632 
3633  endian::Writer LE(Out, little);
3634 
3635  assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen);
3636  LE.write<uint16_t>(DataLen);
3637  // We emit the key length after the data length so that every
3638  // string is preceded by a 16-bit length. This matches the PTH
3639  // format for storing identifiers.
3640  LE.write<uint16_t>(KeyLen);
3641  return std::make_pair(KeyLen, DataLen);
3642  }
3643 
3644  void EmitKey(raw_ostream& Out, const IdentifierInfo* II,
3645  unsigned KeyLen) {
3646  // Record the location of the key data. This is used when generating
3647  // the mapping from persistent IDs to strings.
3648  Writer.SetIdentifierOffset(II, Out.tell());
3649 
3650  // Emit the offset of the key/data length information to the interesting
3651  // identifiers table if necessary.
3652  if (InterestingIdentifierOffsets && isInterestingIdentifier(II))
3653  InterestingIdentifierOffsets->push_back(Out.tell() - 4);
3654 
3655  Out.write(II->getNameStart(), KeyLen);
3656  }
3657 
3658  void EmitData(raw_ostream& Out, IdentifierInfo* II,
3659  IdentID ID, unsigned) {
3660  using namespace llvm::support;
3661 
3662  endian::Writer LE(Out, little);
3663 
3664  auto MacroOffset = Writer.getMacroDirectivesOffset(II);
3665  if (!isInterestingIdentifier(II, MacroOffset)) {
3666  LE.write<uint32_t>(ID << 1);
3667  return;
3668  }
3669 
3670  LE.write<uint32_t>((ID << 1) | 0x01);
3671  uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID();
3672  assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader.");
3673  LE.write<uint16_t>(Bits);
3674  Bits = 0;
3675  bool HadMacroDefinition = MacroOffset != 0;
3676  Bits = (Bits << 1) | unsigned(HadMacroDefinition);
3677  Bits = (Bits << 1) | unsigned(II->isExtensionToken());
3678  Bits = (Bits << 1) | unsigned(II->isPoisoned());
3679  Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin());
3680  Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier());
3681  Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword());
3682  LE.write<uint16_t>(Bits);
3683 
3684  if (HadMacroDefinition)
3685  LE.write<uint32_t>(MacroOffset);
3686 
3687  if (NeedDecls) {
3688  // Emit the declaration IDs in reverse order, because the
3689  // IdentifierResolver provides the declarations as they would be
3690  // visible (e.g., the function "stat" would come before the struct
3691  // "stat"), but the ASTReader adds declarations to the end of the list
3692  // (so we need to see the struct "stat" before the function "stat").
3693  // Only emit declarations that aren't from a chained PCH, though.
3694  SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II),
3695  IdResolver.end());
3696  for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(),
3697  DEnd = Decls.rend();
3698  D != DEnd; ++D)
3699  LE.write<uint32_t>(
3700  Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D)));
3701  }
3702  }
3703 };
3704 
3705 } // namespace
3706 
3707 /// Write the identifier table into the AST file.
3708 ///
3709 /// The identifier table consists of a blob containing string data
3710 /// (the actual identifiers themselves) and a separate "offsets" index
3711 /// that maps identifier IDs to locations within the blob.
3712 void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
3713  IdentifierResolver &IdResolver,
3714  bool IsModule) {
3715  using namespace llvm;
3716 
3717  RecordData InterestingIdents;
3718 
3719  // Create and write out the blob that contains the identifier
3720  // strings.
3721  {
3722  llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator;
3723  ASTIdentifierTableTrait Trait(
3724  *this, PP, IdResolver, IsModule,
3725  (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr);
3726 
3727  // Look for any identifiers that were named while processing the
3728  // headers, but are otherwise not needed. We add these to the hash
3729  // table to enable checking of the predefines buffer in the case
3730  // where the user adds new macro definitions when building the AST
3731  // file.
3733  for (const auto &ID : PP.getIdentifierTable())
3734  IIs.push_back(ID.second);
3735  // Sort the identifiers lexicographically before getting them references so
3736  // that their order is stable.
3737  llvm::sort(IIs, llvm::less_ptr<IdentifierInfo>());
3738  for (const IdentifierInfo *II : IIs)
3739  if (Trait.isInterestingNonMacroIdentifier(II))
3740  getIdentifierRef(II);
3741 
3742  // Create the on-disk hash table representation. We only store offsets
3743  // for identifiers that appear here for the first time.
3744  IdentifierOffsets.resize(NextIdentID - FirstIdentID);
3745  for (auto IdentIDPair : IdentifierIDs) {
3746  auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first);
3747  IdentID ID = IdentIDPair.second;
3748  assert(II && "NULL identifier in identifier table");
3749  // Write out identifiers if either the ID is local or the identifier has
3750  // changed since it was loaded.
3751  if (ID >= FirstIdentID || !Chain || !II->isFromAST()
3752  || II->hasChangedSinceDeserialization() ||
3753  (Trait.needDecls() &&
3754  II->hasFETokenInfoChangedSinceDeserialization()))
3755  Generator.insert(II, ID, Trait);
3756  }
3757 
3758  // Create the on-disk hash table in a buffer.
3760  uint32_t BucketOffset;
3761  {
3762  using namespace llvm::support;
3763 
3764  llvm::raw_svector_ostream Out(IdentifierTable);
3765  // Make sure that no bucket is at offset 0
3766  endian::write<uint32_t>(Out, 0, little);
3767  BucketOffset = Generator.Emit(Out, Trait);
3768  }
3769 
3770  // Create a blob abbreviation
3771  auto Abbrev = std::make_shared<BitCodeAbbrev>();
3772  Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE));
3773  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
3774  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3775  unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3776 
3777  // Write the identifier table
3778  RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset};
3779  Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable);
3780  }
3781 
3782  // Write the offsets table for identifier IDs.
3783  auto Abbrev = std::make_shared<BitCodeAbbrev>();
3784  Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET));
3785  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers
3786  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
3787  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
3788  unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
3789 
3790 #ifndef NDEBUG
3791  for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I)
3792  assert(IdentifierOffsets[I] && "Missing identifier offset?");
3793 #endif
3794 
3795  RecordData::value_type Record[] = {IDENTIFIER_OFFSET,
3796  IdentifierOffsets.size(),
3797  FirstIdentID - NUM_PREDEF_IDENT_IDS};
3798  Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record,
3799  bytes(IdentifierOffsets));
3800 
3801  // In C++, write the list of interesting identifiers (those that are
3802  // defined as macros, poisoned, or similar unusual things).
3803  if (!InterestingIdents.empty())
3804  Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents);
3805 }
3806 
3807 //===----------------------------------------------------------------------===//
3808 // DeclContext's Name Lookup Table Serialization
3809 //===----------------------------------------------------------------------===//
3810 
3811 namespace {
3812 
3813 // Trait used for the on-disk hash table used in the method pool.
3814 class ASTDeclContextNameLookupTrait {
3815  ASTWriter &Writer;
3817 
3818 public:
3819  using key_type = DeclarationNameKey;
3820  using key_type_ref = key_type;
3821 
3822  /// A start and end index into DeclIDs, representing a sequence of decls.
3823  using data_type = std::pair<unsigned, unsigned>;
3824  using data_type_ref = const data_type &;
3825 
3826  using hash_value_type = unsigned;
3827  using offset_type = unsigned;
3828 
3829  explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) {}
3830 
3831  template<typename Coll>
3832  data_type getData(const Coll &Decls) {
3833  unsigned Start = DeclIDs.size();
3834  for (NamedDecl *D : Decls) {
3835  DeclIDs.push_back(
3836  Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D)));
3837  }
3838  return std::make_pair(Start, DeclIDs.size());
3839  }
3840 
3841  data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) {
3842  unsigned Start = DeclIDs.size();
3843  for (auto ID : FromReader)
3844  DeclIDs.push_back(ID);
3845  return std::make_pair(Start, DeclIDs.size());
3846  }
3847 
3848  static bool EqualKey(key_type_ref a, key_type_ref b) {
3849  return a == b;
3850  }
3851 
3852  hash_value_type ComputeHash(DeclarationNameKey Name) {
3853  return Name.getHash();
3854  }
3855 
3856  void EmitFileRef(raw_ostream &Out, ModuleFile *F) const {
3857  assert(Writer.hasChain() &&
3858  "have reference to loaded module file but no chain?");
3859 
3860  using namespace llvm::support;
3861 
3862  endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F), little);
3863  }
3864 
3865  std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out,
3866  DeclarationNameKey Name,
3867  data_type_ref Lookup) {
3868  using namespace llvm::support;
3869 
3870  endian::Writer LE(Out, little);
3871  unsigned KeyLen = 1;
3872  switch (Name.getKind()) {
3879  KeyLen += 4;
3880  break;
3882  KeyLen += 1;
3883  break;
3888  break;
3889  }
3890  LE.write<uint16_t>(KeyLen);
3891 
3892  // 4 bytes for each DeclID.
3893  unsigned DataLen = 4 * (Lookup.second - Lookup.first);
3894  assert(uint16_t(DataLen) == DataLen &&
3895  "too many decls for serialized lookup result");
3896  LE.write<uint16_t>(DataLen);
3897 
3898  return std::make_pair(KeyLen, DataLen);
3899  }
3900 
3901  void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) {
3902  using namespace llvm::support;
3903 
3904  endian::Writer LE(Out, little);
3905  LE.write<uint8_t>(Name.getKind());
3906  switch (Name.getKind()) {
3910  LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier()));
3911  return;
3915  LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector()));
3916  return;
3918  assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS &&
3919  "Invalid operator?");
3920  LE.write<uint8_t>(Name.getOperatorKind());
3921  return;
3926  return;
3927  }
3928 
3929  llvm_unreachable("Invalid name kind?");
3930  }
3931 
3932  void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
3933  unsigned DataLen) {
3934  using namespace llvm::support;
3935 
3936  endian::Writer LE(Out, little);
3937  uint64_t Start = Out.tell(); (void)Start;
3938  for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I)
3939  LE.write<uint32_t>(DeclIDs[I]);
3940  assert(Out.tell() - Start == DataLen && "Data length is wrong");
3941  }
3942 };
3943 
3944 } // namespace
3945 
3946 bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result,
3947  DeclContext *DC) {
3948  return Result.hasExternalDecls() &&
3949  DC->hasNeedToReconcileExternalVisibleStorage();
3950 }
3951 
3952 bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result,
3953  DeclContext *DC) {
3954  for (auto *D : Result.getLookupResult())
3955  if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile())
3956  return false;
3957 
3958  return true;
3959 }
3960 
3961 void
3962 ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC,
3963  llvm::SmallVectorImpl<char> &LookupTable) {
3964  assert(!ConstDC->hasLazyLocalLexicalLookups() &&
3965  !ConstDC->hasLazyExternalLexicalLookups() &&
3966  "must call buildLookups first");
3967 
3968  // FIXME: We need to build the lookups table, which is logically const.
3969  auto *DC = const_cast<DeclContext*>(ConstDC);
3970  assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table");
3971 
3972  // Create the on-disk hash table representation.
3974  ASTDeclContextNameLookupTrait> Generator;
3975  ASTDeclContextNameLookupTrait Trait(*this);
3976 
3977  // The first step is to collect the declaration names which we need to
3978  // serialize into the name lookup table, and to collect them in a stable
3979  // order.
3981 
3982  // We also build up small sets of the constructor and conversion function
3983  // names which are visible.
3984  llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet;
3985 
3986  for (auto &Lookup : *DC->buildLookup()) {
3987  auto &Name = Lookup.first;
3988  auto &Result = Lookup.second;
3989 
3990  // If there are no local declarations in our lookup result, we
3991  // don't need to write an entry for the name at all. If we can't
3992  // write out a lookup set without performing more deserialization,
3993  // just skip this entry.
3994  if (isLookupResultExternal(Result, DC) &&
3995  isLookupResultEntirelyExternal(Result, DC))
3996  continue;
3997 
3998  // We also skip empty results. If any of the results could be external and
3999  // the currently available results are empty, then all of the results are
4000  // external and we skip it above. So the only way we get here with an empty
4001  // results is when no results could have been external *and* we have
4002  // external results.
4003  //
4004  // FIXME: While we might want to start emitting on-disk entries for negative
4005  // lookups into a decl context as an optimization, today we *have* to skip
4006  // them because there are names with empty lookup results in decl contexts
4007  // which we can't emit in any stable ordering: we lookup constructors and
4008  // conversion functions in the enclosing namespace scope creating empty
4009  // results for them. This in almost certainly a bug in Clang's name lookup,
4010  // but that is likely to be hard or impossible to fix and so we tolerate it
4011  // here by omitting lookups with empty results.
4012  if (Lookup.second.getLookupResult().empty())
4013  continue;
4014 
4015  switch (Lookup.first.getNameKind()) {
4016  default:
4017  Names.push_back(Lookup.first);
4018  break;
4019 
4021  assert(isa<CXXRecordDecl>(DC) &&
4022  "Cannot have a constructor name outside of a class!");
4023  ConstructorNameSet.insert(Name);
4024  break;
4025 
4027  assert(isa<CXXRecordDecl>(DC) &&
4028  "Cannot have a conversion function name outside of a class!");
4029  ConversionNameSet.insert(Name);
4030  break;
4031  }
4032  }
4033 
4034  // Sort the names into a stable order.
4035  llvm::sort(Names);
4036 
4037  if (auto *D = dyn_cast<CXXRecordDecl>(DC)) {
4038  // We need to establish an ordering of constructor and conversion function
4039  // names, and they don't have an intrinsic ordering.
4040 
4041  // First we try the easy case by forming the current context's constructor
4042  // name and adding that name first. This is a very useful optimization to
4043  // avoid walking the lexical declarations in many cases, and it also
4044  // handles the only case where a constructor name can come from some other
4045  // lexical context -- when that name is an implicit constructor merged from
4046  // another declaration in the redecl chain. Any non-implicit constructor or
4047  // conversion function which doesn't occur in all the lexical contexts
4048  // would be an ODR violation.
4049  auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName(
4050  Context->getCanonicalType(Context->getRecordType(D)));
4051  if (ConstructorNameSet.erase(ImplicitCtorName))
4052  Names.push_back(ImplicitCtorName);
4053 
4054  // If we still have constructors or conversion functions, we walk all the
4055  // names in the decl and add the constructors and conversion functions
4056  // which are visible in the order they lexically occur within the context.
4057  if (!ConstructorNameSet.empty() || !ConversionNameSet.empty())
4058  for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls())
4059  if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) {
4060  auto Name = ChildND->getDeclName();
4061  switch (Name.getNameKind()) {
4062  default:
4063  continue;
4064 
4066  if (ConstructorNameSet.erase(Name))
4067  Names.push_back(Name);
4068  break;
4069 
4071  if (ConversionNameSet.erase(Name))
4072  Names.push_back(Name);
4073  break;
4074  }
4075 
4076  if (ConstructorNameSet.empty() && ConversionNameSet.empty())
4077  break;
4078  }
4079 
4080  assert(ConstructorNameSet.empty() && "Failed to find all of the visible "
4081  "constructors by walking all the "
4082  "lexical members of the context.");
4083  assert(ConversionNameSet.empty() && "Failed to find all of the visible "
4084  "conversion functions by walking all "
4085  "the lexical members of the context.");
4086  }
4087 
4088  // Next we need to do a lookup with each name into this decl context to fully
4089  // populate any results from external sources. We don't actually use the
4090  // results of these lookups because we only want to use the results after all
4091  // results have been loaded and the pointers into them will be stable.
4092  for (auto &Name : Names)
4093  DC->lookup(Name);
4094 
4095  // Now we need to insert the results for each name into the hash table. For
4096  // constructor names and conversion function names, we actually need to merge
4097  // all of the results for them into one list of results each and insert
4098  // those.
4099  SmallVector<NamedDecl *, 8> ConstructorDecls;
4100  SmallVector<NamedDecl *, 8> ConversionDecls;
4101 
4102  // Now loop over the names, either inserting them or appending for the two
4103  // special cases.
4104  for (auto &Name : Names) {
4105  DeclContext::lookup_result Result = DC->noload_lookup(Name);
4106 
4107  switch (Name.getNameKind()) {
4108  default:
4109  Generator.insert(Name, Trait.getData(Result), Trait);
4110  break;
4111 
4113  ConstructorDecls.append(Result.begin(), Result.end());
4114  break;
4115 
4117  ConversionDecls.append(Result.begin(), Result.end());
4118  break;
4119  }
4120  }
4121 
4122  // Handle our two special cases if we ended up having any. We arbitrarily use
4123  // the first declaration's name here because the name itself isn't part of
4124  // the key, only the kind of name is used.
4125  if (!ConstructorDecls.empty())
4126  Generator.insert(ConstructorDecls.front()->getDeclName(),
4127  Trait.getData(ConstructorDecls), Trait);
4128  if (!ConversionDecls.empty())
4129  Generator.insert(ConversionDecls.front()->getDeclName(),
4130  Trait.getData(ConversionDecls), Trait);
4131 
4132  // Create the on-disk hash table. Also emit the existing imported and
4133  // merged table if there is one.
4134  auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr;
4135  Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr);
4136 }
4137 
4138 /// Write the block containing all of the declaration IDs
4139 /// visible from the given DeclContext.
4140 ///
4141 /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the
4142 /// bitstream, or 0 if no block was written.
4143 uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
4144  DeclContext *DC) {
4145  // If we imported a key declaration of this namespace, write the visible
4146  // lookup results as an update record for it rather than including them
4147  // on this declaration. We will only look at key declarations on reload.
4148  if (isa<NamespaceDecl>(DC) && Chain &&
4149  Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) {
4150  // Only do this once, for the first local declaration of the namespace.
4151  for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev;
4152  Prev = Prev->getPreviousDecl())
4153  if (!Prev->isFromASTFile())
4154  return 0;
4155 
4156  // Note that we need to emit an update record for the primary context.
4157  UpdatedDeclContexts.insert(DC->getPrimaryContext());
4158 
4159  // Make sure all visible decls are written. They will be recorded later. We
4160  // do this using a side data structure so we can sort the names into
4161  // a deterministic order.
4164  LookupResults;
4165  if (Map) {
4166  LookupResults.reserve(Map->size());
4167  for (auto &Entry : *Map)
4168  LookupResults.push_back(
4169  std::make_pair(Entry.first, Entry.second.getLookupResult()));
4170  }
4171 
4172  llvm::sort(LookupResults, llvm::less_first());
4173  for (auto &NameAndResult : LookupResults) {
4174  DeclarationName Name = NameAndResult.first;
4175  DeclContext::lookup_result Result = NameAndResult.second;
4178  // We have to work around a name lookup bug here where negative lookup
4179  // results for these names get cached in namespace lookup tables (these
4180  // names should never be looked up in a namespace).
4181  assert(Result.empty() && "Cannot have a constructor or conversion "
4182  "function name in a namespace!");
4183  continue;
4184  }
4185 
4186  for (NamedDecl *ND : Result)
4187  if (!ND->isFromASTFile())
4188  GetDeclRef(ND);
4189  }
4190 
4191  return 0;
4192  }
4193 
4194  if (DC->getPrimaryContext() != DC)
4195  return 0;
4196 
4197  // Skip contexts which don't support name lookup.
4198  if (!DC->isLookupContext())
4199  return 0;
4200 
4201  // If not in C++, we perform name lookup for the translation unit via the
4202  // IdentifierInfo chains, don't bother to build a visible-declarations table.
4203  if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus)
4204  return 0;
4205 
4206  // Serialize the contents of the mapping used for lookup. Note that,
4207  // although we have two very different code paths, the serialized
4208  // representation is the same for both cases: a declaration name,
4209  // followed by a size, followed by references to the visible
4210  // declarations that have that name.
4211  uint64_t Offset = Stream.GetCurrentBitNo();
4212  StoredDeclsMap *Map = DC->buildLookup();
4213  if (!Map || Map->empty())
4214  return 0;
4215 
4216  // Create the on-disk hash table in a buffer.
4217  SmallString<4096> LookupTable;
4218  GenerateNameLookupTable(DC, LookupTable);
4219 
4220  // Write the lookup table
4221  RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE};
4222  Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record,
4223  LookupTable);
4224  ++NumVisibleDeclContexts;
4225  return Offset;
4226 }
4227 
4228 /// Write an UPDATE_VISIBLE block for the given context.
4229 ///
4230 /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing
4231 /// DeclContext in a dependent AST file. As such, they only exist for the TU
4232 /// (in C++), for namespaces, and for classes with forward-declared unscoped
4233 /// enumeration members (in C++11).
4234 void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) {
4235  StoredDeclsMap *Map = DC->getLookupPtr();
4236  if (!Map || Map->empty())
4237  return;
4238 
4239  // Create the on-disk hash table in a buffer.
4240  SmallString<4096> LookupTable;
4241  GenerateNameLookupTable(DC, LookupTable);
4242 
4243  // If we're updating a namespace, select a key declaration as the key for the
4244  // update record; those are the only ones that will be checked on reload.
4245  if (isa<NamespaceDecl>(DC))
4246  DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC)));
4247 
4248  // Write the lookup table
4249  RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))};
4250  Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable);
4251 }
4252 
4253 /// Write an FP_PRAGMA_OPTIONS block for the given FPOptions.
4254 void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) {
4255  RecordData::value_type Record[] = {Opts.getInt()};
4256  Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record);
4257 }
4258 
4259 /// Write an OPENCL_EXTENSIONS block for the given OpenCLOptions.
4260 void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) {
4261  if (!SemaRef.Context.getLangOpts().OpenCL)
4262  return;
4263 
4264  const OpenCLOptions &Opts = SemaRef.getOpenCLOptions();
4265  RecordData Record;
4266  for (const auto &I:Opts.OptMap) {
4267  AddString(I.getKey(), Record);
4268  auto V = I.getValue();
4269  Record.push_back(V.Supported ? 1 : 0);
4270  Record.push_back(V.Enabled ? 1 : 0);
4271  Record.push_back(V.Avail);
4272  Record.push_back(V.Core);
4273  }
4274  Stream.EmitRecord(OPENCL_EXTENSIONS, Record);
4275 }
4276 
4277 void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) {
4278  if (!SemaRef.Context.getLangOpts().OpenCL)
4279  return;
4280 
4281  RecordData Record;
4282  for (const auto &I : SemaRef.OpenCLTypeExtMap) {
4283  Record.push_back(
4284  static_cast<unsigned>(getTypeID(I.first->getCanonicalTypeInternal())));
4285  Record.push_back(I.second.size());
4286  for (auto Ext : I.second)
4287  AddString(Ext, Record);
4288  }
4289  Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
4290 }
4291 
4292 void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) {
4293  if (!SemaRef.Context.getLangOpts().OpenCL)
4294  return;
4295 
4296  RecordData Record;
4297  for (const auto &I : SemaRef.OpenCLDeclExtMap) {
4298  Record.push_back(getDeclID(I.first));
4299  Record.push_back(static_cast<unsigned>(I.second.size()));
4300  for (auto Ext : I.second)
4301  AddString(Ext, Record);
4302  }
4303  Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record);
4304 }
4305 
4306 void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) {
4307  if (SemaRef.ForceCUDAHostDeviceDepth > 0) {
4308  RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth};
4309  Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record);
4310  }
4311 }
4312 
4313 void ASTWriter::WriteObjCCategories() {
4314  SmallVector<ObjCCategoriesInfo, 2> CategoriesMap;
4315  RecordData Categories;
4316 
4317  for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) {
4318  unsigned Size = 0;
4319  unsigned StartIndex = Categories.size();
4320 
4321  ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I];
4322 
4323  // Allocate space for the size.
4324  Categories.push_back(0);
4325 
4326  // Add the categories.
4328  Cat = Class->known_categories_begin(),
4329  CatEnd = Class->known_categories_end();
4330  Cat != CatEnd; ++Cat, ++Size) {
4331  assert(getDeclID(*Cat) != 0 && "Bogus category");
4332  AddDeclRef(*Cat, Categories);
4333  }
4334 
4335  // Update the size.
4336  Categories[StartIndex] = Size;
4337 
4338  // Record this interface -> category map.
4339  ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex };
4340  CategoriesMap.push_back(CatInfo);
4341  }
4342 
4343  // Sort the categories map by the definition ID, since the reader will be
4344  // performing binary searches on this information.
4345  llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end());
4346 
4347  // Emit the categories map.
4348  using namespace llvm;
4349 
4350  auto Abbrev = std::make_shared<BitCodeAbbrev>();
4351  Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP));
4352  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries
4353  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
4354  unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev));
4355 
4356  RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()};
4357  Stream.EmitRecordWithBlob(AbbrevID, Record,
4358  reinterpret_cast<char *>(CategoriesMap.data()),
4359  CategoriesMap.size() * sizeof(ObjCCategoriesInfo));
4360 
4361  // Emit the category lists.
4362  Stream.EmitRecord(OBJC_CATEGORIES, Categories);
4363 }
4364 
4365 void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) {
4367 
4368  if (LPTMap.empty())
4369  return;
4370 
4371  RecordData Record;
4372  for (auto &LPTMapEntry : LPTMap) {
4373  const FunctionDecl *FD = LPTMapEntry.first;
4374  LateParsedTemplate &LPT = *LPTMapEntry.second;
4375  AddDeclRef(FD, Record);
4376  AddDeclRef(LPT.D, Record);
4377  Record.push_back(LPT.Toks.size());
4378 
4379  for (const auto &Tok : LPT.Toks) {
4380  AddToken(Tok, Record);
4381  }
4382  }
4383  Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record);
4384 }
4385 
4386 /// Write the state of 'pragma clang optimize' at the end of the module.
4387 void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) {
4388  RecordData Record;
4389  SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation();
4390  AddSourceLocation(PragmaLoc, Record);
4391  Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record);
4392 }
4393 
4394 /// Write the state of 'pragma ms_struct' at the end of the module.
4395 void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) {
4396  RecordData Record;
4397  Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF);
4398  Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record);
4399 }
4400 
4401 /// Write the state of 'pragma pointers_to_members' at the end of the
4402 //module.
4403 void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) {
4404  RecordData Record;
4405  Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod);
4406  AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record);
4407  Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record);
4408 }
4409 
4410 /// Write the state of 'pragma pack' at the end of the module.
4411 void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) {
4412  // Don't serialize pragma pack state for modules, since it should only take
4413  // effect on a per-submodule basis.
4414  if (WritingModule)
4415  return;
4416 
4417  RecordData Record;
4418  Record.push_back(SemaRef.PackStack.CurrentValue);
4419  AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record);
4420  Record.push_back(SemaRef.PackStack.Stack.size());
4421  for (const auto &StackEntry : SemaRef.PackStack.Stack) {
4422  Record.push_back(StackEntry.Value);
4423  AddSourceLocation(StackEntry.PragmaLocation, Record);
4424  AddSourceLocation(StackEntry.PragmaPushLocation, Record);
4425  AddString(StackEntry.StackSlotLabel, Record);
4426  }
4427  Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record);
4428 }
4429 
4430 void ASTWriter::WriteModuleFileExtension(Sema &SemaRef,
4431  ModuleFileExtensionWriter &Writer) {
4432  // Enter the extension block.
4433  Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4);
4434 
4435  // Emit the metadata record abbreviation.
4436  auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
4437  Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA));
4438  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
4439  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
4440  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
4441  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
4442  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
4443  unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv));
4444 
4445  // Emit the metadata record.
4446  RecordData Record;
4447  auto Metadata = Writer.getExtension()->getExtensionMetadata();
4448  Record.push_back(EXTENSION_METADATA);
4449  Record.push_back(Metadata.MajorVersion);
4450  Record.push_back(Metadata.MinorVersion);
4451  Record.push_back(Metadata.BlockName.size());
4452  Record.push_back(Metadata.UserInfo.size());
4453  SmallString<64> Buffer;
4454  Buffer += Metadata.BlockName;
4455  Buffer += Metadata.UserInfo;
4456  Stream.EmitRecordWithBlob(Abbrev, Record, Buffer);
4457 
4458  // Emit the contents of the extension block.
4459  Writer.writeExtensionContents(SemaRef, Stream);
4460 
4461  // Exit the extension block.
4462  Stream.ExitBlock();
4463 }
4464 
4465 //===----------------------------------------------------------------------===//
4466 // General Serialization Routines
4467 //===----------------------------------------------------------------------===//
4468 
4470  auto &Record = *this;
4471  if (!A)
4472  return Record.push_back(0);
4473  Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs
4474  Record.AddSourceRange(A->getRange());
4475 
4476 #include "clang/Serialization/AttrPCHWrite.inc"
4477 }
4478 
4479 /// Emit the list of attributes to the specified record.
4481  push_back(Attrs.size());
4482  for (const auto *A : Attrs)
4483  AddAttr(A);
4484 }
4485 
4487  AddSourceLocation(Tok.getLocation(), Record);
4488  Record.push_back(Tok.getLength());
4489 
4490  // FIXME: When reading literal tokens, reconstruct the literal pointer
4491  // if it is needed.
4492  AddIdentifierRef(Tok.getIdentifierInfo(), Record);
4493  // FIXME: Should translate token kind to a stable encoding.
4494  Record.push_back(Tok.getKind());
4495  // FIXME: Should translate token flags to a stable encoding.
4496  Record.push_back(Tok.getFlags());
4497 }
4498 
4499 void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) {
4500  Record.push_back(Str.size());
4501  Record.insert(Record.end(), Str.begin(), Str.end());
4502 }
4503 
4505  assert(Context && "should have context when outputting path");
4506 
4507  bool Changed =
4509 
4510  // Remove a prefix to make the path relative, if relevant.
4511  const char *PathBegin = Path.data();
4512  const char *PathPtr =
4513  adjustFilenameForRelocatableAST(PathBegin, BaseDirectory);
4514  if (PathPtr != PathBegin) {
4515  Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin));
4516  Changed = true;
4517  }
4518 
4519  return Changed;
4520 }
4521 
4522 void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) {
4523  SmallString<128> FilePath(Path);
4524  PreparePathForOutput(FilePath);
4525  AddString(FilePath, Record);
4526 }
4527 
4528 void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
4529  StringRef Path) {
4530  SmallString<128> FilePath(Path);
4531  PreparePathForOutput(FilePath);
4532  Stream.EmitRecordWithBlob(Abbrev, Record, FilePath);
4533 }
4534 
4535 void ASTWriter::AddVersionTuple(const VersionTuple &Version,
4536  RecordDataImpl &Record) {
4537  Record.push_back(Version.getMajor());
4538  if (Optional<unsigned> Minor = Version.getMinor())
4539  Record.push_back(*Minor + 1);
4540  else
4541  Record.push_back(0);
4542  if (Optional<unsigned> Subminor = Version.getSubminor())
4543  Record.push_back(*Subminor + 1);
4544  else
4545  Record.push_back(0);
4546 }
4547 
4548 /// Note that the identifier II occurs at the given offset
4549 /// within the identifier table.
4551  IdentID ID = IdentifierIDs[II];
4552  // Only store offsets new to this AST file. Other identifier names are looked
4553  // up earlier in the chain and thus don't need an offset.
4554  if (ID >= FirstIdentID)
4555  IdentifierOffsets[ID - FirstIdentID] = Offset;
4556 }
4557 
4558 /// Note that the selector Sel occurs at the given offset
4559 /// within the method pool/selector table.
4561  unsigned ID = SelectorIDs[Sel];
4562  assert(ID && "Unknown selector");
4563  // Don't record offsets for selectors that are also available in a different
4564  // file.
4565  if (ID < FirstSelectorID)
4566  return;
4567  SelectorOffsets[ID - FirstSelectorID] = Offset;
4568 }
4569 
4570 ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream,
4571  SmallVectorImpl<char> &Buffer, MemoryBufferCache &PCMCache,
4572  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
4573  bool IncludeTimestamps)
4574  : Stream(Stream), Buffer(Buffer), PCMCache(PCMCache),
4575  IncludeTimestamps(IncludeTimestamps) {
4576  for (const auto &Ext : Extensions) {
4577  if (auto Writer = Ext->createExtensionWriter(*this))
4578  ModuleFileExtensionWriters.push_back(std::move(Writer));
4579  }
4580 }
4581 
4583  llvm::DeleteContainerSeconds(FileDeclIDs);
4584 }
4585 
4587  assert(WritingAST && "can't determine lang opts when not writing AST");
4588  return Context->getLangOpts();
4589 }
4590 
4592  return IncludeTimestamps ? E->getModificationTime() : 0;
4593 }
4594 
4596  const std::string &OutputFile,
4597  Module *WritingModule, StringRef isysroot,
4598  bool hasErrors) {
4599  WritingAST = true;
4600 
4601  ASTHasCompilerErrors = hasErrors;
4602 
4603  // Emit the file header.
4604  Stream.Emit((unsigned)'C', 8);
4605  Stream.Emit((unsigned)'P', 8);
4606  Stream.Emit((unsigned)'C', 8);
4607  Stream.Emit((unsigned)'H', 8);
4608 
4609  WriteBlockInfoBlock();
4610 
4611  Context = &SemaRef.Context;
4612  PP = &SemaRef.PP;
4613  this->WritingModule = WritingModule;
4614  ASTFileSignature Signature =
4615  WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule);
4616  Context = nullptr;
4617  PP = nullptr;
4618  this->WritingModule = nullptr;
4619  this->BaseDirectory.clear();
4620 
4621  WritingAST = false;
4622  if (SemaRef.Context.getLangOpts().ImplicitModules && WritingModule) {
4623  // Construct MemoryBuffer and update buffer manager.
4624  PCMCache.addBuffer(OutputFile,
4625  llvm::MemoryBuffer::getMemBufferCopy(
4626  StringRef(Buffer.begin(), Buffer.size())));
4627  }
4628  return Signature;
4629 }
4630 
4631 template<typename Vector>
4632 static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec,
4633  ASTWriter::RecordData &Record) {
4634  for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end();
4635  I != E; ++I) {
4636  Writer.AddDeclRef(*I, Record);
4637  }
4638 }
4639 
4640 ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
4641  const std::string &OutputFile,
4642  Module *WritingModule) {
4643  using namespace llvm;
4644 
4645  bool isModule = WritingModule != nullptr;
4646 
4647  // Make sure that the AST reader knows to finalize itself.
4648  if (Chain)
4649  Chain->finalizeForWriting();
4650 
4651  ASTContext &Context = SemaRef.Context;
4652  Preprocessor &PP = SemaRef.PP;
4653 
4654  // Set up predefined declaration IDs.
4655  auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) {
4656  if (D) {
4657  assert(D->isCanonicalDecl() && "predefined decl is not canonical");
4658  DeclIDs[D] = ID;
4659  }
4660  };
4661  RegisterPredefDecl(Context.getTranslationUnitDecl(),
4663  RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID);
4664  RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID);
4665  RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID);
4666  RegisterPredefDecl(Context.ObjCProtocolClassDecl,
4668  RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID);
4669  RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID);
4670  RegisterPredefDecl(Context.ObjCInstanceTypeDecl,
4672  RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID);
4673  RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG);
4674  RegisterPredefDecl(Context.BuiltinMSVaListDecl,
4676  RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID);
4677  RegisterPredefDecl(Context.MakeIntegerSeqDecl,
4679  RegisterPredefDecl(Context.CFConstantStringTypeDecl,
4681  RegisterPredefDecl(Context.CFConstantStringTagDecl,
4683  RegisterPredefDecl(Context.TypePackElementDecl,
4685 
4686  // Build a record containing all of the tentative definitions in this file, in
4687  // TentativeDefinitions order. Generally, this record will be empty for
4688  // headers.
4689  RecordData TentativeDefinitions;
4690  AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions);
4691 
4692  // Build a record containing all of the file scoped decls in this file.
4693  RecordData UnusedFileScopedDecls;
4694  if (!isModule)
4696  UnusedFileScopedDecls);
4697 
4698  // Build a record containing all of the delegating constructors we still need
4699  // to resolve.
4700  RecordData DelegatingCtorDecls;
4701  if (!isModule)
4702  AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls);
4703 
4704  // Write the set of weak, undeclared identifiers. We always write the
4705  // entire table, since later PCH files in a PCH chain are only interested in
4706  // the results at the end of the chain.
4707  RecordData WeakUndeclaredIdentifiers;
4708  for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) {
4709  IdentifierInfo *II = WeakUndeclaredIdentifier.first;
4710  WeakInfo &WI = WeakUndeclaredIdentifier.second;
4711  AddIdentifierRef(II, WeakUndeclaredIdentifiers);
4712  AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
4713  AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
4714  WeakUndeclaredIdentifiers.push_back(WI.getUsed());
4715  }
4716 
4717  // Build a record containing all of the ext_vector declarations.
4718  RecordData ExtVectorDecls;
4719  AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls);
4720 
4721  // Build a record containing all of the VTable uses information.
4722  RecordData VTableUses;
4723  if (!SemaRef.VTableUses.empty()) {
4724  for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) {
4725  AddDeclRef(SemaRef.VTableUses[I].first, VTableUses);
4726  AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses);
4727  VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]);
4728  }
4729  }
4730 
4731  // Build a record containing all of the UnusedLocalTypedefNameCandidates.
4732  RecordData UnusedLocalTypedefNameCandidates;
4733  for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates)
4734  AddDeclRef(TD, UnusedLocalTypedefNameCandidates);
4735 
4736  // Build a record containing all of pending implicit instantiations.
4737  RecordData PendingInstantiations;
4738  for (const auto &I : SemaRef.PendingInstantiations) {
4739  AddDeclRef(I.first, PendingInstantiations);
4740  AddSourceLocation(I.second, PendingInstantiations);
4741  }
4742  assert(SemaRef.PendingLocalImplicitInstantiations.empty() &&
4743  "There are local ones at end of translation unit!");
4744 
4745  // Build a record containing some declaration references.
4746  RecordData SemaDeclRefs;
4747  if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) {
4748  AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs);
4749  AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs);
4750  AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs);
4751  }
4752 
4753  RecordData CUDASpecialDeclRefs;
4754  if (Context.getcudaConfigureCallDecl()) {
4755  AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs);
4756  }
4757 
4758  // Build a record containing all of the known namespaces.
4759  RecordData KnownNamespaces;
4760  for (const auto &I : SemaRef.KnownNamespaces) {
4761  if (!I.second)
4762  AddDeclRef(I.first, KnownNamespaces);
4763  }
4764 
4765  // Build a record of all used, undefined objects that require definitions.
4766  RecordData UndefinedButUsed;
4767 
4769  SemaRef.getUndefinedButUsed(Undefined);
4770  for (const auto &I : Undefined) {
4771  AddDeclRef(I.first, UndefinedButUsed);
4772  AddSourceLocation(I.second, UndefinedButUsed);
4773  }
4774 
4775  // Build a record containing all delete-expressions that we would like to
4776  // analyze later in AST.
4777  RecordData DeleteExprsToAnalyze;
4778 
4779  if (!isModule) {
4780  for (const auto &DeleteExprsInfo :
4781  SemaRef.getMismatchingDeleteExpressions()) {
4782  AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze);
4783  DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size());
4784  for (const auto &DeleteLoc : DeleteExprsInfo.second) {
4785  AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze);
4786  DeleteExprsToAnalyze.push_back(DeleteLoc.second);
4787  }
4788  }
4789  }
4790 
4791  // Write the control block
4792  WriteControlBlock(PP, Context, isysroot, OutputFile);
4793 
4794  // Write the remaining AST contents.
4795  Stream.EnterSubblock(AST_BLOCK_ID, 5);
4796 
4797  // This is so that older clang versions, before the introduction
4798  // of the control block, can read and reject the newer PCH format.
4799  {
4800  RecordData Record = {VERSION_MAJOR};
4801  Stream.EmitRecord(METADATA_OLD_FORMAT, Record);
4802  }
4803 
4804  // Create a lexical update block containing all of the declarations in the
4805  // translation unit that do not come from other AST files.
4806  const TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
4807  SmallVector<uint32_t, 128> NewGlobalKindDeclPairs;
4808  for (const auto *D : TU->noload_decls()) {
4809  if (!D->isFromASTFile()) {
4810  NewGlobalKindDeclPairs.push_back(D->getKind());
4811  NewGlobalKindDeclPairs.push_back(GetDeclRef(D));
4812  }
4813  }
4814 
4815  auto Abv = std::make_shared<BitCodeAbbrev>();
4816  Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL));
4817  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
4818  unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
4819  {
4820  RecordData::value_type Record[] = {TU_UPDATE_LEXICAL};
4821  Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record,
4822  bytes(NewGlobalKindDeclPairs));
4823  }
4824 
4825  // And a visible updates block for the translation unit.
4826  Abv = std::make_shared<BitCodeAbbrev>();
4827  Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE));
4828  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
4829  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
4830  UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
4831  WriteDeclContextVisibleUpdate(TU);
4832 
4833  // If we have any extern "C" names, write out a visible update for them.
4834  if (Context.ExternCContext)
4835  WriteDeclContextVisibleUpdate(Context.ExternCContext);
4836 
4837  // If the translation unit has an anonymous namespace, and we don't already
4838  // have an update block for it, write it as an update block.
4839  // FIXME: Why do we not do this if there's already an update block?
4840  if (NamespaceDecl *NS = TU->getAnonymousNamespace()) {
4841  ASTWriter::UpdateRecord &Record = DeclUpdates[TU];
4842  if (Record.empty())
4843  Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS));
4844  }
4845 
4846  // Add update records for all mangling numbers and static local numbers.
4847  // These aren't really update records, but this is a convenient way of
4848  // tagging this rare extra data onto the declarations.
4849  for (const auto &Number : Context.MangleNumbers)
4850  if (!Number.first->isFromASTFile())
4851  DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER,
4852  Number.second));
4853  for (const auto &Number : Context.StaticLocalNumbers)
4854  if (!Number.first->isFromASTFile())
4855  DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER,
4856  Number.second));
4857 
4858  // Make sure visible decls, added to DeclContexts previously loaded from
4859  // an AST file, are registered for serialization. Likewise for template
4860  // specializations added to imported templates.
4861  for (const auto *I : DeclsToEmitEvenIfUnreferenced) {
4862  GetDeclRef(I);
4863  }
4864 
4865  // Make sure all decls associated with an identifier are registered for
4866  // serialization, if we're storing decls with identifiers.
4867  if (!WritingModule || !getLangOpts().CPlusPlus) {
4869  for (const auto &ID : PP.getIdentifierTable()) {
4870  const IdentifierInfo *II = ID.second;
4871  if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization())
4872  IIs.push_back(II);
4873  }
4874  // Sort the identifiers to visit based on their name.
4875  llvm::sort(IIs, llvm::less_ptr<IdentifierInfo>());
4876  for (const IdentifierInfo *II : IIs) {
4877  for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II),
4878  DEnd = SemaRef.IdResolver.end();
4879  D != DEnd; ++D) {
4880  GetDeclRef(*D);
4881  }
4882  }
4883  }
4884 
4885  // For method pool in the module, if it contains an entry for a selector,
4886  // the entry should be complete, containing everything introduced by that
4887  // module and all modules it imports. It's possible that the entry is out of
4888  // date, so we need to pull in the new content here.
4889 
4890  // It's possible that updateOutOfDateSelector can update SelectorIDs. To be
4891  // safe, we copy all selectors out.
4892  llvm::SmallVector<Selector, 256> AllSelectors;
4893  for (auto &SelectorAndID : SelectorIDs)
4894  AllSelectors.push_back(SelectorAndID.first);
4895  for (auto &Selector : AllSelectors)
4897 
4898  // Form the record of special types.
4899  RecordData SpecialTypes;
4900  AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
4901  AddTypeRef(Context.getFILEType(), SpecialTypes);
4902  AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
4903  AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
4904  AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes);
4905  AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
4906  AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
4907  AddTypeRef(Context.getucontext_tType(), SpecialTypes);
4908 
4909  if (Chain) {
4910  // Write the mapping information describing our module dependencies and how
4911  // each of those modules were mapped into our own offset/ID space, so that
4912  // the reader can build the appropriate mapping to its own offset/ID space.
4913  // The map consists solely of a blob with the following format:
4914  // *(module-kind:i8
4915  // module-name-len:i16 module-name:len*i8
4916  // source-location-offset:i32
4917  // identifier-id:i32
4918  // preprocessed-entity-id:i32
4919  // macro-definition-id:i32
4920  // submodule-id:i32
4921  // selector-id:i32
4922  // declaration-id:i32
4923  // c++-base-specifiers-id:i32
4924  // type-id:i32)
4925  //
4926  // module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule or
4927  // MK_ExplicitModule, then the module-name is the module name. Otherwise,
4928  // it is the module file name.
4929  auto Abbrev = std::make_shared<BitCodeAbbrev>();
4930  Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP));
4931  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
4932  unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
4933  SmallString<2048> Buffer;
4934  {
4935  llvm::raw_svector_ostream Out(Buffer);
4936  for (ModuleFile &M : Chain->ModuleMgr) {
4937  using namespace llvm::support;
4938 
4939  endian::Writer LE(Out, little);
4940  LE.write<uint8_t>(static_cast<uint8_t>(M.Kind));
4941  StringRef Name =
4943  ? M.ModuleName
4944  : M.FileName;
4945  LE.write<uint16_t>(Name.size());
4946  Out.write(Name.data(), Name.size());
4947 
4948  // Note: if a base ID was uint max, it would not be possible to load
4949  // another module after it or have more than one entity inside it.
4951 
4952  auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) {
4953  assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high");
4954  if (ShouldWrite)
4955  LE.write<uint32_t>(BaseID);
4956  else
4957  LE.write<uint32_t>(None);
4958  };
4959 
4960  // These values should be unique within a chain, since they will be read
4961  // as keys into ContinuousRangeMaps.
4962  writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries);
4963  writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers);
4964  writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros);
4965  writeBaseIDOrNone(M.BasePreprocessedEntityID,
4967  writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules);
4968  writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors);
4969  writeBaseIDOrNone(M.BaseDeclID, M.LocalNumDecls);
4970  writeBaseIDOrNone(M.BaseTypeIndex, M.LocalNumTypes);
4971  }
4972  }
4973  RecordData::value_type Record[] = {MODULE_OFFSET_MAP};
4974  Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
4975  Buffer.data(), Buffer.size());
4976  }
4977 
4978  RecordData DeclUpdatesOffsetsRecord;
4979 
4980  // Keep writing types, declarations, and declaration update records
4981  // until we've emitted all of them.
4982  Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5);
4983  WriteTypeAbbrevs();
4984  WriteDeclAbbrevs();
4985  do {
4986  WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord);
4987  while (!DeclTypesToEmit.empty()) {
4988  DeclOrType DOT = DeclTypesToEmit.front();
4989  DeclTypesToEmit.pop();
4990  if (DOT.isType())
4991  WriteType(DOT.getType());
4992  else
4993  WriteDecl(Context, DOT.getDecl());
4994  }
4995  } while (!DeclUpdates.empty());
4996  Stream.ExitBlock();
4997 
4998  DoneWritingDeclsAndTypes = true;
4999 
5000  // These things can only be done once we've written out decls and types.
5001  WriteTypeDeclOffsets();
5002  if (!DeclUpdatesOffsetsRecord.empty())
5003  Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
5004  WriteFileDeclIDsMap();
5005  WriteSourceManagerBlock(Context.getSourceManager(), PP);
5006  WriteComments();
5007  WritePreprocessor(PP, isModule);
5008  WriteHeaderSearch(PP.getHeaderSearchInfo());
5009  WriteSelectors(SemaRef);
5010  WriteReferencedSelectorsPool(SemaRef);
5011  WriteLateParsedTemplates(SemaRef);
5012  WriteIdentifierTable(PP, SemaRef.IdResolver, isModule);
5013  WriteFPPragmaOptions(SemaRef.getFPOptions());
5014  WriteOpenCLExtensions(SemaRef);
5015  WriteOpenCLExtensionTypes(SemaRef);
5016  WriteCUDAPragmas(SemaRef);
5017 
5018  // If we're emitting a module, write out the submodule information.
5019  if (WritingModule)
5020  WriteSubmodules(WritingModule);
5021 
5022  // We need to have information about submodules to correctly deserialize
5023  // decls from OpenCLExtensionDecls block
5024  WriteOpenCLExtensionDecls(SemaRef);
5025 
5026  Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
5027 
5028  // Write the record containing external, unnamed definitions.
5029  if (!EagerlyDeserializedDecls.empty())
5030  Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls);
5031 
5032  if (!ModularCodegenDecls.empty())
5033  Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls);
5034 
5035  // Write the record containing tentative definitions.
5036  if (!TentativeDefinitions.empty())
5037  Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions);
5038 
5039  // Write the record containing unused file scoped decls.
5040  if (!UnusedFileScopedDecls.empty())
5041  Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls);
5042 
5043  // Write the record containing weak undeclared identifiers.
5044  if (!WeakUndeclaredIdentifiers.empty())
5045  Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS,
5046  WeakUndeclaredIdentifiers);
5047 
5048  // Write the record containing ext_vector type names.
5049  if (!ExtVectorDecls.empty())
5050  Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls);
5051 
5052  // Write the record containing VTable uses information.
5053  if (!VTableUses.empty())
5054  Stream.EmitRecord(VTABLE_USES, VTableUses);
5055 
5056  // Write the record containing potentially unused local typedefs.
5057  if (!UnusedLocalTypedefNameCandidates.empty())
5058  Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES,
5059  UnusedLocalTypedefNameCandidates);
5060 
5061  // Write the record containing pending implicit instantiations.
5062  if (!PendingInstantiations.empty())
5063  Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations);
5064 
5065  // Write the record containing declaration references of Sema.
5066  if (!SemaDeclRefs.empty())
5067  Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs);
5068 
5069  // Write the record containing CUDA-specific declaration references.
5070  if (!CUDASpecialDeclRefs.empty())
5071  Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs);
5072 
5073  // Write the delegating constructors.
5074  if (!DelegatingCtorDecls.empty())
5075  Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls);
5076 
5077  // Write the known namespaces.
5078  if (!KnownNamespaces.empty())
5079  Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces);
5080 
5081  // Write the undefined internal functions and variables, and inline functions.
5082  if (!UndefinedButUsed.empty())
5083  Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed);
5084 
5085  if (!DeleteExprsToAnalyze.empty())
5086  Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze);
5087 
5088  // Write the visible updates to DeclContexts.
5089  for (auto *DC : UpdatedDeclContexts)
5090  WriteDeclContextVisibleUpdate(DC);
5091 
5092  if (!WritingModule) {
5093  // Write the submodules that were imported, if any.
5094  struct ModuleInfo {
5095  uint64_t ID;
5096  Module *M;
5097  ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {}
5098  };
5100  for (const auto *I : Context.local_imports()) {
5101  assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end());
5102  Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()],
5103  I->getImportedModule()));
5104  }
5105 
5106  if (!Imports.empty()) {
5107  auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) {
5108  return A.ID < B.ID;
5109  };
5110  auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) {
5111  return A.ID == B.ID;
5112  };
5113 
5114  // Sort and deduplicate module IDs.
5115  llvm::sort(Imports, Cmp);
5116  Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq),
5117  Imports.end());
5118 
5119  RecordData ImportedModules;
5120  for (const auto &Import : Imports) {
5121  ImportedModules.push_back(Import.ID);
5122  // FIXME: If the module has macros imported then later has declarations
5123  // imported, this location won't be the right one as a location for the
5124  // declaration imports.
5125  AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules);
5126  }
5127 
5128  Stream.EmitRecord(IMPORTED_MODULES, ImportedModules);
5129  }
5130  }
5131 
5132  WriteObjCCategories();
5133  if(!WritingModule) {
5134  WriteOptimizePragmaOptions(SemaRef);
5135  WriteMSStructPragmaOptions(SemaRef);
5136  WriteMSPointersToMembersPragmaOptions(SemaRef);
5137  }
5138  WritePackPragmaOptions(SemaRef);
5139 
5140  // Some simple statistics
5141  RecordData::value_type Record[] = {
5142  NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts};
5143  Stream.EmitRecord(STATISTICS, Record);
5144  Stream.ExitBlock();
5145 
5146  // Write the module file extension blocks.
5147  for (const auto &ExtWriter : ModuleFileExtensionWriters)
5148  WriteModuleFileExtension(SemaRef, *ExtWriter);
5149 
5150  return writeUnhashedControlBlock(PP, Context);
5151 }
5152 
5153 void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
5154  if (DeclUpdates.empty())
5155  return;
5156 
5157  DeclUpdateMap LocalUpdates;
5158  LocalUpdates.swap(DeclUpdates);
5159 
5160  for (auto &DeclUpdate : LocalUpdates) {
5161  const Decl *D = DeclUpdate.first;
5162 
5163  bool HasUpdatedBody = false;
5165  ASTRecordWriter Record(*this, RecordData);
5166  for (auto &Update : DeclUpdate.second) {
5168 
5169  // An updated body is emitted last, so that the reader doesn't need
5170  // to skip over the lazy body to reach statements for other records.
5172  HasUpdatedBody = true;
5173  else
5174  Record.push_back(Kind);
5175 
5176  switch (Kind) {
5180  assert(Update.getDecl() && "no decl to add?");
5181  Record.push_back(GetDeclRef(Update.getDecl()));
5182  break;
5183 
5185  break;
5186 
5188  // FIXME: Do we need to also save the template specialization kind here?
5189  Record.AddSourceLocation(Update.getLoc());
5190  break;
5191 
5193  const VarDecl *VD = cast<VarDecl>(D);
5194  Record.push_back(VD->isInline());
5195  Record.push_back(VD->isInlineSpecified());
5196  if (VD->getInit()) {
5197  Record.push_back(!VD->isInitKnownICE() ? 1
5198  : (VD->isInitICE() ? 3 : 2));
5199  Record.AddStmt(const_cast<Expr*>(VD->getInit()));
5200  } else {
5201  Record.push_back(0);
5202  }
5203  break;
5204  }
5205 
5207  Record.AddStmt(const_cast<Expr *>(
5208  cast<ParmVarDecl>(Update.getDecl())->getDefaultArg()));
5209  break;
5210 
5212  Record.AddStmt(
5213  cast<FieldDecl>(Update.getDecl())->getInClassInitializer());
5214  break;
5215 
5217  auto *RD = cast<CXXRecordDecl>(D);
5218  UpdatedDeclContexts.insert(RD->getPrimaryContext());
5219  Record.push_back(RD->isParamDestroyedInCallee());
5220  Record.push_back(RD->getArgPassingRestrictions());
5221  Record.AddCXXDefinitionData(RD);
5222  Record.AddOffset(WriteDeclContextLexicalBlock(
5223  *Context, const_cast<CXXRecordDecl *>(RD)));
5224 
5225  // This state is sometimes updated by template instantiation, when we
5226  // switch from the specialization referring to the template declaration
5227  // to it referring to the template definition.
5228  if (auto *MSInfo = RD->getMemberSpecializationInfo()) {
5229  Record.push_back(MSInfo->getTemplateSpecializationKind());
5230  Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
5231  } else {
5232  auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
5233  Record.push_back(Spec->getTemplateSpecializationKind());
5234  Record.AddSourceLocation(Spec->getPointOfInstantiation());
5235 
5236  // The instantiation might have been resolved to a partial
5237  // specialization. If so, record which one.
5238  auto From = Spec->getInstantiatedFrom();
5239  if (auto PartialSpec =
5240  From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) {
5241  Record.push_back(true);
5242  Record.AddDeclRef(PartialSpec);
5243  Record.AddTemplateArgumentList(
5244  &Spec->getTemplateInstantiationArgs());
5245  } else {
5246  Record.push_back(false);
5247  }
5248  }
5249  Record.push_back(RD->getTagKind());
5250  Record.AddSourceLocation(RD->getLocation());
5251  Record.AddSourceLocation(RD->getBeginLoc());
5252  Record.AddSourceRange(RD->getBraceRange());
5253 
5254  // Instantiation may change attributes; write them all out afresh.
5255  Record.push_back(D->hasAttrs());
5256  if (D->hasAttrs())
5257  Record.AddAttributes(D->getAttrs());
5258 
5259  // FIXME: Ensure we don't get here for explicit instantiations.
5260  break;
5261  }
5262 
5264  Record.AddDeclRef(Update.getDecl());
5265  Record.AddStmt(cast<CXXDestructorDecl>(D)->getOperatorDeleteThisArg());
5266  break;
5267 
5270  cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(),
5271  Record);
5272  break;
5273 
5275  Record.push_back(GetOrCreateTypeID(Update.getType()));
5276  break;
5277 
5278  case UPD_DECL_MARKED_USED:
5279  break;
5280 
5281  case UPD_MANGLING_NUMBER:
5283  Record.push_back(Update.getNumber());
5284  break;
5285 
5287  Record.AddSourceRange(
5288  D->getAttr<OMPThreadPrivateDeclAttr>()->getRange());
5289  break;
5290 
5292  Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType());
5293  Record.AddSourceRange(
5294  D->getAttr<OMPDeclareTargetDeclAttr>()->getRange());
5295  break;
5296 
5297  case UPD_DECL_EXPORTED:
5298  Record.push_back(getSubmoduleID(Update.getModule()));
5299  break;
5300 
5302  Record.AddAttributes(llvm::makeArrayRef(Update.getAttr()));
5303  break;
5304  }
5305  }
5306 
5307  if (HasUpdatedBody) {
5308  const auto *Def = cast<FunctionDecl>(D);
5310  Record.push_back(Def->isInlined());
5311  Record.AddSourceLocation(Def->getInnerLocStart());
5312  Record.AddFunctionDefinition(Def);
5313  }
5314 
5315  OffsetsRecord.push_back(GetDeclRef(D));
5316  OffsetsRecord.push_back(Record.Emit(DECL_UPDATES));
5317  }
5318 }
5319 
5321  uint32_t Raw = Loc.getRawEncoding();
5322  Record.push_back((Raw << 1) | (Raw >> 31));
5323 }
5324 
5326  AddSourceLocation(Range.getBegin(), Record);
5327  AddSourceLocation(Range.getEnd(), Record);
5328 }
5329 
5330 void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) {
5331  Record->push_back(Value.getBitWidth());
5332  const uint64_t *Words = Value.getRawData();
5333  Record->append(Words, Words + Value.getNumWords());
5334 }
5335 
5336 void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) {
5337  Record->push_back(Value.isUnsigned());
5338  AddAPInt(Value);
5339 }
5340 
5341 void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) {
5342  AddAPInt(Value.bitcastToAPInt());
5343 }
5344 
5346  Record.push_back(getIdentifierRef(II));
5347 }
5348 
5350  if (!II)
5351  return 0;
5352 
5353  IdentID &ID = IdentifierIDs[II];
5354  if (ID == 0)
5355  ID = NextIdentID++;
5356  return ID;
5357 }
5358 
5360  // Don't emit builtin macros like __LINE__ to the AST file unless they
5361  // have been redefined by the header (in which case they are not
5362  // isBuiltinMacro).
5363  if (!MI || MI->isBuiltinMacro())
5364  return 0;
5365 
5366  MacroID &ID = MacroIDs[MI];
5367  if (ID == 0) {
5368  ID = NextMacroID++;
5369  MacroInfoToEmitData Info = { Name, MI, ID };
5370  MacroInfosToEmit.push_back(Info);
5371  }
5372  return ID;
5373 }
5374 
5376  if (!MI || MI->isBuiltinMacro())
5377  return 0;
5378 
5379  assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!");
5380  return MacroIDs[MI];
5381 }
5382 
5384  return IdentMacroDirectivesOffsetMap.lookup(Name);
5385 }
5386 
5388  Record->push_back(Writer->getSelectorRef(SelRef));
5389 }
5390 
5392  if (Sel.getAsOpaquePtr() == nullptr) {
5393  return 0;
5394  }
5395 
5396  SelectorID SID = SelectorIDs[Sel];
5397  if (SID == 0 && Chain) {
5398  // This might trigger a ReadSelector callback, which will set the ID for
5399  // this selector.
5400  Chain->LoadSelector(Sel);
5401  SID = SelectorIDs[Sel];
5402  }
5403  if (SID == 0) {
5404  SID = NextSelectorID++;
5405  SelectorIDs[Sel] = SID;
5406  }
5407  return SID;
5408 }
5409 
5411  AddDeclRef(Temp->getDestructor());
5412 }
5413 
5416  switch (Kind) {
5418  AddStmt(Arg.getAsExpr());
5419  break;
5421  AddTypeSourceInfo(Arg.getAsTypeSourceInfo());
5422  break;
5424  AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc());
5426  break;
5428  AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc());
5431  break;
5437  // FIXME: Is this right?
5438  break;
5439  }
5440 }
5441 
5443  AddTemplateArgument(Arg.getArgument());
5444 
5446  bool InfoHasSameExpr
5447  = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr();
5448  Record->push_back(InfoHasSameExpr);
5449  if (InfoHasSameExpr)
5450  return; // Avoid storing the same expr twice.
5451  }
5452  AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo());
5453 }
5454 
5456  if (!TInfo) {
5457  AddTypeRef(QualType());
5458  return;
5459  }
5460 
5461  AddTypeRef(TInfo->getType());
5462  AddTypeLoc(TInfo->getTypeLoc());
5463 }
5464 
5466  TypeLocWriter TLW(*this);
5467  for (; !TL.isNull(); TL = TL.getNextTypeLoc())
5468  TLW.Visit(TL);
5469 }
5470 
5472  Record.push_back(GetOrCreateTypeID(T));
5473 }
5474 
5476  assert(Context);
5477  return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx {
5478  if (T.isNull())
5479  return TypeIdx();
5480  assert(!T.getLocalFastQualifiers());
5481 
5482  TypeIdx &Idx = TypeIdxs[T];
5483  if (Idx.getIndex() == 0) {
5484  if (DoneWritingDeclsAndTypes) {
5485  assert(0 && "New type seen after serializing all the types to emit!");
5486  return TypeIdx();
5487  }
5488 
5489  // We haven't seen this type before. Assign it a new ID and put it
5490  // into the queue of types to emit.
5491  Idx = TypeIdx(NextTypeID++);
5492  DeclTypesToEmit.push(T);
5493  }
5494  return Idx;
5495  });
5496 }
5497 
5499  assert(Context);
5500  return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx {
5501  if (T.isNull())
5502  return TypeIdx();
5503  assert(!T.getLocalFastQualifiers());
5504 
5505  TypeIdxMap::const_iterator I = TypeIdxs.find(T);
5506  assert(I != TypeIdxs.end() && "Type not emitted!");
5507  return I->second;
5508  });
5509 }
5510 
5511 void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) {
5512  Record.push_back(GetDeclRef(D));
5513 }
5514 
5516  assert(WritingAST && "Cannot request a declaration ID before AST writing");
5517 
5518  if (!D) {
5519  return 0;
5520  }
5521 
5522  // If D comes from an AST file, its declaration ID is already known and
5523  // fixed.
5524  if (D->isFromASTFile())
5525  return D->getGlobalID();
5526 
5527  assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer");
5528  DeclID &ID = DeclIDs[D];
5529  if (ID == 0) {
5530  if (DoneWritingDeclsAndTypes) {
5531  assert(0 && "New decl seen after serializing all the decls to emit!");
5532  return 0;
5533  }
5534 
5535  // We haven't seen this declaration before. Give it a new ID and
5536  // enqueue it in the list of declarations to emit.
5537  ID = NextDeclID++;
5538  DeclTypesToEmit.push(const_cast<Decl *>(D));
5539  }
5540 
5541  return ID;
5542 }
5543 
5545  if (!D)
5546  return 0;
5547 
5548  // If D comes from an AST file, its declaration ID is already known and
5549  // fixed.
5550  if (D->isFromASTFile())
5551  return D->getGlobalID();
5552 
5553  assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!");
5554  return DeclIDs[D];
5555 }
5556 
5557 void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
5558  assert(ID);
5559  assert(D);
5560 
5561  SourceLocation Loc = D->getLocation();
5562  if (Loc.isInvalid())
5563  return;
5564 
5565  // We only keep track of the file-level declarations of each file.
5566  if (!D->getLexicalDeclContext()->isFileContext())
5567  return;
5568  // FIXME: ParmVarDecls that are part of a function type of a parameter of
5569  // a function/objc method, should not have TU as lexical context.
5570  // TemplateTemplateParmDecls that are part of an alias template, should not
5571  // have TU as lexical context.
5572  if (isa<ParmVarDecl>(D) || isa<TemplateTemplateParmDecl>(D))
5573  return;
5574 
5575  SourceManager &SM = Context->getSourceManager();
5576  SourceLocation FileLoc = SM.getFileLoc(Loc);
5577  assert(SM.isLocalSourceLocation(FileLoc));
5578  FileID FID;
5579  unsigned Offset;
5580  std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc);
5581  if (FID.isInvalid())
5582  return;
5583  assert(SM.getSLocEntry(FID).isFile());
5584 
5585  DeclIDInFileInfo *&Info = FileDeclIDs[FID];
5586  if (!Info)
5587  Info = new DeclIDInFileInfo();
5588 
5589  std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID);
5590  LocDeclIDsTy &Decls = Info->DeclIDs;
5591 
5592  if (Decls.empty() || Decls.back().first <= Offset) {
5593  Decls.push_back(LocDecl);
5594  return;
5595  }
5596 
5597  LocDeclIDsTy::iterator I =
5598  std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first());
5599 
5600  Decls.insert(I, LocDecl);
5601 }
5602 
5604  // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc.
5605  Record->push_back(Name.getNameKind());
5606  switch (Name.getNameKind()) {
5609  break;
5610 
5614  AddSelectorRef(Name.getObjCSelector());
5615  break;
5616 
5620  AddTypeRef(Name.getCXXNameType());
5621  break;
5622 
5625  break;
5626 
5628  Record->push_back(Name.getCXXOverloadedOperator());
5629  break;
5630 
5633  break;
5634 
5636  // No extra data to emit
5637  break;
5638  }
5639 }
5640 
5642  assert(needsAnonymousDeclarationNumber(D) &&
5643  "expected an anonymous declaration");
5644 
5645  // Number the anonymous declarations within this context, if we've not
5646  // already done so.
5647  auto It = AnonymousDeclarationNumbers.find(D);
5648  if (It == AnonymousDeclarationNumbers.end()) {
5649  auto *DC = D->getLexicalDeclContext();
5650  numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) {
5651  AnonymousDeclarationNumbers[ND] = Number;
5652  });
5653 
5654  It = AnonymousDeclarationNumbers.find(D);
5655  assert(It != AnonymousDeclarationNumbers.end() &&
5656  "declaration not found within its lexical context");
5657  }
5658 
5659  return It->second;
5660 }
5661 
5663  DeclarationName Name) {
5664  switch (Name.getNameKind()) {
5668  AddTypeSourceInfo(DNLoc.NamedType.TInfo);
5669  break;
5670 
5676  break;
5677 
5681  break;
5682 
5689  break;
5690  }
5691 }
5692 
5694  const DeclarationNameInfo &NameInfo) {
5695  AddDeclarationName(NameInfo.getName());
5696  AddSourceLocation(NameInfo.getLoc());
5697  AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName());
5698 }
5699 
5701  AddNestedNameSpecifierLoc(Info.QualifierLoc);
5702  Record->push_back(Info.NumTemplParamLists);
5703  for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i)
5704  AddTemplateParameterList(Info.TemplParamLists[i]);
5705 }
5706 
5708  // Nested name specifiers usually aren't too long. I think that 8 would
5709  // typically accommodate the vast majority.
5711 
5712  // Push each of the NNS's onto a stack for serialization in reverse order.
5713  while (NNS) {
5714  NestedNames.push_back(NNS);
5715  NNS = NNS->getPrefix();
5716  }
5717 
5718  Record->push_back(NestedNames.size());
5719  while(!NestedNames.empty()) {
5720  NNS = NestedNames.pop_back_val();
5722  Record->push_back(Kind);
5723  switch (Kind) {
5726  break;
5727 
5729  AddDeclRef(NNS->getAsNamespace());
5730  break;
5731 
5734  break;
5735 
5738  AddTypeRef(QualType(NNS->getAsType(), 0));
5739  Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate);
5740  break;
5741 
5743  // Don't need to write an associated value.
5744  break;
5745 
5747  AddDeclRef(NNS->getAsRecordDecl());
5748  break;
5749  }
5750  }
5751 }
5752 
5754  // Nested name specifiers usually aren't too long. I think that 8 would
5755  // typically accommodate the vast majority.
5757 
5758  // Push each of the nested-name-specifiers's onto a stack for
5759  // serialization in reverse order.
5760  while (NNS) {
5761  NestedNames.push_back(NNS);
5762  NNS = NNS.getPrefix();
5763  }
5764 
5765  Record->push_back(NestedNames.size());
5766  while(!NestedNames.empty()) {
5767  NNS = NestedNames.pop_back_val();
5769  = NNS.getNestedNameSpecifier()->getKind();
5770  Record->push_back(Kind);
5771  switch (Kind) {
5775  break;
5776 
5780  break;
5781 
5785  break;
5786 
5789  Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate);
5790  AddTypeRef(NNS.getTypeLoc().getType());
5791  AddTypeLoc(NNS.getTypeLoc());
5793  break;
5794 
5797  break;
5798 
5802  break;
5803  }
5804  }
5805 }
5806 
5809  Record->push_back(Kind);
5810  switch (Kind) {
5812  AddDeclRef(Name.getAsTemplateDecl());
5813  break;
5814 
5817  Record->push_back(OvT->size());
5818  for (const auto &I : *OvT)
5819  AddDeclRef(I);
5820  break;
5821  }
5822 
5825  AddNestedNameSpecifier(QualT->getQualifier());
5826  Record->push_back(QualT->hasTemplateKeyword());
5827  AddDeclRef(QualT->getTemplateDecl());
5828  break;
5829  }
5830 
5833  AddNestedNameSpecifier(DepT->getQualifier());
5834  Record->push_back(DepT->isIdentifier());
5835  if (DepT->isIdentifier())
5837  else
5838  Record->push_back(DepT->getOperator());
5839  break;
5840  }
5841 
5845  AddDeclRef(subst->getParameter());
5846  AddTemplateName(subst->getReplacement());
5847  break;
5848  }
5849 
5853  AddDeclRef(SubstPack->getParameterPack());
5854  AddTemplateArgument(SubstPack->getArgumentPack());
5855  break;
5856  }
5857  }
5858 }
5859 
5861  Record->push_back(Arg.getKind());
5862  switch (Arg.getKind()) {
5864  break;
5866  AddTypeRef(Arg.getAsType());
5867  break;
5869  AddDeclRef(Arg.getAsDecl());
5871  break;
5873  AddTypeRef(Arg.getNullPtrType());
5874  break;
5876  AddAPSInt(Arg.getAsIntegral());
5877  AddTypeRef(Arg.getIntegralType());
5878  break;
5880  AddTemplateName(Arg.getAsTemplateOrTemplatePattern());
5881  break;
5883  AddTemplateName(Arg.getAsTemplateOrTemplatePattern());
5884  if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions())
5885  Record->push_back(*NumExpansions + 1);
5886  else
5887  Record->push_back(0);
5888  break;
5890  AddStmt(Arg.getAsExpr());
5891  break;
5893  Record->push_back(Arg.pack_size());
5894  for (const auto &P : Arg.pack_elements())
5895  AddTemplateArgument(P);
5896  break;
5897  }
5898 }
5899 
5901  const TemplateParameterList *TemplateParams) {
5902  assert(TemplateParams && "No TemplateParams!");
5903  AddSourceLocation(TemplateParams->getTemplateLoc());
5904  AddSourceLocation(TemplateParams->getLAngleLoc());
5905  AddSourceLocation(TemplateParams->getRAngleLoc());
5906  // TODO: Concepts
5907  Record->push_back(TemplateParams->size());
5908  for (const auto &P : *TemplateParams)
5909  AddDeclRef(P);
5910 }
5911 
5912 /// Emit a template argument list.
5914  const TemplateArgumentList *TemplateArgs) {
5915  assert(TemplateArgs && "No TemplateArgs!");
5916  Record->push_back(TemplateArgs->size());
5917  for (int i = 0, e = TemplateArgs->size(); i != e; ++i)
5918  AddTemplateArgument(TemplateArgs->get(i));
5919 }
5920 
5922  const ASTTemplateArgumentListInfo *ASTTemplArgList) {
5923  assert(ASTTemplArgList && "No ASTTemplArgList!");
5924  AddSourceLocation(ASTTemplArgList->LAngleLoc);
5925  AddSourceLocation(ASTTemplArgList->RAngleLoc);
5926  Record->push_back(ASTTemplArgList->NumTemplateArgs);
5927  const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs();
5928  for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i)
5929  AddTemplateArgumentLoc(TemplArgs[i]);
5930 }
5931 
5933  Record->push_back(Set.size());
5935  I = Set.begin(), E = Set.end(); I != E; ++I) {
5936  AddDeclRef(I.getDecl());
5937  Record->push_back(I.getAccess());
5938  }
5939 }
5940 
5941 // FIXME: Move this out of the main ASTRecordWriter interface.
5943  Record->push_back(Base.isVirtual());
5944  Record->push_back(Base.isBaseOfClass());
5945  Record->push_back(Base.getAccessSpecifierAsWritten());
5946  Record->push_back(Base.getInheritConstructors());
5947  AddTypeSourceInfo(Base.getTypeSourceInfo());
5950  : SourceLocation());
5951 }
5952 
5955  ASTWriter::RecordData Record;
5956  ASTRecordWriter Writer(W, Record);
5957  Writer.push_back(Bases.size());
5958 
5959  for (auto &Base : Bases)
5960  Writer.AddCXXBaseSpecifier(Base);
5961 
5963 }
5964 
5965 // FIXME: Move this out of the main ASTRecordWriter interface.
5967  AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases));
5968 }
5969 
5970 static uint64_t
5972  ArrayRef<CXXCtorInitializer *> CtorInits) {
5973  ASTWriter::RecordData Record;
5974  ASTRecordWriter Writer(W, Record);
5975  Writer.push_back(CtorInits.size());
5976 
5977  for (auto *Init : CtorInits) {
5978  if (Init->isBaseInitializer()) {
5980  Writer.AddTypeSourceInfo(Init->getTypeSourceInfo());
5981  Writer.push_back(Init->isBaseVirtual());
5982  } else if (Init->isDelegatingInitializer()) {
5984  Writer.AddTypeSourceInfo(Init->getTypeSourceInfo());
5985  } else if (Init->isMemberInitializer()){
5987  Writer.AddDeclRef(Init->getMember());
5988  } else {
5990  Writer.AddDeclRef(Init->getIndirectMember());
5991  }
5992 
5993  Writer.AddSourceLocation(Init->getMemberLocation());
5994  Writer.AddStmt(Init->getInit());
5995  Writer.AddSourceLocation(Init->getLParenLoc());
5996  Writer.AddSourceLocation(Init->getRParenLoc());
5997  Writer.push_back(Init->isWritten());
5998  if (Init->isWritten())
5999  Writer.push_back(Init->getSourceOrder());
6000  }
6001 
6003 }
6004 
6005 // FIXME: Move this out of the main ASTRecordWriter interface.
6007  ArrayRef<CXXCtorInitializer *> CtorInits) {
6008  AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits));
6009 }
6010 
6012  auto &Data = D->data();
6013  Record->push_back(Data.IsLambda);
6014  Record->push_back(Data.UserDeclaredConstructor);
6015  Record->push_back(Data.UserDeclaredSpecialMembers);
6016  Record->push_back(Data.Aggregate);
6017  Record->push_back(Data.PlainOldData);
6018  Record->push_back(Data.Empty);
6019  Record->push_back(Data.Polymorphic);
6020  Record->push_back(Data.Abstract);
6021  Record->push_back(Data.IsStandardLayout);
6022  Record->push_back(Data.IsCXX11StandardLayout);
6023  Record->push_back(Data.HasBasesWithFields);
6024  Record->push_back(Data.HasBasesWithNonStaticDataMembers);
6025  Record->push_back(Data.HasPrivateFields);
6026  Record->push_back(Data.HasProtectedFields);
6027  Record->push_back(Data.HasPublicFields);
6028  Record->push_back(Data.HasMutableFields);
6029  Record->push_back(Data.HasVariantMembers);
6030  Record->push_back(Data.HasOnlyCMembers);
6031  Record->push_back(Data.HasInClassInitializer);
6032  Record->push_back(Data.HasUninitializedReferenceMember);
6033  Record->push_back(Data.HasUninitializedFields);
6034  Record->push_back(Data.HasInheritedConstructor);
6035  Record->push_back(Data.HasInheritedAssignment);
6036  Record->push_back(Data.NeedOverloadResolutionForCopyConstructor);
6037  Record->push_back(Data.NeedOverloadResolutionForMoveConstructor);
6038  Record->push_back(Data.NeedOverloadResolutionForMoveAssignment);
6039  Record->push_back(Data.NeedOverloadResolutionForDestructor);
6040  Record->push_back(Data.DefaultedCopyConstructorIsDeleted);
6041  Record->push_back(Data.DefaultedMoveConstructorIsDeleted);
6042  Record->push_back(Data.DefaultedMoveAssignmentIsDeleted);
6043  Record->push_back(Data.DefaultedDestructorIsDeleted);
6044  Record->push_back(Data.HasTrivialSpecialMembers);
6045  Record->push_back(Data.HasTrivialSpecialMembersForCall);
6046  Record->push_back(Data.DeclaredNonTrivialSpecialMembers);
6047  Record->push_back(Data.DeclaredNonTrivialSpecialMembersForCall);
6048  Record->push_back(Data.HasIrrelevantDestructor);
6049  Record->push_back(Data.HasConstexprNonCopyMoveConstructor);
6050  Record->push_back(Data.HasDefaultedDefaultConstructor);
6051  Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr);
6052  Record->push_back(Data.HasConstexprDefaultConstructor);
6053  Record->push_back(Data.HasNonLiteralTypeFieldsOrBases);
6054  Record->push_back(Data.ComputedVisibleConversions);
6055  Record->push_back(Data.UserProvidedDefaultConstructor);
6056  Record->push_back(Data.DeclaredSpecialMembers);
6057  Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForVBase);
6058  Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase);
6059  Record->push_back(Data.ImplicitCopyAssignmentHasConstParam);
6060  Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam);
6061  Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam);
6062 
6063  // getODRHash will compute the ODRHash if it has not been previously computed.
6064  Record->push_back(D->getODRHash());
6065  bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo &&
6066  Writer->WritingModule && !D->isDependentType();
6067  Record->push_back(ModulesDebugInfo);
6068  if (ModulesDebugInfo)
6069  Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D));
6070 
6071  // IsLambda bit is already saved.
6072 
6073  Record->push_back(Data.NumBases);
6074  if (Data.NumBases > 0)
6075  AddCXXBaseSpecifiers(Data.bases());
6076 
6077  // FIXME: Make VBases lazily computed when needed to avoid storing them.
6078  Record->push_back(Data.NumVBases);
6079  if (Data.NumVBases > 0)
6080  AddCXXBaseSpecifiers(Data.vbases());
6081 
6082  AddUnresolvedSet(Data.Conversions.get(*Writer->Context));
6083  AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context));
6084  // Data.Definition is the owning decl, no need to write it.
6085  AddDeclRef(D->getFirstFriend());
6086 
6087  // Add lambda-specific data.
6088  if (Data.IsLambda) {
6089  auto &Lambda = D->getLambdaData();
6090  Record->push_back(Lambda.Dependent);
6091  Record->push_back(Lambda.IsGenericLambda);
6092  Record->push_back(Lambda.CaptureDefault);
6093  Record->push_back(Lambda.NumCaptures);
6094  Record->push_back(Lambda.NumExplicitCaptures);
6095  Record->push_back(Lambda.ManglingNumber);
6097  AddTypeSourceInfo(Lambda.MethodTyInfo);
6098  for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
6099  const LambdaCapture &Capture = Lambda.Captures[I];
6100  AddSourceLocation(Capture.getLocation());
6101  Record->push_back(Capture.isImplicit());
6102  Record->push_back(Capture.getCaptureKind());
6103  switch (Capture.getCaptureKind()) {
6104  case LCK_StarThis:
6105  case LCK_This:
6106  case LCK_VLAType:
6107  break;
6108  case LCK_ByCopy:
6109  case LCK_ByRef:
6110  VarDecl *Var =
6111  Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr;
6112  AddDeclRef(Var);
6113  AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc()
6114  : SourceLocation());
6115  break;
6116  }
6117  }
6118  }
6119 }
6120 
6121 void ASTWriter::ReaderInitialized(ASTReader *Reader) {
6122  assert(Reader && "Cannot remove chain");
6123  assert((!Chain || Chain == Reader) && "Cannot replace chain");
6124  assert(FirstDeclID == NextDeclID &&
6125  FirstTypeID == NextTypeID &&
6126  FirstIdentID == NextIdentID &&
6127  FirstMacroID == NextMacroID &&
6128  FirstSubmoduleID == NextSubmoduleID &&
6129  FirstSelectorID == NextSelectorID &&
6130  "Setting chain after writing has started.");
6131 
6132  Chain = Reader;
6133 
6134  // Note, this will get called multiple times, once one the reader starts up
6135  // and again each time it's done reading a PCH or module.
6136  FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls();
6137  FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes();
6138  FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers();
6139  FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros();
6140  FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules();
6141  FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors();
6142  NextDeclID = FirstDeclID;
6143  NextTypeID = FirstTypeID;
6144  NextIdentID = FirstIdentID;
6145  NextMacroID = FirstMacroID;
6146  NextSelectorID = FirstSelectorID;
6147  NextSubmoduleID = FirstSubmoduleID;
6148 }
6149 
6150 void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) {
6151  // Always keep the highest ID. See \p TypeRead() for more information.
6152  IdentID &StoredID = IdentifierIDs[II];
6153  if (ID > StoredID)
6154  StoredID = ID;
6155 }
6156 
6157 void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) {
6158  // Always keep the highest ID. See \p TypeRead() for more information.
6159  MacroID &StoredID = MacroIDs[MI];
6160  if (ID > StoredID)
6161  StoredID = ID;
6162 }
6163 
6164 void ASTWriter::TypeRead(TypeIdx Idx, QualType T) {
6165  // Always take the highest-numbered type index. This copes with an interesting
6166  // case for chained AST writing where we schedule writing the type and then,
6167  // later, deserialize the type from another AST. In this case, we want to
6168  // keep the higher-numbered entry so that we can properly write it out to
6169  // the AST file.
6170  TypeIdx &StoredIdx = TypeIdxs[T];
6171  if (Idx.getIndex() >= StoredIdx.getIndex())
6172  StoredIdx = Idx;
6173 }
6174 
6175 void ASTWriter::SelectorRead(SelectorID ID, Selector S) {
6176  // Always keep the highest ID. See \p TypeRead() for more information.
6177  SelectorID &StoredID = SelectorIDs[S];
6178  if (ID > StoredID)
6179  StoredID = ID;
6180 }
6181 
6182 void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID,
6183  MacroDefinitionRecord *MD) {
6184  assert(MacroDefinitions.find(MD) == MacroDefinitions.end());
6185  MacroDefinitions[MD] = ID;
6186 }
6187 
6188 void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) {
6189  assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end());
6190  SubmoduleIDs[Mod] = ID;
6191 }
6192 
6193 void ASTWriter::CompletedTagDefinition(const TagDecl *D) {
6194  if (Chain && Chain->isProcessingUpdateRecords()) return;
6195  assert(D->isCompleteDefinition());
6196  assert(!WritingAST && "Already writing the AST!");
6197  if (auto *RD = dyn_cast<CXXRecordDecl>(D)) {
6198  // We are interested when a PCH decl is modified.
6199  if (RD->isFromASTFile()) {
6200  // A forward reference was mutated into a definition. Rewrite it.
6201  // FIXME: This happens during template instantiation, should we
6202  // have created a new definition decl instead ?
6203  assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) &&
6204  "completed a tag from another module but not by instantiation?");
6205  DeclUpdates[RD].push_back(
6207  }
6208  }
6209 }
6210 
6211 static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) {
6212  if (D->isFromASTFile())
6213  return true;
6214 
6215  // The predefined __va_list_tag struct is imported if we imported any decls.
6216  // FIXME: This is a gross hack.
6217  return D == D->getASTContext().getVaListTagDecl();
6218 }
6219 
6220 void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) {
6221  if (Chain && Chain->isProcessingUpdateRecords()) return;
6222  assert(DC->isLookupContext() &&
6223  "Should not add lookup results to non-lookup contexts!");
6224 
6225  // TU is handled elsewhere.
6226  if (isa<TranslationUnitDecl>(DC))
6227  return;
6228 
6229  // Namespaces are handled elsewhere, except for template instantiations of
6230  // FunctionTemplateDecls in namespaces. We are interested in cases where the
6231  // local instantiations are added to an imported context. Only happens when
6232  // adding ADL lookup candidates, for example templated friends.
6233  if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None &&
6234  !isa<FunctionTemplateDecl>(D))
6235  return;
6236 
6237  // We're only interested in cases where a local declaration is added to an
6238  // imported context.
6239  if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC)))
6240  return;
6241 
6242  assert(DC == DC->getPrimaryContext() && "added to non-primary context");
6243  assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!");
6244  assert(!WritingAST && "Already writing the AST!");
6245  if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) {
6246  // We're adding a visible declaration to a predefined decl context. Ensure
6247  // that we write out all of its lookup results so we don't get a nasty
6248  // surprise when we try to emit its lookup table.
6249  for (auto *Child : DC->decls())
6250  DeclsToEmitEvenIfUnreferenced.push_back(Child);
6251  }
6252  DeclsToEmitEvenIfUnreferenced.push_back(D);
6253 }
6254 
6255 void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) {
6256  if (Chain && Chain->isProcessingUpdateRecords()) return;
6257  assert(D->isImplicit());
6258 
6259  // We're only interested in cases where a local declaration is added to an
6260  // imported context.
6261  if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD))
6262  return;
6263 
6264  if (!isa<CXXMethodDecl>(D))
6265  return;
6266 
6267  // A decl coming from PCH was modified.
6268  assert(RD->isCompleteDefinition());
6269  assert(!WritingAST && "Already writing the AST!");
6270  DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D));
6271 }
6272 
6273 void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) {
6274  if (Chain && Chain->isProcessingUpdateRecords()) return;
6275  assert(!DoneWritingDeclsAndTypes && "Already done writing updates!");
6276  if (!Chain) return;
6277  Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) {
6278  // If we don't already know the exception specification for this redecl
6279  // chain, add an update record for it.
6280  if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D)
6281  ->getType()
6282  ->castAs<FunctionProtoType>()
6283  ->getExceptionSpecType()))
6284  DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC);
6285  });
6286 }
6287 
6288 void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) {
6289  if (Chain && Chain->isProcessingUpdateRecords()) return;
6290  assert(!WritingAST && "Already writing the AST!");
6291  if (!Chain) return;
6292  Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) {
6293  DeclUpdates[D].push_back(
6294  DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType));
6295  });
6296 }
6297 
6298 void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD,
6299  const FunctionDecl *Delete,
6300  Expr *ThisArg) {
6301  if (Chain && Chain->isProcessingUpdateRecords()) return;
6302  assert(!WritingAST && "Already writing the AST!");
6303  assert(Delete && "Not given an operator delete");
6304  if (!Chain) return;
6305  Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) {
6306  DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete));
6307  });
6308 }
6309 
6310 void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) {
6311  if (Chain && Chain->isProcessingUpdateRecords()) return;
6312  assert(!WritingAST && "Already writing the AST!");
6313  if (!D->isFromASTFile())
6314  return; // Declaration not imported from PCH.
6315 
6316  // Implicit function decl from a PCH was defined.
6317  DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION));
6318 }
6319 
6320 void ASTWriter::VariableDefinitionInstantiated(const VarDecl *D) {
6321  if (Chain && Chain->isProcessingUpdateRecords()) return;
6322  assert(!WritingAST && "Already writing the AST!");
6323  if (!D->isFromASTFile())
6324  return;
6325 
6326  DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_VAR_DEFINITION));
6327 }
6328 
6329 void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) {
6330  if (Chain && Chain->isProcessingUpdateRecords()) return;
6331  assert(!WritingAST && "Already writing the AST!");
6332  if (!D->isFromASTFile())
6333  return;
6334 
6335  DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION));
6336 }
6337 
6338 void ASTWriter::InstantiationRequested(const ValueDecl *D) {
6339  if (Chain && Chain->isProcessingUpdateRecords()) return;
6340  assert(!WritingAST && "Already writing the AST!");
6341  if (!D->isFromASTFile())
6342  return;
6343 
6344  // Since the actual instantiation is delayed, this really means that we need
6345  // to update the instantiation location.
6346  SourceLocation POI;
6347  if (auto *VD = dyn_cast<VarDecl>(D))
6348  POI = VD->getPointOfInstantiation();
6349  else
6350  POI = cast<FunctionDecl>(D)->getPointOfInstantiation();
6351  DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_POINT_OF_INSTANTIATION, POI));
6352 }
6353 
6354 void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) {
6355  if (Chain && Chain->isProcessingUpdateRecords()) return;
6356  assert(!WritingAST && "Already writing the AST!");
6357  if (!D->isFromASTFile())
6358  return;
6359 
6360  DeclUpdates[D].push_back(
6361  DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D));
6362 }
6363 
6364 void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) {
6365  assert(!WritingAST && "Already writing the AST!");
6366  if (!D->isFromASTFile())
6367  return;
6368 
6369  DeclUpdates[D].push_back(
6371 }
6372 
6373 void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
6374  const ObjCInterfaceDecl *IFD) {
6375  if (Chain && Chain->isProcessingUpdateRecords()) return;
6376  assert(!WritingAST && "Already writing the AST!");
6377  if (!IFD->isFromASTFile())
6378  return; // Declaration not imported from PCH.
6379 
6380  assert(IFD->getDefinition() && "Category on a class without a definition?");
6381  ObjCClassesWithCategories.insert(
6382  const_cast<ObjCInterfaceDecl *>(IFD->getDefinition()));
6383 }
6384 
6385 void ASTWriter::DeclarationMarkedUsed(const Decl *D) {
6386  if (Chain && Chain->isProcessingUpdateRecords()) return;
6387  assert(!WritingAST && "Already writing the AST!");
6388 
6389  // If there is *any* declaration of the entity that's not from an AST file,
6390  // we can skip writing the update record. We make sure that isUsed() triggers
6391  // completion of the redeclaration chain of the entity.
6392  for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl())
6393  if (IsLocalDecl(Prev))
6394  return;
6395 
6396  DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED));
6397 }
6398 
6399 void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {
6400  if (Chain && Chain->isProcessingUpdateRecords()) return;
6401  assert(!WritingAST && "Already writing the AST!");
6402  if (!D->isFromASTFile())
6403  return;
6404 
6405  DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE));
6406 }
6407 
6408 void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
6409  const Attr *Attr) {
6410  if (Chain && Chain->isProcessingUpdateRecords()) return;
6411  assert(!WritingAST && "Already writing the AST!");
6412  if (!D->isFromASTFile())
6413  return;
6414 
6415  DeclUpdates[D].push_back(
6416  DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr));
6417 }
6418 
6419 void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) {
6420  if (Chain && Chain->isProcessingUpdateRecords()) return;
6421  assert(!WritingAST && "Already writing the AST!");
6422  assert(D->isHidden() && "expected a hidden declaration");
6423  DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M));
6424 }
6425 
6426 void ASTWriter::AddedAttributeToRecord(const Attr *Attr,
6427  const RecordDecl *Record) {
6428  if (Chain && Chain->isProcessingUpdateRecords()) return;
6429  assert(!WritingAST && "Already writing the AST!");
6430  if (!Record->isFromASTFile())
6431  return;
6432  DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr));
6433 }
6434 
6435 void ASTWriter::AddedCXXTemplateSpecialization(
6436  const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
6437  assert(!WritingAST && "Already writing the AST!");
6438 
6439  if (!TD->getFirstDecl()->isFromASTFile())
6440  return;
6441  if (Chain && Chain->isProcessingUpdateRecords())
6442  return;
6443 
6444  DeclsToEmitEvenIfUnreferenced.push_back(D);
6445 }
6446 
6447 void ASTWriter::AddedCXXTemplateSpecialization(
6448  const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
6449  assert(!WritingAST && "Already writing the AST!");
6450 
6451  if (!TD->getFirstDecl()->isFromASTFile())
6452  return;
6453  if (Chain && Chain->isProcessingUpdateRecords())
6454  return;
6455 
6456  DeclsToEmitEvenIfUnreferenced.push_back(D);
6457 }
6458 
6459 void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
6460  const FunctionDecl *D) {
6461  assert(!WritingAST && "Already writing the AST!");
6462 
6463  if (!TD->getFirstDecl()->isFromASTFile())
6464  return;
6465  if (Chain && Chain->isProcessingUpdateRecords())
6466  return;
6467 
6468  DeclsToEmitEvenIfUnreferenced.push_back(D);
6469 }
6470 
6471 //===----------------------------------------------------------------------===//
6472 //// OMPClause Serialization
6473 ////===----------------------------------------------------------------------===//
6474 
6476  Record.push_back(C->getClauseKind());
6477  Visit(C);
6478  Record.AddSourceLocation(C->getBeginLoc());
6479  Record.AddSourceLocation(C->getEndLoc());
6480 }
6481 
6483  Record.push_back(C->getCaptureRegion());
6484  Record.AddStmt(C->getPreInitStmt());
6485 }
6486 
6488  VisitOMPClauseWithPreInit(C);
6489  Record.AddStmt(C->getPostUpdateExpr());
6490 }
6491 
6492 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
6493  VisitOMPClauseWithPreInit(C);
6494  Record.push_back(C->getNameModifier());
6495  Record.AddSourceLocation(C->getNameModifierLoc());
6496  Record.AddSourceLocation(C->getColonLoc());
6497  Record.AddStmt(C->getCondition());
6498  Record.AddSourceLocation(C->getLParenLoc());
6499 }
6500 
6501 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
6502  Record.AddStmt(C->getCondition());
6503  Record.AddSourceLocation(C->getLParenLoc());
6504 }
6505 
6506 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
6507  VisitOMPClauseWithPreInit(C);
6508  Record.AddStmt(C->getNumThreads());
6509  Record.AddSourceLocation(C->getLParenLoc());
6510 }
6511 
6512 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
6513  Record.AddStmt(C->getSafelen());
6514  Record.AddSourceLocation(C->getLParenLoc());
6515 }
6516 
6517 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
6518  Record.AddStmt(C->getSimdlen());
6519  Record.AddSourceLocation(C->getLParenLoc());
6520 }
6521 
6522 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
6523  Record.AddStmt(C->getNumForLoops());
6524  Record.AddSourceLocation(C->getLParenLoc());
6525 }
6526 
6527 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
6528  Record.push_back(C->getDefaultKind());
6529  Record.AddSourceLocation(C->getLParenLoc());
6530  Record.AddSourceLocation(C->getDefaultKindKwLoc());
6531 }
6532 
6533 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
6534  Record.push_back(C->getProcBindKind());
6535  Record.AddSourceLocation(C->getLParenLoc());
6536  Record.AddSourceLocation(C->getProcBindKindKwLoc());
6537 }
6538 
6539 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
6540  VisitOMPClauseWithPreInit(C);
6541  Record.push_back(C->getScheduleKind());
6542  Record.push_back(C->getFirstScheduleModifier());
6543  Record.push_back(C->getSecondScheduleModifier());
6544  Record.AddStmt(C->getChunkSize());
6545  Record.AddSourceLocation(C->getLParenLoc());
6546  Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
6547  Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
6548  Record.AddSourceLocation(C->getScheduleKindLoc());
6549  Record.AddSourceLocation(C->getCommaLoc());
6550 }
6551 
6552 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
6553  Record.push_back(C->getLoopNumIterations().size());
6554  Record.AddStmt(C->getNumForLoops());
6555  for (Expr *NumIter : C->getLoopNumIterations())
6556  Record.AddStmt(NumIter);
6557  for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I)
6558  Record.AddStmt(C->getLoopCounter(I));
6559  Record.AddSourceLocation(C->getLParenLoc());
6560 }
6561 
6562 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
6563 
6564 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
6565 
6566 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
6567 
6568 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
6569 
6570 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
6571 
6572 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
6573 
6574 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
6575 
6576 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
6577 
6578 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
6579 
6580 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
6581 
6582 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
6583 
6584 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
6585  Record.push_back(C->varlist_size());
6586  Record.AddSourceLocation(C->getLParenLoc());
6587  for (auto *VE : C->varlists()) {
6588  Record.AddStmt(VE);
6589  }
6590  for (auto *VE : C->private_copies()) {
6591  Record.AddStmt(VE);
6592  }
6593 }
6594 
6595 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
6596  Record.push_back(C->varlist_size());
6597  VisitOMPClauseWithPreInit(C);
6598  Record.AddSourceLocation(C->getLParenLoc());
6599  for (auto *VE : C->varlists()) {
6600  Record.AddStmt(VE);
6601  }
6602  for (auto *VE : C->private_copies()) {
6603  Record.AddStmt(VE);
6604  }
6605  for (auto *VE : C->inits()) {
6606  Record.AddStmt(VE);
6607  }
6608 }
6609 
6610 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
6611  Record.push_back(C->varlist_size());
6612  VisitOMPClauseWithPostUpdate(C);
6613  Record.AddSourceLocation(C->getLParenLoc());
6614  for (auto *VE : C->varlists())
6615  Record.AddStmt(VE);
6616  for (auto *E : C->private_copies())
6617  Record.AddStmt(E);
6618  for (auto *E : C->source_exprs())
6619  Record.AddStmt(E);
6620  for (auto *E : C->destination_exprs())
6621  Record.AddStmt(E);
6622  for (auto *E : C->assignment_ops())
6623  Record.AddStmt(E);
6624 }
6625 
6626 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
6627  Record.push_back(C->varlist_size());
6628  Record.AddSourceLocation(C->getLParenLoc());
6629  for (auto *VE : C->varlists())
6630  Record.AddStmt(VE);
6631 }
6632 
6633 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
6634  Record.push_back(C->varlist_size());
6635  VisitOMPClauseWithPostUpdate(C);
6636  Record.AddSourceLocation(C->getLParenLoc());
6637  Record.AddSourceLocation(C->getColonLoc());
6638  Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
6639  Record.AddDeclarationNameInfo(C->getNameInfo());
6640  for (auto *VE : C->varlists())
6641  Record.AddStmt(VE);
6642  for (auto *VE : C->privates())
6643  Record.AddStmt(VE);
6644  for (auto *E : C->lhs_exprs())
6645  Record.AddStmt(E);
6646  for (auto *E : C->rhs_exprs())
6647  Record.AddStmt(E);
6648  for (auto *E : C->reduction_ops())
6649  Record.AddStmt(E);
6650 }
6651 
6652 void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
6653  Record.push_back(C->varlist_size());
6654  VisitOMPClauseWithPostUpdate(C);
6655  Record.AddSourceLocation(C->getLParenLoc());
6656  Record.AddSourceLocation(C->getColonLoc());
6657  Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
6658  Record.AddDeclarationNameInfo(C->getNameInfo());
6659  for (auto *VE : C->varlists())
6660  Record.AddStmt(VE);
6661  for (auto *VE : C->privates())
6662  Record.AddStmt(VE);
6663  for (auto *E : C->lhs_exprs())
6664  Record.AddStmt(E);
6665  for (auto *E : C->rhs_exprs())
6666  Record.AddStmt(E);
6667  for (auto *E : C->reduction_ops())
6668  Record.AddStmt(E);
6669 }
6670 
6671 void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) {
6672  Record.push_back(C->varlist_size());
6673  VisitOMPClauseWithPostUpdate(C);
6674  Record.AddSourceLocation(C->getLParenLoc());
6675  Record.AddSourceLocation(C->getColonLoc());
6676  Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
6677  Record.AddDeclarationNameInfo(C->getNameInfo());
6678  for (auto *VE : C->varlists())
6679  Record.AddStmt(VE);
6680  for (auto *VE : C->privates())
6681  Record.AddStmt(VE);
6682  for (auto *E : C->lhs_exprs())
6683  Record.AddStmt(E);
6684  for (auto *E : C->rhs_exprs())
6685  Record.AddStmt(E);
6686  for (auto *E : C->reduction_ops())
6687  Record.AddStmt(E);
6688  for (auto *E : C->taskgroup_descriptors())
6689  Record.AddStmt(E);
6690 }
6691 
6692 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
6693  Record.push_back(C->varlist_size());
6694  VisitOMPClauseWithPostUpdate(C);
6695  Record.AddSourceLocation(C->getLParenLoc());
6696  Record.AddSourceLocation(C->getColonLoc());
6697  Record.push_back(C->getModifier());
6698  Record.AddSourceLocation(C->getModifierLoc());
6699  for (auto *VE : C->varlists()) {
6700  Record.AddStmt(VE);
6701  }
6702  for (auto *VE : C->privates()) {
6703  Record.AddStmt(VE);
6704  }
6705  for (auto *VE : C->inits()) {
6706  Record.AddStmt(VE);
6707  }
6708  for (auto *VE : C->updates()) {
6709  Record.AddStmt(VE);
6710  }
6711  for (auto *VE : C->finals()) {
6712  Record.AddStmt(VE);
6713  }
6714  Record.AddStmt(C->getStep());
6715  Record.AddStmt(C->getCalcStep());
6716 }
6717 
6718 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
6719  Record.push_back(C->varlist_size());
6720  Record.AddSourceLocation(C->getLParenLoc());
6721  Record.AddSourceLocation(C->getColonLoc());
6722  for (auto *VE : C->varlists())
6723  Record.AddStmt(VE);
6724  Record.AddStmt(C->getAlignment());
6725 }
6726 
6727 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
6728  Record.push_back(C->varlist_size());
6729  Record.AddSourceLocation(C->getLParenLoc());
6730  for (auto *VE : C->varlists())
6731  Record.AddStmt(VE);
6732  for (auto *E : C->source_exprs())
6733  Record.AddStmt(E);
6734  for (auto *E : C->destination_exprs())
6735  Record.AddStmt(E);
6736  for (auto *E : C->assignment_ops())
6737  Record.AddStmt(E);
6738 }
6739 
6740 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
6741  Record.push_back(C->varlist_size());
6742  Record.AddSourceLocation(C->getLParenLoc());
6743  for (auto *VE : C->varlists())
6744  Record.AddStmt(VE);
6745  for (auto *E : C->source_exprs())
6746  Record.AddStmt(E);
6747  for (auto *E : C->destination_exprs())
6748  Record.AddStmt(E);
6749  for (auto *E : C->assignment_ops())
6750  Record.AddStmt(E);
6751 }
6752 
6753 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
6754  Record.push_back(C->varlist_size());
6755  Record.AddSourceLocation(C->getLParenLoc());
6756  for (auto *VE : C->varlists())
6757  Record.AddStmt(VE);
6758 }
6759 
6760 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
6761  Record.push_back(C->varlist_size());
6762  Record.push_back(C->getNumLoops());
6763  Record.AddSourceLocation(C->getLParenLoc());
6764  Record.push_back(C->getDependencyKind());
6765  Record.AddSourceLocation(C->getDependencyLoc());
6766  Record.AddSourceLocation(C->getColonLoc());
6767  for (auto *VE : C->varlists())
6768  Record.AddStmt(VE);
6769  for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
6770  Record.AddStmt(C->getLoopData(I));
6771 }
6772 
6773 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
6774  VisitOMPClauseWithPreInit(C);
6775  Record.AddStmt(C->getDevice());
6776  Record.AddSourceLocation(C->getLParenLoc());
6777 }
6778 
6779 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
6780  Record.push_back(C->varlist_size());
6781  Record.push_back(C->getUniqueDeclarationsNum());
6782  Record.push_back(C->getTotalComponentListNum());
6783  Record.push_back(C->getTotalComponentsNum());
6784  Record.AddSourceLocation(C->getLParenLoc());
6785  for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
6786  Record.push_back(C->getMapTypeModifier(I));
6787  Record.AddSourceLocation(C->getMapTypeModifierLoc(I));
6788  }
6789  Record.push_back(C->getMapType());
6790  Record.AddSourceLocation(C->getMapLoc());
6791  Record.AddSourceLocation(C->getColonLoc());
6792  for (auto *E : C->varlists())
6793  Record.AddStmt(E);
6794  for (auto *D : C->all_decls())
6795  Record.AddDeclRef(D);
6796  for (auto N : C->all_num_lists())
6797  Record.push_back(N);
6798  for (auto N : C->all_lists_sizes())
6799  Record.push_back(N);
6800  for (auto &M : C->all_components()) {
6801  Record.AddStmt(M.getAssociatedExpression());
6802  Record.AddDeclRef(M.getAssociatedDeclaration());
6803  }
6804 }
6805 
6806 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
6807  VisitOMPClauseWithPreInit(C);
6808  Record.AddStmt(C->getNumTeams());
6809  Record.AddSourceLocation(C->getLParenLoc());
6810 }
6811 
6812 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
6813  VisitOMPClauseWithPreInit(C);
6814  Record.AddStmt(C->getThreadLimit());
6815  Record.AddSourceLocation(C->getLParenLoc());
6816 }
6817 
6818 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
6819  Record.AddStmt(C->getPriority());
6820  Record.AddSourceLocation(C->getLParenLoc());
6821 }
6822 
6823 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
6824  Record.AddStmt(C->getGrainsize());
6825  Record.AddSourceLocation(C->getLParenLoc());
6826 }
6827 
6828 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
6829  Record.AddStmt(C->getNumTasks());
6830  Record.AddSourceLocation(C->getLParenLoc());
6831 }
6832 
6833 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
6834  Record.AddStmt(C->getHint());
6835  Record.AddSourceLocation(C->getLParenLoc());
6836 }
6837 
6838 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
6839  VisitOMPClauseWithPreInit(C);
6840  Record.push_back(C->getDistScheduleKind());
6841  Record.AddStmt(C->getChunkSize());
6842  Record.AddSourceLocation(C->getLParenLoc());
6843  Record.AddSourceLocation(C->getDistScheduleKindLoc());
6844  Record.AddSourceLocation(C->getCommaLoc());
6845 }
6846 
6847 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
6848  Record.push_back(C->getDefaultmapKind());
6849  Record.push_back(C->getDefaultmapModifier());
6850  Record.AddSourceLocation(C->getLParenLoc());
6851  Record.AddSourceLocation(C->getDefaultmapModifierLoc());
6852  Record.AddSourceLocation(C->getDefaultmapKindLoc());
6853 }
6854 
6855 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
6856  Record.push_back(C->varlist_size());
6857  Record.push_back(C->getUniqueDeclarationsNum());
6858  Record.push_back(C->getTotalComponentListNum());
6859  Record.push_back(C->getTotalComponentsNum());
6860  Record.AddSourceLocation(C->getLParenLoc());
6861  for (auto *E : C->varlists())
6862  Record.AddStmt(E);
6863  for (auto *D : C->all_decls())
6864  Record.AddDeclRef(D);
6865  for (auto N : C->all_num_lists())
6866  Record.push_back(N);
6867  for (auto N : C->all_lists_sizes())
6868  Record.push_back(N);
6869  for (auto &M : C->all_components()) {
6870  Record.AddStmt(M.getAssociatedExpression());
6871  Record.AddDeclRef(M.getAssociatedDeclaration());
6872  }
6873 }
6874 
6875 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
6876  Record.push_back(C->varlist_size());
6877  Record.push_back(C->getUniqueDeclarationsNum());
6878  Record.push_back(C->getTotalComponentListNum());
6879  Record.push_back(C->getTotalComponentsNum());
6880  Record.AddSourceLocation(C->getLParenLoc());
6881  for (auto *E : C->varlists())
6882  Record.AddStmt(E);
6883  for (auto *D : C->all_decls())
6884  Record.AddDeclRef(D);
6885  for (auto N : C->all_num_lists())
6886  Record.push_back(N);
6887  for (auto N : C->all_lists_sizes())
6888  Record.push_back(N);
6889  for (auto &M : C->all_components()) {
6890  Record.AddStmt(M.getAssociatedExpression());
6891  Record.AddDeclRef(M.getAssociatedDeclaration());
6892  }
6893 }
6894 
6895 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
6896  Record.push_back(C->varlist_size());
6897  Record.push_back(C->getUniqueDeclarationsNum());
6898  Record.push_back(C->getTotalComponentListNum());
6899  Record.push_back(C->getTotalComponentsNum());
6900  Record.AddSourceLocation(C->getLParenLoc());
6901  for (auto *E : C->varlists())
6902  Record.AddStmt(E);
6903  for (auto *VE : C->private_copies())
6904  Record.AddStmt(VE);
6905  for (auto *VE : C->inits())
6906  Record.AddStmt(VE);
6907  for (auto *D : C->all_decls())
6908  Record.AddDeclRef(D);
6909  for (auto N : C->all_num_lists())
6910  Record.push_back(N);
6911  for (auto N : C->all_lists_sizes())
6912  Record.push_back(N);
6913  for (auto &M : C->all_components()) {
6914  Record.AddStmt(M.getAssociatedExpression());
6915  Record.AddDeclRef(M.getAssociatedDeclaration());
6916  }
6917 }
6918 
6919 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
6920  Record.push_back(C->varlist_size());
6921  Record.push_back(C->getUniqueDeclarationsNum());
6922  Record.push_back(C->getTotalComponentListNum());
6923  Record.push_back(C->getTotalComponentsNum());
6924  Record.AddSourceLocation(C->getLParenLoc());
6925  for (auto *E : C->varlists())
6926  Record.AddStmt(E);
6927  for (auto *D : C->all_decls())
6928  Record.AddDeclRef(D);
6929  for (auto N : C->all_num_lists())
6930  Record.push_back(N);
6931  for (auto N : C->all_lists_sizes())
6932  Record.push_back(N);
6933  for (auto &M : C->all_components()) {
6934  Record.AddStmt(M.getAssociatedExpression());
6935  Record.AddDeclRef(M.getAssociatedDeclaration());
6936  }
6937 }
6938 
6939 void OMPClauseWriter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {}
6940 
6941 void OMPClauseWriter::VisitOMPUnifiedSharedMemoryClause(
6943 
6944 void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {}
6945 
6946 void
6947 OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) {
6948 }
6949 
6950 void OMPClauseWriter::VisitOMPAtomicDefaultMemOrderClause(
6952  Record.push_back(C->getAtomicDefaultMemOrderKind());
6953  Record.AddSourceLocation(C->getLParenLoc());
6954  Record.AddSourceLocation(C->getAtomicDefaultMemOrderKindKwLoc());
6955 }
A PredefinedExpr record.
Definition: ASTBitCodes.h:1629
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
TemplateTemplateParmDecl * getParameterPack() const
Retrieve the template template parameter pack being substituted.
Definition: TemplateName.h:136
A FriendTemplateDecl record.
Definition: ASTBitCodes.h:1458
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:5376
Defines the clang::ASTContext interface.
A CompoundLiteralExpr record.
Definition: ASTBitCodes.h:1689
A NonTypeTemplateParmDecl record.
Definition: ASTBitCodes.h:1485
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it&#39;s either not been deduced or was deduce...
Definition: Type.h:4735
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition: TargetInfo.h:151
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:5129
const FileEntry * OrigEntry
Reference to the file entry representing this ContentCache.
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:611
Record code for the preprocessor options table.
Definition: ASTBitCodes.h:358
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1196
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:5641
uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:5383
Represents a function declaration or definition.
Definition: Decl.h:1738
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1382
llvm::SmallSetVector< const TypedefNameDecl *, 4 > UnusedLocalTypedefNameCandidates
Set containing all typedefs that are likely unused.
Definition: Sema.h:573
std::string Name
The name of this module.
Definition: Module.h:68
helper_expr_const_range reduction_ops() const
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
NamespaceDecl * getStdNamespace() const
This represents &#39;thread_limit&#39; clause in the &#39;#pragma omp ...&#39; directive.
SourceLocation getOptimizeOffPragmaLocation() const
Get the location for the currently active "\#pragma clang optimize off". If this location is invalid...
Definition: Sema.h:8531
void VisitArrayType(const ArrayType *T)
Definition: ASTWriter.cpp:233
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.
ExtVectorDeclsType ExtVectorDecls
ExtVectorDecls - This is a list all the extended vector types.
Definition: Sema.h:561
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:5655
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:178
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl< char > &Buffer, MemoryBufferCache &PCMCache, ArrayRef< std::shared_ptr< ModuleFileExtension >> Extensions, bool IncludeTimestamps=true)
Create a new precompiled header writer that outputs to the given bitstream.
Definition: ASTWriter.cpp:4570
std::vector< std::pair< std::string, bool > > Macros
no exception specification
Record code for potentially unused local typedef names.
Definition: ASTBitCodes.h:619
Smart pointer class that efficiently represents Objective-C method names.
Record code for map of Objective-C class definition IDs to the ObjC categories in a module that are a...
Definition: ASTBitCodes.h:577
This is a discriminated union of FileInfo and ExpansionInfo.
An IndirectGotoStmt record.
Definition: ASTBitCodes.h:1602
helper_expr_const_range lhs_exprs() const
const_all_decls_range all_decls() const
This represents clause &#39;copyin&#39; in the &#39;#pragma omp ...&#39; directives.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:4023
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2537
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:5649
QualType getElementType() const
Definition: Type.h:6016
QualType getPointeeType() const
Definition: Type.h:2550
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
Definition: Type.h:4121
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:393
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:188
A (possibly-)qualified type.
Definition: Type.h:638
static void EmitBlockID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, ASTWriter::RecordDataImpl &Record)
Definition: ASTWriter.cpp:908
#define BLOCK(X)
void * getAsOpaquePtr() const
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:495
bool getNoCfCheck() const
Definition: Type.h:3515
An AddrLabelExpr record.
Definition: ASTBitCodes.h:1719
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
The macro directives history for a particular identifier.
Definition: ASTBitCodes.h:698
unsigned ImplicitModuleMaps
Implicit module maps.
QualType getInjectedSpecializationType() const
Definition: Type.h:5010
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:479
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:122
const DeclarationNameLoc & getInfo() const
const std::vector< SourceRange > & getSkippedRanges()
Retrieve all ranges that got skipped while preprocessing.
SourceLocation getSpellingLoc() const
void AddToken(const Token &Tok, RecordDataImpl &Record)
Emit a token.
Definition: ASTWriter.cpp:4486
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:3948
LateParsedTemplateMapT LateParsedTemplateMap
Definition: Sema.h:648
SourceLocation getCommaLoc()
Get location of &#39;,&#39;.
OpenCL supported extensions and optional core features.
Definition: OpenCLOptions.h:23
A CXXStaticCastExpr record.
Definition: ASTBitCodes.h:1841
Defines the clang::FileManager interface and associated types.
time_t getModificationTime() const
Definition: FileManager.h:93
Record code for the source manager line table information, which stores information about #line direc...
Definition: ASTBitCodes.h:573
An AttributedStmt record.
Definition: ASTBitCodes.h:1581
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
A CXXReinterpretCastExpr record.
Definition: ASTBitCodes.h:1847
std::string ModuleUserBuildPath
The directory used for a user build.
This represents &#39;atomic_default_mem_order&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:870
An OMPThreadPrivateDecl record.
Definition: ASTBitCodes.h:1521
bool isLookupContext() const
Test whether the context supports looking up names.
Definition: DeclBase.h:1813
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2271
helper_expr_const_range rhs_exprs() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
An ObjCBoolLiteralExpr record.
Definition: ASTBitCodes.h:1809
void getUndefinedButUsed(SmallVectorImpl< std::pair< NamedDecl *, SourceLocation > > &Undefined)
Obtain a sorted list of functions that are undefined but ODR-used.
Definition: Sema.cpp:626
submodule_iterator submodule_begin()
Definition: Module.h:556
Expr * getUnderlyingExpr() const
Definition: Type.h:4256
private_copies_range private_copies()
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:168
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:1029
This represents clause &#39;in_reduction&#39; in the &#39;#pragma omp task&#39; directives.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3355
Expr * getLoopData(unsigned NumLoop)
Get the loop data.
unsigned IsExternC
Whether this is an &#39;extern "C"&#39; module (which implicitly puts all headers in it within an &#39;extern "C"...
Definition: Module.h:231
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
Definition: Type.h:4059
Class that handles pre-initialization statement for some clauses, like &#39;shedule&#39;, &#39;firstprivate&#39; etc...
Definition: OpenMPClause.h:99
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:451
void AddUnresolvedSet(const ASTUnresolvedSet &Set)
Emit a UnresolvedSet structure.
Definition: ASTWriter.cpp:5932
void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Emit a nested name specifier with source-location information.
Definition: ASTWriter.cpp:5753
C Language Family Type Representation.
Defines the SourceManager interface.
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
static bool isImportedDeclContext(ASTReader *Chain, const Decl *D)
Definition: ASTWriter.cpp:6211
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5212
An OMPDeclareReductionDecl record.
Definition: ASTBitCodes.h:1542
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:532
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:270
FileManager & getFileManager() const
Definition: Preprocessor.h:818
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5231
RawCommentList Comments
All comments in this translation unit.
Definition: ASTContext.h:724
helper_expr_const_range rhs_exprs() const
bool isInitICE() const
Determines whether the initializer is an integral constant expression, or in C++11, whether the initializer is a constant expression.
Definition: Decl.cpp:2324
void GetUniqueIDMapping(SmallVectorImpl< const FileEntry *> &UIDToFiles) const
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry poi...
An ImplicitValueInitExpr record.
Definition: ASTBitCodes.h:1713
Defines the clang::Module class, which describes a module in the source code.
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:157
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
This represents &#39;grainsize&#39; clause in the &#39;#pragma omp ...&#39; directive.
An ImplicitCastExpr record.
Definition: ASTBitCodes.h:1683
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4002
TagDecl * getDecl() const
Definition: Type.cpp:3166
static constexpr unsigned NumberOfModifiers
Number of allowed map-type-modifiers.
A VarTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1476
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:245
std::deque< PendingImplicitInstantiation > PendingInstantiations
The queue of implicit template instantiations that are required but have not yet been performed...
Definition: Sema.h:7649
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:219
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
ModuleKind Kind
The type of this module.
Definition: Module.h:120
This represents &#39;if&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:240
Defines the C++ template declaration subclasses.
StringRef P
Describes a source location entry (SLocEntry) for a macro expansion.
Definition: ASTBitCodes.h:676
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
SourceLocation getAtomicDefaultMemOrderKindKwLoc() const
Returns location of clause kind.
Definition: OpenMPClause.h:930
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4749
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:3520
std::vector< std::string > Includes
bool makeAbsolutePath(SmallVectorImpl< char > &Path) const
Makes Path absolute taking into account FileSystemOptions and the working directory option...
An LValueReferenceType record.
Definition: ASTBitCodes.h:1051
Not a friend object.
Definition: DeclBase.h:1095
static unsigned getNumberOfModules(Module *Mod)
Compute the number of modules within the given tree (including the given module). ...
Definition: ASTWriter.cpp:2793
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
Definition: DeclBase.h:953
Defines the clang::MacroInfo and clang::MacroDirective classes.
A CXXOperatorCallExpr record.
Definition: ASTBitCodes.h:1826
helper_expr_const_range assignment_ops() const
Defines types useful for describing an Objective-C runtime.
Specifies the submodules that are imported by this submodule.
Definition: ASTBitCodes.h:742
std::string ModuleName
The name of the module.
Definition: Module.h:126
A record that stores the set of declarations that are lexically stored within a given DeclContext...
Definition: ASTBitCodes.h:1383
This represents &#39;priority&#39; clause in the &#39;#pragma omp ...&#39; directive.
Specifies an umbrella directory.
Definition: ASTBitCodes.h:738
helper_expr_const_range lhs_exprs() const
A CXXTemporaryObjectExpr record.
Definition: ASTBitCodes.h:1838
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
Definition: Sema.h:7700
llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > LateParsedTemplateMapT
Definition: Sema.h:647
QualType getsigjmp_bufType() const
Retrieve the C sigjmp_buf type.
Definition: ASTContext.h:1766
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded...
DiagnosticsEngine & getDiagnostics() const
A SubstTemplateTypeParmType record.
Definition: ASTBitCodes.h:1108
Class that performs name lookup into a DeclContext stored in an AST file.
Declaration of a variable template.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2812
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
Represent a C++ namespace.
Definition: Decl.h:515
A ObjCPropertyDecl record.
Definition: ASTBitCodes.h:1340
Wrapper for source info for typedefs.
Definition: TypeLoc.h:664
serialization::DeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its ID.
Definition: ASTWriter.cpp:5515
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:365
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:690
A container of type source information.
Definition: Decl.h:87
This represents &#39;update&#39; clause in the &#39;#pragma omp atomic&#39; directive.
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:5983
Record code for enabled OpenCL extensions.
Definition: ASTBitCodes.h:556
Record code for the module build directory.
Definition: ASTBitCodes.h:334
Floating point control options.
Definition: LangOptions.h:307
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4591
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:308
SourceLocation getAttributeLoc() const
Definition: Type.h:3260
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:5471
An ElaboratedType record.
Definition: ASTBitCodes.h:1105
ObjCMethodDecl * getMethod() const
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
Definition: Module.h:384
An UnresolvedUsingType record.
Definition: ASTBitCodes.h:1111
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
static void AddStmtsExprs(llvm::BitstreamWriter &Stream, ASTWriter::RecordDataImpl &Record)
Definition: ASTWriter.cpp:934
Wrapper for source info for pointers decayed from arrays and functions.
Definition: TypeLoc.h:1163
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack...
static uint64_t EmitCXXCtorInitializers(ASTWriter &W, ArrayRef< CXXCtorInitializer *> CtorInits)
Definition: ASTWriter.cpp:5971
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4569
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:76
An IncompleteArrayType record.
Definition: ASTBitCodes.h:1063
The internal &#39;__type_pack_element&#39; template.
Definition: ASTBitCodes.h:1270
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:207
Specifies a header that is part of the module but must be textually included.
Definition: ASTBitCodes.h:769
Expr * getAlignment()
Returns alignment.
Expr * getNumForLoops() const
Return the number of associated for-loops.
SourceLocation getSecondScheduleModifierLoc() const
Get the second modifier location.
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier at &#39;Cnt&#39; index of array of modifiers.
uint64_t Emit(unsigned Code, unsigned Abbrev=0)
Emit the record to the stream, followed by its substatements, and return its offset.
Definition: ASTWriter.h:808
IdentifierInfo * getAlias() const
Definition: Weak.h:34
bool hasBaseTypeAsWritten() const
Definition: TypeLoc.h:1003
QualType getElementType() const
Definition: Type.h:2847
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3169
bool hasLocalNonFastQualifiers() const
Determine whether this particular QualType instance has any "non-fast" qualifiers, e.g., those that are stored in an ExtQualType instance.
Definition: Type.h:750
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:485
A ClassTemplateDecl record.
Definition: ASTBitCodes.h:1461
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:4803
ArrayRef< RawComment * > getComments() const
A PragmaDetectMismatchDecl record.
Definition: ASTBitCodes.h:1539
An UnresolvedUsingTypenameDecl record.
Definition: ASTBitCodes.h:1422
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1792
An identifier, stored as an IdentifierInfo*.
The internal &#39;__builtin_va_list&#39; typedef.
Definition: ASTBitCodes.h:1249
The stack of open #ifs/#ifdefs recorded in a preamble.
Definition: ASTBitCodes.h:648
static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, ArrayRef< CXXBaseSpecifier > Bases)
Definition: ASTWriter.cpp:5953
SourceLocation getDependencyLoc() const
Get dependency type location.
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:49
This represents &#39;read&#39; clause in the &#39;#pragma omp atomic&#39; directive.
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:5359
helper_expr_const_range assignment_ops() const
Represents a variable declaration or definition.
Definition: Decl.h:813
This represents clause &#39;private&#39; in the &#39;#pragma omp ...&#39; directives.
Record code for #pragma pack options.
Definition: ASTBitCodes.h:645
A block with unhashed content.
Definition: ASTBitCodes.h:297
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:382
Wrapper for source info for member pointers.
Definition: TypeLoc.h:1232
An OMPCapturedExprDecl record.
Definition: ASTBitCodes.h:1533
void AddFunctionDefinition(const FunctionDecl *FD)
Add a definition for the given function to the queue of statements to emit.
unsigned getNumParams() const
Definition: Type.h:3888
Options for controlling the target.
Definition: TargetOptions.h:27
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:271
Manage memory buffers across multiple users.
Record code for declarations associated with OpenCL extensions.
Definition: ASTBitCodes.h:640
A UsingShadowDecl record.
Definition: ASTBitCodes.h:1410
varlist_range varlists()
Definition: OpenMPClause.h:207
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
QualType getRawCFConstantStringType() const
Get the structure type used to representation CFStrings, or NULL if it hasn&#39;t yet been built...
Definition: ASTContext.h:1611
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1997
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
Definition: Module.h:367
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:1277
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1205
Represents a C++17 deduced template specialization type.
Definition: Type.h:4785
static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a file.
Definition: ASTWriter.cpp:1859
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Represents a variable template specialization, which refers to a variable template with a given set o...
The value of the next COUNTER to dispense.
Definition: ASTBitCodes.h:481
unsigned getNextLocalOffset() const
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:173
const DeclContext * getDefinitiveDeclContext(const DeclContext *DC)
Retrieve the "definitive" declaration that provides all of the visible entries for the given declarat...
Definition: ASTCommon.cpp:259
A TemplateTemplateParmDecl record that stores an expanded template template parameter pack...
Definition: ASTBitCodes.h:1511
Specifies the umbrella header used to create this module, if any.
Definition: ASTBitCodes.h:729
SourceLocation getLBracketLoc() const
Definition: Type.h:2998
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:604
A namespace, stored as a NamespaceDecl*.
SourceLocation getColonLoc() const
Return the location of &#39;:&#39;.
Definition: OpenMPClause.h:305
iterator local_end()
End iterator for local, non-loaded, preprocessed entities.
unsigned isCompilingModuleHeader
Whether this header is part of the module that we are building.
Definition: HeaderSearch.h:72
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:655
Record code for header search information.
Definition: ASTBitCodes.h:550
BlockCommandNamesTy BlockCommandNames
Command names to treat as block commands in comments.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
unsigned getODRHash() const
Definition: DeclCXX.cpp:475
std::string ModuleCachePath
The directory used for the module cache.
This represents implicit clause &#39;flush&#39; for the &#39;#pragma omp flush&#39; directive.
Describes a source location entry (SLocEntry) for a buffer.
Definition: ASTBitCodes.h:662
Used to hold and unique data used to represent #line information.
llvm::MapVector< Selector, SourceLocation > ReferencedSelectors
Method selectors used in a @selector expression.
Definition: Sema.h:1164
A CXXConstructExpr record.
Definition: ASTBitCodes.h:1832
Record code for the target options table.
Definition: ASTBitCodes.h:349
serialization::IdentID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:5349
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:120
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
unsigned getTotalComponentsNum() const
Return the total number of components in all lists derived from the clause.
This represents &#39;reverse_offload&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
Definition: OpenMPClause.h:807
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
A TemplateTemplateParmDecl record.
Definition: ASTBitCodes.h:1488
Record code for the array of eagerly deserialized decls.
Definition: ASTBitCodes.h:452
Expr * getAttrExprOperand() const
The attribute&#39;s expression operand, if it has one.
Definition: TypeLoc.h:1676
Represents a parameter to a function.
Definition: Decl.h:1550
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4603
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:877
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:1232
Defines the clang::Expr interface and subclasses for C++ expressions.
FPOptions & getFPOptions()
Definition: Sema.h:1233
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:1888
const HeaderFileInfo * getExistingFileInfo(const FileEntry *FE, bool WantExternal=true) const
Return the HeaderFileInfo structure for the specified FileEntry, if it has ever been filled in...
A ObjCInterfaceDecl record.
Definition: ASTBitCodes.h:1316
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:315
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:329
tok::TokenKind getKind() const
Definition: Token.h:90
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
void AddSourceRange(SourceRange Range)
Emit a source range.
Definition: ASTWriter.h:852
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:5345
Expr * getGrainsize() const
Return safe iteration space distance.
This represents &#39;nogroup&#39; clause in the &#39;#pragma omp ...&#39; directive.
SourceLocation getAmpAmpLoc() const
Definition: TypeLoc.h:1310
The collection of all-type qualifiers we support.
Definition: Type.h:141
A ShuffleVectorExpr record.
Definition: ASTBitCodes.h:1731
This represents &#39;safelen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:447
bool needsExtraLocalData() const
Definition: TypeLoc.h:576
PipeType - OpenCL20.
Definition: Type.h:6002
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:720
iterator begin(DeclarationName Name)
begin - Returns an iterator for decls with the name &#39;Name&#39;.
ModuleKind Kind
The kind of this module.
Definition: Module.h:87
void AddTypeSourceInfo(TypeSourceInfo *TInfo)
Emits a reference to a declarator info.
Definition: ASTWriter.cpp:5455
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
SourceLocation getAttributeLoc() const
Definition: Type.h:3145
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:57
A CXXConstructorDecl record for an inherited constructor.
Definition: ASTBitCodes.h:1443
Represents a struct/union/class.
Definition: Decl.h:3593
const unsigned VERSION_MAJOR
AST file major version number supported by this version of Clang.
Definition: ASTBitCodes.h:45
unsigned varlist_size() const
Definition: OpenMPClause.h:204
QualType getOriginalType() const
Definition: Type.h:2601
TypeSpecifierSign getWrittenSignSpec() const
Definition: TypeLoc.h:596
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
ArrayRef< PPConditionalInfo > getPreambleConditionalStack() const
A macro directive exported by a module.
Definition: ASTBitCodes.h:702
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1878
An ObjCAtThrowStmt record.
Definition: ASTBitCodes.h:1803
FileManager & getFileManager() const
Specifies a top-level header that falls into this (sub)module.
Definition: ASTBitCodes.h:735
The block containing comments.
Definition: ASTBitCodes.h:270
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:255
void AddTypeRef(QualType T)
Emit a reference to a type.
Definition: ASTWriter.h:883
A DesignatedInitExpr record.
Definition: ASTBitCodes.h:1698
The Objective-C &#39;SEL&#39; type.
Definition: ASTBitCodes.h:1231
SourceLocation getColonLoc() const
Gets location of &#39;:&#39; symbol in clause.
unsigned getRegParm() const
Definition: Type.h:3518
Represents a class type in Objective C.
Definition: Type.h:5538
Iteration over the preprocessed entities.
QualType getPointeeType() const
Definition: Type.h:2654
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
A C++ nested-name-specifier augmented with source location information.
Record the location of a macro definition.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:423
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1187
LineState State
This represents &#39;simd&#39; clause in the &#39;#pragma omp ...&#39; directive.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
TypeSourceInfo * getUnderlyingTInfo() const
Definition: TypeLoc.h:1841
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
Definition: ModuleMap.cpp:1141
bool isSpelledAsLValue() const
Definition: Type.h:2689
Specifies a header that has been explicitly excluded from this submodule.
Definition: ASTBitCodes.h:753
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:198
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
Definition: Decl.h:2579
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4904
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
This represents clause &#39;lastprivate&#39; in the &#39;#pragma omp ...&#39; directives.
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:1837
bool isCPlusPlusOperatorKeyword() const
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1875
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:587
Record code for the module map file that was used to build this AST file.
Definition: ASTBitCodes.h:331
One instance of this struct is kept for every file loaded or used.
Definition: SourceManager.h:95
std::vector< Entry > UserEntries
User specified include entries.
An ExtVectorType record.
Definition: ASTBitCodes.h:1072
SourceLocation getProtocolLAngleLoc() const
Definition: TypeLoc.h:963
Delete expressions that will be analyzed later.
Definition: ASTBitCodes.h:624
std::vector< SystemHeaderPrefix > SystemHeaderPrefixes
User-specified system header prefixes.
bool hasCommaPasting() const
Definition: MacroInfo.h:218
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2006
Expr * getChunkSize()
Get chunk size.
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:483
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
This represents clause &#39;map&#39; in the &#39;#pragma omp ...&#39; directives.
SourceLocation getDefaultKindKwLoc() const
Returns location of clause kind.
Definition: OpenMPClause.h:656
CXXRecordDecl * getStdBadAlloc() const
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:32
CachedTokens Toks
Definition: Sema.h:10908
This represents clause &#39;to&#39; in the &#39;#pragma omp ...&#39; directives.
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4659
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
FileManager & getFileMgr() const
Definition: HeaderSearch.h:271
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:5179
SourceLocation getProtocolRAngleLoc() const
Definition: TypeLoc.h:971
ParmVarDecl * getParam(unsigned i) const
Definition: TypeLoc.h:1408
ASTReader * getChain() const
Definition: ASTWriter.h:699
static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a macro expansion.
Definition: ASTWriter.cpp:1908
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:686
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1370
An AttributedType record.
Definition: ASTBitCodes.h:1141
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:141
Expr * getSafelen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:481
An object-like macro definition.
Definition: ASTBitCodes.h:686
unsigned IsTransient
True if this file may be transient, that is, if it might not exist at some later point in time when t...
The signature of a module, which is a hash of the AST content.
Definition: Module.h:55
~ASTWriter() override
Definition: ASTWriter.cpp:4582
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
unsigned char getOpaqueValue() const
Definition: Type.h:3430
void AddTemplateParameterList(const TemplateParameterList *TemplateParams)
Emit a template parameter list.
Definition: ASTWriter.cpp:5900
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:172
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:815
Describes one token.
Definition: ASTBitCodes.h:695
Expr * getNumTeams()
Return NumTeams number.
An AdjustedType record.
Definition: ASTBitCodes.h:1159
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:269
Describes a module or submodule.
Definition: Module.h:65
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1784
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:6091
A IndirectFieldDecl record.
Definition: ASTBitCodes.h:1503
Record code for the set of ext_vector type names.
Definition: ASTBitCodes.h:496
iterator end()
end - Returns an iterator that has &#39;finished&#39;.
void VisitTagType(const TagType *T)
Definition: ASTWriter.cpp:386
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
bool getProducesResult() const
Definition: Type.h:3513
serialization::MacroID getMacroID(MacroInfo *MI)
Determine the ID of an already-emitted macro.
Definition: ASTWriter.cpp:5375
This represents clause &#39;copyprivate&#39; in the &#39;#pragma omp ...&#39; directives.
static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
Definition: ModuleMap.cpp:92
SourceLocation getLAngleLoc() const
Definition: TypeLoc.h:1564
TypeSpecifierWidth getWrittenWidthSpec() const
Definition: TypeLoc.h:612
Specifies the submodules that are re-exported from this submodule.
Definition: ASTBitCodes.h:746
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition: Decl.h:676
serialization::MacroID BaseMacroID
Base macro ID for macros local to this module.
Definition: Module.h:312
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2738
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4132
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
The Objective-C &#39;id&#39; type.
Definition: ASTBitCodes.h:1228
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
Definition: Module.h:248
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:199
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2224
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:675
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
< Capturing the *this object by copy
Definition: Lambda.h:37
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:821
static void hash_combine(std::size_t &seed, const T &v)
SourceLocation getDefaultmapKindLoc()
Get kind location.
An AccessSpecDecl record.
Definition: ASTBitCodes.h:1452
unsigned getNumProtocols() const
Definition: TypeLoc.h:786
const Token & getReplacementToken(unsigned Tok) const
Definition: MacroInfo.h:236
SourceLocation getProtocolLoc(unsigned i) const
Definition: TypeLoc.h:983
Describes a blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:668
const FormatToken & Tok
const FileInfo & getFile() const
Record code for the language options table.
Definition: ASTBitCodes.h:346
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:3956
bool getInheritConstructors() const
Determine whether this base class&#39;s constructors get inherited.
Definition: DeclCXX.h:255
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Wrapper for source info for functions.
Definition: TypeLoc.h:1327
Specifies a conflict with another module.
Definition: ASTBitCodes.h:762
The signed 128-bit integer type.
Definition: ASTBitCodes.h:1240
unsigned getHash() const
Compute a fingerprint of this key for use in on-disk hash table.
Definition: ASTReader.cpp:1052
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1530
A UnaryTransformType record.
Definition: ASTBitCodes.h:1150
A reference to a previously [de]serialized Stmt record.
Definition: ASTBitCodes.h:1563
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier, not including the prefix.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:275
A UsingDirecitveDecl record.
Definition: ASTBitCodes.h:1416
const Stmt * getPreInitStmt() const
Get pre-initialization statement for the clause.
Definition: OpenMPClause.h:121
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1998
An ObjCObjectType record.
Definition: ASTBitCodes.h:1117
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
A ConstantArrayType record.
Definition: ASTBitCodes.h:1060
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:838
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Represents a typeof (or typeof) expression (a GCC extension).
Definition: Type.h:4176
Record code for #pragma optimize options.
Definition: ASTBitCodes.h:616
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Definition: Sema.h:1160
void AddSourceRange(SourceRange Range, RecordDataImpl &Record)
Emit a source range.
Definition: ASTWriter.cpp:5325
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
Specifies a header that is private to this submodule but must be textually included.
Definition: ASTBitCodes.h:773
Record code for pending implicit instantiations.
Definition: ASTBitCodes.h:526
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:831
SourceLocation RAngleLoc
The source location of the right angle bracket (&#39;>&#39;).
Definition: TemplateBase.h:618
SourceLocation getColonLoc() const
Gets location of &#39;:&#39; symbol in clause.
The internal &#39;__make_integer_seq&#39; template.
Definition: ASTBitCodes.h:1261
ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record)
Definition: ASTWriter.cpp:149
bool hasChain() const
Definition: ASTWriter.h:698
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1362
SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier location at &#39;Cnt&#39; index of array of modifiers&#39; locations.
Module * Parent
The parent of this module.
Definition: Module.h:91
const Type * getClass() const
Definition: Type.h:2790
bool isNull() const
Definition: TypeLoc.h:119
Record code for floating point #pragma options.
Definition: ASTBitCodes.h:553
CXXRecordDecl * getDecl() const
Definition: Type.cpp:3255
void AddTypeLoc(TypeLoc TL)
Emits source location information for a type. Does not emit the type.
Definition: ASTWriter.cpp:5465
Class that handles post-update expression for some clauses, like &#39;lastprivate&#39;, &#39;reduction&#39; etc...
Definition: OpenMPClause.h:135
Defines the Diagnostic-related interfaces.
LazyDeclPtr StdBadAlloc
The C++ "std::bad_alloc" class, which is defined by the C++ standard library.
Definition: Sema.h:835
This represents &#39;default&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:606
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2087
Expr * getSizeExpr() const
Definition: Type.h:2991
Wrapper for source info for ObjC interfaces.
Definition: TypeLoc.h:1049
Record code for the set of known namespaces, which are used for typo correction.
Definition: ASTBitCodes.h:563
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:728
TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType)
Definition: ASTCommon.h:50
bool hasRevertedBuiltin() const
True if setNotBuiltin() was called.
Record code for an array of all of the (sub)modules that were imported by the AST file...
Definition: ASTBitCodes.h:584
This represents &#39;final&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:330
This represents &#39;mergeable&#39; clause in the &#39;#pragma omp ...&#39; directive.
submodule_iterator submodule_end()
Definition: Module.h:558
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
Definition: Module.h:416
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:352
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
import_range local_imports() const
Definition: ASTContext.h:967
std::vector< std::string > Warnings
The list of -W...
This represents clause &#39;reduction&#39; in the &#39;#pragma omp ...&#39; directives.
A marker record that indicates that we are at the end of an expression.
Definition: ASTBitCodes.h:1557
A ClassTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1464
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
Definition: MacroInfo.h:223
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:821
SourceLocation getNameLoc() const
Definition: TypeLoc.h:1058
TemplateTemplateParmDecl * getParameter() const
Definition: TemplateName.h:339
A BlockPointerType record.
Definition: ASTBitCodes.h:1048
uint32_t getIndex() const
Definition: ASTBitCodes.h:96
SourceLocation getDefaultmapModifierLoc() const
Get the modifier location.
Preprocessor & PP
Definition: Sema.h:323
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:112
A MemberPointerType record.
Definition: ASTBitCodes.h:1057
TemplateArgumentLoc getArgLoc(unsigned i) const
Definition: TypeLoc.h:1592
helper_expr_const_range source_exprs() const
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
This represents clause &#39;is_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
SourceLocation getIncludeLoc() const
bool getNoReturn() const
Definition: Type.h:3512
unsigned getUniqueDeclarationsNum() const
Return the number of unique base declarations in this clause.
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:51
SourceLocation getProtocolRAngleLoc() const
Definition: TypeLoc.h:776
Qualifiers getTypeQuals() const
Definition: Type.h:4015
A DependentSizedExtVectorType record.
Definition: ASTBitCodes.h:1171
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:113
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2055
helper_expr_const_range source_exprs() const
unsigned getLength() const
Efficiently return the length of this identifier info.
Expr * getSizeExpr() const
Definition: Type.h:3048
Record code for the table of offsets into the block of source-location information.
Definition: ASTBitCodes.h:485
bool getNoCallerSavedRegs() const
Definition: Type.h:3514
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2692
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:870
Expr * getSizeExpr() const
Definition: Type.h:3258
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:5446
QualType getElementType() const
Definition: Type.h:3144
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3128
helper_expr_const_range privates() const
private_copies_range private_copies()
A SubstTemplateTypeParmPackType record.
Definition: ASTBitCodes.h:1144
This represents clause &#39;from&#39; in the &#39;#pragma omp ...&#39; directives.
TypeCode
Record codes for each kind of type.
Definition: ASTBitCodes.h:1037
unsigned header_file_size() const
Definition: HeaderSearch.h:660
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:223
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:233
Iterator that walks over the list of categories, filtering out those that do not meet specific criter...
Definition: DeclObjC.h:1598
bool MSStructPragmaOn
Definition: Sema.h:346
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:148
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:443
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:1556
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3650
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
Definition: Module.h:226
The block containing information about the source manager.
Definition: ASTBitCodes.h:253
Expr * getAddrSpaceExpr() const
Definition: Type.h:3099
helper_expr_const_range reduction_ops() const
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:335
A VariableArrayType record.
Definition: ASTBitCodes.h:1066
This represents &#39;dynamic_allocators&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:838
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:5601
SourceLocation getBuiltinLoc() const
Definition: TypeLoc.h:549
unsigned getLocalFastQualifiers() const
Definition: Type.h:665
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
const unsigned int NUM_PREDEF_PP_ENTITY_IDS
The number of predefined preprocessed entity IDs.
Definition: ASTBitCodes.h:242
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
OpenMPDefaultClauseKind getDefaultKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:653
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition: Decl.h:669
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn&#39;t been determined yet (either because...
Definition: Type.h:3973
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
TentativeDefinitionsType TentativeDefinitions
All the tentative definitions encountered in the TU.
Definition: Sema.h:603
Defines the major attributes of a submodule, including its name and parent.
Definition: ASTBitCodes.h:725
This represents &#39;threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, DeclarationName Name)
Definition: ASTWriter.cpp:5662
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:227
helper_expr_const_range destination_exprs() const
Expr * getSimdlen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:535
void AddCXXTemporary(const CXXTemporary *Temp)
Emit a CXXTemporary.
Definition: ASTWriter.cpp:5410
helper_expr_const_range source_exprs() const
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:124
This represents clause &#39;aligned&#39; in the &#39;#pragma omp ...&#39; directives.
qual_range quals() const
Definition: Type.h:5438
OverloadedOperatorKind getOperatorKind() const
Definition: ASTBitCodes.h:2097
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
Definition: OpenMPClause.h:79
SourceLocation getNameLoc() const
Definition: TypeLoc.h:2018
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:2005
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:282
StringRef Filename
Definition: Format.cpp:1629
A table of skipped ranges within the preprocessing record.
Definition: ASTBitCodes.h:651
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:203
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:569
helper_expr_const_range private_copies() const
This represents clause &#39;task_reduction&#39; in the &#39;#pragma omp taskgroup&#39; directives.
unsigned LocalNumSLocEntries
The number of source location entries in this AST file.
Definition: Module.h:245
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:5507
bool isInlineSpecified() const
Definition: Decl.h:1367
A StaticAssertDecl record.
Definition: ASTBitCodes.h:1494
Captures information about a #pragma weak directive.
Definition: Weak.h:25
for(unsigned I=0, E=TL.getNumArgs();I !=E;++I)
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:264
void AddPath(StringRef Path, RecordDataImpl &Record)
Add a path to the given record.
Definition: ASTWriter.cpp:4522
helper_expr_const_range destination_exprs() const
OpenMPProcBindClauseKind getProcBindKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:723
A VarTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1473
Record code for the table of offsets of each macro ID.
Definition: ASTBitCodes.h:601
SourceLocation getLParenLoc() const
Returns the locaiton of &#39;(&#39;.
Definition: OpenMPClause.h:922
unsigned getNumParams() const
Definition: MacroInfo.h:183
unsigned getNumLoops() const
Get number of loops associated with the clause.
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:1346
llvm::MemoryBuffer & addBuffer(llvm::StringRef Filename, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Store the Buffer under the Filename.
unsigned Offset
Definition: Format.cpp:1631
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
An ObjCTypeParamDecl record.
Definition: ASTBitCodes.h:1530
Exposes information about the current target.
Definition: TargetInfo.h:54
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1497
unsigned IgnoreSysRoot
IgnoreSysRoot - This is false if an absolute path should be treated relative to the sysroot...
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3026
void AddAttr(const Attr *A)
Definition: ASTWriter.cpp:4469
const_all_num_lists_range all_num_lists() const
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:236
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2095
TypeSourceInfo * getUnderlyingTInfo() const
Definition: TypeLoc.h:1881
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:876
Specifies some declarations with initializers that must be emitted to initialize the module...
Definition: ASTBitCodes.h:777
An ObjCObjectPointerType record.
Definition: ASTBitCodes.h:1099
An TemplateSpecializationType record.
Definition: ASTBitCodes.h:1123
File is from a prebuilt module path.
Definition: Module.h:60
QualType getElementType() const
Definition: Type.h:2490
Type source information for an attributed type.
Definition: TypeLoc.h:849
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
An ObjCInterfaceType record.
Definition: ASTBitCodes.h:1096
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:5299
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
This represents &#39;proc_bind&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:675
This represents &#39;capture&#39; clause in the &#39;#pragma omp atomic&#39; directive.
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3220
llvm::MemoryBuffer * getBuffer(DiagnosticsEngine &Diag, const SourceManager &SM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) const
Returns the memory buffer for the associated content.
Describes a zlib-compressed blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:672
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
This represents one expression.
Definition: Expr.h:106
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Definition: ASTReader.cpp:8498
A ObjCCategoryImplDecl record.
Definition: ASTBitCodes.h:1331
Defines the clang::LangOptions interface.
unsigned getCounterValue() const
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1354
TemplateDecl * getTemplateDecl() const
The template declaration to which this qualified name refers.
Definition: TemplateName.h:401
Record code for the array of VTable uses.
Definition: ASTBitCodes.h:506
ObjCMethodList * getNext() const
static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, bool IsModule)
Whether the given identifier is "interesting".
Definition: ASTReader.cpp:904
QualType getucontext_tType() const
Retrieve the C ucontext_t type.
Definition: ASTContext.h:1778
The directory that the PCH was originally created in.
Definition: ASTBitCodes.h:316
SourceLocation getMapLoc() const LLVM_READONLY
Fetches location of clause mapping kind.
unsigned getAsOpaqueValue() const
Definition: Type.h:254
int Id
Definition: ASTDiff.cpp:191
A ObjCPropertyImplDecl record.
Definition: ASTBitCodes.h:1343
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
This represents &#39;simdlen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:501
Expr * getNumTasks() const
Return safe iteration space distance.
SourceLocation getScheduleKindLoc()
Get kind location.
unsigned getIndex() const
Definition: Type.h:4566
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
NamespaceDecl * getAnonymousNamespace() const
Definition: Decl.h:122
unsigned LocalNumIdentifiers
The number of identifiers in this AST file.
Definition: Module.h:266
void AddCXXDefinitionData(const CXXRecordDecl *D)
Definition: ASTWriter.cpp:6011
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:621
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:247
Implements an efficient mapping from strings to IdentifierInfo nodes.
Defines implementation details of the clang::SourceManager class.
bool getHasRegParm() const
Definition: Type.h:3516
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2305
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
Inits[]
Definition: OpenMPClause.h:151
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:255
Record code for the table of offsets to entries in the preprocessing record.
Definition: ASTBitCodes.h:503
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2706
LazyDeclPtr StdNamespace
The C++ "std" namespace, where the standard library resides.
Definition: Sema.h:831
A CXXConstructorDecl record.
Definition: ASTBitCodes.h:1440
Defines version macros and version-related utility functions for Clang.
const FileEntry * ContentsEntry
References the file which the contents were actually loaded from.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:547
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Defines the clang::Preprocessor interface.
ArgKind
The kind of template argument we&#39;re storing.
Definition: TemplateBase.h:54
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:968
The block containing the detailed preprocessing record.
Definition: ASTBitCodes.h:264
llvm::MapVector< IdentifierInfo *, WeakInfo > WeakUndeclaredIdentifiers
WeakUndeclaredIdentifiers - Identifiers contained in #pragma weak before declared.
Definition: Sema.h:804
Record code for #pragma diagnostic mappings.
Definition: ASTBitCodes.h:370
bool isFileContext() const
Definition: DeclBase.h:1818
serialization::TypeID GetOrCreateTypeID(QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:5475
DeclContext * getDeclContext()
Definition: DeclBase.h:427
A structure for storing the information associated with a substituted template template parameter...
Definition: TemplateName.h:326
QualType getBaseType() const
Definition: Type.h:4315
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:5238
unsigned LocalNumMacros
The number of macros in this AST file.
Definition: Module.h:302
SourceLocation getCaretLoc() const
Definition: TypeLoc.h:1218
A CXXStdInitializerListExpr record.
Definition: ASTBitCodes.h:1859
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2176
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1500
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition: Module.cpp:246
A VarTemplateDecl record.
Definition: ASTBitCodes.h:1470
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
Record code for the original file that was used to generate the AST file, including both its file ID ...
Definition: ASTBitCodes.h:313
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
An ArraySubscriptExpr record.
Definition: ASTBitCodes.h:1665
Represents a C++ template name within the type system.
Definition: TemplateName.h:179
llvm::Optional< PreambleSkipInfo > getPreambleSkipInfo() const
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:336
Represents the type decltype(expr) (C++11).
Definition: Type.h:4246
helper_expr_const_range rhs_exprs() const
Information about a module that has been loaded by the ASTReader.
Definition: Module.h:108
QualType getFILEType() const
Retrieve the C FILE type.
Definition: ASTContext.h:1742
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:482
A namespace alias, stored as a NamespaceAliasDecl*.
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4499
This represents &#39;ordered&#39; clause in the &#39;#pragma omp ...&#39; directive.
HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized. ...
Definition: HeaderSearch.h:269
Record code for the diagnostic options table.
Definition: ASTBitCodes.h:367
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn&#39;t...
A CXXDestructorDecl record.
Definition: ASTBitCodes.h:1446
unsigned getLocalOrImportedSubmoduleID(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:2764
A FunctionProtoType record.
Definition: ASTBitCodes.h:1078
A NonTypeTemplateParmDecl record that stores an expanded non-type template parameter pack...
Definition: ASTBitCodes.h:1507
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
SourceLocation getColonLoc() const
Get colon location.
Describes a source location entry (SLocEntry) for a file.
Definition: ASTBitCodes.h:658
SmallVector< VTableUse, 16 > VTableUses
The list of vtables that are required but have not yet been materialized.
Definition: Sema.h:5848
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1346
Wrapper for source info for enum types.
Definition: TypeLoc.h:724
A unary type transform, which is a type constructed from another.
Definition: Type.h:4289
A block containing a module file extension.
Definition: ASTBitCodes.h:291
SourceLocation getProtocolLAngleLoc() const
Definition: TypeLoc.h:766
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:207
std::string FileName
The file name of the module file.
Definition: Module.h:123
A NamespaceAliasDecl record.
Definition: ASTBitCodes.h:1401
Record code for an update to a decl context&#39;s lookup table.
Definition: ASTBitCodes.h:533
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition: TypeLoc.h:746
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:627
void AddDeclRef(const Decl *D)
Emit a reference to a declaration.
Definition: ASTWriter.h:905
QualType getRecordType(const RecordDecl *Decl) const
const unsigned VERSION_MINOR
AST file minor version number supported by this version of Clang.
Definition: ASTBitCodes.h:55
void AddQualifierInfo(const QualifierInfo &Info)
Definition: ASTWriter.cpp:5700
A DesignatedInitUpdateExpr record.
Definition: ASTBitCodes.h:1701
void AddStmt(Stmt *S)
Add the given statement or expression to the queue of statements to emit.
Definition: ASTWriter.h:838
SourceLocation getEnd() const
void AddSelectorRef(Selector S)
Emit a Selector (which is a smart pointer reference).
Definition: ASTWriter.cpp:5387
Represents a GCC generic vector type.
Definition: Type.h:3168
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2849
struct CXXOpName CXXOperatorName
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2720
UTTKind getUTTKind() const
Definition: Type.h:4317
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the &#39;class&#39; keyword (vs...
Definition: DeclCXX.h:249
An ImplicitParamDecl record.
Definition: ASTBitCodes.h:1355
unsigned getNumArgs() const
Expr * getDevice()
Return device number.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Definition: Module.h:379
This represents &#39;collapse&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:555
This represents clause &#39;firstprivate&#39; in the &#39;#pragma omp ...&#39; directives.
bool isObjectLike() const
Definition: MacroInfo.h:201
SourceLocation getCommaLoc()
Get location of &#39;,&#39;.
SourceLocation getKWLoc() const
Definition: TypeLoc.h:1872
unsigned SLocEntryBaseOffset
The base offset in the source manager&#39;s view of this module.
Definition: Module.h:251
An EnumConstantDecl record.
Definition: ASTBitCodes.h:1307
Record code for the table of offsets of each identifier ID.
Definition: ASTBitCodes.h:423
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:703
Record code for undefined but used functions and variables that need a definition in this TU...
Definition: ASTBitCodes.h:610
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:170
A DependentNameType record.
Definition: ASTBitCodes.h:1126
do v
Definition: arm_acle.h:78
Abstract base class that writes a module file extension block into a module file. ...
const SourceManager & SM
Definition: Format.cpp:1490
SourceLocation getLocation() const
Definition: Weak.h:35
An ImportDecl recording a module import.
Definition: ASTBitCodes.h:1518
A ObjCCategoryDecl record.
Definition: ASTBitCodes.h:1328
const ExpansionInfo & getExpansion() const
unsigned getOffset() const
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:1104
An ObjCForCollectionStmt record.
Definition: ASTBitCodes.h:1788
Expr * getUnderlyingExpr() const
Definition: Type.h:4185
void Visit(QualType T)
Definition: ASTWriter.cpp:156
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
Record code for the identifier table.
Definition: ASTBitCodes.h:442
bool isRecordingPreamble() const
bool decls_empty() const
Definition: DeclBase.cpp:1377
ArrayRef< Expr * > getLoopNumIterations() const
Get number of iterations for all the loops.
A ObjCCompatibleAliasDecl record.
Definition: ASTBitCodes.h:1337
This represents &#39;seq_cst&#39; clause in the &#39;#pragma omp atomic&#39; directive.
helper_expr_const_range assignment_ops() const
This represents &#39;untied&#39; clause in the &#39;#pragma omp ...&#39; directive.
AttrVec & getAttrs()
Definition: DeclBase.h:479
bool hasAttrs() const
Definition: DeclBase.h:473
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:426
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:291
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:619
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:37
A MS-style AsmStmt record.
Definition: ASTBitCodes.h:1623
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4013
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:96
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record)
Emit a source location.
Definition: ASTWriter.cpp:5320
void push_back(uint64_t N)
Minimal vector-like interface.
Definition: ASTWriter.h:795
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:89
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:138
The Objective-C &#39;Class&#39; type.
Definition: ASTBitCodes.h:1234
This represents &#39;unified_address&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
Definition: OpenMPClause.h:745
SpecifierKind
The kind of specifier that completes this nested name specifier.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:434
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:172
SourceLocation getExpansionLocEnd() const
Defines the clang::OpenCLOptions class.
SourceLocation getLParenLoc()
Get location of &#39;(&#39;.
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:389
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:212
Wrapper for source info for arrays.
Definition: TypeLoc.h:1460
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
SourceLocation getColonLoc() const
Returns the location of &#39;:&#39;.
Record code for the set of source location entries that need to be preloaded by the AST reader...
Definition: ASTBitCodes.h:493
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:662
This represents &#39;num_teams&#39; clause in the &#39;#pragma omp ...&#39; directive.
Information about a FileID, basically just the logical file that it represents and include stack info...
The list of delegating constructor declarations.
Definition: ASTBitCodes.h:559
Record code for types associated with OpenCL extensions.
Definition: ASTBitCodes.h:637
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1918
DeclContext::lookup_result getLookupResult()
getLookupResult - Return an array of all the decls that this list represents.
unsigned isModuleHeader
Whether this header is part of a module.
Definition: HeaderSearch.h:69
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Definition: MacroInfo.h:291
An UnresolvedUsingValueDecl record.
Definition: ASTBitCodes.h:1419
serialization::TypeID BaseTypeIndex
Base type ID for types local to this module as represented in the global type ID space.
Definition: Module.h:456
Kind
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:43
SourceLocation getLParenLoc()
Get location of &#39;(&#39;.
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:4078
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5090
const ContentCache * getContentCache() const
helper_expr_const_range taskgroup_descriptors() const
serialization::IdentID BaseIdentifierID
Base identifier ID for identifiers local to this module.
Definition: Module.h:276
const Attr * getAttr() const
The type attribute.
Definition: TypeLoc.h:871
LazyDeclPtr StdAlignValT
The C++ "std::align_val_t" enum class, which is defined by the C++ standard library.
Definition: Sema.h:839
unsigned getTotalComponentListNum() const
Return the number of lists derived from the clause expressions.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
Encodes a location in the source.
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.h:5751
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1274
Sugar for parentheses used when specifying types.
Definition: Type.h:2507
QualType getAdjustedType() const
Definition: Type.h:2602
QualType getReturnType() const
Definition: Type.h:3613
This represents &#39;hint&#39; clause in the &#39;#pragma omp ...&#39; directive.
SourceLocation CurrentPragmaLocation
Definition: Sema.h:444
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4396
void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg)
Emits a template argument location info.
Definition: ASTWriter.cpp:5414
StringRef getName() const
Definition: FileManager.h:86
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Definition: FileManager.h:223
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1392
Specifies a library or framework to link against.
Definition: ASTBitCodes.h:756
Record code for file ID of the file or buffer that was used to generate the AST file.
Definition: ASTBitCodes.h:320
Represents a C++ temporary.
Definition: ExprCXX.h:1185
Represents typeof(type), a GCC extension.
Definition: Type.h:4219
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5738
Specifies a header that falls into this (sub)module.
Definition: ASTBitCodes.h:732
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed, for use in "private" modules.
Definition: Module.h:113
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:122
private_copies_range private_copies()
Record code for special CUDA declarations.
Definition: ASTBitCodes.h:547
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
Options for controlling the compiler diagnostics engine.
A list of "interesting" identifiers.
Definition: ASTBitCodes.h:606
The block of configuration options, used to check that a module is being used in a configuration comp...
Definition: ASTBitCodes.h:288
void AddDeclarationName(DeclarationName Name)
Emit a declaration name.
Definition: ASTWriter.cpp:5603
unsigned IsSystemFile
True if this content cache was initially created for a source file considered as a system one...
DeclarationName getName() const
getName - Returns the embedded declaration name.
void AddOffset(uint64_t BitOffset)
Add a bit offset into the record.
Definition: ASTWriter.h:826
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3064
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3272
This represents &#39;schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:948
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
Kind getKind() const
Definition: ObjCRuntime.h:77
CallingConv getCC() const
Definition: Type.h:3525
QualType getElementType() const
Definition: Type.h:3203
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
virtual void writeExtensionContents(Sema &SemaRef, llvm::BitstreamWriter &Stream)=0
Write the contents of the extension block into the given bitstream.
This is so that older clang versions, before the introduction of the control block, can read and reject the newer PCH format.
Definition: ASTBitCodes.h:428
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:823
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
This represents clause &#39;shared&#39; in the &#39;#pragma omp ...&#39; directives.
Represents a vector type where either the type or size is dependent.
Definition: Type.h:3245
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3866
SourceLocation getProcBindKindKwLoc() const
Returns location of clause kind.
Definition: OpenMPClause.h:726
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
Metadata describing this particular extension.
Definition: ASTBitCodes.h:376
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a local SLocEntry. This is exposed for indexing.
static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, const Preprocessor &PP)
Definition: ASTWriter.cpp:2420
An ObjCTypeParamType record.
Definition: ASTBitCodes.h:1165
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:168
A CXXFunctionalCastExpr record.
Definition: ASTBitCodes.h:1853
std::vector< std::string > Remarks
The list of -R...
Record code for the offsets of each decl.
Definition: ASTBitCodes.h:415
Metadata for submodules as a whole.
Definition: ASTBitCodes.h:721
Expr * getPriority()
Return Priority number.
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
bool isModuleMap(CharacteristicKind CK)
Determine whether a file characteristic is for a module map.
Definition: SourceManager.h:88
void AddTemplateArgument(const TemplateArgument &Arg)
Emit a template argument.
Definition: ASTWriter.cpp:5860
An ObjCEncodeExpr record.
Definition: ASTBitCodes.h:1758
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
Record code for late parsed template functions.
Definition: ASTBitCodes.h:613
A dependentSizedVectorType record.
Definition: ASTBitCodes.h:1177
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1097
bool isPackExpansion() const
Determine whether this base specifier is a pack expansion.
Definition: DeclCXX.h:252
Defines the clang::TargetOptions class.
A TemplateTypeParmDecl record.
Definition: ASTBitCodes.h:1482
bool isParameterPack() const
Definition: Type.h:4567
bool isPoisoned() const
Return true if this token has been poisoned.
frontend::IncludeDirGroup Group
Expr * getLoopCounter(unsigned NumLoop)
Get loops counter for the specified loop.
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings startin...
Definition: TargetOptions.h:56
unsigned LocalNumDecls
The number of declarations in this AST file.
Definition: Module.h:409
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2280
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:360
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:51
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4677
bool SawDateOrTime() const
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
QualType getEquivalentType() const
Definition: Type.h:4451
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:3963
The internal &#39;instancetype&#39; typedef.
Definition: ASTBitCodes.h:1246
SourceLocation getStarLoc() const
Definition: TypeLoc.h:1236
void AddNestedNameSpecifier(NestedNameSpecifier *NNS)
Emit a nested name specifier.
Definition: ASTWriter.cpp:5707
serialization::TypeID getTypeID(QualType T) const
Determine the type ID of an already-emitted type.
Definition: ASTWriter.cpp:5498
QualType getInnerType() const
Definition: Type.h:2520
IdentifierInfo * getIdentifier() const
Definition: ASTBitCodes.h:2083
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:2036
The AST block, which acts as a container around the full AST block.
Definition: ASTBitCodes.h:249
SourceLocation getNameModifierLoc() const
Return the location of directive name modifier.
Definition: OpenMPClause.h:314
A DeducedTemplateSpecializationType record.
Definition: ASTBitCodes.h:1168
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:695
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:86
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5166
void AddAttributes(ArrayRef< const Attr *> Attrs)
Emit a list of attributes.
Definition: ASTWriter.cpp:4480
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:52
const unsigned int DECL_UPDATES
Record of updates for a declaration that was modified after being deserialized.
Definition: ASTBitCodes.h:1281
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:4586
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4535
void updateOutOfDateSelector(Selector Sel)
void AddSourceLocation(SourceLocation Loc)
Emit a source location.
Definition: ASTWriter.h:847
Expr * getNumForLoops() const
Return the number of associated for-loops.
Definition: OpenMPClause.h:590
AutoTypeKeyword getKeyword() const
Definition: Type.h:4764
TypeClass getTypeClass() const
Definition: Type.h:1811
static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, unsigned SLocBufferBlobCompressedAbbrv, unsigned SLocBufferBlobAbbrv)
Definition: ASTWriter.cpp:2190
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:5511
An InjectedClassNameType record.
Definition: ASTBitCodes.h:1114
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:301
Record code for the extra statistics we gather while generating an AST file.
Definition: ASTBitCodes.h:465
SourceLocation getRAngleLoc() const
Definition: TypeLoc.h:1572
FunctionDecl * getcudaConfigureCallDecl()
Definition: ASTContext.h:1279
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:174
bool isC99Varargs() const
Definition: MacroInfo.h:206
A NamespaceDecl record.
Definition: ASTBitCodes.h:1398
SourceLocation getExpansionLocStart() const
const_all_lists_sizes_range all_lists_sizes() const
SourceRange getBracketsRange() const
Definition: Type.h:3054
An array of decls optimized for the common case of only containing one entry.
void AddAPFloat(const llvm::APFloat &Value)
Emit a floating-point value.
Definition: ASTWriter.cpp:5341
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:169
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:4504
const VersionTuple & getVersion() const
Definition: ObjCRuntime.h:78
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5380
unsigned LocalNumSubmodules
The number of submodules in this module.
Definition: Module.h:364
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:296
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:247
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:423
helper_expr_const_range lhs_exprs() const
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
Record code for the signature that identifiers this AST file.
Definition: ASTBitCodes.h:364
Record code for referenced selector pool.
Definition: ASTBitCodes.h:511
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3922
std::vector< std::string > MacroIncludes
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2622
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:391
void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Definition: ASTWriter.cpp:5693
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4978
Record code for the set of non-builtin, special types.
Definition: ASTBitCodes.h:461
QualType getPointeeType() const
Definition: Type.h:3100
A ObjCProtocolDecl record.
Definition: ASTBitCodes.h:1319
Represents a pack expansion of types.
Definition: Type.h:5355
OpenMPDirectiveKind getCaptureRegion() const
Get capture region for the stmt in the clause.
Definition: OpenMPClause.h:127
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:354
Kind getKind() const
Definition: MacroInfo.h:321
Defines various enumerations that describe declaration and type specifiers.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
ArrayRef< Decl * > getModuleInitializers(Module *M)
Get the initializations to perform when importing a module, if any.
StringRef getName() const
Return the actual identifier string.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:627
static void addExceptionSpec(const FunctionProtoType *T, ASTRecordWriter &Record)
Definition: ASTWriter.cpp:291
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C)
Definition: ASTWriter.cpp:6482
SourceRange getRange() const
Definition: Attr.h:95
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
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:4550
unsigned LocalNumSelectors
The number of selectors new to this file.
Definition: Module.h:377
unsigned getObjCOrBuiltinID() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
SourceLocation getTypeofLoc() const
Definition: TypeLoc.h:1776
Represents a template argument.
Definition: TemplateBase.h:51
Record code for the list of other AST files imported by this AST file.
Definition: ASTBitCodes.h:308
A CXXConversionDecl record.
Definition: ASTBitCodes.h:1449
Describes a macro definition within the preprocessing record.
Definition: ASTBitCodes.h:711
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C)
Definition: ASTWriter.cpp:6487
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2585
TypeSourceInfo * getClassTInfo() const
Definition: TypeLoc.h:1248
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:367
The internal &#39;__NSConstantString&#39; typedef.
Definition: ASTBitCodes.h:1264
Record code for the module name.
Definition: ASTBitCodes.h:327
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:154
void writeClause(OMPClause *C)
Definition: ASTWriter.cpp:6475
Dataflow Directional Tag Classes.
SourceLocation getColonLoc() const
Get colon location.
This represents &#39;device&#39; clause in the &#39;#pragma omp ...&#39; directive.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getRBracketLoc() const
Definition: Type.h:2999
Describes an inclusion directive within the preprocessing record.
Definition: ASTBitCodes.h:715
An InitListExpr record.
Definition: ASTBitCodes.h:1695
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:356
The internal &#39;__builtin_ms_va_list&#39; typedef.
Definition: ASTBitCodes.h:1255
OpenMPDefaultmapClauseKind getDefaultmapKind() const
Get kind of the clause.
ExtInfo getExtInfo() const
Definition: Type.h:3624
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:499
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Definition: MacroInfo.h:234
not evaluated yet, for special member function
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5290
Record code for a file sorted array of DeclIDs in a module.
Definition: ASTBitCodes.h:580
A CXXBoolLiteralExpr record.
Definition: ASTBitCodes.h:1862
Record code for the array of Objective-C categories (including extensions).
Definition: ASTBitCodes.h:594
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:439
Specifies a configuration macro for this module.
Definition: ASTBitCodes.h:759
virtual ModuleFileExtensionMetadata getExtensionMetadata() const =0
Retrieves the metadata for this module file extension.
helper_expr_const_range privates() const
bool isInitKnownICE() const
Determines whether it is already known whether the initializer is an integral constant expression or ...
Definition: Decl.cpp:2317
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:131
An ExtVectorElementExpr record.
Definition: ASTBitCodes.h:1692
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
Record code for the array of unused file scoped decls.
Definition: ASTBitCodes.h:499
void AddCXXBaseSpecifiers(ArrayRef< CXXBaseSpecifier > Bases)
Emit a set of C++ base specifiers.
Definition: ASTWriter.cpp:5966
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:561
A FunctionNoProtoType record.
Definition: ASTBitCodes.h:1075
off_t getSize() const
Definition: FileManager.h:89
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:243
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:355
File is an explicitly-loaded module.
Definition: Module.h:48
ArrayRef< KnownHeader > findAllModulesForHeader(const FileEntry *File) const
Retrieve all the modules that contain the given header file.
Definition: ModuleMap.cpp:660
A ClassTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1467
const_all_components_range all_components() const
#define RECORD(X)
TemplateArgumentLoc getArgLoc(unsigned i) const
Definition: TypeLoc.h:2131
ModuleFileExtension * getExtension() const
Retrieve the module file extension with which this writer is associated.
const Expr * getInit() const
Definition: Decl.h:1220
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1549
FileID getMainFileID() const
Returns the FileID of the main source file.
QualType getUnderlyingType() const
Definition: Type.h:4257
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1076
void AddCXXCtorInitializers(ArrayRef< CXXCtorInitializer *> CtorInits)
Emit a CXXCtorInitializer array.
Definition: ASTWriter.cpp:6006
The name of a declaration.
A ClassScopeFunctionSpecializationDecl record a class scope function specialization.
Definition: ASTBitCodes.h:1515
VectorKind getVectorKind() const
Definition: Type.h:3213
Record code for the Objective-C method pool,.
Definition: ASTBitCodes.h:477
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension...
static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream)
Create an abbreviation for the SLocEntry that refers to a buffer.
Definition: ASTWriter.cpp:1878
Kind getKind() const
Definition: DeclBase.h:421
Specifies a header that is private to this submodule.
Definition: ASTBitCodes.h:765
SourceLocation getLParenLoc()
Get location of &#39;(&#39;.
A LinkageSpecDecl record.
Definition: ASTBitCodes.h:1425
Describes a macro expansion within the preprocessing record.
Definition: ASTBitCodes.h:708
A CXXDynamicCastExpr record.
Definition: ASTBitCodes.h:1844
This represents &#39;unified_shared_memory&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:776
This represents clause &#39;linear&#39; in the &#39;#pragma omp ...&#39; directives.
SourceLocation LAngleLoc
The source location of the left angle bracket (&#39;<&#39;).
Definition: TemplateBase.h:615
void * getFETokenInfo() const
Get and set FETokenInfo.
SourceLocation getLocation() const
Definition: MacroInfo.h:323
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2756
IdentifierResolver IdResolver
Definition: Sema.h:823
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
An RValueReferenceType record.
Definition: ASTBitCodes.h:1054
OpenMPDefaultmapClauseModifier getDefaultmapModifier() const
Get the modifier of the clause.
SourceLocation getBeginLoc() const
Returns the starting location of the clause.
Definition: OpenMPClause.h:67
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4618
bool hasModeAttr() const
Definition: TypeLoc.h:639
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:767
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
unsigned getLength() const
Definition: Token.h:127
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:69
An AtomicType record.
Definition: ASTBitCodes.h:1153
An ObjCAtFinallyStmt record.
Definition: ASTBitCodes.h:1794
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:1947
QualType getUnderlyingType() const
Definition: Type.h:4314
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:618
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1939
QualType getModifiedType() const
Definition: Type.h:4450
unsigned getNumParams() const
Definition: TypeLoc.h:1402
SourceLocation getRBracketLoc() const
Definition: TypeLoc.h:1473
SourceLocation getEndLoc() const
Returns the ending location of the clause.
Definition: OpenMPClause.h:70
Represents a pointer to an Objective C object.
Definition: Type.h:5794
helper_expr_const_range privates() const
Number of unmatched #pragma clang cuda_force_host_device begin directives we&#39;ve seen.
Definition: ASTBitCodes.h:634
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map...
Definition: Module.h:263
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
Pointer to a block type.
Definition: Type.h:2639
Capturing variable-length array type.
Definition: Lambda.h:39
A PragmaCommentDecl record.
Definition: ASTBitCodes.h:1536
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
struct CXXLitOpName CXXLiteralOperatorName
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
Complex values, per C99 6.2.5p11.
Definition: Type.h:2477
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2857
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4912
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:369
TypeSourceInfo * getTypeArgTInfo(unsigned i) const
Definition: TypeLoc.h:953
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:650
Record code for the table of offsets into the Objective-C method pool.
Definition: ASTBitCodes.h:474
OpenMPDirectiveKind getNameModifier() const
Return directive name modifier associated with the clause.
Definition: OpenMPClause.h:311
QualType getCanonicalTypeInternal() const
Definition: Type.h:2355
ValueType CurrentValue
Definition: Sema.h:443
Defines the clang::FileSystemOptions interface.
bool getUsed()
Definition: Weak.h:37
A DependentSizedArrayType record.
Definition: ASTBitCodes.h:1132
Record code for the remapping information used to relate loaded modules to the various offsets and ID...
Definition: ASTBitCodes.h:569
An ObjCAtSynchronizedStmt record.
Definition: ASTBitCodes.h:1800
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1596
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:135
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:2069
T * getAttr() const
Definition: DeclBase.h:527
helper_expr_const_range destination_exprs() const
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2216
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2232
An UnresolvedSet-like class which uses the ASTContext&#39;s allocator.
Record code for declarations that Sema keeps references of.
Definition: ASTBitCodes.h:520
const llvm::APInt & getSize() const
Definition: Type.h:2890
Kind getAttrKind() const
Definition: Type.h:4446
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:151
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:362
bool WriteCommentListToPCH
Whether to write comment locations into the PCH when building it.
Offsets into the input-files block where input files reside.
Definition: ASTBitCodes.h:324
A CXXMemberCallExpr record.
Definition: ASTBitCodes.h:1829
ExtVectorType - Extended vector type.
Definition: Type.h:3287
SourceLocation getColonLoc() const
Gets location of &#39;:&#39; symbol in clause.
SourceLocation getProtocolLoc(unsigned i) const
Definition: TypeLoc.h:790
Expr * getSizeExpr() const
Definition: TypeLoc.h:1485
void AddAPSInt(const llvm::APSInt &Value)
Emit a signed integral value.
Definition: ASTWriter.cpp:5336
unsigned getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.h:699
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1730
The block containing the submodule structure.
Definition: ASTBitCodes.h:267
Wrapper for source info for record types.
Definition: TypeLoc.h:716
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1915
SourceLocation getLBracketLoc() const
Definition: TypeLoc.h:1465
The template argument is a type.
Definition: TemplateBase.h:60
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:239
Wraps an ObjCPointerType with source location information.
Definition: TypeLoc.h:1270
QualType getUnderlyingType() const
Definition: Type.h:4234
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:124
SourceLocation getDistScheduleKindLoc()
Get kind location.
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:5391
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
Definition: Module.h:331
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:3170
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
Capturing the *this object by reference.
Definition: Lambda.h:35
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:4528
Represents a base class of a C++ class.
Definition: DeclCXX.h:192
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:810
This represents &#39;write&#39; clause in the &#39;#pragma omp atomic&#39; directive.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1093
unsigned BufferOverridden
Indicates whether the buffer itself was provided to override the actual file contents.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceManager & getSourceManager()
Definition: ASTContext.h:662
Keeps track of options that affect how file operations are performed.
The type-property cache.
Definition: Type.cpp:3448
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
Definition: MacroInfo.h:130
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2253
EnumDecl * getStdAlignValT() const
A template argument list.
Definition: DeclTemplate.h:210
SourceLocation getModuleImportLoc(Module *M) const
VectorType::VectorKind getVectorKind() const
Definition: Type.h:3261
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
TypedefNameDecl * getDecl() const
Definition: Type.h:4167
SourceLocation getTypeArgsLAngleLoc() const
Definition: TypeLoc.h:933
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:663
known_categories_iterator known_categories_end() const
Retrieve an iterator to the end of the known-categories list.
Definition: DeclObjC.h:1699
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
unsigned getDepth() const
Definition: Type.h:4565
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4425
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
Definition: Type.h:3890
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
Represents a type parameter type in Objective C.
Definition: Type.h:5464
OpenMPScheduleClauseModifier getSecondScheduleModifier() const
Get the second modifier of the clause.
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1009
Defines the clang::SourceLocation class and associated facilities.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
A GCC-style AsmStmt record.
Definition: ASTBitCodes.h:1620
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:4560
This represents &#39;nowait&#39; clause in the &#39;#pragma omp ...&#39; directive.
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:240
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:5264
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
Definition: Preprocessor.h:900
OpenMPScheduleClauseModifier getFirstScheduleModifier() const
Get the first modifier of the clause.
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:812
An TemplateTypeParmType record.
Definition: ASTBitCodes.h:1120
This represents &#39;num_tasks&#39; clause in the &#39;#pragma omp ...&#39; directive.
Decl * D
The template function declaration to be late parsed.
Definition: Sema.h:10910
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
Represents a C array with an unspecified size.
Definition: Type.h:2926
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:503
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:263
OpenMPScheduleClauseKind getScheduleKind() const
Get kind of the clause.
Record code for the filesystem options table.
Definition: ASTBitCodes.h:352
An object for streaming information to a record.
Definition: ASTWriter.h:747
static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, ASTWriter::RecordData &Record)
Definition: ASTWriter.cpp:4632
An ObjCAtCatchStmt record.
Definition: ASTBitCodes.h:1791
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:1329
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:410
A ObjCImplementationDecl record.
Definition: ASTBitCodes.h:1334
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5169
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:350
SourceLocation getFirstScheduleModifierLoc() const
Get the first modifier location.
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:96
Capturing by reference.
Definition: Lambda.h:38
ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false)
Write a precompiled header for the given semantic analysis.
Definition: ASTWriter.cpp:4595
unsigned getNumProtocols() const
Definition: TypeLoc.h:979
helper_expr_const_range reduction_ops() const
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:216
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4624
Location information for a TemplateArgument.
Definition: TemplateBase.h:393
A ObjCAtDefsFieldDecl record.
Definition: ASTBitCodes.h:1325
Declaration of a class template.
Record code for the offsets of each type.
Definition: ASTBitCodes.h:403
A DependentAddressSpaceType record.
Definition: ASTBitCodes.h:1174
Expr * getThreadLimit()
Return ThreadLimit number.
The block containing the definitions of all of the types and decls used within the AST file...
Definition: ASTBitCodes.h:261
The internal &#39;__va_list_tag&#39; struct, if any.
Definition: ASTBitCodes.h:1252
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2391
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:104
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition: DeclCXX.cpp:1421
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
bool hasRecordedPreamble() const
serialization::DeclID getDeclID(const Decl *D)
Determine the declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:5544
const unsigned int LOCAL_REDECLARATIONS
Record code for a list of local redeclarations of a declaration.
Definition: ASTBitCodes.h:1285
void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base)
Emit a C++ base specifier.
Definition: ASTWriter.cpp:5942
A TypeAliasDecl record.
Definition: ASTBitCodes.h:1298
void AddASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *ASTTemplArgList)
Emits an AST template argument list info.
Definition: ASTWriter.cpp:5921
SourceLocation getLocation() const
Retrieve the source location of the capture.
void AddAPInt(const llvm::APInt &Value)
Emit an integral value.
Definition: ASTWriter.cpp:5330
LineTableInfo & getLineTable()
Retrieve the stored line table.
Specifies the name of the module that will eventually re-export the entities in this module...
Definition: ASTBitCodes.h:781
Defines the clang::TargetInfo interface.
MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)
Retrieve the macro definition that corresponds to the given MacroInfo.
SourceLocation getNameLoc() const
Definition: TypeLoc.h:517
ArrayRef< ModuleMacro * > getLeafModuleMacros(const IdentifierInfo *II) const
Get the list of leaf (non-overridden) module macros for a name.
a linked list of methods with the same selector name but different signatures.
Specifies a required feature.
Definition: ASTBitCodes.h:749
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
This represents &#39;dist_schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
SourceRange getAttrOperandParensRange() const
The location of the parentheses around the operand, if there is an operand.
Definition: TypeLoc.h:1687
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:344
bool isGNUVarargs() const
Definition: MacroInfo.h:207
QualType getjmp_bufType() const
Retrieve the C jmp_buf type.
Definition: ASTContext.h:1754
__DEVICE__ int max(int __a, int __b)
unsigned getNumTypeArgs() const
Definition: TypeLoc.h:949
NameKind getKind() const
unsigned getNumElements() const
Definition: Type.h:3204
Expr * getHint() const
Returns number of threads.
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
Record for offsets of DECL_UPDATES records for declarations that were modified after being deserializ...
Definition: ASTBitCodes.h:537
unsigned ModuleMapFileHomeIsCwd
Set the &#39;home directory&#39; of a module map file to the current working directory (or the home directory...
SourceLocation getAmpLoc() const
Definition: TypeLoc.h:1296
The top declaration context.
Definition: Decl.h:108
bool isReadOnly() const
Definition: Type.h:6035
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2079
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:257
void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs)
Emit a template argument list.
Definition: ASTWriter.cpp:5913
Represents an extended address space qualifier where the input address space value is dependent...
Definition: Type.h:3086
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4841
static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, bool Compressed)
Create an abbreviation for the SLocEntry that refers to a buffer&#39;s blob.
Definition: ASTWriter.cpp:1893
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1158
A FunctionTemplateDecl record.
Definition: ASTBitCodes.h:1479
Expr * getChunkSize()
Get chunk size.
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:5854
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
A TypeAliasTemplateDecl record.
Definition: ASTBitCodes.h:1491
Contains a late templated function.
Definition: Sema.h:10907
SourceLocation getAttrNameLoc() const
The location of the attribute name, i.e.
Definition: TypeLoc.h:1666
Record code for weak undeclared identifiers.
Definition: ASTBitCodes.h:523
The block containing information about the preprocessor.
Definition: ASTBitCodes.h:257
Expr * getNumThreads() const
Returns number of threads.
Definition: OpenMPClause.h:426
void AddTemplateName(TemplateName Name)
Emit a template name.
Definition: ASTWriter.cpp:5807
PragmaStack< unsigned > PackStack
Definition: Sema.h:461
TypeSpecifierType getWrittenTypeSpec() const
Definition: TypeLoc.cpp:309
void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg)
Emits a template argument location.
Definition: ASTWriter.cpp:5442
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:284
Wrapper for source info for builtin types.
Definition: TypeLoc.h:544
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
void VisitFunctionType(const FunctionType *T)
Definition: ASTWriter.cpp:270
A set of overloaded template declarations.
Definition: TemplateName.h:195
Wrapper for template type parameters.
Definition: TypeLoc.h:732
Record code for the headers search options table.
Definition: ASTBitCodes.h:355
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:324
unsigned getFlags() const
Return the internal represtation of the flags.
Definition: Token.h:252
known_categories_iterator known_categories_begin() const
Retrieve an iterator to the beginning of the known-categories list.
Definition: DeclObjC.h:1694
This represents a decl that may have a name.
Definition: Decl.h:249
bool isTranslationUnit() const
Definition: DeclBase.h:1823
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:478
AST file metadata, including the AST file version number and information about the compiler used to b...
Definition: ASTBitCodes.h:304
static void EmitRecordID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, ASTWriter::RecordDataImpl &Record)
Definition: ASTWriter.cpp:924
The block of input files, which were used as inputs to create this AST file.
Definition: ASTBitCodes.h:281
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:3984
unsigned IsExplicit
Whether this is an explicit submodule.
Definition: Module.h:222
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2971
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:96
unsigned LocalNumTypes
The number of types in this AST file.
Definition: Module.h:448
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2063
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:235
The internal &#39;__NSConstantString&#39; tag type.
Definition: ASTBitCodes.h:1267
SourceLocation getAttributeLoc() const
Definition: Type.h:3101
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1364
A function-like macro definition.
Definition: ASTBitCodes.h:691
QualType getElementType() const
Definition: Type.h:3259
attr::Kind getKind() const
Definition: Attr.h:87
The Objective-C &#39;Protocol&#39; type.
Definition: ASTBitCodes.h:1237
const Expr * getPostUpdateExpr() const
Get post-update expression for the clause.
Definition: OpenMPClause.h:151
SourceLocation getLParenLoc() const
Returns the location of &#39;(&#39;.
Definition: OpenMPClause.h:302
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
The global specifier &#39;::&#39;. There is no stored value.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:288
The control block, which contains all of the information that needs to be validated prior to committi...
Definition: ASTBitCodes.h:275
OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:925
Wrapper for source info for pointers.
Definition: TypeLoc.h:1202
SourceLocation getBegin() const
SmallVector< Slot, 2 > Stack
Definition: Sema.h:441
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:30
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1215
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
This class handles loading and caching of source files into memory.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2872
PredefinedDeclIDs
Predefined declaration IDs.
Definition: ASTBitCodes.h:1220
Declaration of a template function.
Definition: DeclTemplate.h:969
iterator - Iterate over the decls of a specified declaration name.
Record code for an update to the TU&#39;s lexically contained declarations.
Definition: ASTBitCodes.h:515
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Definition: MacroInfo.h:272
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3466
A GenericSelectionExpr record.
Definition: ASTBitCodes.h:1740
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:89
Attr - This represents one attribute.
Definition: Attr.h:44
SourceLocation getLocation() const
Definition: DeclBase.h:418
This represents clause &#39;use_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
SourceLocation getTypeArgsRAngleLoc() const
Definition: TypeLoc.h:941
QualType getPointeeType() const
Definition: Type.h:2776
A PackExpansionType record.
Definition: ASTBitCodes.h:1138
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:98
A single template declaration.
Definition: TemplateName.h:192
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:175
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Defines the LambdaCapture class.
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:244
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:630
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5291
A DependentTemplateSpecializationType record.
Definition: ASTBitCodes.h:1129
bool hasLineTable() const
Determine if the source manager has a line table.
StringRef getName() const
Definition: FileManager.h:52
ArrayRef< const IdentifierInfo * > params() const
Definition: MacroInfo.h:184
bool ParseAllComments
Treat ordinary comments as documentation comments.
Record code for the array of tentative definitions.
Definition: ASTBitCodes.h:468
iterator local_begin()
Begin iterator for local, non-loaded, preprocessed entities.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5810