Coverage Report

Created: 2022-01-25 06:29

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