Coverage Report

Created: 2022-07-16 07:03

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