Coverage Report

Created: 2018-07-21 08:31

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Serialization/ASTReader.h
Line
Count
Source (jump to first uncovered line)
1
//===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===//
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 ASTReader class, which reads AST files.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
15
#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
16
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/DeclarationName.h"
20
#include "clang/AST/NestedNameSpecifier.h"
21
#include "clang/AST/TemplateBase.h"
22
#include "clang/AST/TemplateName.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/Diagnostic.h"
25
#include "clang/Basic/DiagnosticOptions.h"
26
#include "clang/Basic/IdentifierTable.h"
27
#include "clang/Basic/Module.h"
28
#include "clang/Basic/OpenCLOptions.h"
29
#include "clang/Basic/SourceLocation.h"
30
#include "clang/Basic/Version.h"
31
#include "clang/Lex/ExternalPreprocessorSource.h"
32
#include "clang/Lex/HeaderSearch.h"
33
#include "clang/Lex/PreprocessingRecord.h"
34
#include "clang/Lex/Token.h"
35
#include "clang/Sema/ExternalSemaSource.h"
36
#include "clang/Sema/IdentifierResolver.h"
37
#include "clang/Serialization/ASTBitCodes.h"
38
#include "clang/Serialization/ContinuousRangeMap.h"
39
#include "clang/Serialization/Module.h"
40
#include "clang/Serialization/ModuleFileExtension.h"
41
#include "clang/Serialization/ModuleManager.h"
42
#include "llvm/ADT/APFloat.h"
43
#include "llvm/ADT/APInt.h"
44
#include "llvm/ADT/APSInt.h"
45
#include "llvm/ADT/ArrayRef.h"
46
#include "llvm/ADT/DenseMap.h"
47
#include "llvm/ADT/DenseSet.h"
48
#include "llvm/ADT/IntrusiveRefCntPtr.h"
49
#include "llvm/ADT/MapVector.h"
50
#include "llvm/ADT/Optional.h"
51
#include "llvm/ADT/STLExtras.h"
52
#include "llvm/ADT/SetVector.h"
53
#include "llvm/ADT/SmallPtrSet.h"
54
#include "llvm/ADT/SmallVector.h"
55
#include "llvm/ADT/StringMap.h"
56
#include "llvm/ADT/StringRef.h"
57
#include "llvm/ADT/iterator.h"
58
#include "llvm/ADT/iterator_range.h"
59
#include "llvm/Bitcode/BitstreamReader.h"
60
#include "llvm/Support/Casting.h"
61
#include "llvm/Support/Endian.h"
62
#include "llvm/Support/MemoryBuffer.h"
63
#include "llvm/Support/Timer.h"
64
#include "llvm/Support/VersionTuple.h"
65
#include <cassert>
66
#include <cstddef>
67
#include <cstdint>
68
#include <ctime>
69
#include <deque>
70
#include <memory>
71
#include <set>
72
#include <string>
73
#include <utility>
74
#include <vector>
75
76
namespace clang {
77
78
class ASTConsumer;
79
class ASTContext;
80
class ASTDeserializationListener;
81
class ASTReader;
82
class ASTRecordReader;
83
class CXXTemporary;
84
class Decl;
85
class DeclaratorDecl;
86
class DeclContext;
87
class EnumDecl;
88
class Expr;
89
class FieldDecl;
90
class FileEntry;
91
class FileManager;
92
class FileSystemOptions;
93
class FunctionDecl;
94
class GlobalModuleIndex;
95
struct HeaderFileInfo;
96
class HeaderSearchOptions;
97
class LangOptions;
98
class LazyASTUnresolvedSet;
99
class MacroInfo;
100
class MemoryBufferCache;
101
class NamedDecl;
102
class NamespaceDecl;
103
class ObjCCategoryDecl;
104
class ObjCInterfaceDecl;
105
class PCHContainerReader;
106
class Preprocessor;
107
class PreprocessorOptions;
108
struct QualifierInfo;
109
class Sema;
110
class SourceManager;
111
class Stmt;
112
class SwitchCase;
113
class TargetOptions;
114
class TemplateParameterList;
115
class TypedefNameDecl;
116
class TypeSourceInfo;
117
class ValueDecl;
118
class VarDecl;
119
120
/// Abstract interface for callback invocations by the ASTReader.
121
///
122
/// While reading an AST file, the ASTReader will call the methods of the
123
/// listener to pass on specific information. Some of the listener methods can
124
/// return true to indicate to the ASTReader that the information (and
125
/// consequently the AST file) is invalid.
126
class ASTReaderListener {
127
public:
128
  virtual ~ASTReaderListener();
129
130
  /// Receives the full Clang version information.
131
  ///
132
  /// \returns true to indicate that the version is invalid. Subclasses should
133
  /// generally defer to this implementation.
134
17
  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
135
17
    return FullVersion != getClangFullRepositoryVersion();
136
17
  }
137
138
3.51k
  virtual void ReadModuleName(StringRef ModuleName) {}
139
4.51k
  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
140
141
  /// Receives the language options.
142
  ///
143
  /// \returns true to indicate the options are invalid or false otherwise.
144
  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
145
                                   bool Complain,
146
802
                                   bool AllowCompatibleDifferences) {
147
802
    return false;
148
802
  }
149
150
  /// Receives the target options.
151
  ///
152
  /// \returns true to indicate the target options are invalid, or false
153
  /// otherwise.
154
  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
155
802
                                 bool AllowCompatibleDifferences) {
156
802
    return false;
157
802
  }
158
159
  /// Receives the diagnostic options.
160
  ///
161
  /// \returns true to indicate the diagnostic options are invalid, or false
162
  /// otherwise.
163
  virtual bool
164
  ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
165
547
                        bool Complain) {
166
547
    return false;
167
547
  }
168
169
  /// Receives the file system options.
170
  ///
171
  /// \returns true to indicate the file system options are invalid, or false
172
  /// otherwise.
173
  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
174
4.06k
                                     bool Complain) {
175
4.06k
    return false;
176
4.06k
  }
177
178
  /// Receives the header search options.
179
  ///
180
  /// \returns true to indicate the header search options are invalid, or false
181
  /// otherwise.
182
  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
183
                                       StringRef SpecificModuleCachePath,
184
422
                                       bool Complain) {
185
422
    return false;
186
422
  }
187
188
  /// Receives the preprocessor options.
189
  ///
190
  /// \param SuggestedPredefines Can be filled in with the set of predefines
191
  /// that are suggested by the preprocessor options. Typically only used when
192
  /// loading a precompiled header.
193
  ///
194
  /// \returns true to indicate the preprocessor options are invalid, or false
195
  /// otherwise.
196
  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
197
                                       bool Complain,
198
55
                                       std::string &SuggestedPredefines) {
199
55
    return false;
200
55
  }
201
202
  /// Receives __COUNTER__ value.
203
  virtual void ReadCounter(const serialization::ModuleFile &M,
204
0
                           unsigned Value) {}
205
206
  /// This is called for each AST file loaded.
207
  virtual void visitModuleFile(StringRef Filename,
208
7.11k
                               serialization::ModuleKind Kind) {}
209
210
  /// Returns true if this \c ASTReaderListener wants to receive the
211
  /// input files of the AST file via \c visitInputFile, false otherwise.
212
7.25k
  virtual bool needsInputFileVisitation() { return false; }
213
214
  /// Returns true if this \c ASTReaderListener wants to receive the
215
  /// system input files of the AST file via \c visitInputFile, false otherwise.
216
31
  virtual bool needsSystemInputFileVisitation() { return false; }
217
218
  /// if \c needsInputFileVisitation returns true, this is called for
219
  /// each non-system input file of the AST File. If
220
  /// \c needsSystemInputFileVisitation is true, then it is called for all
221
  /// system input files as well.
222
  ///
223
  /// \returns true to continue receiving the next input file, false to stop.
224
  virtual bool visitInputFile(StringRef Filename, bool isSystem,
225
0
                              bool isOverridden, bool isExplicitModule) {
226
0
    return true;
227
0
  }
228
229
  /// Returns true if this \c ASTReaderListener wants to receive the
230
  /// imports of the AST file via \c visitImport, false otherwise.
231
17
  virtual bool needsImportVisitation() const { return false; }
232
233
  /// If needsImportVisitation returns \c true, this is called for each
234
  /// AST file imported by this AST file.
235
0
  virtual void visitImport(StringRef Filename) {}
236
237
  /// Indicates that a particular module file extension has been read.
238
  virtual void readModuleFileExtension(
239
0
                 const ModuleFileExtensionMetadata &Metadata) {}
240
};
241
242
/// Simple wrapper class for chaining listeners.
243
class ChainedASTReaderListener : public ASTReaderListener {
244
  std::unique_ptr<ASTReaderListener> First;
245
  std::unique_ptr<ASTReaderListener> Second;
246
247
public:
248
  /// Takes ownership of \p First and \p Second.
249
  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
250
                           std::unique_ptr<ASTReaderListener> Second)
251
459
      : First(std::move(First)), Second(std::move(Second)) {}
252
253
0
  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
254
382
  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
255
256
  bool ReadFullVersionInformation(StringRef FullVersion) override;
257
  void ReadModuleName(StringRef ModuleName) override;
258
  void ReadModuleMapFile(StringRef ModuleMapPath) override;
259
  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
260
                           bool AllowCompatibleDifferences) override;
261
  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
262
                         bool AllowCompatibleDifferences) override;
263
  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
264
                             bool Complain) override;
265
  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
266
                             bool Complain) override;
267
268
  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
269
                               StringRef SpecificModuleCachePath,
270
                               bool Complain) override;
271
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
272
                               bool Complain,
273
                               std::string &SuggestedPredefines) override;
274
275
  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
276
  bool needsInputFileVisitation() override;
277
  bool needsSystemInputFileVisitation() override;
278
  void visitModuleFile(StringRef Filename,
279
                       serialization::ModuleKind Kind) override;
280
  bool visitInputFile(StringRef Filename, bool isSystem,
281
                      bool isOverridden, bool isExplicitModule) override;
282
  void readModuleFileExtension(
283
         const ModuleFileExtensionMetadata &Metadata) override;
284
};
285
286
/// ASTReaderListener implementation to validate the information of
287
/// the PCH file against an initialized Preprocessor.
288
class PCHValidator : public ASTReaderListener {
289
  Preprocessor &PP;
290
  ASTReader &Reader;
291
292
public:
293
  PCHValidator(Preprocessor &PP, ASTReader &Reader)
294
4.52k
      : PP(PP), Reader(Reader) {}
295
296
  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
297
                           bool AllowCompatibleDifferences) override;
298
  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
299
                         bool AllowCompatibleDifferences) override;
300
  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
301
                             bool Complain) override;
302
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
303
                               std::string &SuggestedPredefines) override;
304
  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
305
                               StringRef SpecificModuleCachePath,
306
                               bool Complain) override;
307
  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
308
309
private:
310
  void Error(const char *Msg);
311
};
312
313
/// ASTReaderListenter implementation to set SuggestedPredefines of
314
/// ASTReader which is required to use a pch file. This is the replacement
315
/// of PCHValidator or SimplePCHValidator when using a pch file without
316
/// validating it.
317
class SimpleASTReaderListener : public ASTReaderListener {
318
  Preprocessor &PP;
319
320
public:
321
372
  SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
322
323
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
324
                               std::string &SuggestedPredefines) override;
325
};
326
327
namespace serialization {
328
329
class ReadMethodPoolVisitor;
330
331
namespace reader {
332
333
class ASTIdentifierLookupTrait;
334
335
/// The on-disk hash table(s) used for DeclContext name lookup.
336
struct DeclContextLookupTable;
337
338
} // namespace reader
339
340
} // namespace serialization
341
342
/// Reads an AST files chain containing the contents of a translation
343
/// unit.
344
///
345
/// The ASTReader class reads bitstreams (produced by the ASTWriter
346
/// class) containing the serialized representation of a given
347
/// abstract syntax tree and its supporting data structures. An
348
/// instance of the ASTReader can be attached to an ASTContext object,
349
/// which will provide access to the contents of the AST files.
350
///
351
/// The AST reader provides lazy de-serialization of declarations, as
352
/// required when traversing the AST. Only those AST nodes that are
353
/// actually required will be de-serialized.
354
class ASTReader
355
  : public ExternalPreprocessorSource,
356
    public ExternalPreprocessingRecordSource,
357
    public ExternalHeaderFileInfoSource,
358
    public ExternalSemaSource,
359
    public IdentifierInfoLookup,
360
    public ExternalSLocEntrySource
361
{
362
public:
363
  /// Types of AST files.
364
  friend class ASTDeclReader;
365
  friend class ASTIdentifierIterator;
366
  friend class ASTRecordReader;
367
  friend class ASTStmtReader;
368
  friend class ASTUnit; // ASTUnit needs to remap source locations.
369
  friend class ASTWriter;
370
  friend class PCHValidator;
371
  friend class serialization::reader::ASTIdentifierLookupTrait;
372
  friend class serialization::ReadMethodPoolVisitor;
373
  friend class TypeLocReader;
374
375
  using RecordData = SmallVector<uint64_t, 64>;
376
  using RecordDataImpl = SmallVectorImpl<uint64_t>;
377
378
  /// The result of reading the control block of an AST file, which
379
  /// can fail for various reasons.
380
  enum ASTReadResult {
381
    /// The control block was read successfully. Aside from failures,
382
    /// the AST file is safe to read into the current context.
383
    Success,
384
385
    /// The AST file itself appears corrupted.
386
    Failure,
387
388
    /// The AST file was missing.
389
    Missing,
390
391
    /// The AST file is out-of-date relative to its input files,
392
    /// and needs to be regenerated.
393
    OutOfDate,
394
395
    /// The AST file was written by a different version of Clang.
396
    VersionMismatch,
397
398
    /// The AST file was writtten with a different language/target
399
    /// configuration.
400
    ConfigurationMismatch,
401
402
    /// The AST file has errors.
403
    HadErrors
404
  };
405
406
  using ModuleFile = serialization::ModuleFile;
407
  using ModuleKind = serialization::ModuleKind;
408
  using ModuleManager = serialization::ModuleManager;
409
  using ModuleIterator = ModuleManager::ModuleIterator;
410
  using ModuleConstIterator = ModuleManager::ModuleConstIterator;
411
  using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
412
413
private:
414
  /// The receiver of some callbacks invoked by ASTReader.
415
  std::unique_ptr<ASTReaderListener> Listener;
416
417
  /// The receiver of deserialization events.
418
  ASTDeserializationListener *DeserializationListener = nullptr;
419
420
  bool OwnsDeserializationListener = false;
421
422
  SourceManager &SourceMgr;
423
  FileManager &FileMgr;
424
  const PCHContainerReader &PCHContainerRdr;
425
  DiagnosticsEngine &Diags;
426
427
  /// The semantic analysis object that will be processing the
428
  /// AST files and the translation unit that uses it.
429
  Sema *SemaObj = nullptr;
430
431
  /// The preprocessor that will be loading the source file.
432
  Preprocessor &PP;
433
434
  /// The AST context into which we'll read the AST files.
435
  ASTContext *ContextObj = nullptr;
436
437
  /// The AST consumer.
438
  ASTConsumer *Consumer = nullptr;
439
440
  /// The module manager which manages modules and their dependencies
441
  ModuleManager ModuleMgr;
442
443
  /// The cache that manages memory buffers for PCM files.
444
  MemoryBufferCache &PCMCache;
445
446
  /// A dummy identifier resolver used to merge TU-scope declarations in
447
  /// C, for the cases where we don't have a Sema object to provide a real
448
  /// identifier resolver.
449
  IdentifierResolver DummyIdResolver;
450
451
  /// A mapping from extension block names to module file extensions.
452
  llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
453
454
  /// A timer used to track the time spent deserializing.
455
  std::unique_ptr<llvm::Timer> ReadTimer;
456
457
  /// The location where the module file will be considered as
458
  /// imported from. For non-module AST types it should be invalid.
459
  SourceLocation CurrentImportLoc;
460
461
  /// The global module index, if loaded.
462
  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
463
464
  /// A map of global bit offsets to the module that stores entities
465
  /// at those bit offsets.
466
  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
467
468
  /// A map of negated SLocEntryIDs to the modules containing them.
469
  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
470
471
  using GlobalSLocOffsetMapType =
472
      ContinuousRangeMap<unsigned, ModuleFile *, 64>;
473
474
  /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
475
  /// SourceLocation offsets to the modules containing them.
476
  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
477
478
  /// Types that have already been loaded from the chain.
479
  ///
480
  /// When the pointer at index I is non-NULL, the type with
481
  /// ID = (I + 1) << FastQual::Width has already been loaded
482
  std::vector<QualType> TypesLoaded;
483
484
  using GlobalTypeMapType =
485
      ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>;
486
487
  /// Mapping from global type IDs to the module in which the
488
  /// type resides along with the offset that should be added to the
489
  /// global type ID to produce a local ID.
490
  GlobalTypeMapType GlobalTypeMap;
491
492
  /// Declarations that have already been loaded from the chain.
493
  ///
494
  /// When the pointer at index I is non-NULL, the declaration with ID
495
  /// = I + 1 has already been loaded.
496
  std::vector<Decl *> DeclsLoaded;
497
498
  using GlobalDeclMapType =
499
      ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>;
500
501
  /// Mapping from global declaration IDs to the module in which the
502
  /// declaration resides.
503
  GlobalDeclMapType GlobalDeclMap;
504
505
  using FileOffset = std::pair<ModuleFile *, uint64_t>;
506
  using FileOffsetsTy = SmallVector<FileOffset, 2>;
507
  using DeclUpdateOffsetsMap =
508
      llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
509
510
  /// Declarations that have modifications residing in a later file
511
  /// in the chain.
512
  DeclUpdateOffsetsMap DeclUpdateOffsets;
513
514
  struct PendingUpdateRecord {
515
    Decl *D;
516
    serialization::GlobalDeclID ID;
517
518
    // Whether the declaration was just deserialized.
519
    bool JustLoaded;
520
521
    PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
522
                        bool JustLoaded)
523
240k
        : D(D), ID(ID), JustLoaded(JustLoaded) {}
524
  };
525
526
  /// Declaration updates for already-loaded declarations that we need
527
  /// to apply once we finish processing an import.
528
  llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
529
530
  enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
531
532
  /// The DefinitionData pointers that we faked up for class definitions
533
  /// that we needed but hadn't loaded yet.
534
  llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
535
536
  /// Exception specification updates that have been loaded but not yet
537
  /// propagated across the relevant redeclaration chain. The map key is the
538
  /// canonical declaration (used only for deduplication) and the value is a
539
  /// declaration that has an exception specification.
540
  llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
541
542
  /// Declarations that have been imported and have typedef names for
543
  /// linkage purposes.
544
  llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
545
      ImportedTypedefNamesForLinkage;
546
547
  /// Mergeable declaration contexts that have anonymous declarations
548
  /// within them, and those anonymous declarations.
549
  llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
550
    AnonymousDeclarationsForMerging;
551
552
  struct FileDeclsInfo {
553
    ModuleFile *Mod = nullptr;
554
    ArrayRef<serialization::LocalDeclID> Decls;
555
556
3.32k
    FileDeclsInfo() = default;
557
    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
558
3.32k
        : Mod(Mod), Decls(Decls) {}
559
  };
560
561
  /// Map from a FileID to the file-level declarations that it contains.
562
  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
563
564
  /// An array of lexical contents of a declaration context, as a sequence of
565
  /// Decl::Kind, DeclID pairs.
566
  using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
567
568
  /// Map from a DeclContext to its lexical contents.
569
  llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
570
      LexicalDecls;
571
572
  /// Map from the TU to its lexical contents from each module file.
573
  std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
574
575
  /// Map from a DeclContext to its lookup tables.
576
  llvm::DenseMap<const DeclContext *,
577
                 serialization::reader::DeclContextLookupTable> Lookups;
578
579
  // Updates for visible decls can occur for other contexts than just the
580
  // TU, and when we read those update records, the actual context may not
581
  // be available yet, so have this pending map using the ID as a key. It
582
  // will be realized when the context is actually loaded.
583
  struct PendingVisibleUpdate {
584
    ModuleFile *Mod;
585
    const unsigned char *Data;
586
  };
587
  using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
588
589
  /// Updates to the visible declarations of declaration contexts that
590
  /// haven't been loaded yet.
591
  llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
592
      PendingVisibleUpdates;
593
594
  /// The set of C++ or Objective-C classes that have forward 
595
  /// declarations that have not yet been linked to their definitions.
596
  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
597
598
  using PendingBodiesMap =
599
      llvm::MapVector<Decl *, uint64_t,
600
                      llvm::SmallDenseMap<Decl *, unsigned, 4>,
601
                      SmallVector<std::pair<Decl *, uint64_t>, 4>>;
602
603
  /// Functions or methods that have bodies that will be attached.
604
  PendingBodiesMap PendingBodies;
605
606
  /// Definitions for which we have added merged definitions but not yet
607
  /// performed deduplication.
608
  llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
609
610
  /// Read the record that describes the lexical contents of a DC.
611
  bool ReadLexicalDeclContextStorage(ModuleFile &M,
612
                                     llvm::BitstreamCursor &Cursor,
613
                                     uint64_t Offset, DeclContext *DC);
614
615
  /// Read the record that describes the visible contents of a DC.
616
  bool ReadVisibleDeclContextStorage(ModuleFile &M,
617
                                     llvm::BitstreamCursor &Cursor,
618
                                     uint64_t Offset, serialization::DeclID ID);
619
620
  /// A vector containing identifiers that have already been
621
  /// loaded.
622
  ///
623
  /// If the pointer at index I is non-NULL, then it refers to the
624
  /// IdentifierInfo for the identifier with ID=I+1 that has already
625
  /// been loaded.
626
  std::vector<IdentifierInfo *> IdentifiersLoaded;
627
628
  using GlobalIdentifierMapType =
629
      ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
630
631
  /// Mapping from global identifier IDs to the module in which the
632
  /// identifier resides along with the offset that should be added to the
633
  /// global identifier ID to produce a local ID.
634
  GlobalIdentifierMapType GlobalIdentifierMap;
635
636
  /// A vector containing macros that have already been
637
  /// loaded.
638
  ///
639
  /// If the pointer at index I is non-NULL, then it refers to the
640
  /// MacroInfo for the identifier with ID=I+1 that has already
641
  /// been loaded.
642
  std::vector<MacroInfo *> MacrosLoaded;
643
644
  using LoadedMacroInfo =
645
      std::pair<IdentifierInfo *, serialization::SubmoduleID>;
646
647
  /// A set of #undef directives that we have loaded; used to
648
  /// deduplicate the same #undef information coming from multiple module
649
  /// files.
650
  llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
651
652
  using GlobalMacroMapType =
653
      ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
654
655
  /// Mapping from global macro IDs to the module in which the
656
  /// macro resides along with the offset that should be added to the
657
  /// global macro ID to produce a local ID.
658
  GlobalMacroMapType GlobalMacroMap;
659
660
  /// A vector containing submodules that have already been loaded.
661
  ///
662
  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
663
  /// indicate that the particular submodule ID has not yet been loaded.
664
  SmallVector<Module *, 2> SubmodulesLoaded;
665
  
666
  using GlobalSubmoduleMapType =
667
      ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
668
  
669
  /// Mapping from global submodule IDs to the module file in which the
670
  /// submodule resides along with the offset that should be added to the
671
  /// global submodule ID to produce a local ID.
672
  GlobalSubmoduleMapType GlobalSubmoduleMap;
673
674
  /// A set of hidden declarations.
675
  using HiddenNames = SmallVector<Decl *, 2>;
676
  using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
677
678
  /// A mapping from each of the hidden submodules to the deserialized
679
  /// declarations in that submodule that could be made visible.
680
  HiddenNamesMapType HiddenNamesMap;
681
  
682
  /// A module import, export, or conflict that hasn't yet been resolved.
683
  struct UnresolvedModuleRef {
684
    /// The file in which this module resides.
685
    ModuleFile *File;
686
    
687
    /// The module that is importing or exporting.
688
    Module *Mod;
689
690
    /// The kind of module reference.
691
    enum { Import, Export, Conflict } Kind;
692
693
    /// The local ID of the module that is being exported.
694
    unsigned ID;
695
696
    /// Whether this is a wildcard export.
697
    unsigned IsWildcard : 1;
698
699
    /// String data.
700
    StringRef String;
701
  };
702
  
703
  /// The set of module imports and exports that still need to be 
704
  /// resolved.
705
  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
706
  
707
  /// A vector containing selectors that have already been loaded.
708
  ///
709
  /// This vector is indexed by the Selector ID (-1). NULL selector
710
  /// entries indicate that the particular selector ID has not yet
711
  /// been loaded.
712
  SmallVector<Selector, 16> SelectorsLoaded;
713
714
  using GlobalSelectorMapType =
715
      ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
716
717
  /// Mapping from global selector IDs to the module in which the
718
  /// global selector ID to produce a local ID.
719
  GlobalSelectorMapType GlobalSelectorMap;
720
721
  /// The generation number of the last time we loaded data from the
722
  /// global method pool for this selector.
723
  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
724
725
  /// Whether a selector is out of date. We mark a selector as out of date
726
  /// if we load another module after the method pool entry was pulled in.
727
  llvm::DenseMap<Selector, bool> SelectorOutOfDate;
728
729
  struct PendingMacroInfo {
730
    ModuleFile *M;
731
    uint64_t MacroDirectivesOffset;
732
733
    PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
734
37.9k
        : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
735
  };
736
737
  using PendingMacroIDsMap =
738
      llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
739
740
  /// Mapping from identifiers that have a macro history to the global
741
  /// IDs have not yet been deserialized to the global IDs of those macros.
742
  PendingMacroIDsMap PendingMacroIDs;
743
744
  using GlobalPreprocessedEntityMapType =
745
      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
746
747
  /// Mapping from global preprocessing entity IDs to the module in
748
  /// which the preprocessed entity resides along with the offset that should be
749
  /// added to the global preprocessing entity ID to produce a local ID.
750
  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
751
752
  using GlobalSkippedRangeMapType =
753
      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
754
755
  /// Mapping from global skipped range base IDs to the module in which
756
  /// the skipped ranges reside.
757
  GlobalSkippedRangeMapType GlobalSkippedRangeMap;
758
759
  /// \name CodeGen-relevant special data
760
  /// Fields containing data that is relevant to CodeGen.
761
  //@{
762
763
  /// The IDs of all declarations that fulfill the criteria of
764
  /// "interesting" decls.
765
  ///
766
  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
767
  /// in the chain. The referenced declarations are deserialized and passed to
768
  /// the consumer eagerly.
769
  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
770
771
  /// The IDs of all tentative definitions stored in the chain.
772
  ///
773
  /// Sema keeps track of all tentative definitions in a TU because it has to
774
  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
775
  /// the PCH chain must be eagerly deserialized.
776
  SmallVector<uint64_t, 16> TentativeDefinitions;
777
778
  /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
779
  /// used.
780
  ///
781
  /// CodeGen has to emit VTables for these records, so they have to be eagerly
782
  /// deserialized.
783
  SmallVector<uint64_t, 64> VTableUses;
784
785
  /// A snapshot of the pending instantiations in the chain.
786
  ///
787
  /// This record tracks the instantiations that Sema has to perform at the
788
  /// end of the TU. It consists of a pair of values for every pending
789
  /// instantiation where the first value is the ID of the decl and the second
790
  /// is the instantiation location.
791
  SmallVector<uint64_t, 64> PendingInstantiations;
792
793
  //@}
794
795
  /// \name DiagnosticsEngine-relevant special data
796
  /// Fields containing data that is used for generating diagnostics
797
  //@{
798
799
  /// A snapshot of Sema's unused file-scoped variable tracking, for
800
  /// generating warnings.
801
  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
802
803
  /// A list of all the delegating constructors we've seen, to diagnose
804
  /// cycles.
805
  SmallVector<uint64_t, 4> DelegatingCtorDecls;
806
807
  /// Method selectors used in a @selector expression. Used for
808
  /// implementation of -Wselector.
809
  SmallVector<uint64_t, 64> ReferencedSelectorsData;
810
811
  /// A snapshot of Sema's weak undeclared identifier tracking, for
812
  /// generating warnings.
813
  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
814
815
  /// The IDs of type aliases for ext_vectors that exist in the chain.
816
  ///
817
  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
818
  SmallVector<uint64_t, 4> ExtVectorDecls;
819
820
  //@}
821
822
  /// \name Sema-relevant special data
823
  /// Fields containing data that is used for semantic analysis
824
  //@{
825
826
  /// The IDs of all potentially unused typedef names in the chain.
827
  ///
828
  /// Sema tracks these to emit warnings.
829
  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
830
831
  /// Our current depth in #pragma cuda force_host_device begin/end
832
  /// macros.
833
  unsigned ForceCUDAHostDeviceDepth = 0;
834
835
  /// The IDs of the declarations Sema stores directly.
836
  ///
837
  /// Sema tracks a few important decls, such as namespace std, directly.
838
  SmallVector<uint64_t, 4> SemaDeclRefs;
839
840
  /// The IDs of the types ASTContext stores directly.
841
  ///
842
  /// The AST context tracks a few important types, such as va_list, directly.
843
  SmallVector<uint64_t, 16> SpecialTypes;
844
845
  /// The IDs of CUDA-specific declarations ASTContext stores directly.
846
  ///
847
  /// The AST context tracks a few important decls, currently cudaConfigureCall,
848
  /// directly.
849
  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
850
851
  /// The floating point pragma option settings.
852
  SmallVector<uint64_t, 1> FPPragmaOptions;
853
854
  /// The pragma clang optimize location (if the pragma state is "off").
855
  SourceLocation OptimizeOffPragmaLocation;
856
857
  /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
858
  int PragmaMSStructState = -1;
859
860
  /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
861
  int PragmaMSPointersToMembersState = -1;
862
  SourceLocation PointersToMembersPragmaLocation;
863
864
  /// The pragma pack state.
865
  Optional<unsigned> PragmaPackCurrentValue;
866
  SourceLocation PragmaPackCurrentLocation;
867
  struct PragmaPackStackEntry {
868
    unsigned Value;
869
    SourceLocation Location;
870
    SourceLocation PushLocation;
871
    StringRef SlotLabel;
872
  };
873
  llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
874
  llvm::SmallVector<std::string, 2> PragmaPackStrings;
875
876
  /// The OpenCL extension settings.
877
  OpenCLOptions OpenCLExtensions;
878
879
  /// Extensions required by an OpenCL type.
880
  llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
881
882
  /// Extensions required by an OpenCL declaration.
883
  llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
884
885
  /// A list of the namespaces we've seen.
886
  SmallVector<uint64_t, 4> KnownNamespaces;
887
888
  /// A list of undefined decls with internal linkage followed by the
889
  /// SourceLocation of a matching ODR-use.
890
  SmallVector<uint64_t, 8> UndefinedButUsed;
891
892
  /// Delete expressions to analyze at the end of translation unit.
893
  SmallVector<uint64_t, 8> DelayedDeleteExprs;
894
895
  // A list of late parsed template function data.
896
  SmallVector<uint64_t, 1> LateParsedTemplates;
897
898
public:
899
  struct ImportedSubmodule {
900
    serialization::SubmoduleID ID;
901
    SourceLocation ImportLoc;
902
903
    ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
904
61
        : ID(ID), ImportLoc(ImportLoc) {}
905
  };
906
907
private:
908
  /// A list of modules that were imported by precompiled headers or
909
  /// any other non-module AST file.
910
  SmallVector<ImportedSubmodule, 2> ImportedModules;
911
  //@}
912
913
  /// The system include root to be used when loading the
914
  /// precompiled header.
915
  std::string isysroot;
916
917
  /// Whether to disable the normal validation performed on precompiled
918
  /// headers when they are loaded.
919
  bool DisableValidation;
920
921
  /// Whether to accept an AST file with compiler errors.
922
  bool AllowASTWithCompilerErrors;
923
924
  /// Whether to accept an AST file that has a different configuration
925
  /// from the current compiler instance.
926
  bool AllowConfigurationMismatch;
927
928
  /// Whether validate system input files.
929
  bool ValidateSystemInputs;
930
931
  /// Whether we are allowed to use the global module index.
932
  bool UseGlobalIndex;
933
934
  /// Whether we have tried loading the global module index yet.
935
  bool TriedLoadingGlobalIndex = false;
936
937
  ///Whether we are currently processing update records.
938
  bool ProcessingUpdateRecords = false;
939
940
  using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
941
942
  /// Mapping from switch-case IDs in the chain to switch-case statements
943
  ///
944
  /// Statements usually don't have IDs, but switch cases need them, so that the
945
  /// switch statement can refer to them.
946
  SwitchCaseMapTy SwitchCaseStmts;
947
948
  SwitchCaseMapTy *CurrSwitchCaseStmts;
949
950
  /// The number of source location entries de-serialized from
951
  /// the PCH file.
952
  unsigned NumSLocEntriesRead = 0;
953
954
  /// The number of source location entries in the chain.
955
  unsigned TotalNumSLocEntries = 0;
956
957
  /// The number of statements (and expressions) de-serialized
958
  /// from the chain.
959
  unsigned NumStatementsRead = 0;
960
961
  /// The total number of statements (and expressions) stored
962
  /// in the chain.
963
  unsigned TotalNumStatements = 0;
964
965
  /// The number of macros de-serialized from the chain.
966
  unsigned NumMacrosRead = 0;
967
968
  /// The total number of macros stored in the chain.
969
  unsigned TotalNumMacros = 0;
970
971
  /// The number of lookups into identifier tables.
972
  unsigned NumIdentifierLookups = 0;
973
974
  /// The number of lookups into identifier tables that succeed.
975
  unsigned NumIdentifierLookupHits = 0;
976
977
  /// The number of selectors that have been read.
978
  unsigned NumSelectorsRead = 0;
979
980
  /// The number of method pool entries that have been read.
981
  unsigned NumMethodPoolEntriesRead = 0;
982
983
  /// The number of times we have looked up a selector in the method
984
  /// pool.
985
  unsigned NumMethodPoolLookups = 0;
986
987
  /// The number of times we have looked up a selector in the method
988
  /// pool and found something.
989
  unsigned NumMethodPoolHits = 0;
990
991
  /// The number of times we have looked up a selector in the method
992
  /// pool within a specific module.
993
  unsigned NumMethodPoolTableLookups = 0;
994
995
  /// The number of times we have looked up a selector in the method
996
  /// pool within a specific module and found something.
997
  unsigned NumMethodPoolTableHits = 0;
998
999
  /// The total number of method pool entries in the selector table.
1000
  unsigned TotalNumMethodPoolEntries = 0;
1001
1002
  /// Number of lexical decl contexts read/total.
1003
  unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1004
1005
  /// Number of visible decl contexts read/total.
1006
  unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1007
1008
  /// Total size of modules, in bits, currently loaded
1009
  uint64_t TotalModulesSizeInBits = 0;
1010
1011
  /// Number of Decl/types that are currently deserializing.
1012
  unsigned NumCurrentElementsDeserializing = 0;
1013
1014
  /// Set true while we are in the process of passing deserialized
1015
  /// "interesting" decls to consumer inside FinishedDeserializing().
1016
  /// This is used as a guard to avoid recursively repeating the process of
1017
  /// passing decls to consumer.
1018
  bool PassingDeclsToConsumer = false;
1019
1020
  /// The set of identifiers that were read while the AST reader was
1021
  /// (recursively) loading declarations.
1022
  ///
1023
  /// The declarations on the identifier chain for these identifiers will be
1024
  /// loaded once the recursive loading has completed.
1025
  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1026
    PendingIdentifierInfos;
1027
1028
  /// The set of lookup results that we have faked in order to support
1029
  /// merging of partially deserialized decls but that we have not yet removed.
1030
  llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1031
    PendingFakeLookupResults;
1032
1033
  /// The generation number of each identifier, which keeps track of
1034
  /// the last time we loaded information about this identifier.
1035
  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1036
1037
  class InterestingDecl {
1038
    Decl *D;
1039
    bool DeclHasPendingBody;
1040
1041
  public:
1042
    InterestingDecl(Decl *D, bool HasBody)
1043
237k
        : D(D), DeclHasPendingBody(HasBody) {}
1044
1045
248k
    Decl *getDecl() { return D; }
1046
1047
    /// Whether the declaration has a pending body.
1048
234k
    bool hasPendingBody() { return DeclHasPendingBody; }
1049
  };
1050
1051
  /// Contains declarations and definitions that could be
1052
  /// "interesting" to the ASTConsumer, when we get that AST consumer.
1053
  ///
1054
  /// "Interesting" declarations are those that have data that may
1055
  /// need to be emitted, such as inline function definitions or
1056
  /// Objective-C protocols.
1057
  std::deque<InterestingDecl> PotentiallyInterestingDecls;
1058
1059
  /// The list of redeclaration chains that still need to be 
1060
  /// reconstructed, and the local offset to the corresponding list
1061
  /// of redeclarations.
1062
  SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1063
1064
  /// The list of canonical declarations whose redeclaration chains
1065
  /// need to be marked as incomplete once we're done deserializing things.
1066
  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1067
1068
  /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1069
  /// been loaded but its DeclContext was not set yet.
1070
  struct PendingDeclContextInfo {
1071
    Decl *D;
1072
    serialization::GlobalDeclID SemaDC;
1073
    serialization::GlobalDeclID LexicalDC;
1074
  };
1075
1076
  /// The set of Decls that have been loaded but their DeclContexts are
1077
  /// not set yet.
1078
  ///
1079
  /// The DeclContexts for these Decls will be set once recursive loading has
1080
  /// been completed.
1081
  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1082
1083
  /// The set of NamedDecls that have been loaded, but are members of a
1084
  /// context that has been merged into another context where the corresponding
1085
  /// declaration is either missing or has not yet been loaded.
1086
  ///
1087
  /// We will check whether the corresponding declaration is in fact missing
1088
  /// once recursing loading has been completed.
1089
  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1090
1091
  using DataPointers =
1092
      std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1093
1094
  /// Record definitions in which we found an ODR violation.
1095
  llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1096
      PendingOdrMergeFailures;
1097
1098
  /// Function definitions in which we found an ODR violation.
1099
  llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1100
      PendingFunctionOdrMergeFailures;
1101
1102
  /// DeclContexts in which we have diagnosed an ODR violation.
1103
  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1104
1105
  /// The set of Objective-C categories that have been deserialized
1106
  /// since the last time the declaration chains were linked.
1107
  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1108
1109
  /// The set of Objective-C class definitions that have already been
1110
  /// loaded, for which we will need to check for categories whenever a new
1111
  /// module is loaded.
1112
  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1113
1114
  using KeyDeclsMap =
1115
      llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1116
    
1117
  /// A mapping from canonical declarations to the set of global
1118
  /// declaration IDs for key declaration that have been merged with that
1119
  /// canonical declaration. A key declaration is a formerly-canonical
1120
  /// declaration whose module did not import any other key declaration for that
1121
  /// entity. These are the IDs that we use as keys when finding redecl chains.
1122
  KeyDeclsMap KeyDecls;
1123
  
1124
  /// A mapping from DeclContexts to the semantic DeclContext that we
1125
  /// are treating as the definition of the entity. This is used, for instance,
1126
  /// when merging implicit instantiations of class templates across modules.
1127
  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1128
1129
  /// A mapping from canonical declarations of enums to their canonical
1130
  /// definitions. Only populated when using modules in C++.
1131
  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1132
1133
  /// When reading a Stmt tree, Stmt operands are placed in this stack.
1134
  SmallVector<Stmt *, 16> StmtStack;
1135
1136
  /// What kind of records we are reading.
1137
  enum ReadingKind {
1138
    Read_None, Read_Decl, Read_Type, Read_Stmt
1139
  };
1140
1141
  /// What kind of records we are reading.
1142
  ReadingKind ReadingKind = Read_None;
1143
1144
  /// RAII object to change the reading kind.
1145
  class ReadingKindTracker {
1146
    ASTReader &Reader;
1147
    enum ReadingKind PrevKind;
1148
1149
  public:
1150
    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1151
699k
        : Reader(reader), PrevKind(Reader.ReadingKind) {
1152
699k
      Reader.ReadingKind = newKind;
1153
699k
    }
1154
1155
    ReadingKindTracker(const ReadingKindTracker &) = delete;
1156
    ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1157
699k
    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1158
  };
1159
1160
  /// RAII object to mark the start of processing updates.
1161
  class ProcessingUpdatesRAIIObj {
1162
    ASTReader &Reader;
1163
    bool PrevState;
1164
1165
  public:
1166
    ProcessingUpdatesRAIIObj(ASTReader &reader)
1167
240k
        : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1168
240k
      Reader.ProcessingUpdateRecords = true;
1169
240k
    }
1170
1171
    ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1172
    ProcessingUpdatesRAIIObj &
1173
    operator=(const ProcessingUpdatesRAIIObj &) = delete;
1174
240k
    ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1175
  };
1176
1177
  /// Suggested contents of the predefines buffer, after this
1178
  /// PCH file has been processed.
1179
  ///
1180
  /// In most cases, this string will be empty, because the predefines
1181
  /// buffer computed to build the PCH file will be identical to the
1182
  /// predefines buffer computed from the command line. However, when
1183
  /// there are differences that the PCH reader can work around, this
1184
  /// predefines buffer may contain additional definitions.
1185
  std::string SuggestedPredefines;
1186
1187
  llvm::DenseMap<const Decl *, bool> DefinitionSource;
1188
1189
  /// Reads a statement from the specified cursor.
1190
  Stmt *ReadStmtFromStream(ModuleFile &F);
1191
1192
  struct InputFileInfo {
1193
    std::string Filename;
1194
    off_t StoredSize;
1195
    time_t StoredTime;
1196
    bool Overridden;
1197
    bool Transient;
1198
    bool TopLevelModuleMap;
1199
  };
1200
1201
  /// Reads the stored information about an input file.
1202
  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1203
1204
  /// Retrieve the file entry and 'overridden' bit for an input
1205
  /// file in the given module file.
1206
  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1207
                                        bool Complain = true);
1208
1209
public:
1210
  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1211
  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1212
1213
  /// Returns the first key declaration for the given declaration. This
1214
  /// is one that is formerly-canonical (or still canonical) and whose module
1215
  /// did not import any other key declaration of the entity.
1216
588
  Decl *getKeyDeclaration(Decl *D) {
1217
588
    D = D->getCanonicalDecl();
1218
588
    if (D->isFromASTFile())
1219
126
      return D;
1220
462
1221
462
    auto I = KeyDecls.find(D);
1222
462
    if (I == KeyDecls.end() || 
I->second.empty()40
)
1223
422
      return D;
1224
40
    return GetExistingDecl(I->second[0]);
1225
40
  }
1226
80
  const Decl *getKeyDeclaration(const Decl *D) {
1227
80
    return getKeyDeclaration(const_cast<Decl*>(D));
1228
80
  }
1229
1230
  /// Run a callback on each imported key declaration of \p D.
1231
  template <typename Fn>
1232
362
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1233
362
    D = D->getCanonicalDecl();
1234
362
    if (D->isFromASTFile())
1235
23
      Visit(D);
1236
362
1237
362
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1238
362
    if (It != KeyDecls.end())
1239
5
      for (auto ID : It->second)
1240
11
        Visit(GetExistingDecl(ID));
1241
362
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::ResolvedExceptionSpec(clang::FunctionDecl const*)::$_12>(clang::Decl const*, clang::ASTWriter::ResolvedExceptionSpec(clang::FunctionDecl const*)::$_12)
Line
Count
Source
1232
326
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1233
326
    D = D->getCanonicalDecl();
1234
326
    if (D->isFromASTFile())
1235
19
      Visit(D);
1236
326
1237
326
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1238
326
    if (It != KeyDecls.end())
1239
3
      for (auto ID : It->second)
1240
9
        Visit(GetExistingDecl(ID));
1241
326
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::DeducedReturnType(clang::FunctionDecl const*, clang::QualType)::$_13>(clang::Decl const*, clang::ASTWriter::DeducedReturnType(clang::FunctionDecl const*, clang::QualType)::$_13)
Line
Count
Source
1232
28
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1233
28
    D = D->getCanonicalDecl();
1234
28
    if (D->isFromASTFile())
1235
1
      Visit(D);
1236
28
1237
28
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1238
28
    if (It != KeyDecls.end())
1239
0
      for (auto ID : It->second)
1240
0
        Visit(GetExistingDecl(ID));
1241
28
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::ResolvedOperatorDelete(clang::CXXDestructorDecl const*, clang::FunctionDecl const*, clang::Expr*)::$_14>(clang::Decl const*, clang::ASTWriter::ResolvedOperatorDelete(clang::CXXDestructorDecl const*, clang::FunctionDecl const*, clang::Expr*)::$_14)
Line
Count
Source
1232
8
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1233
8
    D = D->getCanonicalDecl();
1234
8
    if (D->isFromASTFile())
1235
3
      Visit(D);
1236
8
1237
8
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1238
8
    if (It != KeyDecls.end())
1239
2
      for (auto ID : It->second)
1240
2
        Visit(GetExistingDecl(ID));
1241
8
  }
1242
1243
  /// Get the loaded lookup tables for \p Primary, if any.
1244
  const serialization::reader::DeclContextLookupTable *
1245
  getLoadedLookupTables(DeclContext *Primary) const;
1246
1247
private:
1248
  struct ImportedModule {
1249
    ModuleFile *Mod;
1250
    ModuleFile *ImportedBy;
1251
    SourceLocation ImportLoc;
1252
1253
    ImportedModule(ModuleFile *Mod,
1254
                   ModuleFile *ImportedBy,
1255
                   SourceLocation ImportLoc)
1256
5.91k
        : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1257
  };
1258
1259
  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1260
                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
1261
                            SmallVectorImpl<ImportedModule> &Loaded,
1262
                            off_t ExpectedSize, time_t ExpectedModTime,
1263
                            ASTFileSignature ExpectedSignature,
1264
                            unsigned ClientLoadCapabilities);
1265
  ASTReadResult ReadControlBlock(ModuleFile &F,
1266
                                 SmallVectorImpl<ImportedModule> &Loaded,
1267
                                 const ModuleFile *ImportedBy,
1268
                                 unsigned ClientLoadCapabilities);
1269
  static ASTReadResult ReadOptionsBlock(
1270
      llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1271
      bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1272
      std::string &SuggestedPredefines);
1273
1274
  /// Read the unhashed control block.
1275
  ///
1276
  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1277
  /// \c F.Data and reading ahead.
1278
  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1279
                                         unsigned ClientLoadCapabilities);
1280
1281
  static ASTReadResult
1282
  readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1283
                               unsigned ClientLoadCapabilities,
1284
                               bool AllowCompatibleConfigurationMismatch,
1285
                               ASTReaderListener *Listener,
1286
                               bool ValidateDiagnosticOptions);
1287
1288
  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1289
  ASTReadResult ReadExtensionBlock(ModuleFile &F);
1290
  void ReadModuleOffsetMap(ModuleFile &F) const;
1291
  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1292
  bool ReadSourceManagerBlock(ModuleFile &F);
1293
  llvm::BitstreamCursor &SLocCursorForID(int ID);
1294
  SourceLocation getImportLocation(ModuleFile *F);
1295
  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1296
                                       const ModuleFile *ImportedBy,
1297
                                       unsigned ClientLoadCapabilities);
1298
  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1299
                                   unsigned ClientLoadCapabilities);
1300
  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1301
                                   ASTReaderListener &Listener,
1302
                                   bool AllowCompatibleDifferences);
1303
  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1304
                                 ASTReaderListener &Listener,
1305
                                 bool AllowCompatibleDifferences);
1306
  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1307
                                     ASTReaderListener &Listener);
1308
  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1309
                                     ASTReaderListener &Listener);
1310
  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1311
                                       ASTReaderListener &Listener);
1312
  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1313
                                       ASTReaderListener &Listener,
1314
                                       std::string &SuggestedPredefines);
1315
1316
  struct RecordLocation {
1317
    ModuleFile *F;
1318
    uint64_t Offset;
1319
1320
395k
    RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1321
  };
1322
1323
  QualType readTypeRecord(unsigned Index);
1324
  void readExceptionSpec(ModuleFile &ModuleFile,
1325
                         SmallVectorImpl<QualType> &ExceptionStorage,
1326
                         FunctionProtoType::ExceptionSpecInfo &ESI,
1327
                         const RecordData &Record, unsigned &Index);
1328
  RecordLocation TypeCursorForIndex(unsigned Index);
1329
  void LoadedDecl(unsigned Index, Decl *D);
1330
  Decl *ReadDeclRecord(serialization::DeclID ID);
1331
  void markIncompleteDeclChain(Decl *Canon);
1332
1333
  /// Returns the most recent declaration of a declaration (which must be
1334
  /// of a redeclarable kind) that is either local or has already been loaded
1335
  /// merged into its redecl chain.
1336
  Decl *getMostRecentExistingDecl(Decl *D);
1337
1338
  RecordLocation DeclCursorForID(serialization::DeclID ID,
1339
                                 SourceLocation &Location);
1340
  void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1341
  void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1342
  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1343
                          unsigned PreviousGeneration = 0);
1344
1345
  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1346
  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1347
1348
  /// Returns the first preprocessed entity ID that begins or ends after
1349
  /// \arg Loc.
1350
  serialization::PreprocessedEntityID
1351
  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1352
1353
  /// Find the next module that contains entities and return the ID
1354
  /// of the first entry.
1355
  ///
1356
  /// \param SLocMapI points at a chunk of a module that contains no
1357
  /// preprocessed entities or the entities it contains are not the
1358
  /// ones we are looking for.
1359
  serialization::PreprocessedEntityID
1360
    findNextPreprocessedEntity(
1361
                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1362
1363
  /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1364
  /// preprocessed entity.
1365
  std::pair<ModuleFile *, unsigned>
1366
    getModulePreprocessedEntity(unsigned GlobalIndex);
1367
1368
  /// Returns (begin, end) pair for the preprocessed entities of a
1369
  /// particular module.
1370
  llvm::iterator_range<PreprocessingRecord::iterator>
1371
  getModulePreprocessedEntities(ModuleFile &Mod) const;
1372
1373
public:
1374
  class ModuleDeclIterator
1375
      : public llvm::iterator_adaptor_base<
1376
            ModuleDeclIterator, const serialization::LocalDeclID *,
1377
            std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1378
            const Decl *, const Decl *> {
1379
    ASTReader *Reader = nullptr;
1380
    ModuleFile *Mod = nullptr;
1381
1382
  public:
1383
    ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1384
1385
    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1386
                       const serialization::LocalDeclID *Pos)
1387
22
        : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1388
1389
63
    value_type operator*() const {
1390
63
      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1391
63
    }
1392
1393
0
    value_type operator->() const { return **this; }
1394
1395
74
    bool operator==(const ModuleDeclIterator &RHS) const {
1396
74
      assert(Reader == RHS.Reader && Mod == RHS.Mod);
1397
74
      return I == RHS.I;
1398
74
    }
1399
  };
1400
1401
  llvm::iterator_range<ModuleDeclIterator>
1402
  getModuleFileLevelDecls(ModuleFile &Mod);
1403
1404
private:
1405
  void PassInterestingDeclsToConsumer();
1406
  void PassInterestingDeclToConsumer(Decl *D);
1407
1408
  void finishPendingActions();
1409
  void diagnoseOdrViolations();
1410
1411
  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1412
1413
  void addPendingDeclContextInfo(Decl *D,
1414
                                 serialization::GlobalDeclID SemaDC,
1415
19.5k
                                 serialization::GlobalDeclID LexicalDC) {
1416
19.5k
    assert(D);
1417
19.5k
    PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1418
19.5k
    PendingDeclContextInfos.push_back(Info);
1419
19.5k
  }
1420
1421
  /// Produce an error diagnostic and return true.
1422
  ///
1423
  /// This routine should only be used for fatal errors that have to
1424
  /// do with non-routine failures (e.g., corrupted AST file).
1425
  void Error(StringRef Msg) const;
1426
  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1427
             StringRef Arg2 = StringRef()) const;
1428
1429
public:
1430
  /// Load the AST file and validate its contents against the given
1431
  /// Preprocessor.
1432
  ///
1433
  /// \param PP the preprocessor associated with the context in which this
1434
  /// precompiled header will be loaded.
1435
  ///
1436
  /// \param Context the AST context that this precompiled header will be
1437
  /// loaded into, if any.
1438
  ///
1439
  /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1440
  /// creating modules.
1441
  ///
1442
  /// \param Extensions the list of module file extensions that can be loaded
1443
  /// from the AST files.
1444
  ///
1445
  /// \param isysroot If non-NULL, the system include path specified by the
1446
  /// user. This is only used with relocatable PCH files. If non-NULL,
1447
  /// a relocatable PCH file will use the default path "/".
1448
  ///
1449
  /// \param DisableValidation If true, the AST reader will suppress most
1450
  /// of its regular consistency checking, allowing the use of precompiled
1451
  /// headers that cannot be determined to be compatible.
1452
  ///
1453
  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1454
  /// AST file the was created out of an AST with compiler errors,
1455
  /// otherwise it will reject it.
1456
  ///
1457
  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1458
  /// for configuration differences between the AST file and the invocation.
1459
  ///
1460
  /// \param ValidateSystemInputs If true, the AST reader will validate
1461
  /// system input files in addition to user input files. This is only
1462
  /// meaningful if \p DisableValidation is false.
1463
  ///
1464
  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1465
  /// the global module index.
1466
  ///
1467
  /// \param ReadTimer If non-null, a timer used to track the time spent
1468
  /// deserializing.
1469
  ASTReader(Preprocessor &PP, ASTContext *Context,
1470
            const PCHContainerReader &PCHContainerRdr,
1471
            ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1472
            StringRef isysroot = "", bool DisableValidation = false,
1473
            bool AllowASTWithCompilerErrors = false,
1474
            bool AllowConfigurationMismatch = false,
1475
            bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1476
            std::unique_ptr<llvm::Timer> ReadTimer = {});
1477
  ASTReader(const ASTReader &) = delete;
1478
  ASTReader &operator=(const ASTReader &) = delete;
1479
  ~ASTReader() override;
1480
1481
122k
  SourceManager &getSourceManager() const { return SourceMgr; }
1482
14.9k
  FileManager &getFileManager() const { return FileMgr; }
1483
2
  DiagnosticsEngine &getDiags() const { return Diags; }
1484
1485
  /// Flags that indicate what kind of AST loading failures the client
1486
  /// of the AST reader can directly handle.
1487
  ///
1488
  /// When a client states that it can handle a particular kind of failure,
1489
  /// the AST reader will not emit errors when producing that kind of failure.
1490
  enum LoadFailureCapabilities {
1491
    /// The client can't handle any AST loading failures.
1492
    ARR_None = 0,
1493
1494
    /// The client can handle an AST file that cannot load because it
1495
    /// is missing.
1496
    ARR_Missing = 0x1,
1497
1498
    /// The client can handle an AST file that cannot load because it
1499
    /// is out-of-date relative to its input files.
1500
    ARR_OutOfDate = 0x2,
1501
1502
    /// The client can handle an AST file that cannot load because it
1503
    /// was built with a different version of Clang.
1504
    ARR_VersionMismatch = 0x4,
1505
1506
    /// The client can handle an AST file that cannot load because it's
1507
    /// compiled configuration doesn't match that of the context it was
1508
    /// loaded into.
1509
    ARR_ConfigurationMismatch = 0x8
1510
  };
1511
1512
  /// Load the AST file designated by the given file name.
1513
  ///
1514
  /// \param FileName The name of the AST file to load.
1515
  ///
1516
  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1517
  /// or preamble.
1518
  ///
1519
  /// \param ImportLoc the location where the module file will be considered as
1520
  /// imported from. For non-module AST types it should be invalid.
1521
  ///
1522
  /// \param ClientLoadCapabilities The set of client load-failure
1523
  /// capabilities, represented as a bitset of the enumerators of
1524
  /// LoadFailureCapabilities.
1525
  ///
1526
  /// \param Imported optional out-parameter to append the list of modules
1527
  /// that were imported by precompiled headers or any other non-module AST file
1528
  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1529
                        SourceLocation ImportLoc,
1530
                        unsigned ClientLoadCapabilities,
1531
                        SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1532
1533
  /// Make the entities in the given module and any of its (non-explicit)
1534
  /// submodules visible to name lookup.
1535
  ///
1536
  /// \param Mod The module whose names should be made visible.
1537
  ///
1538
  /// \param NameVisibility The level of visibility to give the names in the
1539
  /// module.  Visibility can only be increased over time.
1540
  ///
1541
  /// \param ImportLoc The location at which the import occurs.
1542
  void makeModuleVisible(Module *Mod,
1543
                         Module::NameVisibilityKind NameVisibility,
1544
                         SourceLocation ImportLoc);
1545
1546
  /// Make the names within this set of hidden names visible.
1547
  void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1548
1549
  /// Note that MergedDef is a redefinition of the canonical definition
1550
  /// Def, so Def should be visible whenever MergedDef is.
1551
  void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1552
1553
  /// Take the AST callbacks listener.
1554
764
  std::unique_ptr<ASTReaderListener> takeListener() {
1555
764
    return std::move(Listener);
1556
764
  }
1557
1558
  /// Set the AST callbacks listener.
1559
886
  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1560
886
    this->Listener = std::move(Listener);
1561
886
  }
1562
1563
  /// Add an AST callback listener.
1564
  ///
1565
  /// Takes ownership of \p L.
1566
77
  void addListener(std::unique_ptr<ASTReaderListener> L) {
1567
77
    if (Listener)
1568
77
      L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1569
77
                                                      std::move(Listener));
1570
77
    Listener = std::move(L);
1571
77
  }
1572
1573
  /// RAII object to temporarily add an AST callback listener.
1574
  class ListenerScope {
1575
    ASTReader &Reader;
1576
    bool Chained = false;
1577
1578
  public:
1579
    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1580
382
        : Reader(Reader) {
1581
382
      auto Old = Reader.takeListener();
1582
382
      if (Old) {
1583
382
        Chained = true;
1584
382
        L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1585
382
                                                        std::move(Old));
1586
382
      }
1587
382
      Reader.setListener(std::move(L));
1588
382
    }
1589
1590
382
    ~ListenerScope() {
1591
382
      auto New = Reader.takeListener();
1592
382
      if (Chained)
1593
382
        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1594
382
                               ->takeSecond());
1595
382
    }
1596
  };
1597
1598
  /// Set the AST deserialization listener.
1599
  void setDeserializationListener(ASTDeserializationListener *Listener,
1600
                                  bool TakeOwnership = false);
1601
1602
  /// Get the AST deserialization listener.
1603
0
  ASTDeserializationListener *getDeserializationListener() {
1604
0
    return DeserializationListener;
1605
0
  }
1606
1607
  /// Determine whether this AST reader has a global index.
1608
1.86k
  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1609
1610
  /// Return global module index.
1611
3
  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1612
1613
  /// Reset reader for a reload try.
1614
2
  void resetForReload() { TriedLoadingGlobalIndex = false; }
1615
1616
  /// Attempts to load the global index.
1617
  ///
1618
  /// \returns true if loading the global index has failed for any reason.
1619
  bool loadGlobalIndex();
1620
1621
  /// Determine whether we tried to load the global index, but failed,
1622
  /// e.g., because it is out-of-date or does not exist.
1623
  bool isGlobalIndexUnavailable() const;
1624
  
1625
  /// Initializes the ASTContext
1626
  void InitializeContext();
1627
1628
  /// Update the state of Sema after loading some additional modules.
1629
  void UpdateSema();
1630
1631
  /// Add in-memory (virtual file) buffer.
1632
  void addInMemoryBuffer(StringRef &FileName,
1633
65
                         std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1634
65
    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1635
65
  }
1636
1637
  /// Finalizes the AST reader's state before writing an AST file to
1638
  /// disk.
1639
  ///
1640
  /// This operation may undo temporary state in the AST that should not be
1641
  /// emitted.
1642
  void finalizeForWriting();
1643
1644
  /// Retrieve the module manager.
1645
5.09k
  ModuleManager &getModuleManager() { return ModuleMgr; }
1646
1647
  /// Retrieve the preprocessor.
1648
435k
  Preprocessor &getPreprocessor() const { return PP; }
1649
1650
  /// Retrieve the name of the original source file name for the primary
1651
  /// module file.
1652
121
  StringRef getOriginalSourceFile() {
1653
121
    return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 
1654
121
  }
1655
1656
  /// Retrieve the name of the original source file name directly from
1657
  /// the AST file, without actually loading the AST file.
1658
  static std::string
1659
  getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1660
                        const PCHContainerReader &PCHContainerRdr,
1661
                        DiagnosticsEngine &Diags);
1662
1663
  /// Read the control block for the named AST file.
1664
  ///
1665
  /// \returns true if an error occurred, false otherwise.
1666
  static bool
1667
  readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1668
                          const PCHContainerReader &PCHContainerRdr,
1669
                          bool FindModuleFileExtensions,
1670
                          ASTReaderListener &Listener,
1671
                          bool ValidateDiagnosticOptions);
1672
1673
  /// Determine whether the given AST file is acceptable to load into a
1674
  /// translation unit with the given language and target options.
1675
  static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1676
                                  const PCHContainerReader &PCHContainerRdr,
1677
                                  const LangOptions &LangOpts,
1678
                                  const TargetOptions &TargetOpts,
1679
                                  const PreprocessorOptions &PPOpts,
1680
                                  StringRef ExistingModuleCachePath);
1681
1682
  /// Returns the suggested contents of the predefines buffer,
1683
  /// which contains a (typically-empty) subset of the predefines
1684
  /// build prior to including the precompiled header.
1685
2.31k
  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1686
1687
  /// Read a preallocated preprocessed entity from the external source.
1688
  ///
1689
  /// \returns null if an error occurred that prevented the preprocessed
1690
  /// entity from being loaded.
1691
  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1692
1693
  /// Returns a pair of [Begin, End) indices of preallocated
1694
  /// preprocessed entities that \p Range encompasses.
1695
  std::pair<unsigned, unsigned>
1696
      findPreprocessedEntitiesInRange(SourceRange Range) override;
1697
1698
  /// Optionally returns true or false if the preallocated preprocessed
1699
  /// entity with index \p Index came from file \p FID.
1700
  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1701
                                              FileID FID) override;
1702
1703
  /// Read a preallocated skipped range from the external source.
1704
  SourceRange ReadSkippedRange(unsigned Index) override;
1705
1706
  /// Read the header file information for the given file entry.
1707
  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1708
1709
  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1710
1711
  /// Returns the number of source locations found in the chain.
1712
11.9k
  unsigned getTotalNumSLocs() const {
1713
11.9k
    return TotalNumSLocEntries;
1714
11.9k
  }
1715
1716
  /// Returns the number of identifiers found in the chain.
1717
13.1k
  unsigned getTotalNumIdentifiers() const {
1718
13.1k
    return static_cast<unsigned>(IdentifiersLoaded.size());
1719
13.1k
  }
1720
1721
  /// Returns the number of macros found in the chain.
1722
11.7k
  unsigned getTotalNumMacros() const {
1723
11.7k
    return static_cast<unsigned>(MacrosLoaded.size());
1724
11.7k
  }
1725
1726
  /// Returns the number of types found in the chain.
1727
13.9k
  unsigned getTotalNumTypes() const {
1728
13.9k
    return static_cast<unsigned>(TypesLoaded.size());
1729
13.9k
  }
1730
1731
  /// Returns the number of declarations found in the chain.
1732
13.8k
  unsigned getTotalNumDecls() const {
1733
13.8k
    return static_cast<unsigned>(DeclsLoaded.size());
1734
13.8k
  }
1735
1736
  /// Returns the number of submodules known.
1737
9.04k
  unsigned getTotalNumSubmodules() const {
1738
9.04k
    return static_cast<unsigned>(SubmodulesLoaded.size());
1739
9.04k
  }
1740
  
1741
  /// Returns the number of selectors found in the chain.
1742
2.89k
  unsigned getTotalNumSelectors() const {
1743
2.89k
    return static_cast<unsigned>(SelectorsLoaded.size());
1744
2.89k
  }
1745
1746
  /// Returns the number of preprocessed entities known to the AST
1747
  /// reader.
1748
457
  unsigned getTotalNumPreprocessedEntities() const {
1749
457
    unsigned Result = 0;
1750
457
    for (const auto &M : ModuleMgr)
1751
470
      Result += M.NumPreprocessedEntities;
1752
457
    return Result;
1753
457
  }
1754
1755
  /// Reads a TemplateArgumentLocInfo appropriate for the
1756
  /// given TemplateArgument kind.
1757
  TemplateArgumentLocInfo
1758
  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1759
                             const RecordData &Record, unsigned &Idx);
1760
1761
  /// Reads a TemplateArgumentLoc.
1762
  TemplateArgumentLoc
1763
  ReadTemplateArgumentLoc(ModuleFile &F,
1764
                          const RecordData &Record, unsigned &Idx);
1765
1766
  const ASTTemplateArgumentListInfo*
1767
  ReadASTTemplateArgumentListInfo(ModuleFile &F,
1768
                                  const RecordData &Record, unsigned &Index);
1769
1770
  /// Reads a declarator info from the given record.
1771
  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1772
                                    const RecordData &Record, unsigned &Idx);
1773
1774
  /// Raad the type locations for the given TInfo.
1775
  void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
1776
                   TypeLoc TL);
1777
1778
  /// Resolve a type ID into a type, potentially building a new
1779
  /// type.
1780
  QualType GetType(serialization::TypeID ID);
1781
1782
  /// Resolve a local type ID within a given AST file into a type.
1783
  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1784
1785
  /// Map a local type ID within a given AST file into a global type ID.
1786
  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1787
1788
  /// Read a type from the current position in the given record, which
1789
  /// was read from the given AST file.
1790
946k
  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1791
946k
    if (Idx >= Record.size())
1792
0
      return {};
1793
946k
1794
946k
    return getLocalType(F, Record[Idx++]);
1795
946k
  }
1796
1797
  /// Map from a local declaration ID within a given module to a
1798
  /// global declaration ID.
1799
  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1800
                                      serialization::LocalDeclID LocalID) const;
1801
1802
  /// Returns true if global DeclID \p ID originated from module \p M.
1803
  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1804
1805
  /// Retrieve the module file that owns the given declaration, or NULL
1806
  /// if the declaration is not from a module file.
1807
  ModuleFile *getOwningModuleFile(const Decl *D);
1808
1809
  /// Get the best name we know for the module that owns the given
1810
  /// declaration, or an empty string if the declaration is not from a module.
1811
  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1812
1813
  /// Returns the source location for the decl \p ID.
1814
  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1815
1816
  /// Resolve a declaration ID into a declaration, potentially
1817
  /// building a new declaration.
1818
  Decl *GetDecl(serialization::DeclID ID);
1819
  Decl *GetExternalDecl(uint32_t ID) override;
1820
1821
  /// Resolve a declaration ID into a declaration. Return 0 if it's not
1822
  /// been loaded yet.
1823
  Decl *GetExistingDecl(serialization::DeclID ID);
1824
1825
  /// Reads a declaration with the given local ID in the given module.
1826
33.1k
  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1827
33.1k
    return GetDecl(getGlobalDeclID(F, LocalID));
1828
33.1k
  }
1829
1830
  /// Reads a declaration with the given local ID in the given module.
1831
  ///
1832
  /// \returns The requested declaration, casted to the given return type.
1833
  template<typename T>
1834
83
  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1835
83
    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1836
83
  }
1837
1838
  /// Map a global declaration ID into the declaration ID used to 
1839
  /// refer to this declaration within the given module fule.
1840
  ///
1841
  /// \returns the global ID of the given declaration as known in the given
1842
  /// module file.
1843
  serialization::DeclID 
1844
  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1845
                                  serialization::DeclID GlobalID);
1846
  
1847
  /// Reads a declaration ID from the given position in a record in the
1848
  /// given module.
1849
  ///
1850
  /// \returns The declaration ID read from the record, adjusted to a global ID.
1851
  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1852
                                   unsigned &Idx);
1853
1854
  /// Reads a declaration from the given position in a record in the
1855
  /// given module.
1856
44.0k
  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1857
44.0k
    return GetDecl(ReadDeclID(F, R, I));
1858
44.0k
  }
1859
1860
  /// Reads a declaration from the given position in a record in the
1861
  /// given module.
1862
  ///
1863
  /// \returns The declaration read from this location, casted to the given
1864
  /// result type.
1865
  template<typename T>
1866
872k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
872k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
872k
  }
clang::UnresolvedUsingTypenameDecl* clang::ASTReader::ReadDeclAs<clang::UnresolvedUsingTypenameDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
1
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
1
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
1
  }
clang::TypedefNameDecl* clang::ASTReader::ReadDeclAs<clang::TypedefNameDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
12.3k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
12.3k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
12.3k
  }
clang::RecordDecl* clang::ASTReader::ReadDeclAs<clang::RecordDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
69.9k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
69.9k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
69.9k
  }
clang::EnumDecl* clang::ASTReader::ReadDeclAs<clang::EnumDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
649
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
649
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
649
  }
clang::TagDecl* clang::ASTReader::ReadDeclAs<clang::TagDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
1.07k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
1.07k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
1.07k
  }
clang::ObjCInterfaceDecl* clang::ASTReader::ReadDeclAs<clang::ObjCInterfaceDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
555
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
555
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
555
  }
clang::ObjCTypeParamDecl* clang::ASTReader::ReadDeclAs<clang::ObjCTypeParamDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
8
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
8
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
8
  }
clang::ObjCProtocolDecl* clang::ASTReader::ReadDeclAs<clang::ObjCProtocolDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
42
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
42
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
42
  }
clang::CXXRecordDecl* clang::ASTReader::ReadDeclAs<clang::CXXRecordDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
1.83k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
1.83k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
1.83k
  }
clang::TemplateTypeParmDecl* clang::ASTReader::ReadDeclAs<clang::TemplateTypeParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
6.39k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
6.39k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
6.39k
  }
clang::FunctionDecl* clang::ASTReader::ReadDeclAs<clang::FunctionDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
6.94k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
6.94k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
6.94k
  }
clang::ParmVarDecl* clang::ASTReader::ReadDeclAs<clang::ParmVarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
24.9k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
24.9k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
24.9k
  }
clang::TemplateDecl* clang::ASTReader::ReadDeclAs<clang::TemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
9.45k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
9.45k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
9.45k
  }
clang::NamedDecl* clang::ASTReader::ReadDeclAs<clang::NamedDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
13.7k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
13.7k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
13.7k
  }
clang::TemplateTemplateParmDecl* clang::ASTReader::ReadDeclAs<clang::TemplateTemplateParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
8
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
8
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
8
  }
clang::ValueDecl* clang::ASTReader::ReadDeclAs<clang::ValueDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
140k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
140k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
140k
  }
clang::FieldDecl* clang::ASTReader::ReadDeclAs<clang::FieldDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
9.29k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
9.29k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
9.29k
  }
clang::IndirectFieldDecl* clang::ASTReader::ReadDeclAs<clang::IndirectFieldDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
2
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
2
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
2
  }
clang::NamespaceDecl* clang::ASTReader::ReadDeclAs<clang::NamespaceDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
299
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
299
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
299
  }
clang::NamespaceAliasDecl* clang::ASTReader::ReadDeclAs<clang::NamespaceAliasDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
9
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
9
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
9
  }
clang::CXXDestructorDecl* clang::ASTReader::ReadDeclAs<clang::CXXDestructorDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
1.10k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
1.10k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
1.10k
  }
clang::DeclContext* clang::ASTReader::ReadDeclAs<clang::DeclContext>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
435k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
435k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
435k
  }
clang::TypeAliasTemplateDecl* clang::ASTReader::ReadDeclAs<clang::TypeAliasTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
178
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
178
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
178
  }
clang::FunctionTemplateDecl* clang::ASTReader::ReadDeclAs<clang::FunctionTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
3.66k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
3.66k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
3.66k
  }
clang::ImplicitParamDecl* clang::ASTReader::ReadDeclAs<clang::ImplicitParamDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
64.1k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
64.1k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
64.1k
  }
clang::ObjCMethodDecl* clang::ASTReader::ReadDeclAs<clang::ObjCMethodDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
158
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
158
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
158
  }
clang::ObjCIvarDecl* clang::ASTReader::ReadDeclAs<clang::ObjCIvarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
51
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
51
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
51
  }
clang::ObjCPropertyDecl* clang::ASTReader::ReadDeclAs<clang::ObjCPropertyDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
10
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
10
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
10
  }
clang::VarTemplateDecl* clang::ASTReader::ReadDeclAs<clang::VarTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
121
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
121
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
121
  }
clang::VarDecl* clang::ASTReader::ReadDeclAs<clang::VarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
34.2k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
34.2k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
34.2k
  }
clang::BindingDecl* clang::ASTReader::ReadDeclAs<clang::BindingDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
4
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
4
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
4
  }
clang::UsingShadowDecl* clang::ASTReader::ReadDeclAs<clang::UsingShadowDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
643
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
643
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
643
  }
clang::ConstructorUsingShadowDecl* clang::ASTReader::ReadDeclAs<clang::ConstructorUsingShadowDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
124
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
124
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
124
  }
clang::ClassTemplateDecl* clang::ASTReader::ReadDeclAs<clang::ClassTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
6.76k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
6.76k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
6.76k
  }
clang::CXXMethodDecl* clang::ASTReader::ReadDeclAs<clang::CXXMethodDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
16
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
16
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
16
  }
clang::CXXConstructorDecl* clang::ASTReader::ReadDeclAs<clang::CXXConstructorDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
4.92k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
4.92k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
4.92k
  }
clang::RedeclarableTemplateDecl* clang::ASTReader::ReadDeclAs<clang::RedeclarableTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
3.56k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
3.56k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
3.56k
  }
clang::ClassTemplatePartialSpecializationDecl* clang::ASTReader::ReadDeclAs<clang::ClassTemplatePartialSpecializationDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
160
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
160
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
160
  }
clang::VarTemplatePartialSpecializationDecl* clang::ASTReader::ReadDeclAs<clang::VarTemplatePartialSpecializationDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
10
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
10
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
10
  }
clang::LabelDecl* clang::ASTReader::ReadDeclAs<clang::LabelDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
8
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
8
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
8
  }
clang::CapturedDecl* clang::ASTReader::ReadDeclAs<clang::CapturedDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
18.8k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
18.8k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
18.8k
  }
clang::BlockDecl* clang::ASTReader::ReadDeclAs<clang::BlockDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
10
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
10
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
10
  }
clang::NonTypeTemplateParmDecl* clang::ASTReader::ReadDeclAs<clang::NonTypeTemplateParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
346
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
346
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
346
  }
clang::MSPropertyDecl* clang::ASTReader::ReadDeclAs<clang::MSPropertyDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1866
22
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1867
22
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1868
22
  }
1869
1870
  /// If any redeclarations of \p D have been imported since it was
1871
  /// last checked, this digs out those redeclarations and adds them to the
1872
  /// redeclaration chain for \p D.
1873
  void CompleteRedeclChain(const Decl *D) override;
1874
1875
  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1876
1877
  /// Resolve the offset of a statement into a statement.
1878
  ///
1879
  /// This operation will read a new statement from the external
1880
  /// source each time it is called, and is meant to be used via a
1881
  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1882
  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1883
1884
  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1885
  /// specified cursor.  Read the abbreviations that are at the top of the block
1886
  /// and then leave the cursor pointing into the block.
1887
  static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1888
1889
  /// Finds all the visible declarations with a given name.
1890
  /// The current implementation of this method just loads the entire
1891
  /// lookup table as unmaterialized references.
1892
  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1893
                                      DeclarationName Name) override;
1894
1895
  /// Read all of the declarations lexically stored in a
1896
  /// declaration context.
1897
  ///
1898
  /// \param DC The declaration context whose declarations will be
1899
  /// read.
1900
  ///
1901
  /// \param IsKindWeWant A predicate indicating which declaration kinds
1902
  /// we are interested in.
1903
  ///
1904
  /// \param Decls Vector that will contain the declarations loaded
1905
  /// from the external source. The caller is responsible for merging
1906
  /// these declarations with any declarations already stored in the
1907
  /// declaration context.
1908
  void
1909
  FindExternalLexicalDecls(const DeclContext *DC,
1910
                           llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1911
                           SmallVectorImpl<Decl *> &Decls) override;
1912
1913
  /// Get the decls that are contained in a file in the Offset/Length
1914
  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1915
  /// a range.
1916
  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1917
                           SmallVectorImpl<Decl *> &Decls) override;
1918
1919
  /// Notify ASTReader that we started deserialization of
1920
  /// a decl or type so until FinishedDeserializing is called there may be
1921
  /// decls that are initializing. Must be paired with FinishedDeserializing.
1922
  void StartedDeserializing() override;
1923
1924
  /// Notify ASTReader that we finished the deserialization of
1925
  /// a decl or type. Must be paired with StartedDeserializing.
1926
  void FinishedDeserializing() override;
1927
1928
  /// Function that will be invoked when we begin parsing a new
1929
  /// translation unit involving this external AST source.
1930
  ///
1931
  /// This function will provide all of the external definitions to
1932
  /// the ASTConsumer.
1933
  void StartTranslationUnit(ASTConsumer *Consumer) override;
1934
1935
  /// Print some statistics about AST usage.
1936
  void PrintStats() override;
1937
1938
  /// Dump information about the AST reader to standard error.
1939
  void dump();
1940
1941
  /// Return the amount of memory used by memory buffers, breaking down
1942
  /// by heap-backed versus mmap'ed memory.
1943
  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1944
1945
  /// Initialize the semantic source with the Sema instance
1946
  /// being used to perform semantic analysis on the abstract syntax
1947
  /// tree.
1948
  void InitializeSema(Sema &S) override;
1949
1950
  /// Inform the semantic consumer that Sema is no longer available.
1951
4.75k
  void ForgetSema() override { SemaObj = nullptr; }
1952
1953
  /// Retrieve the IdentifierInfo for the named identifier.
1954
  ///
1955
  /// This routine builds a new IdentifierInfo for the given identifier. If any
1956
  /// declarations with this name are visible from translation unit scope, their
1957
  /// declarations will be deserialized and introduced into the declaration
1958
  /// chain of the identifier.
1959
  IdentifierInfo *get(StringRef Name) override;
1960
1961
  /// Retrieve an iterator into the set of all identifiers
1962
  /// in all loaded AST files.
1963
  IdentifierIterator *getIdentifiers() override;
1964
1965
  /// Load the contents of the global method pool for a given
1966
  /// selector.
1967
  void ReadMethodPool(Selector Sel) override;
1968
1969
  /// Load the contents of the global method pool for a given
1970
  /// selector if necessary.
1971
  void updateOutOfDateSelector(Selector Sel) override;
1972
1973
  /// Load the set of namespaces that are known to the external source,
1974
  /// which will be used during typo correction.
1975
  void ReadKnownNamespaces(
1976
                         SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1977
1978
  void ReadUndefinedButUsed(
1979
      llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1980
1981
  void ReadMismatchingDeleteExpressions(llvm::MapVector<
1982
      FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1983
                                            Exprs) override;
1984
1985
  void ReadTentativeDefinitions(
1986
                            SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1987
1988
  void ReadUnusedFileScopedDecls(
1989
                       SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1990
1991
  void ReadDelegatingConstructors(
1992
                         SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1993
1994
  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1995
1996
  void ReadUnusedLocalTypedefNameCandidates(
1997
      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
1998
1999
  void ReadReferencedSelectors(
2000
           SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2001
2002
  void ReadWeakUndeclaredIdentifiers(
2003
           SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
2004
2005
  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
2006
2007
  void ReadPendingInstantiations(
2008
                  SmallVectorImpl<std::pair<ValueDecl *,
2009
                                            SourceLocation>> &Pending) override;
2010
2011
  void ReadLateParsedTemplates(
2012
      llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2013
          &LPTMap) override;
2014
2015
  /// Load a selector from disk, registering its ID if it exists.
2016
  void LoadSelector(Selector Sel);
2017
2018
  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2019
  void SetGloballyVisibleDecls(IdentifierInfo *II,
2020
                               const SmallVectorImpl<uint32_t> &DeclIDs,
2021
                               SmallVectorImpl<Decl *> *Decls = nullptr);
2022
2023
  /// Report a diagnostic.
2024
  DiagnosticBuilder Diag(unsigned DiagID) const;
2025
2026
  /// Report a diagnostic.
2027
  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2028
2029
  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2030
2031
  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2032
207k
                                    unsigned &Idx) {
2033
207k
    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2034
207k
  }
2035
2036
65
  IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2037
65
    // Note that we are loading an identifier.
2038
65
    Deserializing AnIdentifier(this);
2039
65
2040
65
    return DecodeIdentifierInfo(ID);
2041
65
  }
2042
2043
  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2044
2045
  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2046
                                                    unsigned LocalID);
2047
2048
  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2049
2050
  /// Retrieve the macro with the given ID.
2051
  MacroInfo *getMacro(serialization::MacroID ID);
2052
2053
  /// Retrieve the global macro ID corresponding to the given local
2054
  /// ID within the given module file.
2055
  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2056
2057
  /// Read the source location entry with index ID.
2058
  bool ReadSLocEntry(int ID) override;
2059
2060
  /// Retrieve the module import location and module name for the
2061
  /// given source manager entry ID.
2062
  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2063
2064
  /// Retrieve the global submodule ID given a module and its local ID
2065
  /// number.
2066
  serialization::SubmoduleID 
2067
  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2068
2069
  /// Retrieve the submodule that corresponds to a global submodule ID.
2070
  ///
2071
  Module *getSubmodule(serialization::SubmoduleID GlobalID);
2072
2073
  /// Retrieve the module that corresponds to the given module ID.
2074
  ///
2075
  /// Note: overrides method in ExternalASTSource
2076
  Module *getModule(unsigned ID) override;
2077
2078
  bool DeclIsFromPCHWithObjectFile(const Decl *D) override;
2079
2080
  /// Retrieve the module file with a given local ID within the specified
2081
  /// ModuleFile.
2082
  ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2083
2084
  /// Get an ID for the given module file.
2085
  unsigned getModuleFileID(ModuleFile *M);
2086
2087
  /// Return a descriptor for the corresponding module.
2088
  llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2089
2090
  ExtKind hasExternalDefinitions(const Decl *D) override;
2091
2092
  /// Retrieve a selector from the given module with its local ID
2093
  /// number.
2094
  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2095
2096
  Selector DecodeSelector(serialization::SelectorID Idx);
2097
2098
  Selector GetExternalSelector(serialization::SelectorID ID) override;
2099
  uint32_t GetNumExternalSelectors() override;
2100
2101
445
  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2102
445
    return getLocalSelector(M, Record[Idx++]);
2103
445
  }
2104
2105
  /// Retrieve the global selector ID that corresponds to this
2106
  /// the local selector ID in a given module.
2107
  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2108
                                                unsigned LocalID) const;
2109
2110
  /// Read a declaration name.
2111
  DeclarationName ReadDeclarationName(ModuleFile &F,
2112
                                      const RecordData &Record, unsigned &Idx);
2113
  void ReadDeclarationNameLoc(ModuleFile &F,
2114
                              DeclarationNameLoc &DNLoc, DeclarationName Name,
2115
                              const RecordData &Record, unsigned &Idx);
2116
  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2117
                               const RecordData &Record, unsigned &Idx);
2118
2119
  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2120
                         const RecordData &Record, unsigned &Idx);
2121
2122
  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2123
                                               const RecordData &Record,
2124
                                               unsigned &Idx);
2125
2126
  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2127
                                                    const RecordData &Record,
2128
                                                    unsigned &Idx);
2129
2130
  /// Read a template name.
2131
  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2132
                                unsigned &Idx);
2133
2134
  /// Read a template argument.
2135
  TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2136
                                        unsigned &Idx,
2137
                                        bool Canonicalize = false);
2138
2139
  /// Read a template parameter list.
2140
  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2141
                                                   const RecordData &Record,
2142
                                                   unsigned &Idx);
2143
2144
  /// Read a template argument array.
2145
  void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2146
                                ModuleFile &F, const RecordData &Record,
2147
                                unsigned &Idx, bool Canonicalize = false);
2148
2149
  /// Read a UnresolvedSet structure.
2150
  void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2151
                         const RecordData &Record, unsigned &Idx);
2152
2153
  /// Read a C++ base specifier.
2154
  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2155
                                        const RecordData &Record,unsigned &Idx);
2156
2157
  /// Read a CXXCtorInitializer array.
2158
  CXXCtorInitializer **
2159
  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2160
                          unsigned &Idx);
2161
2162
  /// Read the contents of a CXXCtorInitializer array.
2163
  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2164
2165
  /// Read a source location from raw form and return it in its
2166
  /// originating module file's source location space.
2167
1.47M
  SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2168
1.47M
    return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2169
1.47M
  }
2170
2171
  /// Read a source location from raw form.
2172
1.47M
  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2173
1.47M
    SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2174
1.47M
    return TranslateSourceLocation(ModuleFile, Loc);
2175
1.47M
  }
2176
2177
  /// Translate a source location from another module file's source
2178
  /// location space into ours.
2179
  SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2180
1.82M
                                         SourceLocation Loc) const {
2181
1.82M
    if (!ModuleFile.ModuleOffsetMap.empty())
2182
0
      ReadModuleOffsetMap(ModuleFile);
2183
1.82M
    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2184
1.82M
               ModuleFile.SLocRemap.end() &&
2185
1.82M
           "Cannot find offset to remap.");
2186
1.82M
    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2187
1.82M
    return Loc.getLocWithOffset(Remap);
2188
1.82M
  }
2189
2190
  /// Read a source location.
2191
  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2192
                                    const RecordDataImpl &Record,
2193
1.44M
                                    unsigned &Idx) {
2194
1.44M
    return ReadSourceLocation(ModuleFile, Record[Idx++]);
2195
1.44M
  }
2196
2197
  /// Read a source range.
2198
  SourceRange ReadSourceRange(ModuleFile &F,
2199
                              const RecordData &Record, unsigned &Idx);
2200
2201
  /// Read an integral value
2202
  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2203
2204
  /// Read a signed integral value
2205
  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2206
2207
  /// Read a floating-point value
2208
  llvm::APFloat ReadAPFloat(const RecordData &Record,
2209
                            const llvm::fltSemantics &Sem, unsigned &Idx);
2210
2211
  // Read a string
2212
  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2213
2214
  // Skip a string
2215
5
  static void SkipString(const RecordData &Record, unsigned &Idx) {
2216
5
    Idx += Record[Idx] + 1;
2217
5
  }
2218
2219
  // Read a path
2220
  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2221
2222
  // Skip a path
2223
5
  static void SkipPath(const RecordData &Record, unsigned &Idx) {
2224
5
    SkipString(Record, Idx);
2225
5
  }
2226
2227
  /// Read a version tuple.
2228
  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2229
2230
  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2231
                                 unsigned &Idx);
2232
2233
  /// Reads attributes from the current stream position.
2234
  void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2235
2236
  /// Reads a statement.
2237
  Stmt *ReadStmt(ModuleFile &F);
2238
2239
  /// Reads an expression.
2240
  Expr *ReadExpr(ModuleFile &F);
2241
2242
  /// Reads a sub-statement operand during statement reading.
2243
644k
  Stmt *ReadSubStmt() {
2244
644k
    assert(ReadingKind == Read_Stmt &&
2245
644k
           "Should be called only during statement reading!");
2246
644k
    // Subexpressions are stored from last to first, so the next Stmt we need
2247
644k
    // is at the back of the stack.
2248
644k
    assert(!StmtStack.empty() && "Read too many sub-statements!");
2249
644k
    return StmtStack.pop_back_val();
2250
644k
  }
2251
2252
  /// Reads a sub-expression operand during statement reading.
2253
  Expr *ReadSubExpr();
2254
2255
  /// Reads a token out of a record.
2256
  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2257
2258
  /// Reads the macro record located at the given offset.
2259
  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2260
2261
  /// Determine the global preprocessed entity ID that corresponds to
2262
  /// the given local ID within the given module.
2263
  serialization::PreprocessedEntityID
2264
  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2265
2266
  /// Add a macro to deserialize its macro directive history.
2267
  ///
2268
  /// \param II The name of the macro.
2269
  /// \param M The module file.
2270
  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2271
  /// history.
2272
  void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2273
                       uint64_t MacroDirectivesOffset);
2274
2275
  /// Read the set of macros defined by this external macro source.
2276
  void ReadDefinedMacros() override;
2277
2278
  /// Update an out-of-date identifier.
2279
  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2280
2281
  /// Note that this identifier is up-to-date.
2282
  void markIdentifierUpToDate(IdentifierInfo *II);
2283
2284
  /// Load all external visible decls in the given DeclContext.
2285
  void completeVisibleDeclsMap(const DeclContext *DC) override;
2286
2287
  /// Retrieve the AST context that this AST reader supplements.
2288
4.63M
  ASTContext &getContext() {
2289
4.63M
    assert(ContextObj && "requested AST context when not loading AST");
2290
4.63M
    return *ContextObj;
2291
4.63M
  }
2292
2293
  // Contains the IDs for declarations that were requested before we have
2294
  // access to a Sema object.
2295
  SmallVector<uint64_t, 16> PreloadedDeclIDs;
2296
2297
  /// Retrieve the semantic analysis object used to analyze the
2298
  /// translation unit in which the precompiled header is being
2299
  /// imported.
2300
140
  Sema *getSema() { return SemaObj; }
2301
2302
  /// Get the identifier resolver used for name lookup / updates
2303
  /// in the translation unit scope. We have one of these even if we don't
2304
  /// have a Sema object.
2305
  IdentifierResolver &getIdResolver();
2306
2307
  /// Retrieve the identifier table associated with the
2308
  /// preprocessor.
2309
  IdentifierTable &getIdentifierTable();
2310
2311
  /// Record that the given ID maps to the given switch-case
2312
  /// statement.
2313
  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2314
2315
  /// Retrieve the switch-case statement with the given ID.
2316
  SwitchCase *getSwitchCaseWithID(unsigned ID);
2317
2318
  void ClearSwitchCaseIDs();
2319
2320
  /// Cursors for comments blocks.
2321
  SmallVector<std::pair<llvm::BitstreamCursor,
2322
                        serialization::ModuleFile *>, 8> CommentsCursors;
2323
2324
  /// Loads comments ranges.
2325
  void ReadComments() override;
2326
2327
  /// Visit all the input files of the given module file.
2328
  void visitInputFiles(serialization::ModuleFile &MF,
2329
                       bool IncludeSystem, bool Complain,
2330
          llvm::function_ref<void(const serialization::InputFile &IF,
2331
                                  bool isSystem)> Visitor);
2332
2333
  /// Visit all the top-level module maps loaded when building the given module
2334
  /// file.
2335
  void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2336
                               llvm::function_ref<
2337
                                   void(const FileEntry *)> Visitor);
2338
2339
155k
  bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2340
};
2341
2342
/// An object for streaming information from a record.
2343
class ASTRecordReader {
2344
  using ModuleFile = serialization::ModuleFile;
2345
2346
  ASTReader *Reader;
2347
  ModuleFile *F;
2348
  unsigned Idx = 0;
2349
  ASTReader::RecordData Record;
2350
2351
  using RecordData = ASTReader::RecordData;
2352
  using RecordDataImpl = ASTReader::RecordDataImpl;
2353
2354
public:
2355
  /// Construct an ASTRecordReader that uses the default encoding scheme.
2356
316k
  ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {}
2357
2358
  /// Reads a record with id AbbrevID from Cursor, resetting the
2359
  /// internal state.
2360
  unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID);
2361
2362
  /// Is this a module file for a module (rather than a PCH or similar).
2363
28
  bool isModule() const { return F->isModule(); }
2364
2365
  /// Retrieve the AST context that this AST reader supplements.
2366
99.2k
  ASTContext &getContext() { return Reader->getContext(); }
2367
2368
  /// The current position in this record.
2369
262k
  unsigned getIdx() const { return Idx; }
2370
2371
  /// The length of this record.
2372
262k
  size_t size() const { return Record.size(); }
2373
2374
  /// An arbitrary index in this record.
2375
670k
  const uint64_t &operator[](size_t N) { return Record[N]; }
2376
2377
  /// The last element in this record.
2378
298
  const uint64_t &back() const { return Record.back(); }
2379
2380
  /// Returns the current value in this record, and advances to the
2381
  /// next value.
2382
11.9M
  const uint64_t &readInt() { return Record[Idx++]; }
2383
2384
  /// Returns the current value in this record, without advancing.
2385
229
  const uint64_t &peekInt() { return Record[Idx]; }
2386
2387
  /// Skips the specified number of values.
2388
30.9k
  void skipInts(unsigned N) { Idx += N; }
2389
2390
  /// Retrieve the global submodule ID its local ID number.
2391
  serialization::SubmoduleID
2392
239k
  getGlobalSubmoduleID(unsigned LocalID) {
2393
239k
    return Reader->getGlobalSubmoduleID(*F, LocalID);
2394
239k
  }
2395
2396
  /// Retrieve the submodule that corresponds to a global submodule ID.
2397
149
  Module *getSubmodule(serialization::SubmoduleID GlobalID) {
2398
149
    return Reader->getSubmodule(GlobalID);
2399
149
  }
2400
2401
  /// Read the record that describes the lexical contents of a DC.
2402
31
  bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) {
2403
31
    return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset,
2404
31
                                                 DC);
2405
31
  }
2406
2407
  /// Read the record that describes the visible contents of a DC.
2408
  bool readVisibleDeclContextStorage(uint64_t Offset,
2409
                                     serialization::DeclID ID) {
2410
    return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset,
2411
                                                 ID);
2412
  }
2413
2414
  void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage,
2415
28
                         FunctionProtoType::ExceptionSpecInfo &ESI) {
2416
28
    return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2417
28
  }
2418
2419
  /// Get the global offset corresponding to a local offset.
2420
2.45k
  uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
2421
2.45k
    return Reader->getGlobalBitOffset(*F, LocalOffset);
2422
2.45k
  }
2423
2424
  /// Reads a statement.
2425
9
  Stmt *readStmt() { return Reader->ReadStmt(*F); }
2426
2427
  /// Reads an expression.
2428
54.5k
  Expr *readExpr() { return Reader->ReadExpr(*F); }
2429
2430
  /// Reads a sub-statement operand during statement reading.
2431
82.6k
  Stmt *readSubStmt() { return Reader->ReadSubStmt(); }
2432
2433
  /// Reads a sub-expression operand during statement reading.
2434
556k
  Expr *readSubExpr() { return Reader->ReadSubExpr(); }
2435
2436
  /// Reads a declaration with the given local ID in the given module.
2437
  ///
2438
  /// \returns The requested declaration, casted to the given return type.
2439
  template<typename T>
2440
0
  T *GetLocalDeclAs(uint32_t LocalID) {
2441
0
    return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2442
0
  }
Unexecuted instantiation: clang::FunctionDecl* clang::ASTRecordReader::GetLocalDeclAs<clang::FunctionDecl>(unsigned int)
Unexecuted instantiation: clang::NamedDecl* clang::ASTRecordReader::GetLocalDeclAs<clang::NamedDecl>(unsigned int)
2443
2444
  /// Reads a TemplateArgumentLocInfo appropriate for the
2445
  /// given TemplateArgument kind, advancing Idx.
2446
  TemplateArgumentLocInfo
2447
  getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
2448
    return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2449
  }
2450
2451
  /// Reads a TemplateArgumentLoc, advancing Idx.
2452
  TemplateArgumentLoc
2453
1.23k
  readTemplateArgumentLoc() {
2454
1.23k
    return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2455
1.23k
  }
2456
2457
  const ASTTemplateArgumentListInfo*
2458
162
  readASTTemplateArgumentListInfo() {
2459
162
    return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2460
162
  }
2461
2462
  /// Reads a declarator info from the given record, advancing Idx.
2463
15.5k
  TypeSourceInfo *getTypeSourceInfo() {
2464
15.5k
    return Reader->GetTypeSourceInfo(*F, Record, Idx);
2465
15.5k
  }
2466
2467
  /// Reads the location information for a type.
2468
92.5k
  void readTypeLoc(TypeLoc TL) {
2469
92.5k
    return Reader->ReadTypeLoc(*F, Record, Idx, TL);
2470
92.5k
  }
2471
2472
  /// Map a local type ID within a given AST file to a global type ID.
2473
66.4k
  serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
2474
66.4k
    return Reader->getGlobalTypeID(*F, LocalID);
2475
66.4k
  }
2476
2477
  /// Read a type from the current position in the record.
2478
787k
  QualType readType() {
2479
787k
    return Reader->readType(*F, Record, Idx);
2480
787k
  }
2481
2482
  /// Reads a declaration ID from the given position in this record.
2483
  ///
2484
  /// \returns The declaration ID read from the record, adjusted to a global ID.
2485
297k
  serialization::DeclID readDeclID() {
2486
297k
    return Reader->ReadDeclID(*F, Record, Idx);
2487
297k
  }
2488
2489
  /// Reads a declaration from the given position in a record in the
2490
  /// given module, advancing Idx.
2491
44.0k
  Decl *readDecl() {
2492
44.0k
    return Reader->ReadDecl(*F, Record, Idx);
2493
44.0k
  }
2494
2495
  /// Reads a declaration from the given position in the record,
2496
  /// advancing Idx.
2497
  ///
2498
  /// \returns The declaration read from this location, casted to the given
2499
  /// result type.
2500
  template<typename T>
2501
768k
  T *readDeclAs() {
2502
768k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
768k
  }
clang::DeclContext* clang::ASTRecordReader::readDeclAs<clang::DeclContext>()
Line
Count
Source
2501
435k
  T *readDeclAs() {
2502
435k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
435k
  }
clang::TypeAliasTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::TypeAliasTemplateDecl>()
Line
Count
Source
2501
178
  T *readDeclAs() {
2502
178
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
178
  }
clang::EnumDecl* clang::ASTRecordReader::readDeclAs<clang::EnumDecl>()
Line
Count
Source
2501
298
  T *readDeclAs() {
2502
298
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
298
  }
clang::FunctionTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::FunctionTemplateDecl>()
Line
Count
Source
2501
3.66k
  T *readDeclAs() {
2502
3.66k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
3.66k
  }
clang::FunctionDecl* clang::ASTRecordReader::readDeclAs<clang::FunctionDecl>()
Line
Count
Source
2501
4.04k
  T *readDeclAs() {
2502
4.04k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
4.04k
  }
clang::NamedDecl* clang::ASTRecordReader::readDeclAs<clang::NamedDecl>()
Line
Count
Source
2501
8.22k
  T *readDeclAs() {
2502
8.22k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
8.22k
  }
clang::ParmVarDecl* clang::ASTRecordReader::readDeclAs<clang::ParmVarDecl>()
Line
Count
Source
2501
14.4k
  T *readDeclAs() {
2502
14.4k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
14.4k
  }
clang::ImplicitParamDecl* clang::ASTRecordReader::readDeclAs<clang::ImplicitParamDecl>()
Line
Count
Source
2501
64.1k
  T *readDeclAs() {
2502
64.1k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
64.1k
  }
clang::ObjCMethodDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCMethodDecl>()
Line
Count
Source
2501
158
  T *readDeclAs() {
2502
158
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
158
  }
clang::ObjCTypeParamDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCTypeParamDecl>()
Line
Count
Source
2501
4
  T *readDeclAs() {
2502
4
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
4
  }
clang::ObjCProtocolDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCProtocolDecl>()
Line
Count
Source
2501
33
  T *readDeclAs() {
2502
33
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
33
  }
clang::ObjCInterfaceDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCInterfaceDecl>()
Line
Count
Source
2501
183
  T *readDeclAs() {
2502
183
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
183
  }
clang::ObjCIvarDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCIvarDecl>()
Line
Count
Source
2501
51
  T *readDeclAs() {
2502
51
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
51
  }
clang::ObjCPropertyDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCPropertyDecl>()
Line
Count
Source
2501
10
  T *readDeclAs() {
2502
10
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
10
  }
clang::FieldDecl* clang::ASTRecordReader::readDeclAs<clang::FieldDecl>()
Line
Count
Source
2501
7.95k
  T *readDeclAs() {
2502
7.95k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
7.95k
  }
clang::VarTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::VarTemplateDecl>()
Line
Count
Source
2501
121
  T *readDeclAs() {
2502
121
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
121
  }
clang::VarDecl* clang::ASTRecordReader::readDeclAs<clang::VarDecl>()
Line
Count
Source
2501
34.2k
  T *readDeclAs() {
2502
34.2k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
34.2k
  }
clang::BindingDecl* clang::ASTRecordReader::readDeclAs<clang::BindingDecl>()
Line
Count
Source
2501
4
  T *readDeclAs() {
2502
4
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
4
  }
clang::UsingShadowDecl* clang::ASTRecordReader::readDeclAs<clang::UsingShadowDecl>()
Line
Count
Source
2501
643
  T *readDeclAs() {
2502
643
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
643
  }
clang::ConstructorUsingShadowDecl* clang::ASTRecordReader::readDeclAs<clang::ConstructorUsingShadowDecl>()
Line
Count
Source
2501
124
  T *readDeclAs() {
2502
124
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
124
  }
clang::ClassTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::ClassTemplateDecl>()
Line
Count
Source
2501
6.76k
  T *readDeclAs() {
2502
6.76k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
6.76k
  }
clang::CXXRecordDecl* clang::ASTRecordReader::readDeclAs<clang::CXXRecordDecl>()
Line
Count
Source
2501
572
  T *readDeclAs() {
2502
572
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
572
  }
clang::CXXMethodDecl* clang::ASTRecordReader::readDeclAs<clang::CXXMethodDecl>()
Line
Count
Source
2501
16
  T *readDeclAs() {
2502
16
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
16
  }
clang::CXXConstructorDecl* clang::ASTRecordReader::readDeclAs<clang::CXXConstructorDecl>()
Line
Count
Source
2501
4.92k
  T *readDeclAs() {
2502
4.92k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
4.92k
  }
clang::RedeclarableTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::RedeclarableTemplateDecl>()
Line
Count
Source
2501
3.56k
  T *readDeclAs() {
2502
3.56k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
3.56k
  }
clang::ClassTemplatePartialSpecializationDecl* clang::ASTRecordReader::readDeclAs<clang::ClassTemplatePartialSpecializationDecl>()
Line
Count
Source
2501
160
  T *readDeclAs() {
2502
160
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
160
  }
clang::VarTemplatePartialSpecializationDecl* clang::ASTRecordReader::readDeclAs<clang::VarTemplatePartialSpecializationDecl>()
Line
Count
Source
2501
10
  T *readDeclAs() {
2502
10
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
10
  }
clang::NamespaceDecl* clang::ASTRecordReader::readDeclAs<clang::NamespaceDecl>()
Line
Count
Source
2501
18
  T *readDeclAs() {
2502
18
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
18
  }
clang::LabelDecl* clang::ASTRecordReader::readDeclAs<clang::LabelDecl>()
Line
Count
Source
2501
8
  T *readDeclAs() {
2502
8
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
8
  }
clang::CapturedDecl* clang::ASTRecordReader::readDeclAs<clang::CapturedDecl>()
Line
Count
Source
2501
18.8k
  T *readDeclAs() {
2502
18.8k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
18.8k
  }
clang::RecordDecl* clang::ASTRecordReader::readDeclAs<clang::RecordDecl>()
Line
Count
Source
2501
18.8k
  T *readDeclAs() {
2502
18.8k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
18.8k
  }
clang::BlockDecl* clang::ASTRecordReader::readDeclAs<clang::BlockDecl>()
Line
Count
Source
2501
10
  T *readDeclAs() {
2502
10
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
10
  }
clang::NonTypeTemplateParmDecl* clang::ASTRecordReader::readDeclAs<clang::NonTypeTemplateParmDecl>()
Line
Count
Source
2501
346
  T *readDeclAs() {
2502
346
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
346
  }
clang::MSPropertyDecl* clang::ASTRecordReader::readDeclAs<clang::MSPropertyDecl>()
Line
Count
Source
2501
22
  T *readDeclAs() {
2502
22
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
22
  }
clang::ValueDecl* clang::ASTRecordReader::readDeclAs<clang::ValueDecl>()
Line
Count
Source
2501
140k
  T *readDeclAs() {
2502
140k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2503
140k
  }
2504
2505
241
  IdentifierInfo *getIdentifierInfo() {
2506
241
    return Reader->GetIdentifierInfo(*F, Record, Idx);
2507
241
  }
2508
2509
  /// Read a selector from the Record, advancing Idx.
2510
3
  Selector readSelector() {
2511
3
    return Reader->ReadSelector(*F, Record, Idx);
2512
3
  }
2513
2514
  /// Read a declaration name, advancing Idx.
2515
216k
  DeclarationName readDeclarationName() {
2516
216k
    return Reader->ReadDeclarationName(*F, Record, Idx);
2517
216k
  }
2518
156k
  void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
2519
156k
    return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2520
156k
  }
2521
2.04k
  void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) {
2522
2.04k
    return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2523
2.04k
  }
2524
2525
556
  void readQualifierInfo(QualifierInfo &Info) {
2526
556
    return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2527
556
  }
2528
2529
  NestedNameSpecifier *readNestedNameSpecifier() {
2530
    return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2531
  }
2532
2533
2.73k
  NestedNameSpecifierLoc readNestedNameSpecifierLoc() {
2534
2.73k
    return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2535
2.73k
  }
2536
2537
  /// Read a template name, advancing Idx.
2538
  TemplateName readTemplateName() {
2539
    return Reader->ReadTemplateName(*F, Record, Idx);
2540
  }
2541
2542
  /// Read a template argument, advancing Idx.
2543
0
  TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2544
0
    return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2545
0
  }
2546
2547
  /// Read a template parameter list, advancing Idx.
2548
4.20k
  TemplateParameterList *readTemplateParameterList() {
2549
4.20k
    return Reader->ReadTemplateParameterList(*F, Record, Idx);
2550
4.20k
  }
2551
2552
  /// Read a template argument array, advancing Idx.
2553
  void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2554
5.16k
                                bool Canonicalize = false) {
2555
5.16k
    return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2556
5.16k
                                            Canonicalize);
2557
5.16k
  }
2558
2559
  /// Read a UnresolvedSet structure, advancing Idx.
2560
50.1k
  void readUnresolvedSet(LazyASTUnresolvedSet &Set) {
2561
50.1k
    return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2562
50.1k
  }
2563
2564
  /// Read a C++ base specifier, advancing Idx.
2565
570
  CXXBaseSpecifier readCXXBaseSpecifier() {
2566
570
    return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2567
570
  }
2568
2569
  /// Read a CXXCtorInitializer array, advancing Idx.
2570
  CXXCtorInitializer **readCXXCtorInitializers() {
2571
    return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2572
  }
2573
2574
1.10k
  CXXTemporary *readCXXTemporary() {
2575
1.10k
    return Reader->ReadCXXTemporary(*F, Record, Idx);
2576
1.10k
  }
2577
2578
  /// Read a source location, advancing Idx.
2579
807k
  SourceLocation readSourceLocation() {
2580
807k
    return Reader->ReadSourceLocation(*F, Record, Idx);
2581
807k
  }
2582
2583
  /// Read a source range, advancing Idx.
2584
79.3k
  SourceRange readSourceRange() {
2585
79.3k
    return Reader->ReadSourceRange(*F, Record, Idx);
2586
79.3k
  }
2587
2588
  /// Read an integral value, advancing Idx.
2589
69.0k
  llvm::APInt readAPInt() {
2590
69.0k
    return Reader->ReadAPInt(Record, Idx);
2591
69.0k
  }
2592
2593
  /// Read a signed integral value, advancing Idx.
2594
362
  llvm::APSInt readAPSInt() {
2595
362
    return Reader->ReadAPSInt(Record, Idx);
2596
362
  }
2597
2598
  /// Read a floating-point value, advancing Idx.
2599
927
  llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2600
927
    return Reader->ReadAPFloat(Record, Sem,Idx);
2601
927
  }
2602
2603
  /// Read a string, advancing Idx.
2604
57
  std::string readString() {
2605
57
    return Reader->ReadString(Record, Idx);
2606
57
  }
2607
2608
  /// Read a path, advancing Idx.
2609
  std::string readPath() {
2610
    return Reader->ReadPath(*F, Record, Idx);
2611
  }
2612
2613
  /// Read a version tuple, advancing Idx.
2614
12
  VersionTuple readVersionTuple() {
2615
12
    return ASTReader::ReadVersionTuple(Record, Idx);
2616
12
  }
2617
2618
  /// Reads attributes from the current stream position, advancing Idx.
2619
39.0k
  void readAttributes(AttrVec &Attrs) {
2620
39.0k
    return Reader->ReadAttributes(*this, Attrs);
2621
39.0k
  }
2622
2623
  /// Reads a token out of a record, advancing Idx.
2624
0
  Token readToken() {
2625
0
    return Reader->ReadToken(*F, Record, Idx);
2626
0
  }
2627
2628
27
  void recordSwitchCaseID(SwitchCase *SC, unsigned ID) {
2629
27
    Reader->RecordSwitchCaseID(SC, ID);
2630
27
  }
2631
2632
  /// Retrieve the switch-case statement with the given ID.
2633
27
  SwitchCase *getSwitchCaseWithID(unsigned ID) {
2634
27
    return Reader->getSwitchCaseWithID(ID);
2635
27
  }
2636
};
2637
2638
/// Helper class that saves the current stream position and
2639
/// then restores it when destroyed.
2640
struct SavedStreamPosition {
2641
  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2642
587k
      : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {}
2643
2644
587k
  ~SavedStreamPosition() {
2645
587k
    Cursor.JumpToBit(Offset);
2646
587k
  }
2647
2648
private:
2649
  llvm::BitstreamCursor &Cursor;
2650
  uint64_t Offset;
2651
};
2652
2653
0
inline void PCHValidator::Error(const char *Msg) {
2654
0
  Reader.Error(Msg);
2655
0
}
2656
2657
} // namespace clang
2658
2659
#endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H