clang  3.9.0
ASTReader.cpp
Go to the documentation of this file.
1 //===-- ASTReader.cpp - AST File Reader ----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ASTReader class, which reads AST files.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "ASTCommon.h"
16 #include "ASTReaderInternals.h"
17 #include "clang/AST/ASTConsumer.h"
18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/DeclTemplate.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
25 #include "clang/AST/Type.h"
31 #include "clang/Basic/TargetInfo.h"
33 #include "clang/Basic/Version.h"
35 #include "clang/Frontend/Utils.h"
36 #include "clang/Lex/HeaderSearch.h"
38 #include "clang/Lex/MacroInfo.h"
40 #include "clang/Lex/Preprocessor.h"
42 #include "clang/Sema/Scope.h"
43 #include "clang/Sema/Sema.h"
48 #include "llvm/ADT/Hashing.h"
49 #include "llvm/ADT/StringExtras.h"
50 #include "llvm/Bitcode/BitstreamReader.h"
51 #include "llvm/Support/Compression.h"
52 #include "llvm/Support/ErrorHandling.h"
53 #include "llvm/Support/FileSystem.h"
54 #include "llvm/Support/MemoryBuffer.h"
55 #include "llvm/Support/Path.h"
56 #include "llvm/Support/SaveAndRestore.h"
57 #include "llvm/Support/raw_ostream.h"
58 #include <algorithm>
59 #include <cstdio>
60 #include <iterator>
61 #include <system_error>
62 
63 using namespace clang;
64 using namespace clang::serialization;
65 using namespace clang::serialization::reader;
66 using llvm::BitstreamCursor;
67 
68 
69 //===----------------------------------------------------------------------===//
70 // ChainedASTReaderListener implementation
71 //===----------------------------------------------------------------------===//
72 
73 bool
75  return First->ReadFullVersionInformation(FullVersion) ||
76  Second->ReadFullVersionInformation(FullVersion);
77 }
78 void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) {
79  First->ReadModuleName(ModuleName);
80  Second->ReadModuleName(ModuleName);
81 }
82 void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) {
83  First->ReadModuleMapFile(ModuleMapPath);
84  Second->ReadModuleMapFile(ModuleMapPath);
85 }
86 bool
88  bool Complain,
89  bool AllowCompatibleDifferences) {
90  return First->ReadLanguageOptions(LangOpts, Complain,
91  AllowCompatibleDifferences) ||
92  Second->ReadLanguageOptions(LangOpts, Complain,
93  AllowCompatibleDifferences);
94 }
96  const TargetOptions &TargetOpts, bool Complain,
97  bool AllowCompatibleDifferences) {
98  return First->ReadTargetOptions(TargetOpts, Complain,
99  AllowCompatibleDifferences) ||
100  Second->ReadTargetOptions(TargetOpts, Complain,
101  AllowCompatibleDifferences);
102 }
104  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) {
105  return First->ReadDiagnosticOptions(DiagOpts, Complain) ||
106  Second->ReadDiagnosticOptions(DiagOpts, Complain);
107 }
108 bool
110  bool Complain) {
111  return First->ReadFileSystemOptions(FSOpts, Complain) ||
112  Second->ReadFileSystemOptions(FSOpts, Complain);
113 }
114 
116  const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath,
117  bool Complain) {
118  return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
119  Complain) ||
120  Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
121  Complain);
122 }
124  const PreprocessorOptions &PPOpts, bool Complain,
125  std::string &SuggestedPredefines) {
126  return First->ReadPreprocessorOptions(PPOpts, Complain,
127  SuggestedPredefines) ||
128  Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines);
129 }
131  unsigned Value) {
132  First->ReadCounter(M, Value);
133  Second->ReadCounter(M, Value);
134 }
136  return First->needsInputFileVisitation() ||
137  Second->needsInputFileVisitation();
138 }
140  return First->needsSystemInputFileVisitation() ||
141  Second->needsSystemInputFileVisitation();
142 }
144  ModuleKind Kind) {
145  First->visitModuleFile(Filename, Kind);
146  Second->visitModuleFile(Filename, Kind);
147 }
149  bool isSystem,
150  bool isOverridden,
151  bool isExplicitModule) {
152  bool Continue = false;
153  if (First->needsInputFileVisitation() &&
154  (!isSystem || First->needsSystemInputFileVisitation()))
155  Continue |= First->visitInputFile(Filename, isSystem, isOverridden,
156  isExplicitModule);
157  if (Second->needsInputFileVisitation() &&
158  (!isSystem || Second->needsSystemInputFileVisitation()))
159  Continue |= Second->visitInputFile(Filename, isSystem, isOverridden,
160  isExplicitModule);
161  return Continue;
162 }
163 
165  const ModuleFileExtensionMetadata &Metadata) {
166  First->readModuleFileExtension(Metadata);
167  Second->readModuleFileExtension(Metadata);
168 }
169 
170 //===----------------------------------------------------------------------===//
171 // PCH validator implementation
172 //===----------------------------------------------------------------------===//
173 
175 
176 /// \brief Compare the given set of language options against an existing set of
177 /// language options.
178 ///
179 /// \param Diags If non-NULL, diagnostics will be emitted via this engine.
180 /// \param AllowCompatibleDifferences If true, differences between compatible
181 /// language options will be permitted.
182 ///
183 /// \returns true if the languagae options mis-match, false otherwise.
184 static bool checkLanguageOptions(const LangOptions &LangOpts,
185  const LangOptions &ExistingLangOpts,
186  DiagnosticsEngine *Diags,
187  bool AllowCompatibleDifferences = true) {
188 #define LANGOPT(Name, Bits, Default, Description) \
189  if (ExistingLangOpts.Name != LangOpts.Name) { \
190  if (Diags) \
191  Diags->Report(diag::err_pch_langopt_mismatch) \
192  << Description << LangOpts.Name << ExistingLangOpts.Name; \
193  return true; \
194  }
195 
196 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
197  if (ExistingLangOpts.Name != LangOpts.Name) { \
198  if (Diags) \
199  Diags->Report(diag::err_pch_langopt_value_mismatch) \
200  << Description; \
201  return true; \
202  }
203 
204 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
205  if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \
206  if (Diags) \
207  Diags->Report(diag::err_pch_langopt_value_mismatch) \
208  << Description; \
209  return true; \
210  }
211 
212 #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \
213  if (!AllowCompatibleDifferences) \
214  LANGOPT(Name, Bits, Default, Description)
215 
216 #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \
217  if (!AllowCompatibleDifferences) \
218  ENUM_LANGOPT(Name, Bits, Default, Description)
219 
220 #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \
221  if (!AllowCompatibleDifferences) \
222  VALUE_LANGOPT(Name, Bits, Default, Description)
223 
224 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
225 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
226 #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description)
227 #include "clang/Basic/LangOptions.def"
228 
229  if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) {
230  if (Diags)
231  Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features";
232  return true;
233  }
234 
235  if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) {
236  if (Diags)
237  Diags->Report(diag::err_pch_langopt_value_mismatch)
238  << "target Objective-C runtime";
239  return true;
240  }
241 
242  if (ExistingLangOpts.CommentOpts.BlockCommandNames !=
243  LangOpts.CommentOpts.BlockCommandNames) {
244  if (Diags)
245  Diags->Report(diag::err_pch_langopt_value_mismatch)
246  << "block command names";
247  return true;
248  }
249 
250  return false;
251 }
252 
253 /// \brief Compare the given set of target options against an existing set of
254 /// target options.
255 ///
256 /// \param Diags If non-NULL, diagnostics will be emitted via this engine.
257 ///
258 /// \returns true if the target options mis-match, false otherwise.
259 static bool checkTargetOptions(const TargetOptions &TargetOpts,
260  const TargetOptions &ExistingTargetOpts,
261  DiagnosticsEngine *Diags,
262  bool AllowCompatibleDifferences = true) {
263 #define CHECK_TARGET_OPT(Field, Name) \
264  if (TargetOpts.Field != ExistingTargetOpts.Field) { \
265  if (Diags) \
266  Diags->Report(diag::err_pch_targetopt_mismatch) \
267  << Name << TargetOpts.Field << ExistingTargetOpts.Field; \
268  return true; \
269  }
270 
271  // The triple and ABI must match exactly.
272  CHECK_TARGET_OPT(Triple, "target");
273  CHECK_TARGET_OPT(ABI, "target ABI");
274 
275  // We can tolerate different CPUs in many cases, notably when one CPU
276  // supports a strict superset of another. When allowing compatible
277  // differences skip this check.
278  if (!AllowCompatibleDifferences)
279  CHECK_TARGET_OPT(CPU, "target CPU");
280 
281 #undef CHECK_TARGET_OPT
282 
283  // Compare feature sets.
284  SmallVector<StringRef, 4> ExistingFeatures(
285  ExistingTargetOpts.FeaturesAsWritten.begin(),
286  ExistingTargetOpts.FeaturesAsWritten.end());
287  SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(),
288  TargetOpts.FeaturesAsWritten.end());
289  std::sort(ExistingFeatures.begin(), ExistingFeatures.end());
290  std::sort(ReadFeatures.begin(), ReadFeatures.end());
291 
292  // We compute the set difference in both directions explicitly so that we can
293  // diagnose the differences differently.
294  SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures;
295  std::set_difference(
296  ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(),
297  ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures));
298  std::set_difference(ReadFeatures.begin(), ReadFeatures.end(),
299  ExistingFeatures.begin(), ExistingFeatures.end(),
300  std::back_inserter(UnmatchedReadFeatures));
301 
302  // If we are allowing compatible differences and the read feature set is
303  // a strict subset of the existing feature set, there is nothing to diagnose.
304  if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty())
305  return false;
306 
307  if (Diags) {
308  for (StringRef Feature : UnmatchedReadFeatures)
309  Diags->Report(diag::err_pch_targetopt_feature_mismatch)
310  << /* is-existing-feature */ false << Feature;
311  for (StringRef Feature : UnmatchedExistingFeatures)
312  Diags->Report(diag::err_pch_targetopt_feature_mismatch)
313  << /* is-existing-feature */ true << Feature;
314  }
315 
316  return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty();
317 }
318 
319 bool
321  bool Complain,
322  bool AllowCompatibleDifferences) {
323  const LangOptions &ExistingLangOpts = PP.getLangOpts();
324  return checkLanguageOptions(LangOpts, ExistingLangOpts,
325  Complain ? &Reader.Diags : nullptr,
326  AllowCompatibleDifferences);
327 }
328 
330  bool Complain,
331  bool AllowCompatibleDifferences) {
332  const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts();
333  return checkTargetOptions(TargetOpts, ExistingTargetOpts,
334  Complain ? &Reader.Diags : nullptr,
335  AllowCompatibleDifferences);
336 }
337 
338 namespace {
339  typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >
340  MacroDefinitionsMap;
341  typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> >
342  DeclsMap;
343 }
344 
346  DiagnosticsEngine &Diags,
347  bool Complain) {
349 
350  // Check current mappings for new -Werror mappings, and the stored mappings
351  // for cases that were explicitly mapped to *not* be errors that are now
352  // errors because of options like -Werror.
353  DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags };
354 
355  for (DiagnosticsEngine *MappingSource : MappingSources) {
356  for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) {
357  diag::kind DiagID = DiagIDMappingPair.first;
358  Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation());
359  if (CurLevel < DiagnosticsEngine::Error)
360  continue; // not significant
361  Level StoredLevel =
362  StoredDiags.getDiagnosticLevel(DiagID, SourceLocation());
363  if (StoredLevel < DiagnosticsEngine::Error) {
364  if (Complain)
365  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" +
366  Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str();
367  return true;
368  }
369  }
370  }
371 
372  return false;
373 }
374 
377  if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors())
378  return true;
379  return Ext >= diag::Severity::Error;
380 }
381 
383  DiagnosticsEngine &Diags,
384  bool IsSystem, bool Complain) {
385  // Top-level options
386  if (IsSystem) {
387  if (Diags.getSuppressSystemWarnings())
388  return false;
389  // If -Wsystem-headers was not enabled before, be conservative
390  if (StoredDiags.getSuppressSystemWarnings()) {
391  if (Complain)
392  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers";
393  return true;
394  }
395  }
396 
397  if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) {
398  if (Complain)
399  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror";
400  return true;
401  }
402 
403  if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() &&
404  !StoredDiags.getEnableAllWarnings()) {
405  if (Complain)
406  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror";
407  return true;
408  }
409 
410  if (isExtHandlingFromDiagsError(Diags) &&
411  !isExtHandlingFromDiagsError(StoredDiags)) {
412  if (Complain)
413  Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors";
414  return true;
415  }
416 
417  return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain);
418 }
419 
421  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) {
422  DiagnosticsEngine &ExistingDiags = PP.getDiagnostics();
423  IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs());
425  new DiagnosticsEngine(DiagIDs, DiagOpts.get()));
426  // This should never fail, because we would have processed these options
427  // before writing them to an ASTFile.
428  ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false);
429 
430  ModuleManager &ModuleMgr = Reader.getModuleManager();
431  assert(ModuleMgr.size() >= 1 && "what ASTFile is this then");
432 
433  // If the original import came from a file explicitly generated by the user,
434  // don't check the diagnostic mappings.
435  // FIXME: currently this is approximated by checking whether this is not a
436  // module import of an implicitly-loaded module file.
437  // Note: ModuleMgr.rbegin() may not be the current module, but it must be in
438  // the transitive closure of its imports, since unrelated modules cannot be
439  // imported until after this module finishes validation.
440  ModuleFile *TopImport = *ModuleMgr.rbegin();
441  while (!TopImport->ImportedBy.empty())
442  TopImport = TopImport->ImportedBy[0];
443  if (TopImport->Kind != MK_ImplicitModule)
444  return false;
445 
446  StringRef ModuleName = TopImport->ModuleName;
447  assert(!ModuleName.empty() && "diagnostic options read before module name");
448 
449  Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName);
450  assert(M && "missing module");
451 
452  // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that
453  // contains the union of their flags.
454  return checkDiagnosticMappings(*Diags, ExistingDiags, M->IsSystem, Complain);
455 }
456 
457 /// \brief Collect the macro definitions provided by the given preprocessor
458 /// options.
459 static void
461  MacroDefinitionsMap &Macros,
462  SmallVectorImpl<StringRef> *MacroNames = nullptr) {
463  for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) {
464  StringRef Macro = PPOpts.Macros[I].first;
465  bool IsUndef = PPOpts.Macros[I].second;
466 
467  std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
468  StringRef MacroName = MacroPair.first;
469  StringRef MacroBody = MacroPair.second;
470 
471  // For an #undef'd macro, we only care about the name.
472  if (IsUndef) {
473  if (MacroNames && !Macros.count(MacroName))
474  MacroNames->push_back(MacroName);
475 
476  Macros[MacroName] = std::make_pair("", true);
477  continue;
478  }
479 
480  // For a #define'd macro, figure out the actual definition.
481  if (MacroName.size() == Macro.size())
482  MacroBody = "1";
483  else {
484  // Note: GCC drops anything following an end-of-line character.
485  StringRef::size_type End = MacroBody.find_first_of("\n\r");
486  MacroBody = MacroBody.substr(0, End);
487  }
488 
489  if (MacroNames && !Macros.count(MacroName))
490  MacroNames->push_back(MacroName);
491  Macros[MacroName] = std::make_pair(MacroBody, false);
492  }
493 }
494 
495 /// \brief Check the preprocessor options deserialized from the control block
496 /// against the preprocessor options in an existing preprocessor.
497 ///
498 /// \param Diags If non-null, produce diagnostics for any mismatches incurred.
500  const PreprocessorOptions &ExistingPPOpts,
501  DiagnosticsEngine *Diags,
502  FileManager &FileMgr,
503  std::string &SuggestedPredefines,
504  const LangOptions &LangOpts) {
505  // Check macro definitions.
506  MacroDefinitionsMap ASTFileMacros;
507  collectMacroDefinitions(PPOpts, ASTFileMacros);
508  MacroDefinitionsMap ExistingMacros;
509  SmallVector<StringRef, 4> ExistingMacroNames;
510  collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
511 
512  for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
513  // Dig out the macro definition in the existing preprocessor options.
514  StringRef MacroName = ExistingMacroNames[I];
515  std::pair<StringRef, bool> Existing = ExistingMacros[MacroName];
516 
517  // Check whether we know anything about this macro name or not.
518  llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known
519  = ASTFileMacros.find(MacroName);
520  if (Known == ASTFileMacros.end()) {
521  // FIXME: Check whether this identifier was referenced anywhere in the
522  // AST file. If so, we should reject the AST file. Unfortunately, this
523  // information isn't in the control block. What shall we do about it?
524 
525  if (Existing.second) {
526  SuggestedPredefines += "#undef ";
527  SuggestedPredefines += MacroName.str();
528  SuggestedPredefines += '\n';
529  } else {
530  SuggestedPredefines += "#define ";
531  SuggestedPredefines += MacroName.str();
532  SuggestedPredefines += ' ';
533  SuggestedPredefines += Existing.first.str();
534  SuggestedPredefines += '\n';
535  }
536  continue;
537  }
538 
539  // If the macro was defined in one but undef'd in the other, we have a
540  // conflict.
541  if (Existing.second != Known->second.second) {
542  if (Diags) {
543  Diags->Report(diag::err_pch_macro_def_undef)
544  << MacroName << Known->second.second;
545  }
546  return true;
547  }
548 
549  // If the macro was #undef'd in both, or if the macro bodies are identical,
550  // it's fine.
551  if (Existing.second || Existing.first == Known->second.first)
552  continue;
553 
554  // The macro bodies differ; complain.
555  if (Diags) {
556  Diags->Report(diag::err_pch_macro_def_conflict)
557  << MacroName << Known->second.first << Existing.first;
558  }
559  return true;
560  }
561 
562  // Check whether we're using predefines.
563  if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) {
564  if (Diags) {
565  Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines;
566  }
567  return true;
568  }
569 
570  // Detailed record is important since it is used for the module cache hash.
571  if (LangOpts.Modules &&
572  PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord) {
573  if (Diags) {
574  Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord;
575  }
576  return true;
577  }
578 
579  // Compute the #include and #include_macros lines we need.
580  for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) {
581  StringRef File = ExistingPPOpts.Includes[I];
582  if (File == ExistingPPOpts.ImplicitPCHInclude)
583  continue;
584 
585  if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File)
586  != PPOpts.Includes.end())
587  continue;
588 
589  SuggestedPredefines += "#include \"";
590  SuggestedPredefines += File;
591  SuggestedPredefines += "\"\n";
592  }
593 
594  for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) {
595  StringRef File = ExistingPPOpts.MacroIncludes[I];
596  if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(),
597  File)
598  != PPOpts.MacroIncludes.end())
599  continue;
600 
601  SuggestedPredefines += "#__include_macros \"";
602  SuggestedPredefines += File;
603  SuggestedPredefines += "\"\n##\n";
604  }
605 
606  return false;
607 }
608 
610  bool Complain,
611  std::string &SuggestedPredefines) {
612  const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts();
613 
614  return checkPreprocessorOptions(PPOpts, ExistingPPOpts,
615  Complain? &Reader.Diags : nullptr,
616  PP.getFileManager(),
617  SuggestedPredefines,
618  PP.getLangOpts());
619 }
620 
621 /// Check the header search options deserialized from the control block
622 /// against the header search options in an existing preprocessor.
623 ///
624 /// \param Diags If non-null, produce diagnostics for any mismatches incurred.
626  StringRef SpecificModuleCachePath,
627  StringRef ExistingModuleCachePath,
628  DiagnosticsEngine *Diags,
629  const LangOptions &LangOpts) {
630  if (LangOpts.Modules) {
631  if (SpecificModuleCachePath != ExistingModuleCachePath) {
632  if (Diags)
633  Diags->Report(diag::err_pch_modulecache_mismatch)
634  << SpecificModuleCachePath << ExistingModuleCachePath;
635  return true;
636  }
637  }
638 
639  return false;
640 }
641 
643  StringRef SpecificModuleCachePath,
644  bool Complain) {
645  return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
646  PP.getHeaderSearchInfo().getModuleCachePath(),
647  Complain ? &Reader.Diags : nullptr,
648  PP.getLangOpts());
649 }
650 
651 void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) {
652  PP.setCounterValue(Value);
653 }
654 
655 //===----------------------------------------------------------------------===//
656 // AST reader implementation
657 //===----------------------------------------------------------------------===//
658 
660  bool TakeOwnership) {
661  DeserializationListener = Listener;
662  OwnsDeserializationListener = TakeOwnership;
663 }
664 
665 
666 
668  return serialization::ComputeHash(Sel);
669 }
670 
671 
672 std::pair<unsigned, unsigned>
674  using namespace llvm::support;
675  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
676  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
677  return std::make_pair(KeyLen, DataLen);
678 }
679 
681 ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
682  using namespace llvm::support;
683  SelectorTable &SelTable = Reader.getContext().Selectors;
684  unsigned N = endian::readNext<uint16_t, little, unaligned>(d);
685  IdentifierInfo *FirstII = Reader.getLocalIdentifier(
686  F, endian::readNext<uint32_t, little, unaligned>(d));
687  if (N == 0)
688  return SelTable.getNullarySelector(FirstII);
689  else if (N == 1)
690  return SelTable.getUnarySelector(FirstII);
691 
693  Args.push_back(FirstII);
694  for (unsigned I = 1; I != N; ++I)
695  Args.push_back(Reader.getLocalIdentifier(
696  F, endian::readNext<uint32_t, little, unaligned>(d)));
697 
698  return SelTable.getSelector(N, Args.data());
699 }
700 
703  unsigned DataLen) {
704  using namespace llvm::support;
705 
707 
708  Result.ID = Reader.getGlobalSelectorID(
709  F, endian::readNext<uint32_t, little, unaligned>(d));
710  unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d);
711  unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d);
712  Result.InstanceBits = FullInstanceBits & 0x3;
713  Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1;
714  Result.FactoryBits = FullFactoryBits & 0x3;
715  Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1;
716  unsigned NumInstanceMethods = FullInstanceBits >> 3;
717  unsigned NumFactoryMethods = FullFactoryBits >> 3;
718 
719  // Load instance methods
720  for (unsigned I = 0; I != NumInstanceMethods; ++I) {
721  if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
722  F, endian::readNext<uint32_t, little, unaligned>(d)))
723  Result.Instance.push_back(Method);
724  }
725 
726  // Load factory methods
727  for (unsigned I = 0; I != NumFactoryMethods; ++I) {
728  if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
729  F, endian::readNext<uint32_t, little, unaligned>(d)))
730  Result.Factory.push_back(Method);
731  }
732 
733  return Result;
734 }
735 
737  return llvm::HashString(a);
738 }
739 
740 std::pair<unsigned, unsigned>
742  using namespace llvm::support;
743  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
744  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
745  return std::make_pair(KeyLen, DataLen);
746 }
747 
749 ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) {
750  assert(n >= 2 && d[n-1] == '\0');
751  return StringRef((const char*) d, n-1);
752 }
753 
754 /// \brief Whether the given identifier is "interesting".
756  bool IsModule) {
757  return II.hadMacroDefinition() ||
758  II.isPoisoned() ||
759  (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) ||
761  (!(IsModule && Reader.getContext().getLangOpts().CPlusPlus) &&
762  II.getFETokenInfo<void>());
763 }
764 
765 static bool readBit(unsigned &Bits) {
766  bool Value = Bits & 0x1;
767  Bits >>= 1;
768  return Value;
769 }
770 
772  using namespace llvm::support;
773  unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
774  return Reader.getGlobalIdentifierID(F, RawID >> 1);
775 }
776 
777 static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) {
778  if (!II.isFromAST()) {
779  II.setIsFromAST();
780  bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr;
781  if (isInterestingIdentifier(Reader, II, IsModule))
783  }
784 }
785 
787  const unsigned char* d,
788  unsigned DataLen) {
789  using namespace llvm::support;
790  unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
791  bool IsInteresting = RawID & 0x01;
792 
793  // Wipe out the "is interesting" bit.
794  RawID = RawID >> 1;
795 
796  // Build the IdentifierInfo and link the identifier ID with it.
797  IdentifierInfo *II = KnownII;
798  if (!II) {
799  II = &Reader.getIdentifierTable().getOwn(k);
800  KnownII = II;
801  }
802  markIdentifierFromAST(Reader, *II);
803  Reader.markIdentifierUpToDate(II);
804 
805  IdentID ID = Reader.getGlobalIdentifierID(F, RawID);
806  if (!IsInteresting) {
807  // For uninteresting identifiers, there's nothing else to do. Just notify
808  // the reader that we've finished loading this identifier.
809  Reader.SetIdentifierInfo(ID, II);
810  return II;
811  }
812 
813  unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d);
814  unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d);
815  bool CPlusPlusOperatorKeyword = readBit(Bits);
816  bool HasRevertedTokenIDToIdentifier = readBit(Bits);
817  bool HasRevertedBuiltin = readBit(Bits);
818  bool Poisoned = readBit(Bits);
819  bool ExtensionToken = readBit(Bits);
820  bool HadMacroDefinition = readBit(Bits);
821 
822  assert(Bits == 0 && "Extra bits in the identifier?");
823  DataLen -= 8;
824 
825  // Set or check the various bits in the IdentifierInfo structure.
826  // Token IDs are read-only.
827  if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier)
828  II->revertTokenIDToIdentifier();
829  if (!F.isModule())
830  II->setObjCOrBuiltinID(ObjCOrBuiltinID);
831  else if (HasRevertedBuiltin && II->getBuiltinID()) {
832  II->revertBuiltin();
833  assert((II->hasRevertedBuiltin() ||
834  II->getObjCOrBuiltinID() == ObjCOrBuiltinID) &&
835  "Incorrect ObjC keyword or builtin ID");
836  }
837  assert(II->isExtensionToken() == ExtensionToken &&
838  "Incorrect extension token flag");
839  (void)ExtensionToken;
840  if (Poisoned)
841  II->setIsPoisoned(true);
842  assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword &&
843  "Incorrect C++ operator keyword flag");
844  (void)CPlusPlusOperatorKeyword;
845 
846  // If this identifier is a macro, deserialize the macro
847  // definition.
848  if (HadMacroDefinition) {
849  uint32_t MacroDirectivesOffset =
850  endian::readNext<uint32_t, little, unaligned>(d);
851  DataLen -= 4;
852 
853  Reader.addPendingMacro(II, &F, MacroDirectivesOffset);
854  }
855 
856  Reader.SetIdentifierInfo(ID, II);
857 
858  // Read all of the declarations visible at global scope with this
859  // name.
860  if (DataLen > 0) {
861  SmallVector<uint32_t, 4> DeclIDs;
862  for (; DataLen > 0; DataLen -= 4)
863  DeclIDs.push_back(Reader.getGlobalDeclID(
864  F, endian::readNext<uint32_t, little, unaligned>(d)));
865  Reader.SetGloballyVisibleDecls(II, DeclIDs);
866  }
867 
868  return II;
869 }
870 
872  : Kind(Name.getNameKind()) {
873  switch (Kind) {
875  Data = (uint64_t)Name.getAsIdentifierInfo();
876  break;
880  Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr();
881  break;
883  Data = Name.getCXXOverloadedOperator();
884  break;
886  Data = (uint64_t)Name.getCXXLiteralIdentifier();
887  break;
892  Data = 0;
893  break;
894  }
895 }
896 
897 unsigned DeclarationNameKey::getHash() const {
898  llvm::FoldingSetNodeID ID;
899  ID.AddInteger(Kind);
900 
901  switch (Kind) {
904  ID.AddString(((IdentifierInfo*)Data)->getName());
905  break;
909  ID.AddInteger(serialization::ComputeHash(Selector(Data)));
910  break;
912  ID.AddInteger((OverloadedOperatorKind)Data);
913  break;
918  break;
919  }
920 
921  return ID.ComputeHash();
922 }
923 
924 ModuleFile *
925 ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) {
926  using namespace llvm::support;
927  uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d);
928  return Reader.getLocalModuleFile(F, ModuleFileID);
929 }
930 
931 std::pair<unsigned, unsigned>
932 ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) {
933  using namespace llvm::support;
934  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
935  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
936  return std::make_pair(KeyLen, DataLen);
937 }
938 
940 ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
941  using namespace llvm::support;
942 
943  auto Kind = (DeclarationName::NameKind)*d++;
944  uint64_t Data;
945  switch (Kind) {
947  Data = (uint64_t)Reader.getLocalIdentifier(
948  F, endian::readNext<uint32_t, little, unaligned>(d));
949  break;
953  Data =
954  (uint64_t)Reader.getLocalSelector(
955  F, endian::readNext<uint32_t, little, unaligned>(
956  d)).getAsOpaquePtr();
957  break;
959  Data = *d++; // OverloadedOperatorKind
960  break;
962  Data = (uint64_t)Reader.getLocalIdentifier(
963  F, endian::readNext<uint32_t, little, unaligned>(d));
964  break;
969  Data = 0;
970  break;
971  }
972 
973  return DeclarationNameKey(Kind, Data);
974 }
975 
976 void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type,
977  const unsigned char *d,
978  unsigned DataLen,
979  data_type_builder &Val) {
980  using namespace llvm::support;
981  for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) {
982  uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d);
983  Val.insert(Reader.getGlobalDeclID(F, LocalID));
984  }
985 }
986 
987 bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
988  BitstreamCursor &Cursor,
989  uint64_t Offset,
990  DeclContext *DC) {
991  assert(Offset != 0);
992 
993  SavedStreamPosition SavedPosition(Cursor);
994  Cursor.JumpToBit(Offset);
995 
996  RecordData Record;
997  StringRef Blob;
998  unsigned Code = Cursor.ReadCode();
999  unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
1000  if (RecCode != DECL_CONTEXT_LEXICAL) {
1001  Error("Expected lexical block");
1002  return true;
1003  }
1004 
1005  assert(!isa<TranslationUnitDecl>(DC) &&
1006  "expected a TU_UPDATE_LEXICAL record for TU");
1007  // If we are handling a C++ class template instantiation, we can see multiple
1008  // lexical updates for the same record. It's important that we select only one
1009  // of them, so that field numbering works properly. Just pick the first one we
1010  // see.
1011  auto &Lex = LexicalDecls[DC];
1012  if (!Lex.first) {
1013  Lex = std::make_pair(
1014  &M, llvm::makeArrayRef(
1015  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
1016  Blob.data()),
1017  Blob.size() / 4));
1018  }
1019  DC->setHasExternalLexicalStorage(true);
1020  return false;
1021 }
1022 
1023 bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
1024  BitstreamCursor &Cursor,
1025  uint64_t Offset,
1026  DeclID ID) {
1027  assert(Offset != 0);
1028 
1029  SavedStreamPosition SavedPosition(Cursor);
1030  Cursor.JumpToBit(Offset);
1031 
1032  RecordData Record;
1033  StringRef Blob;
1034  unsigned Code = Cursor.ReadCode();
1035  unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
1036  if (RecCode != DECL_CONTEXT_VISIBLE) {
1037  Error("Expected visible lookup table block");
1038  return true;
1039  }
1040 
1041  // We can't safely determine the primary context yet, so delay attaching the
1042  // lookup table until we're done with recursive deserialization.
1043  auto *Data = (const unsigned char*)Blob.data();
1044  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data});
1045  return false;
1046 }
1047 
1048 void ASTReader::Error(StringRef Msg) {
1049  Error(diag::err_fe_pch_malformed, Msg);
1050  if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight() &&
1051  !PP.getHeaderSearchInfo().getModuleCachePath().empty()) {
1052  Diag(diag::note_module_cache_path)
1053  << PP.getHeaderSearchInfo().getModuleCachePath();
1054  }
1055 }
1056 
1057 void ASTReader::Error(unsigned DiagID,
1058  StringRef Arg1, StringRef Arg2) {
1059  if (Diags.isDiagnosticInFlight())
1060  Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2);
1061  else
1062  Diag(DiagID) << Arg1 << Arg2;
1063 }
1064 
1065 //===----------------------------------------------------------------------===//
1066 // Source Manager Deserialization
1067 //===----------------------------------------------------------------------===//
1068 
1069 /// \brief Read the line table in the source manager block.
1070 /// \returns true if there was an error.
1071 bool ASTReader::ParseLineTable(ModuleFile &F,
1072  const RecordData &Record) {
1073  unsigned Idx = 0;
1074  LineTableInfo &LineTable = SourceMgr.getLineTable();
1075 
1076  // Parse the file names
1077  std::map<int, int> FileIDs;
1078  for (unsigned I = 0; Record[Idx]; ++I) {
1079  // Extract the file name
1080  auto Filename = ReadPath(F, Record, Idx);
1081  FileIDs[I] = LineTable.getLineTableFilenameID(Filename);
1082  }
1083  ++Idx;
1084 
1085  // Parse the line entries
1086  std::vector<LineEntry> Entries;
1087  while (Idx < Record.size()) {
1088  int FID = Record[Idx++];
1089  assert(FID >= 0 && "Serialized line entries for non-local file.");
1090  // Remap FileID from 1-based old view.
1091  FID += F.SLocEntryBaseID - 1;
1092 
1093  // Extract the line entries
1094  unsigned NumEntries = Record[Idx++];
1095  assert(NumEntries && "no line entries for file ID");
1096  Entries.clear();
1097  Entries.reserve(NumEntries);
1098  for (unsigned I = 0; I != NumEntries; ++I) {
1099  unsigned FileOffset = Record[Idx++];
1100  unsigned LineNo = Record[Idx++];
1101  int FilenameID = FileIDs[Record[Idx++]];
1103  = (SrcMgr::CharacteristicKind)Record[Idx++];
1104  unsigned IncludeOffset = Record[Idx++];
1105  Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID,
1106  FileKind, IncludeOffset));
1107  }
1108  LineTable.AddEntry(FileID::get(FID), Entries);
1109  }
1110 
1111  return false;
1112 }
1113 
1114 /// \brief Read a source manager block
1115 bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
1116  using namespace SrcMgr;
1117 
1118  BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
1119 
1120  // Set the source-location entry cursor to the current position in
1121  // the stream. This cursor will be used to read the contents of the
1122  // source manager block initially, and then lazily read
1123  // source-location entries as needed.
1124  SLocEntryCursor = F.Stream;
1125 
1126  // The stream itself is going to skip over the source manager block.
1127  if (F.Stream.SkipBlock()) {
1128  Error("malformed block record in AST file");
1129  return true;
1130  }
1131 
1132  // Enter the source manager block.
1133  if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) {
1134  Error("malformed source manager block record in AST file");
1135  return true;
1136  }
1137 
1138  RecordData Record;
1139  while (true) {
1140  llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks();
1141 
1142  switch (E.Kind) {
1143  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1145  Error("malformed block record in AST file");
1146  return true;
1147  case llvm::BitstreamEntry::EndBlock:
1148  return false;
1149  case llvm::BitstreamEntry::Record:
1150  // The interesting case.
1151  break;
1152  }
1153 
1154  // Read a record.
1155  Record.clear();
1156  StringRef Blob;
1157  switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) {
1158  default: // Default behavior: ignore.
1159  break;
1160 
1161  case SM_SLOC_FILE_ENTRY:
1162  case SM_SLOC_BUFFER_ENTRY:
1164  // Once we hit one of the source location entries, we're done.
1165  return false;
1166  }
1167  }
1168 }
1169 
1170 /// \brief If a header file is not found at the path that we expect it to be
1171 /// and the PCH file was moved from its original location, try to resolve the
1172 /// file by assuming that header+PCH were moved together and the header is in
1173 /// the same place relative to the PCH.
1174 static std::string
1176  const std::string &OriginalDir,
1177  const std::string &CurrDir) {
1178  assert(OriginalDir != CurrDir &&
1179  "No point trying to resolve the file if the PCH dir didn't change");
1180  using namespace llvm::sys;
1181  SmallString<128> filePath(Filename);
1182  fs::make_absolute(filePath);
1183  assert(path::is_absolute(OriginalDir));
1184  SmallString<128> currPCHPath(CurrDir);
1185 
1186  path::const_iterator fileDirI = path::begin(path::parent_path(filePath)),
1187  fileDirE = path::end(path::parent_path(filePath));
1188  path::const_iterator origDirI = path::begin(OriginalDir),
1189  origDirE = path::end(OriginalDir);
1190  // Skip the common path components from filePath and OriginalDir.
1191  while (fileDirI != fileDirE && origDirI != origDirE &&
1192  *fileDirI == *origDirI) {
1193  ++fileDirI;
1194  ++origDirI;
1195  }
1196  for (; origDirI != origDirE; ++origDirI)
1197  path::append(currPCHPath, "..");
1198  path::append(currPCHPath, fileDirI, fileDirE);
1199  path::append(currPCHPath, path::filename(Filename));
1200  return currPCHPath.str();
1201 }
1202 
1204  if (ID == 0)
1205  return false;
1206 
1207  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1208  Error("source location entry ID out-of-range for AST file");
1209  return true;
1210  }
1211 
1212  // Local helper to read the (possibly-compressed) buffer data following the
1213  // entry record.
1214  auto ReadBuffer = [this](
1215  BitstreamCursor &SLocEntryCursor,
1216  StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> {
1217  RecordData Record;
1218  StringRef Blob;
1219  unsigned Code = SLocEntryCursor.ReadCode();
1220  unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob);
1221 
1222  if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
1223  SmallString<0> Uncompressed;
1224  if (llvm::zlib::uncompress(Blob, Uncompressed, Record[0]) !=
1225  llvm::zlib::StatusOK) {
1226  Error("could not decompress embedded file contents");
1227  return nullptr;
1228  }
1229  return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name);
1230  } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
1231  return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
1232  } else {
1233  Error("AST record has invalid code");
1234  return nullptr;
1235  }
1236  };
1237 
1238  ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
1239  F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
1240  BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
1241  unsigned BaseOffset = F->SLocEntryBaseOffset;
1242 
1243  ++NumSLocEntriesRead;
1244  llvm::BitstreamEntry Entry = SLocEntryCursor.advance();
1245  if (Entry.Kind != llvm::BitstreamEntry::Record) {
1246  Error("incorrectly-formatted source location entry in AST file");
1247  return true;
1248  }
1249 
1250  RecordData Record;
1251  StringRef Blob;
1252  switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) {
1253  default:
1254  Error("incorrectly-formatted source location entry in AST file");
1255  return true;
1256 
1257  case SM_SLOC_FILE_ENTRY: {
1258  // We will detect whether a file changed and return 'Failure' for it, but
1259  // we will also try to fail gracefully by setting up the SLocEntry.
1260  unsigned InputID = Record[4];
1261  InputFile IF = getInputFile(*F, InputID);
1262  const FileEntry *File = IF.getFile();
1263  bool OverriddenBuffer = IF.isOverridden();
1264 
1265  // Note that we only check if a File was returned. If it was out-of-date
1266  // we have complained but we will continue creating a FileID to recover
1267  // gracefully.
1268  if (!File)
1269  return true;
1270 
1271  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1272  if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) {
1273  // This is the module's main file.
1274  IncludeLoc = getImportLocation(F);
1275  }
1277  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1278  FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter,
1279  ID, BaseOffset + Record[0]);
1280  SrcMgr::FileInfo &FileInfo =
1281  const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
1282  FileInfo.NumCreatedFIDs = Record[5];
1283  if (Record[3])
1284  FileInfo.setHasLineDirectives();
1285 
1286  const DeclID *FirstDecl = F->FileSortedDecls + Record[6];
1287  unsigned NumFileDecls = Record[7];
1288  if (NumFileDecls) {
1289  assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?");
1290  FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl,
1291  NumFileDecls));
1292  }
1293 
1294  const SrcMgr::ContentCache *ContentCache
1295  = SourceMgr.getOrCreateContentCache(File,
1296  /*isSystemFile=*/FileCharacter != SrcMgr::C_User);
1297  if (OverriddenBuffer && !ContentCache->BufferOverridden &&
1298  ContentCache->ContentsEntry == ContentCache->OrigEntry &&
1299  !ContentCache->getRawBuffer()) {
1300  auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
1301  if (!Buffer)
1302  return true;
1303  SourceMgr.overrideFileContents(File, std::move(Buffer));
1304  }
1305 
1306  break;
1307  }
1308 
1309  case SM_SLOC_BUFFER_ENTRY: {
1310  const char *Name = Blob.data();
1311  unsigned Offset = Record[0];
1313  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1314  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1315  if (IncludeLoc.isInvalid() &&
1316  (F->Kind == MK_ImplicitModule || F->Kind == MK_ExplicitModule)) {
1317  IncludeLoc = getImportLocation(F);
1318  }
1319 
1320  auto Buffer = ReadBuffer(SLocEntryCursor, Name);
1321  if (!Buffer)
1322  return true;
1323  SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
1324  BaseOffset + Offset, IncludeLoc);
1325  break;
1326  }
1327 
1328  case SM_SLOC_EXPANSION_ENTRY: {
1329  SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]);
1330  SourceMgr.createExpansionLoc(SpellingLoc,
1331  ReadSourceLocation(*F, Record[2]),
1332  ReadSourceLocation(*F, Record[3]),
1333  Record[4],
1334  ID,
1335  BaseOffset + Record[0]);
1336  break;
1337  }
1338  }
1339 
1340  return false;
1341 }
1342 
1343 std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) {
1344  if (ID == 0)
1345  return std::make_pair(SourceLocation(), "");
1346 
1347  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1348  Error("source location entry ID out-of-range for AST file");
1349  return std::make_pair(SourceLocation(), "");
1350  }
1351 
1352  // Find which module file this entry lands in.
1353  ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second;
1354  if (M->Kind != MK_ImplicitModule && M->Kind != MK_ExplicitModule)
1355  return std::make_pair(SourceLocation(), "");
1356 
1357  // FIXME: Can we map this down to a particular submodule? That would be
1358  // ideal.
1359  return std::make_pair(M->ImportLoc, StringRef(M->ModuleName));
1360 }
1361 
1362 /// \brief Find the location where the module F is imported.
1363 SourceLocation ASTReader::getImportLocation(ModuleFile *F) {
1364  if (F->ImportLoc.isValid())
1365  return F->ImportLoc;
1366 
1367  // Otherwise we have a PCH. It's considered to be "imported" at the first
1368  // location of its includer.
1369  if (F->ImportedBy.empty() || !F->ImportedBy[0]) {
1370  // Main file is the importer.
1371  assert(SourceMgr.getMainFileID().isValid() && "missing main file");
1372  return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
1373  }
1374  return F->ImportedBy[0]->FirstLoc;
1375 }
1376 
1377 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1378 /// specified cursor. Read the abbreviations that are at the top of the block
1379 /// and then leave the cursor pointing into the block.
1380 bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) {
1381  if (Cursor.EnterSubBlock(BlockID))
1382  return true;
1383 
1384  while (true) {
1385  uint64_t Offset = Cursor.GetCurrentBitNo();
1386  unsigned Code = Cursor.ReadCode();
1387 
1388  // We expect all abbrevs to be at the start of the block.
1389  if (Code != llvm::bitc::DEFINE_ABBREV) {
1390  Cursor.JumpToBit(Offset);
1391  return false;
1392  }
1393  Cursor.ReadAbbrevRecord();
1394  }
1395 }
1396 
1398  unsigned &Idx) {
1399  Token Tok;
1400  Tok.startToken();
1401  Tok.setLocation(ReadSourceLocation(F, Record, Idx));
1402  Tok.setLength(Record[Idx++]);
1403  if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++]))
1404  Tok.setIdentifierInfo(II);
1405  Tok.setKind((tok::TokenKind)Record[Idx++]);
1406  Tok.setFlag((Token::TokenFlags)Record[Idx++]);
1407  return Tok;
1408 }
1409 
1411  BitstreamCursor &Stream = F.MacroCursor;
1412 
1413  // Keep track of where we are in the stream, then jump back there
1414  // after reading this macro.
1415  SavedStreamPosition SavedPosition(Stream);
1416 
1417  Stream.JumpToBit(Offset);
1418  RecordData Record;
1420  MacroInfo *Macro = nullptr;
1421 
1422  while (true) {
1423  // Advance to the next record, but if we get to the end of the block, don't
1424  // pop it (removing all the abbreviations from the cursor) since we want to
1425  // be able to reseek within the block and read entries.
1426  unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd;
1427  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags);
1428 
1429  switch (Entry.Kind) {
1430  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1432  Error("malformed block record in AST file");
1433  return Macro;
1434  case llvm::BitstreamEntry::EndBlock:
1435  return Macro;
1436  case llvm::BitstreamEntry::Record:
1437  // The interesting case.
1438  break;
1439  }
1440 
1441  // Read a record.
1442  Record.clear();
1443  PreprocessorRecordTypes RecType =
1444  (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record);
1445  switch (RecType) {
1446  case PP_MODULE_MACRO:
1448  return Macro;
1449 
1450  case PP_MACRO_OBJECT_LIKE:
1451  case PP_MACRO_FUNCTION_LIKE: {
1452  // If we already have a macro, that means that we've hit the end
1453  // of the definition of the macro we were looking for. We're
1454  // done.
1455  if (Macro)
1456  return Macro;
1457 
1458  unsigned NextIndex = 1; // Skip identifier ID.
1459  SubmoduleID SubModID = getGlobalSubmoduleID(F, Record[NextIndex++]);
1460  SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
1461  MacroInfo *MI = PP.AllocateDeserializedMacroInfo(Loc, SubModID);
1462  MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
1463  MI->setIsUsed(Record[NextIndex++]);
1464  MI->setUsedForHeaderGuard(Record[NextIndex++]);
1465 
1466  if (RecType == PP_MACRO_FUNCTION_LIKE) {
1467  // Decode function-like macro info.
1468  bool isC99VarArgs = Record[NextIndex++];
1469  bool isGNUVarArgs = Record[NextIndex++];
1470  bool hasCommaPasting = Record[NextIndex++];
1471  MacroArgs.clear();
1472  unsigned NumArgs = Record[NextIndex++];
1473  for (unsigned i = 0; i != NumArgs; ++i)
1474  MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++]));
1475 
1476  // Install function-like macro info.
1477  MI->setIsFunctionLike();
1478  if (isC99VarArgs) MI->setIsC99Varargs();
1479  if (isGNUVarArgs) MI->setIsGNUVarargs();
1480  if (hasCommaPasting) MI->setHasCommaPasting();
1481  MI->setArgumentList(MacroArgs, PP.getPreprocessorAllocator());
1482  }
1483 
1484  // Remember that we saw this macro last so that we add the tokens that
1485  // form its body to it.
1486  Macro = MI;
1487 
1488  if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() &&
1489  Record[NextIndex]) {
1490  // We have a macro definition. Register the association
1492  GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]);
1493  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
1494  PreprocessingRecord::PPEntityID PPID =
1495  PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true);
1496  MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>(
1497  PPRec.getPreprocessedEntity(PPID));
1498  if (PPDef)
1499  PPRec.RegisterMacroDefinition(Macro, PPDef);
1500  }
1501 
1502  ++NumMacrosRead;
1503  break;
1504  }
1505 
1506  case PP_TOKEN: {
1507  // If we see a TOKEN before a PP_MACRO_*, then the file is
1508  // erroneous, just pretend we didn't see this.
1509  if (!Macro) break;
1510 
1511  unsigned Idx = 0;
1512  Token Tok = ReadToken(F, Record, Idx);
1513  Macro->AddTokenToBody(Tok);
1514  break;
1515  }
1516  }
1517  }
1518 }
1519 
1524  assert(I != M.PreprocessedEntityRemap.end()
1525  && "Invalid index into preprocessed entity index remap");
1526 
1527  return LocalID + I->second;
1528 }
1529 
1531  return llvm::hash_combine(ikey.Size, ikey.ModTime);
1532 }
1533 
1535 HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) {
1536  internal_key_type ikey = {FE->getSize(),
1537  M.HasTimestamps ? FE->getModificationTime() : 0,
1538  FE->getName(), /*Imported*/ false};
1539  return ikey;
1540 }
1541 
1542 bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
1543  if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime))
1544  return false;
1545 
1546  if (llvm::sys::path::is_absolute(a.Filename) &&
1547  strcmp(a.Filename, b.Filename) == 0)
1548  return true;
1549 
1550  // Determine whether the actual files are equivalent.
1551  FileManager &FileMgr = Reader.getFileManager();
1552  auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* {
1553  if (!Key.Imported)
1554  return FileMgr.getFile(Key.Filename);
1555 
1556  std::string Resolved = Key.Filename;
1557  Reader.ResolveImportedPath(M, Resolved);
1558  return FileMgr.getFile(Resolved);
1559  };
1560 
1561  const FileEntry *FEA = GetFile(a);
1562  const FileEntry *FEB = GetFile(b);
1563  return FEA && FEA == FEB;
1564 }
1565 
1566 std::pair<unsigned, unsigned>
1567 HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) {
1568  using namespace llvm::support;
1569  unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d);
1570  unsigned DataLen = (unsigned) *d++;
1571  return std::make_pair(KeyLen, DataLen);
1572 }
1573 
1575 HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) {
1576  using namespace llvm::support;
1577  internal_key_type ikey;
1578  ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d));
1579  ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d));
1580  ikey.Filename = (const char *)d;
1581  ikey.Imported = true;
1582  return ikey;
1583 }
1584 
1586 HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
1587  unsigned DataLen) {
1588  const unsigned char *End = d + DataLen;
1589  using namespace llvm::support;
1590  HeaderFileInfo HFI;
1591  unsigned Flags = *d++;
1592  // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
1593  HFI.isImport |= (Flags >> 4) & 0x01;
1594  HFI.isPragmaOnce |= (Flags >> 3) & 0x01;
1595  HFI.DirInfo = (Flags >> 1) & 0x03;
1596  HFI.IndexHeaderMapHeader = Flags & 0x01;
1597  // FIXME: Find a better way to handle this. Maybe just store a
1598  // "has been included" flag?
1599  HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d),
1600  HFI.NumIncludes);
1601  HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
1602  M, endian::readNext<uint32_t, little, unaligned>(d));
1603  if (unsigned FrameworkOffset =
1604  endian::readNext<uint32_t, little, unaligned>(d)) {
1605  // The framework offset is 1 greater than the actual offset,
1606  // since 0 is used as an indicator for "no framework name".
1607  StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1);
1608  HFI.Framework = HS->getUniqueFrameworkName(FrameworkName);
1609  }
1610 
1611  assert((End - d) % 4 == 0 &&
1612  "Wrong data length in HeaderFileInfo deserialization");
1613  while (d != End) {
1614  uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d);
1615  auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3);
1616  LocalSMID >>= 2;
1617 
1618  // This header is part of a module. Associate it with the module to enable
1619  // implicit module import.
1620  SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
1621  Module *Mod = Reader.getSubmodule(GlobalSMID);
1622  FileManager &FileMgr = Reader.getFileManager();
1623  ModuleMap &ModMap =
1624  Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
1625 
1626  std::string Filename = key.Filename;
1627  if (key.Imported)
1628  Reader.ResolveImportedPath(M, Filename);
1629  // FIXME: This is not always the right filename-as-written, but we're not
1630  // going to use this information to rebuild the module, so it doesn't make
1631  // a lot of difference.
1632  Module::Header H = { key.Filename, FileMgr.getFile(Filename) };
1633  ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
1634  HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
1635  }
1636 
1637  // This HeaderFileInfo was externally loaded.
1638  HFI.External = true;
1639  HFI.IsValid = true;
1640  return HFI;
1641 }
1642 
1644  ModuleFile *M,
1645  uint64_t MacroDirectivesOffset) {
1646  assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
1647  PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset));
1648 }
1649 
1651  // Note that we are loading defined macros.
1652  Deserializing Macros(this);
1653 
1654  for (auto &I : llvm::reverse(ModuleMgr)) {
1655  BitstreamCursor &MacroCursor = I->MacroCursor;
1656 
1657  // If there was no preprocessor block, skip this file.
1658  if (!MacroCursor.getBitStreamReader())
1659  continue;
1660 
1661  BitstreamCursor Cursor = MacroCursor;
1662  Cursor.JumpToBit(I->MacroStartOffset);
1663 
1664  RecordData Record;
1665  while (true) {
1666  llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks();
1667 
1668  switch (E.Kind) {
1669  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1671  Error("malformed block record in AST file");
1672  return;
1673  case llvm::BitstreamEntry::EndBlock:
1674  goto NextCursor;
1675 
1676  case llvm::BitstreamEntry::Record:
1677  Record.clear();
1678  switch (Cursor.readRecord(E.ID, Record)) {
1679  default: // Default behavior: ignore.
1680  break;
1681 
1682  case PP_MACRO_OBJECT_LIKE:
1683  case PP_MACRO_FUNCTION_LIKE: {
1684  IdentifierInfo *II = getLocalIdentifier(*I, Record[0]);
1685  if (II->isOutOfDate())
1686  updateOutOfDateIdentifier(*II);
1687  break;
1688  }
1689 
1690  case PP_TOKEN:
1691  // Ignore tokens.
1692  break;
1693  }
1694  break;
1695  }
1696  }
1697  NextCursor: ;
1698  }
1699 }
1700 
1701 namespace {
1702  /// \brief Visitor class used to look up identifirs in an AST file.
1703  class IdentifierLookupVisitor {
1704  StringRef Name;
1705  unsigned NameHash;
1706  unsigned PriorGeneration;
1707  unsigned &NumIdentifierLookups;
1708  unsigned &NumIdentifierLookupHits;
1709  IdentifierInfo *Found;
1710 
1711  public:
1712  IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration,
1713  unsigned &NumIdentifierLookups,
1714  unsigned &NumIdentifierLookupHits)
1715  : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)),
1716  PriorGeneration(PriorGeneration),
1717  NumIdentifierLookups(NumIdentifierLookups),
1718  NumIdentifierLookupHits(NumIdentifierLookupHits),
1719  Found()
1720  {
1721  }
1722 
1723  bool operator()(ModuleFile &M) {
1724  // If we've already searched this module file, skip it now.
1725  if (M.Generation <= PriorGeneration)
1726  return true;
1727 
1728  ASTIdentifierLookupTable *IdTable
1730  if (!IdTable)
1731  return false;
1732 
1733  ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M,
1734  Found);
1735  ++NumIdentifierLookups;
1737  IdTable->find_hashed(Name, NameHash, &Trait);
1738  if (Pos == IdTable->end())
1739  return false;
1740 
1741  // Dereferencing the iterator has the effect of building the
1742  // IdentifierInfo node and populating it with the various
1743  // declarations it needs.
1744  ++NumIdentifierLookupHits;
1745  Found = *Pos;
1746  return true;
1747  }
1748 
1749  // \brief Retrieve the identifier info found within the module
1750  // files.
1751  IdentifierInfo *getIdentifierInfo() const { return Found; }
1752  };
1753 }
1754 
1756  // Note that we are loading an identifier.
1757  Deserializing AnIdentifier(this);
1758 
1759  unsigned PriorGeneration = 0;
1760  if (getContext().getLangOpts().Modules)
1761  PriorGeneration = IdentifierGeneration[&II];
1762 
1763  // If there is a global index, look there first to determine which modules
1764  // provably do not have any results for this identifier.
1766  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
1767  if (!loadGlobalIndex()) {
1768  if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) {
1769  HitsPtr = &Hits;
1770  }
1771  }
1772 
1773  IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration,
1774  NumIdentifierLookups,
1775  NumIdentifierLookupHits);
1776  ModuleMgr.visit(Visitor, HitsPtr);
1777  markIdentifierUpToDate(&II);
1778 }
1779 
1781  if (!II)
1782  return;
1783 
1784  II->setOutOfDate(false);
1785 
1786  // Update the generation for this identifier.
1787  if (getContext().getLangOpts().Modules)
1788  IdentifierGeneration[II] = getGeneration();
1789 }
1790 
1792  const PendingMacroInfo &PMInfo) {
1793  ModuleFile &M = *PMInfo.M;
1794 
1795  BitstreamCursor &Cursor = M.MacroCursor;
1796  SavedStreamPosition SavedPosition(Cursor);
1797  Cursor.JumpToBit(PMInfo.MacroDirectivesOffset);
1798 
1799  struct ModuleMacroRecord {
1800  SubmoduleID SubModID;
1801  MacroInfo *MI;
1802  SmallVector<SubmoduleID, 8> Overrides;
1803  };
1805 
1806  // We expect to see a sequence of PP_MODULE_MACRO records listing exported
1807  // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete
1808  // macro histroy.
1809  RecordData Record;
1810  while (true) {
1811  llvm::BitstreamEntry Entry =
1812  Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
1813  if (Entry.Kind != llvm::BitstreamEntry::Record) {
1814  Error("malformed block record in AST file");
1815  return;
1816  }
1817 
1818  Record.clear();
1819  switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
1821  break;
1822 
1823  case PP_MODULE_MACRO: {
1824  ModuleMacros.push_back(ModuleMacroRecord());
1825  auto &Info = ModuleMacros.back();
1826  Info.SubModID = getGlobalSubmoduleID(M, Record[0]);
1827  Info.MI = getMacro(getGlobalMacroID(M, Record[1]));
1828  for (int I = 2, N = Record.size(); I != N; ++I)
1829  Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I]));
1830  continue;
1831  }
1832 
1833  default:
1834  Error("malformed block record in AST file");
1835  return;
1836  }
1837 
1838  // We found the macro directive history; that's the last record
1839  // for this macro.
1840  break;
1841  }
1842 
1843  // Module macros are listed in reverse dependency order.
1844  {
1845  std::reverse(ModuleMacros.begin(), ModuleMacros.end());
1847  for (auto &MMR : ModuleMacros) {
1848  Overrides.clear();
1849  for (unsigned ModID : MMR.Overrides) {
1850  Module *Mod = getSubmodule(ModID);
1851  auto *Macro = PP.getModuleMacro(Mod, II);
1852  assert(Macro && "missing definition for overridden macro");
1853  Overrides.push_back(Macro);
1854  }
1855 
1856  bool Inserted = false;
1857  Module *Owner = getSubmodule(MMR.SubModID);
1858  PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted);
1859  }
1860  }
1861 
1862  // Don't read the directive history for a module; we don't have anywhere
1863  // to put it.
1864  if (M.Kind == MK_ImplicitModule || M.Kind == MK_ExplicitModule)
1865  return;
1866 
1867  // Deserialize the macro directives history in reverse source-order.
1868  MacroDirective *Latest = nullptr, *Earliest = nullptr;
1869  unsigned Idx = 0, N = Record.size();
1870  while (Idx < N) {
1871  MacroDirective *MD = nullptr;
1872  SourceLocation Loc = ReadSourceLocation(M, Record, Idx);
1873  MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++];
1874  switch (K) {
1876  MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++]));
1877  MD = PP.AllocateDefMacroDirective(MI, Loc);
1878  break;
1879  }
1881  MD = PP.AllocateUndefMacroDirective(Loc);
1882  break;
1883  }
1885  bool isPublic = Record[Idx++];
1886  MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic);
1887  break;
1888  }
1889 
1890  if (!Latest)
1891  Latest = MD;
1892  if (Earliest)
1893  Earliest->setPrevious(MD);
1894  Earliest = MD;
1895  }
1896 
1897  if (Latest)
1898  PP.setLoadedMacroDirective(II, Latest);
1899 }
1900 
1901 ASTReader::InputFileInfo
1902 ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
1903  // Go find this input file.
1904  BitstreamCursor &Cursor = F.InputFilesCursor;
1905  SavedStreamPosition SavedPosition(Cursor);
1906  Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
1907 
1908  unsigned Code = Cursor.ReadCode();
1909  RecordData Record;
1910  StringRef Blob;
1911 
1912  unsigned Result = Cursor.readRecord(Code, Record, &Blob);
1913  assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE &&
1914  "invalid record type for input file");
1915  (void)Result;
1916 
1917  assert(Record[0] == ID && "Bogus stored ID or offset");
1918  InputFileInfo R;
1919  R.StoredSize = static_cast<off_t>(Record[1]);
1920  R.StoredTime = static_cast<time_t>(Record[2]);
1921  R.Overridden = static_cast<bool>(Record[3]);
1922  R.Transient = static_cast<bool>(Record[4]);
1923  R.Filename = Blob;
1924  ResolveImportedPath(F, R.Filename);
1925  return R;
1926 }
1927 
1928 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
1929  // If this ID is bogus, just return an empty input file.
1930  if (ID == 0 || ID > F.InputFilesLoaded.size())
1931  return InputFile();
1932 
1933  // If we've already loaded this input file, return it.
1934  if (F.InputFilesLoaded[ID-1].getFile())
1935  return F.InputFilesLoaded[ID-1];
1936 
1937  if (F.InputFilesLoaded[ID-1].isNotFound())
1938  return InputFile();
1939 
1940  // Go find this input file.
1941  BitstreamCursor &Cursor = F.InputFilesCursor;
1942  SavedStreamPosition SavedPosition(Cursor);
1943  Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
1944 
1945  InputFileInfo FI = readInputFileInfo(F, ID);
1946  off_t StoredSize = FI.StoredSize;
1947  time_t StoredTime = FI.StoredTime;
1948  bool Overridden = FI.Overridden;
1949  bool Transient = FI.Transient;
1950  StringRef Filename = FI.Filename;
1951 
1952  const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false);
1953 
1954  // If we didn't find the file, resolve it relative to the
1955  // original directory from which this AST file was created.
1956  if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() &&
1957  F.OriginalDir != CurrentDir) {
1958  std::string Resolved = resolveFileRelativeToOriginalDir(Filename,
1959  F.OriginalDir,
1960  CurrentDir);
1961  if (!Resolved.empty())
1962  File = FileMgr.getFile(Resolved);
1963  }
1964 
1965  // For an overridden file, create a virtual file with the stored
1966  // size/timestamp.
1967  if ((Overridden || Transient) && File == nullptr)
1968  File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime);
1969 
1970  if (File == nullptr) {
1971  if (Complain) {
1972  std::string ErrorStr = "could not find file '";
1973  ErrorStr += Filename;
1974  ErrorStr += "' referenced by AST file '";
1975  ErrorStr += F.FileName;
1976  ErrorStr += "'";
1977  Error(ErrorStr.c_str());
1978  }
1979  // Record that we didn't find the file.
1981  return InputFile();
1982  }
1983 
1984  // Check if there was a request to override the contents of the file
1985  // that was part of the precompiled header. Overridding such a file
1986  // can lead to problems when lexing using the source locations from the
1987  // PCH.
1988  SourceManager &SM = getSourceManager();
1989  // FIXME: Reject if the overrides are different.
1990  if ((!Overridden && !Transient) && SM.isFileOverridden(File)) {
1991  if (Complain)
1992  Error(diag::err_fe_pch_file_overridden, Filename);
1993  // After emitting the diagnostic, recover by disabling the override so
1994  // that the original file will be used.
1995  //
1996  // FIXME: This recovery is just as broken as the original state; there may
1997  // be another precompiled module that's using the overridden contents, or
1998  // we might be half way through parsing it. Instead, we should treat the
1999  // overridden contents as belonging to a separate FileEntry.
2000  SM.disableFileContentsOverride(File);
2001  // The FileEntry is a virtual file entry with the size of the contents
2002  // that would override the original contents. Set it to the original's
2003  // size/time.
2004  FileMgr.modifyFileEntry(const_cast<FileEntry*>(File),
2005  StoredSize, StoredTime);
2006  }
2007 
2008  bool IsOutOfDate = false;
2009 
2010  // For an overridden file, there is nothing to validate.
2011  if (!Overridden && //
2012  (StoredSize != File->getSize() ||
2013  (StoredTime && StoredTime != File->getModificationTime() &&
2014  !DisableValidation)
2015  )) {
2016  if (Complain) {
2017  // Build a list of the PCH imports that got us here (in reverse).
2018  SmallVector<ModuleFile *, 4> ImportStack(1, &F);
2019  while (ImportStack.back()->ImportedBy.size() > 0)
2020  ImportStack.push_back(ImportStack.back()->ImportedBy[0]);
2021 
2022  // The top-level PCH is stale.
2023  StringRef TopLevelPCHName(ImportStack.back()->FileName);
2024  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
2025 
2026  // Print the import stack.
2027  if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
2028  Diag(diag::note_pch_required_by)
2029  << Filename << ImportStack[0]->FileName;
2030  for (unsigned I = 1; I < ImportStack.size(); ++I)
2031  Diag(diag::note_pch_required_by)
2032  << ImportStack[I-1]->FileName << ImportStack[I]->FileName;
2033  }
2034 
2035  if (!Diags.isDiagnosticInFlight())
2036  Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
2037  }
2038 
2039  IsOutOfDate = true;
2040  }
2041  // FIXME: If the file is overridden and we've already opened it,
2042  // issue an error (or split it into a separate FileEntry).
2043 
2044  InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate);
2045 
2046  // Note that we've loaded this input file.
2047  F.InputFilesLoaded[ID-1] = IF;
2048  return IF;
2049 }
2050 
2051 /// \brief If we are loading a relocatable PCH or module file, and the filename
2052 /// is not an absolute path, add the system or module root to the beginning of
2053 /// the file name.
2054 void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) {
2055  // Resolve relative to the base directory, if we have one.
2056  if (!M.BaseDirectory.empty())
2057  return ResolveImportedPath(Filename, M.BaseDirectory);
2058 }
2059 
2060 void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) {
2061  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
2062  return;
2063 
2065  llvm::sys::path::append(Buffer, Prefix, Filename);
2066  Filename.assign(Buffer.begin(), Buffer.end());
2067 }
2068 
2069 static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) {
2070  switch (ARR) {
2071  case ASTReader::Failure: return true;
2072  case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing);
2073  case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate);
2076  return !(Caps & ASTReader::ARR_ConfigurationMismatch);
2077  case ASTReader::HadErrors: return true;
2078  case ASTReader::Success: return false;
2079  }
2080 
2081  llvm_unreachable("unknown ASTReadResult");
2082 }
2083 
2084 ASTReader::ASTReadResult ASTReader::ReadOptionsBlock(
2085  BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
2086  bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
2087  std::string &SuggestedPredefines) {
2088  if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID))
2089  return Failure;
2090 
2091  // Read all of the records in the options block.
2092  RecordData Record;
2093  ASTReadResult Result = Success;
2094  while (1) {
2095  llvm::BitstreamEntry Entry = Stream.advance();
2096 
2097  switch (Entry.Kind) {
2099  case llvm::BitstreamEntry::SubBlock:
2100  return Failure;
2101 
2102  case llvm::BitstreamEntry::EndBlock:
2103  return Result;
2104 
2105  case llvm::BitstreamEntry::Record:
2106  // The interesting case.
2107  break;
2108  }
2109 
2110  // Read and process a record.
2111  Record.clear();
2112  switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) {
2113  case LANGUAGE_OPTIONS: {
2114  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2115  if (ParseLanguageOptions(Record, Complain, Listener,
2116  AllowCompatibleConfigurationMismatch))
2117  Result = ConfigurationMismatch;
2118  break;
2119  }
2120 
2121  case TARGET_OPTIONS: {
2122  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2123  if (ParseTargetOptions(Record, Complain, Listener,
2124  AllowCompatibleConfigurationMismatch))
2125  Result = ConfigurationMismatch;
2126  break;
2127  }
2128 
2129  case DIAGNOSTIC_OPTIONS: {
2130  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
2131  if (!AllowCompatibleConfigurationMismatch &&
2132  ParseDiagnosticOptions(Record, Complain, Listener))
2133  return OutOfDate;
2134  break;
2135  }
2136 
2137  case FILE_SYSTEM_OPTIONS: {
2138  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2139  if (!AllowCompatibleConfigurationMismatch &&
2140  ParseFileSystemOptions(Record, Complain, Listener))
2141  Result = ConfigurationMismatch;
2142  break;
2143  }
2144 
2145  case HEADER_SEARCH_OPTIONS: {
2146  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2147  if (!AllowCompatibleConfigurationMismatch &&
2148  ParseHeaderSearchOptions(Record, Complain, Listener))
2149  Result = ConfigurationMismatch;
2150  break;
2151  }
2152 
2153  case PREPROCESSOR_OPTIONS:
2154  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2155  if (!AllowCompatibleConfigurationMismatch &&
2156  ParsePreprocessorOptions(Record, Complain, Listener,
2157  SuggestedPredefines))
2158  Result = ConfigurationMismatch;
2159  break;
2160  }
2161  }
2162 }
2163 
2165 ASTReader::ReadControlBlock(ModuleFile &F,
2167  const ModuleFile *ImportedBy,
2168  unsigned ClientLoadCapabilities) {
2169  BitstreamCursor &Stream = F.Stream;
2170  ASTReadResult Result = Success;
2171 
2172  if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
2173  Error("malformed block record in AST file");
2174  return Failure;
2175  }
2176 
2177  // Read all of the records and blocks in the control block.
2178  RecordData Record;
2179  unsigned NumInputs = 0;
2180  unsigned NumUserInputs = 0;
2181  while (1) {
2182  llvm::BitstreamEntry Entry = Stream.advance();
2183 
2184  switch (Entry.Kind) {
2186  Error("malformed block record in AST file");
2187  return Failure;
2188  case llvm::BitstreamEntry::EndBlock: {
2189  // Validate input files.
2190  const HeaderSearchOptions &HSOpts =
2191  PP.getHeaderSearchInfo().getHeaderSearchOpts();
2192 
2193  // All user input files reside at the index range [0, NumUserInputs), and
2194  // system input files reside at [NumUserInputs, NumInputs). For explicitly
2195  // loaded module files, ignore missing inputs.
2196  if (!DisableValidation && F.Kind != MK_ExplicitModule) {
2197  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
2198 
2199  // If we are reading a module, we will create a verification timestamp,
2200  // so we verify all input files. Otherwise, verify only user input
2201  // files.
2202 
2203  unsigned N = NumUserInputs;
2204  if (ValidateSystemInputs ||
2207  F.Kind == MK_ImplicitModule))
2208  N = NumInputs;
2209 
2210  for (unsigned I = 0; I < N; ++I) {
2211  InputFile IF = getInputFile(F, I+1, Complain);
2212  if (!IF.getFile() || IF.isOutOfDate())
2213  return OutOfDate;
2214  }
2215  }
2216 
2217  if (Listener)
2218  Listener->visitModuleFile(F.FileName, F.Kind);
2219 
2220  if (Listener && Listener->needsInputFileVisitation()) {
2221  unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs
2222  : NumUserInputs;
2223  for (unsigned I = 0; I < N; ++I) {
2224  bool IsSystem = I >= NumUserInputs;
2225  InputFileInfo FI = readInputFileInfo(F, I+1);
2226  Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden,
2227  F.Kind == MK_ExplicitModule);
2228  }
2229  }
2230 
2231  return Result;
2232  }
2233 
2234  case llvm::BitstreamEntry::SubBlock:
2235  switch (Entry.ID) {
2236  case INPUT_FILES_BLOCK_ID:
2237  F.InputFilesCursor = Stream;
2238  if (Stream.SkipBlock() || // Skip with the main cursor
2239  // Read the abbreviations
2240  ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) {
2241  Error("malformed block record in AST file");
2242  return Failure;
2243  }
2244  continue;
2245 
2246  case OPTIONS_BLOCK_ID:
2247  // If we're reading the first module for this group, check its options
2248  // are compatible with ours. For modules it imports, no further checking
2249  // is required, because we checked them when we built it.
2250  if (Listener && !ImportedBy) {
2251  // Should we allow the configuration of the module file to differ from
2252  // the configuration of the current translation unit in a compatible
2253  // way?
2254  //
2255  // FIXME: Allow this for files explicitly specified with -include-pch.
2256  bool AllowCompatibleConfigurationMismatch =
2257  F.Kind == MK_ExplicitModule;
2258 
2259  Result = ReadOptionsBlock(Stream, ClientLoadCapabilities,
2260  AllowCompatibleConfigurationMismatch,
2261  *Listener, SuggestedPredefines);
2262  if (Result == Failure) {
2263  Error("malformed block record in AST file");
2264  return Result;
2265  }
2266 
2267  if (DisableValidation ||
2268  (AllowConfigurationMismatch && Result == ConfigurationMismatch))
2269  Result = Success;
2270 
2271  // If we can't load the module, exit early since we likely
2272  // will rebuild the module anyway. The stream may be in the
2273  // middle of a block.
2274  if (Result != Success)
2275  return Result;
2276  } else if (Stream.SkipBlock()) {
2277  Error("malformed block record in AST file");
2278  return Failure;
2279  }
2280  continue;
2281 
2282  default:
2283  if (Stream.SkipBlock()) {
2284  Error("malformed block record in AST file");
2285  return Failure;
2286  }
2287  continue;
2288  }
2289 
2290  case llvm::BitstreamEntry::Record:
2291  // The interesting case.
2292  break;
2293  }
2294 
2295  // Read and process a record.
2296  Record.clear();
2297  StringRef Blob;
2298  switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) {
2299  case METADATA: {
2300  if (Record[0] != VERSION_MAJOR && !DisableValidation) {
2301  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2302  Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old
2303  : diag::err_pch_version_too_new);
2304  return VersionMismatch;
2305  }
2306 
2307  bool hasErrors = Record[6];
2308  if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) {
2309  Diag(diag::err_pch_with_compiler_errors);
2310  return HadErrors;
2311  }
2312  if (hasErrors) {
2313  Diags.ErrorOccurred = true;
2314  Diags.UncompilableErrorOccurred = true;
2315  Diags.UnrecoverableErrorOccurred = true;
2316  }
2317 
2318  F.RelocatablePCH = Record[4];
2319  // Relative paths in a relocatable PCH are relative to our sysroot.
2320  if (F.RelocatablePCH)
2321  F.BaseDirectory = isysroot.empty() ? "/" : isysroot;
2322 
2323  F.HasTimestamps = Record[5];
2324 
2325  const std::string &CurBranch = getClangFullRepositoryVersion();
2326  StringRef ASTBranch = Blob;
2327  if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
2328  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2329  Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch;
2330  return VersionMismatch;
2331  }
2332  break;
2333  }
2334 
2335  case SIGNATURE:
2336  assert((!F.Signature || F.Signature == Record[0]) && "signature changed");
2337  F.Signature = Record[0];
2338  break;
2339 
2340  case IMPORTS: {
2341  // Load each of the imported PCH files.
2342  unsigned Idx = 0, N = Record.size();
2343  while (Idx < N) {
2344  // Read information about the AST file.
2345  ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
2346  // The import location will be the local one for now; we will adjust
2347  // all import locations of module imports after the global source
2348  // location info are setup, in ReadAST.
2349  SourceLocation ImportLoc =
2350  ReadUntranslatedSourceLocation(Record[Idx++]);
2351  off_t StoredSize = (off_t)Record[Idx++];
2352  time_t StoredModTime = (time_t)Record[Idx++];
2353  ASTFileSignature StoredSignature = Record[Idx++];
2354  auto ImportedFile = ReadPath(F, Record, Idx);
2355 
2356  // If our client can't cope with us being out of date, we can't cope with
2357  // our dependency being missing.
2358  unsigned Capabilities = ClientLoadCapabilities;
2359  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2360  Capabilities &= ~ARR_Missing;
2361 
2362  // Load the AST file.
2363  auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F,
2364  Loaded, StoredSize, StoredModTime,
2365  StoredSignature, Capabilities);
2366 
2367  // If we diagnosed a problem, produce a backtrace.
2368  if (isDiagnosedResult(Result, Capabilities))
2369  Diag(diag::note_module_file_imported_by)
2370  << F.FileName << !F.ModuleName.empty() << F.ModuleName;
2371 
2372  switch (Result) {
2373  case Failure: return Failure;
2374  // If we have to ignore the dependency, we'll have to ignore this too.
2375  case Missing:
2376  case OutOfDate: return OutOfDate;
2377  case VersionMismatch: return VersionMismatch;
2378  case ConfigurationMismatch: return ConfigurationMismatch;
2379  case HadErrors: return HadErrors;
2380  case Success: break;
2381  }
2382  }
2383  break;
2384  }
2385 
2386  case ORIGINAL_FILE:
2387  F.OriginalSourceFileID = FileID::get(Record[0]);
2390  ResolveImportedPath(F, F.OriginalSourceFileName);
2391  break;
2392 
2393  case ORIGINAL_FILE_ID:
2394  F.OriginalSourceFileID = FileID::get(Record[0]);
2395  break;
2396 
2397  case ORIGINAL_PCH_DIR:
2398  F.OriginalDir = Blob;
2399  break;
2400 
2401  case MODULE_NAME:
2402  F.ModuleName = Blob;
2403  if (Listener)
2404  Listener->ReadModuleName(F.ModuleName);
2405  break;
2406 
2407  case MODULE_DIRECTORY: {
2408  assert(!F.ModuleName.empty() &&
2409  "MODULE_DIRECTORY found before MODULE_NAME");
2410  // If we've already loaded a module map file covering this module, we may
2411  // have a better path for it (relative to the current build).
2412  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
2413  if (M && M->Directory) {
2414  // If we're implicitly loading a module, the base directory can't
2415  // change between the build and use.
2416  if (F.Kind != MK_ExplicitModule) {
2417  const DirectoryEntry *BuildDir =
2418  PP.getFileManager().getDirectory(Blob);
2419  if (!BuildDir || BuildDir != M->Directory) {
2420  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2421  Diag(diag::err_imported_module_relocated)
2422  << F.ModuleName << Blob << M->Directory->getName();
2423  return OutOfDate;
2424  }
2425  }
2426  F.BaseDirectory = M->Directory->getName();
2427  } else {
2428  F.BaseDirectory = Blob;
2429  }
2430  break;
2431  }
2432 
2433  case MODULE_MAP_FILE:
2434  if (ASTReadResult Result =
2435  ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities))
2436  return Result;
2437  break;
2438 
2439  case INPUT_FILE_OFFSETS:
2440  NumInputs = Record[0];
2441  NumUserInputs = Record[1];
2442  F.InputFileOffsets =
2443  (const llvm::support::unaligned_uint64_t *)Blob.data();
2444  F.InputFilesLoaded.resize(NumInputs);
2445  break;
2446  }
2447  }
2448 }
2449 
2451 ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
2452  BitstreamCursor &Stream = F.Stream;
2453 
2454  if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
2455  Error("malformed block record in AST file");
2456  return Failure;
2457  }
2458 
2459  // Read all of the records and blocks for the AST file.
2460  RecordData Record;
2461  while (1) {
2462  llvm::BitstreamEntry Entry = Stream.advance();
2463 
2464  switch (Entry.Kind) {
2466  Error("error at end of module block in AST file");
2467  return Failure;
2468  case llvm::BitstreamEntry::EndBlock: {
2469  // Outside of C++, we do not store a lookup map for the translation unit.
2470  // Instead, mark it as needing a lookup map to be built if this module
2471  // contains any declarations lexically within it (which it always does!).
2472  // This usually has no cost, since we very rarely need the lookup map for
2473  // the translation unit outside C++.
2475  if (DC->hasExternalLexicalStorage() &&
2476  !getContext().getLangOpts().CPlusPlus)
2478 
2479  return Success;
2480  }
2481  case llvm::BitstreamEntry::SubBlock:
2482  switch (Entry.ID) {
2483  case DECLTYPES_BLOCK_ID:
2484  // We lazily load the decls block, but we want to set up the
2485  // DeclsCursor cursor to point into it. Clone our current bitcode
2486  // cursor to it, enter the block and read the abbrevs in that block.
2487  // With the main cursor, we just skip over it.
2488  F.DeclsCursor = Stream;
2489  if (Stream.SkipBlock() || // Skip with the main cursor.
2490  // Read the abbrevs.
2491  ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) {
2492  Error("malformed block record in AST file");
2493  return Failure;
2494  }
2495  break;
2496 
2497  case PREPROCESSOR_BLOCK_ID:
2498  F.MacroCursor = Stream;
2499  if (!PP.getExternalSource())
2500  PP.setExternalSource(this);
2501 
2502  if (Stream.SkipBlock() ||
2503  ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) {
2504  Error("malformed block record in AST file");
2505  return Failure;
2506  }
2507  F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo();
2508  break;
2509 
2511  F.PreprocessorDetailCursor = Stream;
2512  if (Stream.SkipBlock() ||
2513  ReadBlockAbbrevs(F.PreprocessorDetailCursor,
2515  Error("malformed preprocessor detail record in AST file");
2516  return Failure;
2517  }
2519  = F.PreprocessorDetailCursor.GetCurrentBitNo();
2520 
2521  if (!PP.getPreprocessingRecord())
2522  PP.createPreprocessingRecord();
2523  if (!PP.getPreprocessingRecord()->getExternalSource())
2524  PP.getPreprocessingRecord()->SetExternalSource(*this);
2525  break;
2526 
2528  if (ReadSourceManagerBlock(F))
2529  return Failure;
2530  break;
2531 
2532  case SUBMODULE_BLOCK_ID:
2533  if (ASTReadResult Result = ReadSubmoduleBlock(F, ClientLoadCapabilities))
2534  return Result;
2535  break;
2536 
2537  case COMMENTS_BLOCK_ID: {
2538  BitstreamCursor C = Stream;
2539  if (Stream.SkipBlock() ||
2540  ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) {
2541  Error("malformed comments block in AST file");
2542  return Failure;
2543  }
2544  CommentsCursors.push_back(std::make_pair(C, &F));
2545  break;
2546  }
2547 
2548  default:
2549  if (Stream.SkipBlock()) {
2550  Error("malformed block record in AST file");
2551  return Failure;
2552  }
2553  break;
2554  }
2555  continue;
2556 
2557  case llvm::BitstreamEntry::Record:
2558  // The interesting case.
2559  break;
2560  }
2561 
2562  // Read and process a record.
2563  Record.clear();
2564  StringRef Blob;
2565  switch ((ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) {
2566  default: // Default behavior: ignore.
2567  break;
2568 
2569  case TYPE_OFFSET: {
2570  if (F.LocalNumTypes != 0) {
2571  Error("duplicate TYPE_OFFSET record in AST file");
2572  return Failure;
2573  }
2574  F.TypeOffsets = (const uint32_t *)Blob.data();
2575  F.LocalNumTypes = Record[0];
2576  unsigned LocalBaseTypeIndex = Record[1];
2577  F.BaseTypeIndex = getTotalNumTypes();
2578 
2579  if (F.LocalNumTypes > 0) {
2580  // Introduce the global -> local mapping for types within this module.
2581  GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F));
2582 
2583  // Introduce the local -> global mapping for types within this module.
2585  std::make_pair(LocalBaseTypeIndex,
2586  F.BaseTypeIndex - LocalBaseTypeIndex));
2587 
2588  TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
2589  }
2590  break;
2591  }
2592 
2593  case DECL_OFFSET: {
2594  if (F.LocalNumDecls != 0) {
2595  Error("duplicate DECL_OFFSET record in AST file");
2596  return Failure;
2597  }
2598  F.DeclOffsets = (const DeclOffset *)Blob.data();
2599  F.LocalNumDecls = Record[0];
2600  unsigned LocalBaseDeclID = Record[1];
2601  F.BaseDeclID = getTotalNumDecls();
2602 
2603  if (F.LocalNumDecls > 0) {
2604  // Introduce the global -> local mapping for declarations within this
2605  // module.
2606  GlobalDeclMap.insert(
2607  std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F));
2608 
2609  // Introduce the local -> global mapping for declarations within this
2610  // module.
2612  std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID));
2613 
2614  // Introduce the global -> local mapping for declarations within this
2615  // module.
2616  F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID;
2617 
2618  DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
2619  }
2620  break;
2621  }
2622 
2623  case TU_UPDATE_LEXICAL: {
2625  LexicalContents Contents(
2626  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
2627  Blob.data()),
2628  static_cast<unsigned int>(Blob.size() / 4));
2629  TULexicalDecls.push_back(std::make_pair(&F, Contents));
2630  TU->setHasExternalLexicalStorage(true);
2631  break;
2632  }
2633 
2634  case UPDATE_VISIBLE: {
2635  unsigned Idx = 0;
2636  serialization::DeclID ID = ReadDeclID(F, Record, Idx);
2637  auto *Data = (const unsigned char*)Blob.data();
2638  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data});
2639  // If we've already loaded the decl, perform the updates when we finish
2640  // loading this block.
2641  if (Decl *D = GetExistingDecl(ID))
2642  PendingUpdateRecords.push_back(std::make_pair(ID, D));
2643  break;
2644  }
2645 
2646  case IDENTIFIER_TABLE:
2647  F.IdentifierTableData = Blob.data();
2648  if (Record[0]) {
2650  (const unsigned char *)F.IdentifierTableData + Record[0],
2651  (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t),
2652  (const unsigned char *)F.IdentifierTableData,
2653  ASTIdentifierLookupTrait(*this, F));
2654 
2655  PP.getIdentifierTable().setExternalIdentifierLookup(this);
2656  }
2657  break;
2658 
2659  case IDENTIFIER_OFFSET: {
2660  if (F.LocalNumIdentifiers != 0) {
2661  Error("duplicate IDENTIFIER_OFFSET record in AST file");
2662  return Failure;
2663  }
2664  F.IdentifierOffsets = (const uint32_t *)Blob.data();
2665  F.LocalNumIdentifiers = Record[0];
2666  unsigned LocalBaseIdentifierID = Record[1];
2667  F.BaseIdentifierID = getTotalNumIdentifiers();
2668 
2669  if (F.LocalNumIdentifiers > 0) {
2670  // Introduce the global -> local mapping for identifiers within this
2671  // module.
2672  GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1,
2673  &F));
2674 
2675  // Introduce the local -> global mapping for identifiers within this
2676  // module.
2678  std::make_pair(LocalBaseIdentifierID,
2679  F.BaseIdentifierID - LocalBaseIdentifierID));
2680 
2681  IdentifiersLoaded.resize(IdentifiersLoaded.size()
2682  + F.LocalNumIdentifiers);
2683  }
2684  break;
2685  }
2686 
2688  F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end());
2689  break;
2690 
2692  // FIXME: Skip reading this record if our ASTConsumer doesn't care
2693  // about "interesting" decls (for instance, if we're building a module).
2694  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2695  EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
2696  break;
2697 
2698  case SPECIAL_TYPES:
2699  if (SpecialTypes.empty()) {
2700  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2701  SpecialTypes.push_back(getGlobalTypeID(F, Record[I]));
2702  break;
2703  }
2704 
2705  if (SpecialTypes.size() != Record.size()) {
2706  Error("invalid special-types record");
2707  return Failure;
2708  }
2709 
2710  for (unsigned I = 0, N = Record.size(); I != N; ++I) {
2711  serialization::TypeID ID = getGlobalTypeID(F, Record[I]);
2712  if (!SpecialTypes[I])
2713  SpecialTypes[I] = ID;
2714  // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate
2715  // merge step?
2716  }
2717  break;
2718 
2719  case STATISTICS:
2720  TotalNumStatements += Record[0];
2721  TotalNumMacros += Record[1];
2722  TotalLexicalDeclContexts += Record[2];
2723  TotalVisibleDeclContexts += Record[3];
2724  break;
2725 
2727  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2728  UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I]));
2729  break;
2730 
2731  case DELEGATING_CTORS:
2732  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2733  DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I]));
2734  break;
2735 
2737  if (Record.size() % 4 != 0) {
2738  Error("invalid weak identifiers record");
2739  return Failure;
2740  }
2741 
2742  // FIXME: Ignore weak undeclared identifiers from non-original PCH
2743  // files. This isn't the way to do it :)
2744  WeakUndeclaredIdentifiers.clear();
2745 
2746  // Translate the weak, undeclared identifiers into global IDs.
2747  for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) {
2748  WeakUndeclaredIdentifiers.push_back(
2749  getGlobalIdentifierID(F, Record[I++]));
2750  WeakUndeclaredIdentifiers.push_back(
2751  getGlobalIdentifierID(F, Record[I++]));
2752  WeakUndeclaredIdentifiers.push_back(
2753  ReadSourceLocation(F, Record, I).getRawEncoding());
2754  WeakUndeclaredIdentifiers.push_back(Record[I++]);
2755  }
2756  break;
2757 
2758  case SELECTOR_OFFSETS: {
2759  F.SelectorOffsets = (const uint32_t *)Blob.data();
2760  F.LocalNumSelectors = Record[0];
2761  unsigned LocalBaseSelectorID = Record[1];
2762  F.BaseSelectorID = getTotalNumSelectors();
2763 
2764  if (F.LocalNumSelectors > 0) {
2765  // Introduce the global -> local mapping for selectors within this
2766  // module.
2767  GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F));
2768 
2769  // Introduce the local -> global mapping for selectors within this
2770  // module.
2772  std::make_pair(LocalBaseSelectorID,
2773  F.BaseSelectorID - LocalBaseSelectorID));
2774 
2775  SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
2776  }
2777  break;
2778  }
2779 
2780  case METHOD_POOL:
2781  F.SelectorLookupTableData = (const unsigned char *)Blob.data();
2782  if (Record[0])
2785  F.SelectorLookupTableData + Record[0],
2787  ASTSelectorLookupTrait(*this, F));
2788  TotalNumMethodPoolEntries += Record[1];
2789  break;
2790 
2792  if (!Record.empty()) {
2793  for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) {
2794  ReferencedSelectorsData.push_back(getGlobalSelectorID(F,
2795  Record[Idx++]));
2796  ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx).
2797  getRawEncoding());
2798  }
2799  }
2800  break;
2801 
2802  case PP_COUNTER_VALUE:
2803  if (!Record.empty() && Listener)
2804  Listener->ReadCounter(F, Record[0]);
2805  break;
2806 
2807  case FILE_SORTED_DECLS:
2808  F.FileSortedDecls = (const DeclID *)Blob.data();
2809  F.NumFileSortedDecls = Record[0];
2810  break;
2811 
2812  case SOURCE_LOCATION_OFFSETS: {
2813  F.SLocEntryOffsets = (const uint32_t *)Blob.data();
2814  F.LocalNumSLocEntries = Record[0];
2815  unsigned SLocSpaceSize = Record[1];
2816  std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
2817  SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries,
2818  SLocSpaceSize);
2819  if (!F.SLocEntryBaseID) {
2820  Error("ran out of source locations");
2821  break;
2822  }
2823  // Make our entry in the range map. BaseID is negative and growing, so
2824  // we invert it. Because we invert it, though, we need the other end of
2825  // the range.
2826  unsigned RangeStart =
2828  GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F));
2830 
2831  // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing.
2832  assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0);
2833  GlobalSLocOffsetMap.insert(
2834  std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset
2835  - SLocSpaceSize,&F));
2836 
2837  // Initialize the remapping table.
2838  // Invalid stays invalid.
2839  F.SLocRemap.insertOrReplace(std::make_pair(0U, 0));
2840  // This module. Base was 2 when being compiled.
2841  F.SLocRemap.insertOrReplace(std::make_pair(2U,
2842  static_cast<int>(F.SLocEntryBaseOffset - 2)));
2843 
2844  TotalNumSLocEntries += F.LocalNumSLocEntries;
2845  break;
2846  }
2847 
2848  case MODULE_OFFSET_MAP: {
2849  // Additional remapping information.
2850  const unsigned char *Data = (const unsigned char*)Blob.data();
2851  const unsigned char *DataEnd = Data + Blob.size();
2852 
2853  // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders.
2854  if (F.SLocRemap.find(0) == F.SLocRemap.end()) {
2855  F.SLocRemap.insert(std::make_pair(0U, 0));
2856  F.SLocRemap.insert(std::make_pair(2U, 1));
2857  }
2858 
2859  // Continuous range maps we may be updating in our module.
2861  RemapBuilder;
2862  RemapBuilder SLocRemap(F.SLocRemap);
2863  RemapBuilder IdentifierRemap(F.IdentifierRemap);
2864  RemapBuilder MacroRemap(F.MacroRemap);
2865  RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
2866  RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
2867  RemapBuilder SelectorRemap(F.SelectorRemap);
2868  RemapBuilder DeclRemap(F.DeclRemap);
2869  RemapBuilder TypeRemap(F.TypeRemap);
2870 
2871  while (Data < DataEnd) {
2872  using namespace llvm::support;
2873  uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data);
2874  StringRef Name = StringRef((const char*)Data, Len);
2875  Data += Len;
2876  ModuleFile *OM = ModuleMgr.lookup(Name);
2877  if (!OM) {
2878  Error("SourceLocation remap refers to unknown module");
2879  return Failure;
2880  }
2881 
2882  uint32_t SLocOffset =
2883  endian::readNext<uint32_t, little, unaligned>(Data);
2884  uint32_t IdentifierIDOffset =
2885  endian::readNext<uint32_t, little, unaligned>(Data);
2886  uint32_t MacroIDOffset =
2887  endian::readNext<uint32_t, little, unaligned>(Data);
2888  uint32_t PreprocessedEntityIDOffset =
2889  endian::readNext<uint32_t, little, unaligned>(Data);
2890  uint32_t SubmoduleIDOffset =
2891  endian::readNext<uint32_t, little, unaligned>(Data);
2892  uint32_t SelectorIDOffset =
2893  endian::readNext<uint32_t, little, unaligned>(Data);
2894  uint32_t DeclIDOffset =
2895  endian::readNext<uint32_t, little, unaligned>(Data);
2896  uint32_t TypeIndexOffset =
2897  endian::readNext<uint32_t, little, unaligned>(Data);
2898 
2900 
2901  auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset,
2902  RemapBuilder &Remap) {
2903  if (Offset != None)
2904  Remap.insert(std::make_pair(Offset,
2905  static_cast<int>(BaseOffset - Offset)));
2906  };
2907  mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap);
2908  mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap);
2909  mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
2910  mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
2911  PreprocessedEntityRemap);
2912  mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap);
2913  mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap);
2914  mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap);
2915  mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap);
2916 
2917  // Global -> local mappings.
2918  F.GlobalToLocalDeclIDs[OM] = DeclIDOffset;
2919  }
2920  break;
2921  }
2922 
2924  if (ParseLineTable(F, Record))
2925  return Failure;
2926  break;
2927 
2928  case SOURCE_LOCATION_PRELOADS: {
2929  // Need to transform from the local view (1-based IDs) to the global view,
2930  // which is based off F.SLocEntryBaseID.
2931  if (!F.PreloadSLocEntries.empty()) {
2932  Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file");
2933  return Failure;
2934  }
2935 
2936  F.PreloadSLocEntries.swap(Record);
2937  break;
2938  }
2939 
2940  case EXT_VECTOR_DECLS:
2941  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2942  ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I]));
2943  break;
2944 
2945  case VTABLE_USES:
2946  if (Record.size() % 3 != 0) {
2947  Error("Invalid VTABLE_USES record");
2948  return Failure;
2949  }
2950 
2951  // Later tables overwrite earlier ones.
2952  // FIXME: Modules will have some trouble with this. This is clearly not
2953  // the right way to do this.
2954  VTableUses.clear();
2955 
2956  for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) {
2957  VTableUses.push_back(getGlobalDeclID(F, Record[Idx++]));
2958  VTableUses.push_back(
2959  ReadSourceLocation(F, Record, Idx).getRawEncoding());
2960  VTableUses.push_back(Record[Idx++]);
2961  }
2962  break;
2963 
2965  if (PendingInstantiations.size() % 2 != 0) {
2966  Error("Invalid existing PendingInstantiations");
2967  return Failure;
2968  }
2969 
2970  if (Record.size() % 2 != 0) {
2971  Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block");
2972  return Failure;
2973  }
2974 
2975  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
2976  PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++]));
2977  PendingInstantiations.push_back(
2978  ReadSourceLocation(F, Record, I).getRawEncoding());
2979  }
2980  break;
2981 
2982  case SEMA_DECL_REFS:
2983  if (Record.size() != 2) {
2984  Error("Invalid SEMA_DECL_REFS block");
2985  return Failure;
2986  }
2987  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2988  SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
2989  break;
2990 
2991  case PPD_ENTITIES_OFFSETS: {
2992  F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data();
2993  assert(Blob.size() % sizeof(PPEntityOffset) == 0);
2994  F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset);
2995 
2996  unsigned LocalBasePreprocessedEntityID = Record[0];
2997 
2998  unsigned StartingID;
2999  if (!PP.getPreprocessingRecord())
3000  PP.createPreprocessingRecord();
3001  if (!PP.getPreprocessingRecord()->getExternalSource())
3002  PP.getPreprocessingRecord()->SetExternalSource(*this);
3003  StartingID
3004  = PP.getPreprocessingRecord()
3005  ->allocateLoadedEntities(F.NumPreprocessedEntities);
3006  F.BasePreprocessedEntityID = StartingID;
3007 
3008  if (F.NumPreprocessedEntities > 0) {
3009  // Introduce the global -> local mapping for preprocessed entities in
3010  // this module.
3011  GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F));
3012 
3013  // Introduce the local -> global mapping for preprocessed entities in
3014  // this module.
3016  std::make_pair(LocalBasePreprocessedEntityID,
3017  F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID));
3018  }
3019 
3020  break;
3021  }
3022 
3023  case DECL_UPDATE_OFFSETS: {
3024  if (Record.size() % 2 != 0) {
3025  Error("invalid DECL_UPDATE_OFFSETS block in AST file");
3026  return Failure;
3027  }
3028  for (unsigned I = 0, N = Record.size(); I != N; I += 2) {
3029  GlobalDeclID ID = getGlobalDeclID(F, Record[I]);
3030  DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1]));
3031 
3032  // If we've already loaded the decl, perform the updates when we finish
3033  // loading this block.
3034  if (Decl *D = GetExistingDecl(ID))
3035  PendingUpdateRecords.push_back(std::make_pair(ID, D));
3036  }
3037  break;
3038  }
3039 
3040  case OBJC_CATEGORIES_MAP: {
3041  if (F.LocalNumObjCCategoriesInMap != 0) {
3042  Error("duplicate OBJC_CATEGORIES_MAP record in AST file");
3043  return Failure;
3044  }
3045 
3046  F.LocalNumObjCCategoriesInMap = Record[0];
3047  F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data();
3048  break;
3049  }
3050 
3051  case OBJC_CATEGORIES:
3052  F.ObjCCategories.swap(Record);
3053  break;
3054 
3055  case DIAG_PRAGMA_MAPPINGS:
3056  if (F.PragmaDiagMappings.empty())
3057  F.PragmaDiagMappings.swap(Record);
3058  else
3059  F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(),
3060  Record.begin(), Record.end());
3061  break;
3062 
3064  // Later tables overwrite earlier ones.
3065  // FIXME: Modules will have trouble with this.
3066  CUDASpecialDeclRefs.clear();
3067  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3068  CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
3069  break;
3070 
3071  case HEADER_SEARCH_TABLE: {
3072  F.HeaderFileInfoTableData = Blob.data();
3073  F.LocalNumHeaderFileInfos = Record[1];
3074  if (Record[0]) {
3077  (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
3078  (const unsigned char *)F.HeaderFileInfoTableData,
3079  HeaderFileInfoTrait(*this, F,
3080  &PP.getHeaderSearchInfo(),
3081  Blob.data() + Record[2]));
3082 
3083  PP.getHeaderSearchInfo().SetExternalSource(this);
3084  if (!PP.getHeaderSearchInfo().getExternalLookup())
3085  PP.getHeaderSearchInfo().SetExternalLookup(this);
3086  }
3087  break;
3088  }
3089 
3090  case FP_PRAGMA_OPTIONS:
3091  // Later tables overwrite earlier ones.
3092  FPPragmaOptions.swap(Record);
3093  break;
3094 
3095  case OPENCL_EXTENSIONS:
3096  // Later tables overwrite earlier ones.
3097  OpenCLExtensions.swap(Record);
3098  break;
3099 
3100  case TENTATIVE_DEFINITIONS:
3101  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3102  TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I]));
3103  break;
3104 
3105  case KNOWN_NAMESPACES:
3106  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3107  KnownNamespaces.push_back(getGlobalDeclID(F, Record[I]));
3108  break;
3109 
3110  case UNDEFINED_BUT_USED:
3111  if (UndefinedButUsed.size() % 2 != 0) {
3112  Error("Invalid existing UndefinedButUsed");
3113  return Failure;
3114  }
3115 
3116  if (Record.size() % 2 != 0) {
3117  Error("invalid undefined-but-used record");
3118  return Failure;
3119  }
3120  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3121  UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++]));
3122  UndefinedButUsed.push_back(
3123  ReadSourceLocation(F, Record, I).getRawEncoding());
3124  }
3125  break;
3127  for (unsigned I = 0, N = Record.size(); I != N;) {
3128  DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++]));
3129  const uint64_t Count = Record[I++];
3130  DelayedDeleteExprs.push_back(Count);
3131  for (uint64_t C = 0; C < Count; ++C) {
3132  DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding());
3133  bool IsArrayForm = Record[I++] == 1;
3134  DelayedDeleteExprs.push_back(IsArrayForm);
3135  }
3136  }
3137  break;
3138 
3139  case IMPORTED_MODULES: {
3140  if (F.Kind != MK_ImplicitModule && F.Kind != MK_ExplicitModule) {
3141  // If we aren't loading a module (which has its own exports), make
3142  // all of the imported modules visible.
3143  // FIXME: Deal with macros-only imports.
3144  for (unsigned I = 0, N = Record.size(); I != N; /**/) {
3145  unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]);
3146  SourceLocation Loc = ReadSourceLocation(F, Record, I);
3147  if (GlobalID)
3148  ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc));
3149  }
3150  }
3151  break;
3152  }
3153 
3154  case MACRO_OFFSET: {
3155  if (F.LocalNumMacros != 0) {
3156  Error("duplicate MACRO_OFFSET record in AST file");
3157  return Failure;
3158  }
3159  F.MacroOffsets = (const uint32_t *)Blob.data();
3160  F.LocalNumMacros = Record[0];
3161  unsigned LocalBaseMacroID = Record[1];
3162  F.BaseMacroID = getTotalNumMacros();
3163 
3164  if (F.LocalNumMacros > 0) {
3165  // Introduce the global -> local mapping for macros within this module.
3166  GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F));
3167 
3168  // Introduce the local -> global mapping for macros within this module.
3170  std::make_pair(LocalBaseMacroID,
3171  F.BaseMacroID - LocalBaseMacroID));
3172 
3173  MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros);
3174  }
3175  break;
3176  }
3177 
3178  case LATE_PARSED_TEMPLATE: {
3179  LateParsedTemplates.append(Record.begin(), Record.end());
3180  break;
3181  }
3182 
3184  if (Record.size() != 1) {
3185  Error("invalid pragma optimize record");
3186  return Failure;
3187  }
3188  OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]);
3189  break;
3190 
3192  if (Record.size() != 1) {
3193  Error("invalid pragma ms_struct record");
3194  return Failure;
3195  }
3196  PragmaMSStructState = Record[0];
3197  break;
3198 
3200  if (Record.size() != 2) {
3201  Error("invalid pragma ms_struct record");
3202  return Failure;
3203  }
3204  PragmaMSPointersToMembersState = Record[0];
3205  PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]);
3206  break;
3207 
3209  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3210  UnusedLocalTypedefNameCandidates.push_back(
3211  getGlobalDeclID(F, Record[I]));
3212  break;
3213  }
3214  }
3215 }
3216 
3218 ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
3219  const ModuleFile *ImportedBy,
3220  unsigned ClientLoadCapabilities) {
3221  unsigned Idx = 0;
3222  F.ModuleMapPath = ReadPath(F, Record, Idx);
3223 
3224  if (F.Kind == MK_ExplicitModule) {
3225  // For an explicitly-loaded module, we don't care whether the original
3226  // module map file exists or matches.
3227  return Success;
3228  }
3229 
3230  // Try to resolve ModuleName in the current header search context and
3231  // verify that it is found in the same module map file as we saved. If the
3232  // top-level AST file is a main file, skip this check because there is no
3233  // usable header search context.
3234  assert(!F.ModuleName.empty() &&
3235  "MODULE_NAME should come before MODULE_MAP_FILE");
3236  if (F.Kind == MK_ImplicitModule &&
3237  (*ModuleMgr.begin())->Kind != MK_MainFile) {
3238  // An implicitly-loaded module file should have its module listed in some
3239  // module map file that we've already loaded.
3240  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
3241  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
3242  const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
3243  if (!ModMap) {
3244  assert(ImportedBy && "top-level import should be verified");
3245  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
3246  if (auto *ASTFE = M ? M->getASTFile() : nullptr)
3247  // This module was defined by an imported (explicit) module.
3248  Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName
3249  << ASTFE->getName();
3250  else
3251  // This module was built with a different module map.
3252  Diag(diag::err_imported_module_not_found)
3253  << F.ModuleName << F.FileName << ImportedBy->FileName
3254  << F.ModuleMapPath;
3255  }
3256  return OutOfDate;
3257  }
3258 
3259  assert(M->Name == F.ModuleName && "found module with different name");
3260 
3261  // Check the primary module map file.
3262  const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath);
3263  if (StoredModMap == nullptr || StoredModMap != ModMap) {
3264  assert(ModMap && "found module is missing module map file");
3265  assert(ImportedBy && "top-level import should be verified");
3266  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3267  Diag(diag::err_imported_module_modmap_changed)
3268  << F.ModuleName << ImportedBy->FileName
3269  << ModMap->getName() << F.ModuleMapPath;
3270  return OutOfDate;
3271  }
3272 
3273  llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps;
3274  for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) {
3275  // FIXME: we should use input files rather than storing names.
3276  std::string Filename = ReadPath(F, Record, Idx);
3277  const FileEntry *F =
3278  FileMgr.getFile(Filename, false, false);
3279  if (F == nullptr) {
3280  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3281  Error("could not find file '" + Filename +"' referenced by AST file");
3282  return OutOfDate;
3283  }
3284  AdditionalStoredMaps.insert(F);
3285  }
3286 
3287  // Check any additional module map files (e.g. module.private.modulemap)
3288  // that are not in the pcm.
3289  if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) {
3290  for (const FileEntry *ModMap : *AdditionalModuleMaps) {
3291  // Remove files that match
3292  // Note: SmallPtrSet::erase is really remove
3293  if (!AdditionalStoredMaps.erase(ModMap)) {
3294  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3295  Diag(diag::err_module_different_modmap)
3296  << F.ModuleName << /*new*/0 << ModMap->getName();
3297  return OutOfDate;
3298  }
3299  }
3300  }
3301 
3302  // Check any additional module map files that are in the pcm, but not
3303  // found in header search. Cases that match are already removed.
3304  for (const FileEntry *ModMap : AdditionalStoredMaps) {
3305  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3306  Diag(diag::err_module_different_modmap)
3307  << F.ModuleName << /*not new*/1 << ModMap->getName();
3308  return OutOfDate;
3309  }
3310  }
3311 
3312  if (Listener)
3313  Listener->ReadModuleMapFile(F.ModuleMapPath);
3314  return Success;
3315 }
3316 
3317 
3318 /// \brief Move the given method to the back of the global list of methods.
3320  // Find the entry for this selector in the method pool.
3322  = S.MethodPool.find(Method->getSelector());
3323  if (Known == S.MethodPool.end())
3324  return;
3325 
3326  // Retrieve the appropriate method list.
3327  ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first
3328  : Known->second.second;
3329  bool Found = false;
3330  for (ObjCMethodList *List = &Start; List; List = List->getNext()) {
3331  if (!Found) {
3332  if (List->getMethod() == Method) {
3333  Found = true;
3334  } else {
3335  // Keep searching.
3336  continue;
3337  }
3338  }
3339 
3340  if (List->getNext())
3341  List->setMethod(List->getNext()->getMethod());
3342  else
3343  List->setMethod(Method);
3344  }
3345 }
3346 
3348  assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?");
3349  for (Decl *D : Names) {
3350  bool wasHidden = D->Hidden;
3351  D->Hidden = false;
3352 
3353  if (wasHidden && SemaObj) {
3354  if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) {
3355  moveMethodToBackOfGlobalList(*SemaObj, Method);
3356  }
3357  }
3358  }
3359 }
3360 
3362  Module::NameVisibilityKind NameVisibility,
3363  SourceLocation ImportLoc) {
3364  llvm::SmallPtrSet<Module *, 4> Visited;
3366  Stack.push_back(Mod);
3367  while (!Stack.empty()) {
3368  Mod = Stack.pop_back_val();
3369 
3370  if (NameVisibility <= Mod->NameVisibility) {
3371  // This module already has this level of visibility (or greater), so
3372  // there is nothing more to do.
3373  continue;
3374  }
3375 
3376  if (!Mod->isAvailable()) {
3377  // Modules that aren't available cannot be made visible.
3378  continue;
3379  }
3380 
3381  // Update the module's name visibility.
3382  Mod->NameVisibility = NameVisibility;
3383 
3384  // If we've already deserialized any names from this module,
3385  // mark them as visible.
3386  HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod);
3387  if (Hidden != HiddenNamesMap.end()) {
3388  auto HiddenNames = std::move(*Hidden);
3389  HiddenNamesMap.erase(Hidden);
3390  makeNamesVisible(HiddenNames.second, HiddenNames.first);
3391  assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() &&
3392  "making names visible added hidden names");
3393  }
3394 
3395  // Push any exported modules onto the stack to be marked as visible.
3396  SmallVector<Module *, 16> Exports;
3397  Mod->getExportedModules(Exports);
3399  I = Exports.begin(), E = Exports.end(); I != E; ++I) {
3400  Module *Exported = *I;
3401  if (Visited.insert(Exported).second)
3402  Stack.push_back(Exported);
3403  }
3404  }
3405 }
3406 
3408  if (GlobalIndex)
3409  return false;
3410 
3411  if (TriedLoadingGlobalIndex || !UseGlobalIndex ||
3412  !Context.getLangOpts().Modules)
3413  return true;
3414 
3415  // Try to load the global index.
3416  TriedLoadingGlobalIndex = true;
3417  StringRef ModuleCachePath
3418  = getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
3419  std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result
3420  = GlobalModuleIndex::readIndex(ModuleCachePath);
3421  if (!Result.first)
3422  return true;
3423 
3424  GlobalIndex.reset(Result.first);
3425  ModuleMgr.setGlobalIndex(GlobalIndex.get());
3426  return false;
3427 }
3428 
3430  return Context.getLangOpts().Modules && UseGlobalIndex &&
3431  !hasGlobalIndex() && TriedLoadingGlobalIndex;
3432 }
3433 
3435  // Overwrite the timestamp file contents so that file's mtime changes.
3436  std::string TimestampFilename = MF.getTimestampFilename();
3437  std::error_code EC;
3438  llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
3439  if (EC)
3440  return;
3441  OS << "Timestamp file\n";
3442 }
3443 
3444 /// \brief Given a cursor at the start of an AST file, scan ahead and drop the
3445 /// cursor into the start of the given block ID, returning false on success and
3446 /// true on failure.
3447 static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) {
3448  while (1) {
3449  llvm::BitstreamEntry Entry = Cursor.advance();
3450  switch (Entry.Kind) {
3452  case llvm::BitstreamEntry::EndBlock:
3453  return true;
3454 
3455  case llvm::BitstreamEntry::Record:
3456  // Ignore top-level records.
3457  Cursor.skipRecord(Entry.ID);
3458  break;
3459 
3460  case llvm::BitstreamEntry::SubBlock:
3461  if (Entry.ID == BlockID) {
3462  if (Cursor.EnterSubBlock(BlockID))
3463  return true;
3464  // Found it!
3465  return false;
3466  }
3467 
3468  if (Cursor.SkipBlock())
3469  return true;
3470  }
3471  }
3472 }
3473 
3475  ModuleKind Type,
3476  SourceLocation ImportLoc,
3477  unsigned ClientLoadCapabilities) {
3479  SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
3480 
3481  // Defer any pending actions until we get to the end of reading the AST file.
3482  Deserializing AnASTFile(this);
3483 
3484  // Bump the generation number.
3485  unsigned PreviousGeneration = incrementGeneration(Context);
3486 
3487  unsigned NumModules = ModuleMgr.size();
3489  switch(ASTReadResult ReadResult = ReadASTCore(FileName, Type, ImportLoc,
3490  /*ImportedBy=*/nullptr, Loaded,
3491  0, 0, 0,
3492  ClientLoadCapabilities)) {
3493  case Failure:
3494  case Missing:
3495  case OutOfDate:
3496  case VersionMismatch:
3497  case ConfigurationMismatch:
3498  case HadErrors: {
3499  llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet;
3500  for (const ImportedModule &IM : Loaded)
3501  LoadedSet.insert(IM.Mod);
3502 
3503  ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, ModuleMgr.end(),
3504  LoadedSet,
3505  Context.getLangOpts().Modules
3506  ? &PP.getHeaderSearchInfo().getModuleMap()
3507  : nullptr);
3508 
3509  // If we find that any modules are unusable, the global index is going
3510  // to be out-of-date. Just remove it.
3511  GlobalIndex.reset();
3512  ModuleMgr.setGlobalIndex(nullptr);
3513  return ReadResult;
3514  }
3515  case Success:
3516  break;
3517  }
3518 
3519  // Here comes stuff that we only do once the entire chain is loaded.
3520 
3521  // Load the AST blocks of all of the modules that we loaded.
3522  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
3523  MEnd = Loaded.end();
3524  M != MEnd; ++M) {
3525  ModuleFile &F = *M->Mod;
3526 
3527  // Read the AST block.
3528  if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities))
3529  return Result;
3530 
3531  // Read the extension blocks.
3533  if (ASTReadResult Result = ReadExtensionBlock(F))
3534  return Result;
3535  }
3536 
3537  // Once read, set the ModuleFile bit base offset and update the size in
3538  // bits of all files we've seen.
3539  F.GlobalBitOffset = TotalModulesSizeInBits;
3540  TotalModulesSizeInBits += F.SizeInBits;
3541  GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F));
3542 
3543  // Preload SLocEntries.
3544  for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) {
3545  int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID;
3546  // Load it through the SourceManager and don't call ReadSLocEntry()
3547  // directly because the entry may have already been loaded in which case
3548  // calling ReadSLocEntry() directly would trigger an assertion in
3549  // SourceManager.
3550  SourceMgr.getLoadedSLocEntryByID(Index);
3551  }
3552 
3553  // Preload all the pending interesting identifiers by marking them out of
3554  // date.
3555  for (auto Offset : F.PreloadIdentifierOffsets) {
3556  const unsigned char *Data = reinterpret_cast<const unsigned char *>(
3558 
3559  ASTIdentifierLookupTrait Trait(*this, F);
3560  auto KeyDataLen = Trait.ReadKeyDataLength(Data);
3561  auto Key = Trait.ReadKey(Data, KeyDataLen.first);
3562  auto &II = PP.getIdentifierTable().getOwn(Key);
3563  II.setOutOfDate(true);
3564 
3565  // Mark this identifier as being from an AST file so that we can track
3566  // whether we need to serialize it.
3567  markIdentifierFromAST(*this, II);
3568 
3569  // Associate the ID with the identifier so that the writer can reuse it.
3570  auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
3571  SetIdentifierInfo(ID, &II);
3572  }
3573  }
3574 
3575  // Setup the import locations and notify the module manager that we've
3576  // committed to these module files.
3577  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
3578  MEnd = Loaded.end();
3579  M != MEnd; ++M) {
3580  ModuleFile &F = *M->Mod;
3581 
3582  ModuleMgr.moduleFileAccepted(&F);
3583 
3584  // Set the import location.
3585  F.DirectImportLoc = ImportLoc;
3586  // FIXME: We assume that locations from PCH / preamble do not need
3587  // any translation.
3588  if (!M->ImportedBy)
3589  F.ImportLoc = M->ImportLoc;
3590  else
3591  F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc);
3592  }
3593 
3594  if (!Context.getLangOpts().CPlusPlus ||
3595  (Type != MK_ImplicitModule && Type != MK_ExplicitModule)) {
3596  // Mark all of the identifiers in the identifier table as being out of date,
3597  // so that various accessors know to check the loaded modules when the
3598  // identifier is used.
3599  //
3600  // For C++ modules, we don't need information on many identifiers (just
3601  // those that provide macros or are poisoned), so we mark all of
3602  // the interesting ones via PreloadIdentifierOffsets.
3603  for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(),
3604  IdEnd = PP.getIdentifierTable().end();
3605  Id != IdEnd; ++Id)
3606  Id->second->setOutOfDate(true);
3607  }
3608  // Mark selectors as out of date.
3609  for (auto Sel : SelectorGeneration)
3610  SelectorOutOfDate[Sel.first] = true;
3611 
3612  // Resolve any unresolved module exports.
3613  for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) {
3614  UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I];
3615  SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID);
3616  Module *ResolvedMod = getSubmodule(GlobalID);
3617 
3618  switch (Unresolved.Kind) {
3619  case UnresolvedModuleRef::Conflict:
3620  if (ResolvedMod) {
3621  Module::Conflict Conflict;
3622  Conflict.Other = ResolvedMod;
3623  Conflict.Message = Unresolved.String.str();
3624  Unresolved.Mod->Conflicts.push_back(Conflict);
3625  }
3626  continue;
3627 
3628  case UnresolvedModuleRef::Import:
3629  if (ResolvedMod)
3630  Unresolved.Mod->Imports.insert(ResolvedMod);
3631  continue;
3632 
3633  case UnresolvedModuleRef::Export:
3634  if (ResolvedMod || Unresolved.IsWildcard)
3635  Unresolved.Mod->Exports.push_back(
3636  Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard));
3637  continue;
3638  }
3639  }
3640  UnresolvedModuleRefs.clear();
3641 
3642  // FIXME: How do we load the 'use'd modules? They may not be submodules.
3643  // Might be unnecessary as use declarations are only used to build the
3644  // module itself.
3645 
3646  InitializeContext();
3647 
3648  if (SemaObj)
3649  UpdateSema();
3650 
3651  if (DeserializationListener)
3652  DeserializationListener->ReaderInitialized(this);
3653 
3654  ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule();
3655  if (PrimaryModule.OriginalSourceFileID.isValid()) {
3656  PrimaryModule.OriginalSourceFileID
3657  = FileID::get(PrimaryModule.SLocEntryBaseID
3658  + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1);
3659 
3660  // If this AST file is a precompiled preamble, then set the
3661  // preamble file ID of the source manager to the file source file
3662  // from which the preamble was built.
3663  if (Type == MK_Preamble) {
3664  SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID);
3665  } else if (Type == MK_MainFile) {
3666  SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID);
3667  }
3668  }
3669 
3670  // For any Objective-C class definitions we have already loaded, make sure
3671  // that we load any additional categories.
3672  for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) {
3673  loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(),
3674  ObjCClassesLoaded[I],
3675  PreviousGeneration);
3676  }
3677 
3678  if (PP.getHeaderSearchInfo()
3679  .getHeaderSearchOpts()
3680  .ModulesValidateOncePerBuildSession) {
3681  // Now we are certain that the module and all modules it depends on are
3682  // up to date. Create or update timestamp files for modules that are
3683  // located in the module cache (not for PCH files that could be anywhere
3684  // in the filesystem).
3685  for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
3686  ImportedModule &M = Loaded[I];
3687  if (M.Mod->Kind == MK_ImplicitModule) {
3688  updateModuleTimestamp(*M.Mod);
3689  }
3690  }
3691  }
3692 
3693  return Success;
3694 }
3695 
3696 static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile);
3697 
3698 /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'.
3699 static bool startsWithASTFileMagic(BitstreamCursor &Stream) {
3700  return Stream.Read(8) == 'C' &&
3701  Stream.Read(8) == 'P' &&
3702  Stream.Read(8) == 'C' &&
3703  Stream.Read(8) == 'H';
3704 }
3705 
3707  switch (Kind) {
3708  case MK_PCH:
3709  return 0; // PCH
3710  case MK_ImplicitModule:
3711  case MK_ExplicitModule:
3712  return 1; // module
3713  case MK_MainFile:
3714  case MK_Preamble:
3715  return 2; // main source file
3716  }
3717  llvm_unreachable("unknown module kind");
3718 }
3719 
3721 ASTReader::ReadASTCore(StringRef FileName,
3722  ModuleKind Type,
3723  SourceLocation ImportLoc,
3724  ModuleFile *ImportedBy,
3726  off_t ExpectedSize, time_t ExpectedModTime,
3727  ASTFileSignature ExpectedSignature,
3728  unsigned ClientLoadCapabilities) {
3729  ModuleFile *M;
3730  std::string ErrorStr;
3732  = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy,
3733  getGeneration(), ExpectedSize, ExpectedModTime,
3734  ExpectedSignature, readASTFileSignature,
3735  M, ErrorStr);
3736 
3737  switch (AddResult) {
3739  return Success;
3740 
3742  // Load module file below.
3743  break;
3744 
3746  // The module file was missing; if the client can handle that, return
3747  // it.
3748  if (ClientLoadCapabilities & ARR_Missing)
3749  return Missing;
3750 
3751  // Otherwise, return an error.
3752  Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type)
3753  << FileName << ErrorStr.empty()
3754  << ErrorStr;
3755  return Failure;
3756 
3758  // We couldn't load the module file because it is out-of-date. If the
3759  // client can handle out-of-date, return it.
3760  if (ClientLoadCapabilities & ARR_OutOfDate)
3761  return OutOfDate;
3762 
3763  // Otherwise, return an error.
3764  Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type)
3765  << FileName << ErrorStr.empty()
3766  << ErrorStr;
3767  return Failure;
3768  }
3769 
3770  assert(M && "Missing module file");
3771 
3772  // FIXME: This seems rather a hack. Should CurrentDir be part of the
3773  // module?
3774  if (FileName != "-") {
3775  CurrentDir = llvm::sys::path::parent_path(FileName);
3776  if (CurrentDir.empty()) CurrentDir = ".";
3777  }
3778 
3779  ModuleFile &F = *M;
3780  BitstreamCursor &Stream = F.Stream;
3781  PCHContainerRdr.ExtractPCH(F.Buffer->getMemBufferRef(), F.StreamFile);
3782  Stream.init(&F.StreamFile);
3783  F.SizeInBits = F.Buffer->getBufferSize() * 8;
3784 
3785  // Sniff for the signature.
3786  if (!startsWithASTFileMagic(Stream)) {
3787  Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type)
3788  << FileName;
3789  return Failure;
3790  }
3791 
3792  // This is used for compatibility with older PCH formats.
3793  bool HaveReadControlBlock = false;
3794  while (1) {
3795  llvm::BitstreamEntry Entry = Stream.advance();
3796 
3797  switch (Entry.Kind) {
3799  case llvm::BitstreamEntry::Record:
3800  case llvm::BitstreamEntry::EndBlock:
3801  Error("invalid record at top-level of AST file");
3802  return Failure;
3803 
3804  case llvm::BitstreamEntry::SubBlock:
3805  break;
3806  }
3807 
3808  switch (Entry.ID) {
3809  case CONTROL_BLOCK_ID:
3810  HaveReadControlBlock = true;
3811  switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) {
3812  case Success:
3813  // Check that we didn't try to load a non-module AST file as a module.
3814  //
3815  // FIXME: Should we also perform the converse check? Loading a module as
3816  // a PCH file sort of works, but it's a bit wonky.
3817  if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule) &&
3818  F.ModuleName.empty()) {
3819  auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure;
3820  if (Result != OutOfDate ||
3821  (ClientLoadCapabilities & ARR_OutOfDate) == 0)
3822  Diag(diag::err_module_file_not_module) << FileName;
3823  return Result;
3824  }
3825  break;
3826 
3827  case Failure: return Failure;
3828  case Missing: return Missing;
3829  case OutOfDate: return OutOfDate;
3830  case VersionMismatch: return VersionMismatch;
3831  case ConfigurationMismatch: return ConfigurationMismatch;
3832  case HadErrors: return HadErrors;
3833  }
3834  break;
3835 
3836  case AST_BLOCK_ID:
3837  if (!HaveReadControlBlock) {
3838  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
3839  Diag(diag::err_pch_version_too_old);
3840  return VersionMismatch;
3841  }
3842 
3843  // Record that we've loaded this module.
3844  Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc));
3845  return Success;
3846 
3847  default:
3848  if (Stream.SkipBlock()) {
3849  Error("malformed block record in AST file");
3850  return Failure;
3851  }
3852  break;
3853  }
3854  }
3855 
3856  return Success;
3857 }
3858 
3859 /// Parse a record and blob containing module file extension metadata.
3861  const SmallVectorImpl<uint64_t> &Record,
3862  StringRef Blob,
3863  ModuleFileExtensionMetadata &Metadata) {
3864  if (Record.size() < 4) return true;
3865 
3866  Metadata.MajorVersion = Record[0];
3867  Metadata.MinorVersion = Record[1];
3868 
3869  unsigned BlockNameLen = Record[2];
3870  unsigned UserInfoLen = Record[3];
3871 
3872  if (BlockNameLen + UserInfoLen > Blob.size()) return true;
3873 
3874  Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen);
3875  Metadata.UserInfo = std::string(Blob.data() + BlockNameLen,
3876  Blob.data() + BlockNameLen + UserInfoLen);
3877  return false;
3878 }
3879 
3880 ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) {
3881  BitstreamCursor &Stream = F.Stream;
3882 
3883  RecordData Record;
3884  while (true) {
3885  llvm::BitstreamEntry Entry = Stream.advance();
3886  switch (Entry.Kind) {
3887  case llvm::BitstreamEntry::SubBlock:
3888  if (Stream.SkipBlock())
3889  return Failure;
3890 
3891  continue;
3892 
3893  case llvm::BitstreamEntry::EndBlock:
3894  return Success;
3895 
3897  return HadErrors;
3898 
3899  case llvm::BitstreamEntry::Record:
3900  break;
3901  }
3902 
3903  Record.clear();
3904  StringRef Blob;
3905  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
3906  switch (RecCode) {
3907  case EXTENSION_METADATA: {
3908  ModuleFileExtensionMetadata Metadata;
3909  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
3910  return Failure;
3911 
3912  // Find a module file extension with this block name.
3913  auto Known = ModuleFileExtensions.find(Metadata.BlockName);
3914  if (Known == ModuleFileExtensions.end()) break;
3915 
3916  // Form a reader.
3917  if (auto Reader = Known->second->createExtensionReader(Metadata, *this,
3918  F, Stream)) {
3919  F.ExtensionReaders.push_back(std::move(Reader));
3920  }
3921 
3922  break;
3923  }
3924  }
3925  }
3926 
3927  return Success;
3928 }
3929 
3931  // If there's a listener, notify them that we "read" the translation unit.
3932  if (DeserializationListener)
3933  DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID,
3935 
3936  // FIXME: Find a better way to deal with collisions between these
3937  // built-in types. Right now, we just ignore the problem.
3938 
3939  // Load the special types.
3940  if (SpecialTypes.size() >= NumSpecialTypeIDs) {
3941  if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
3942  if (!Context.CFConstantStringTypeDecl)
3943  Context.setCFConstantStringType(GetType(String));
3944  }
3945 
3946  if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
3947  QualType FileType = GetType(File);
3948  if (FileType.isNull()) {
3949  Error("FILE type is NULL");
3950  return;
3951  }
3952 
3953  if (!Context.FILEDecl) {
3954  if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
3955  Context.setFILEDecl(Typedef->getDecl());
3956  else {
3957  const TagType *Tag = FileType->getAs<TagType>();
3958  if (!Tag) {
3959  Error("Invalid FILE type in AST file");
3960  return;
3961  }
3962  Context.setFILEDecl(Tag->getDecl());
3963  }
3964  }
3965  }
3966 
3967  if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
3968  QualType Jmp_bufType = GetType(Jmp_buf);
3969  if (Jmp_bufType.isNull()) {
3970  Error("jmp_buf type is NULL");
3971  return;
3972  }
3973 
3974  if (!Context.jmp_bufDecl) {
3975  if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
3976  Context.setjmp_bufDecl(Typedef->getDecl());
3977  else {
3978  const TagType *Tag = Jmp_bufType->getAs<TagType>();
3979  if (!Tag) {
3980  Error("Invalid jmp_buf type in AST file");
3981  return;
3982  }
3983  Context.setjmp_bufDecl(Tag->getDecl());
3984  }
3985  }
3986  }
3987 
3988  if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
3989  QualType Sigjmp_bufType = GetType(Sigjmp_buf);
3990  if (Sigjmp_bufType.isNull()) {
3991  Error("sigjmp_buf type is NULL");
3992  return;
3993  }
3994 
3995  if (!Context.sigjmp_bufDecl) {
3996  if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
3997  Context.setsigjmp_bufDecl(Typedef->getDecl());
3998  else {
3999  const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
4000  assert(Tag && "Invalid sigjmp_buf type in AST file");
4002  }
4003  }
4004  }
4005 
4006  if (unsigned ObjCIdRedef
4007  = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
4008  if (Context.ObjCIdRedefinitionType.isNull())
4009  Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef);
4010  }
4011 
4012  if (unsigned ObjCClassRedef
4013  = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
4014  if (Context.ObjCClassRedefinitionType.isNull())
4015  Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef);
4016  }
4017 
4018  if (unsigned ObjCSelRedef
4019  = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
4020  if (Context.ObjCSelRedefinitionType.isNull())
4021  Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef);
4022  }
4023 
4024  if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
4025  QualType Ucontext_tType = GetType(Ucontext_t);
4026  if (Ucontext_tType.isNull()) {
4027  Error("ucontext_t type is NULL");
4028  return;
4029  }
4030 
4031  if (!Context.ucontext_tDecl) {
4032  if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>())
4033  Context.setucontext_tDecl(Typedef->getDecl());
4034  else {
4035  const TagType *Tag = Ucontext_tType->getAs<TagType>();
4036  assert(Tag && "Invalid ucontext_t type in AST file");
4038  }
4039  }
4040  }
4041  }
4042 
4043  ReadPragmaDiagnosticMappings(Context.getDiagnostics());
4044 
4045  // If there were any CUDA special declarations, deserialize them.
4046  if (!CUDASpecialDeclRefs.empty()) {
4047  assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!");
4049  cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0])));
4050  }
4051 
4052  // Re-export any modules that were imported by a non-module AST file.
4053  // FIXME: This does not make macro-only imports visible again.
4054  for (auto &Import : ImportedModules) {
4055  if (Module *Imported = getSubmodule(Import.ID)) {
4056  makeModuleVisible(Imported, Module::AllVisible,
4057  /*ImportLoc=*/Import.ImportLoc);
4058  if (Import.ImportLoc.isValid())
4059  PP.makeModuleVisible(Imported, Import.ImportLoc);
4060  // FIXME: should we tell Sema to make the module visible too?
4061  }
4062  }
4063  ImportedModules.clear();
4064 }
4065 
4067  // Nothing to do for now.
4068 }
4069 
4070 /// \brief Reads and return the signature record from \p StreamFile's control
4071 /// block, or else returns 0.
4072 static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile){
4073  BitstreamCursor Stream(StreamFile);
4074  if (!startsWithASTFileMagic(Stream))
4075  return 0;
4076 
4077  // Scan for the CONTROL_BLOCK_ID block.
4078  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID))
4079  return 0;
4080 
4081  // Scan for SIGNATURE inside the control block.
4082  ASTReader::RecordData Record;
4083  while (1) {
4084  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
4085  if (Entry.Kind == llvm::BitstreamEntry::EndBlock ||
4086  Entry.Kind != llvm::BitstreamEntry::Record)
4087  return 0;
4088 
4089  Record.clear();
4090  StringRef Blob;
4091  if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob))
4092  return Record[0];
4093  }
4094 }
4095 
4096 /// \brief Retrieve the name of the original source file name
4097 /// directly from the AST file, without actually loading the AST
4098 /// file.
4100  const std::string &ASTFileName, FileManager &FileMgr,
4101  const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) {
4102  // Open the AST file.
4103  auto Buffer = FileMgr.getBufferForFile(ASTFileName);
4104  if (!Buffer) {
4105  Diags.Report(diag::err_fe_unable_to_read_pch_file)
4106  << ASTFileName << Buffer.getError().message();
4107  return std::string();
4108  }
4109 
4110  // Initialize the stream
4111  llvm::BitstreamReader StreamFile;
4112  PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
4113  BitstreamCursor Stream(StreamFile);
4114 
4115  // Sniff for the signature.
4116  if (!startsWithASTFileMagic(Stream)) {
4117  Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName;
4118  return std::string();
4119  }
4120 
4121  // Scan for the CONTROL_BLOCK_ID block.
4122  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) {
4123  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4124  return std::string();
4125  }
4126 
4127  // Scan for ORIGINAL_FILE inside the control block.
4128  RecordData Record;
4129  while (1) {
4130  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
4131  if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
4132  return std::string();
4133 
4134  if (Entry.Kind != llvm::BitstreamEntry::Record) {
4135  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4136  return std::string();
4137  }
4138 
4139  Record.clear();
4140  StringRef Blob;
4141  if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE)
4142  return Blob.str();
4143  }
4144 }
4145 
4146 namespace {
4147  class SimplePCHValidator : public ASTReaderListener {
4148  const LangOptions &ExistingLangOpts;
4149  const TargetOptions &ExistingTargetOpts;
4150  const PreprocessorOptions &ExistingPPOpts;
4151  std::string ExistingModuleCachePath;
4152  FileManager &FileMgr;
4153 
4154  public:
4155  SimplePCHValidator(const LangOptions &ExistingLangOpts,
4156  const TargetOptions &ExistingTargetOpts,
4157  const PreprocessorOptions &ExistingPPOpts,
4158  StringRef ExistingModuleCachePath,
4159  FileManager &FileMgr)
4160  : ExistingLangOpts(ExistingLangOpts),
4161  ExistingTargetOpts(ExistingTargetOpts),
4162  ExistingPPOpts(ExistingPPOpts),
4163  ExistingModuleCachePath(ExistingModuleCachePath),
4164  FileMgr(FileMgr)
4165  {
4166  }
4167 
4168  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
4169  bool AllowCompatibleDifferences) override {
4170  return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr,
4171  AllowCompatibleDifferences);
4172  }
4173  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
4174  bool AllowCompatibleDifferences) override {
4175  return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr,
4176  AllowCompatibleDifferences);
4177  }
4178  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
4179  StringRef SpecificModuleCachePath,
4180  bool Complain) override {
4181  return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
4182  ExistingModuleCachePath,
4183  nullptr, ExistingLangOpts);
4184  }
4185  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
4186  bool Complain,
4187  std::string &SuggestedPredefines) override {
4188  return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr,
4189  SuggestedPredefines, ExistingLangOpts);
4190  }
4191  };
4192 }
4193 
4195  StringRef Filename, FileManager &FileMgr,
4196  const PCHContainerReader &PCHContainerRdr,
4197  bool FindModuleFileExtensions,
4198  ASTReaderListener &Listener) {
4199  // Open the AST file.
4200  // FIXME: This allows use of the VFS; we do not allow use of the
4201  // VFS when actually loading a module.
4202  auto Buffer = FileMgr.getBufferForFile(Filename);
4203  if (!Buffer) {
4204  return true;
4205  }
4206 
4207  // Initialize the stream
4208  llvm::BitstreamReader StreamFile;
4209  PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
4210  BitstreamCursor Stream(StreamFile);
4211 
4212  // Sniff for the signature.
4213  if (!startsWithASTFileMagic(Stream))
4214  return true;
4215 
4216  // Scan for the CONTROL_BLOCK_ID block.
4217  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID))
4218  return true;
4219 
4220  bool NeedsInputFiles = Listener.needsInputFileVisitation();
4221  bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation();
4222  bool NeedsImports = Listener.needsImportVisitation();
4223  BitstreamCursor InputFilesCursor;
4224 
4225  RecordData Record;
4226  std::string ModuleDir;
4227  bool DoneWithControlBlock = false;
4228  while (!DoneWithControlBlock) {
4229  llvm::BitstreamEntry Entry = Stream.advance();
4230 
4231  switch (Entry.Kind) {
4232  case llvm::BitstreamEntry::SubBlock: {
4233  switch (Entry.ID) {
4234  case OPTIONS_BLOCK_ID: {
4235  std::string IgnoredSuggestedPredefines;
4236  if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate,
4237  /*AllowCompatibleConfigurationMismatch*/ false,
4238  Listener, IgnoredSuggestedPredefines) != Success)
4239  return true;
4240  break;
4241  }
4242 
4243  case INPUT_FILES_BLOCK_ID:
4244  InputFilesCursor = Stream;
4245  if (Stream.SkipBlock() ||
4246  (NeedsInputFiles &&
4247  ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID)))
4248  return true;
4249  break;
4250 
4251  default:
4252  if (Stream.SkipBlock())
4253  return true;
4254  break;
4255  }
4256 
4257  continue;
4258  }
4259 
4260  case llvm::BitstreamEntry::EndBlock:
4261  DoneWithControlBlock = true;
4262  break;
4263 
4265  return true;
4266 
4267  case llvm::BitstreamEntry::Record:
4268  break;
4269  }
4270 
4271  if (DoneWithControlBlock) break;
4272 
4273  Record.clear();
4274  StringRef Blob;
4275  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
4276  switch ((ControlRecordTypes)RecCode) {
4277  case METADATA: {
4278  if (Record[0] != VERSION_MAJOR)
4279  return true;
4280 
4281  if (Listener.ReadFullVersionInformation(Blob))
4282  return true;
4283 
4284  break;
4285  }
4286  case MODULE_NAME:
4287  Listener.ReadModuleName(Blob);
4288  break;
4289  case MODULE_DIRECTORY:
4290  ModuleDir = Blob;
4291  break;
4292  case MODULE_MAP_FILE: {
4293  unsigned Idx = 0;
4294  auto Path = ReadString(Record, Idx);
4295  ResolveImportedPath(Path, ModuleDir);
4296  Listener.ReadModuleMapFile(Path);
4297  break;
4298  }
4299  case INPUT_FILE_OFFSETS: {
4300  if (!NeedsInputFiles)
4301  break;
4302 
4303  unsigned NumInputFiles = Record[0];
4304  unsigned NumUserFiles = Record[1];
4305  const uint64_t *InputFileOffs = (const uint64_t *)Blob.data();
4306  for (unsigned I = 0; I != NumInputFiles; ++I) {
4307  // Go find this input file.
4308  bool isSystemFile = I >= NumUserFiles;
4309 
4310  if (isSystemFile && !NeedsSystemInputFiles)
4311  break; // the rest are system input files
4312 
4313  BitstreamCursor &Cursor = InputFilesCursor;
4314  SavedStreamPosition SavedPosition(Cursor);
4315  Cursor.JumpToBit(InputFileOffs[I]);
4316 
4317  unsigned Code = Cursor.ReadCode();
4318  RecordData Record;
4319  StringRef Blob;
4320  bool shouldContinue = false;
4321  switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) {
4322  case INPUT_FILE:
4323  bool Overridden = static_cast<bool>(Record[3]);
4324  std::string Filename = Blob;
4325  ResolveImportedPath(Filename, ModuleDir);
4326  shouldContinue = Listener.visitInputFile(
4327  Filename, isSystemFile, Overridden, /*IsExplicitModule*/false);
4328  break;
4329  }
4330  if (!shouldContinue)
4331  break;
4332  }
4333  break;
4334  }
4335 
4336  case IMPORTS: {
4337  if (!NeedsImports)
4338  break;
4339 
4340  unsigned Idx = 0, N = Record.size();
4341  while (Idx < N) {
4342  // Read information about the AST file.
4343  Idx += 5; // ImportLoc, Size, ModTime, Signature
4344  std::string Filename = ReadString(Record, Idx);
4345  ResolveImportedPath(Filename, ModuleDir);
4346  Listener.visitImport(Filename);
4347  }
4348  break;
4349  }
4350 
4351  default:
4352  // No other validation to perform.
4353  break;
4354  }
4355  }
4356 
4357  // Look for module file extension blocks, if requested.
4358  if (FindModuleFileExtensions) {
4359  while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) {
4360  bool DoneWithExtensionBlock = false;
4361  while (!DoneWithExtensionBlock) {
4362  llvm::BitstreamEntry Entry = Stream.advance();
4363 
4364  switch (Entry.Kind) {
4365  case llvm::BitstreamEntry::SubBlock:
4366  if (Stream.SkipBlock())
4367  return true;
4368 
4369  continue;
4370 
4371  case llvm::BitstreamEntry::EndBlock:
4372  DoneWithExtensionBlock = true;
4373  continue;
4374 
4376  return true;
4377 
4378  case llvm::BitstreamEntry::Record:
4379  break;
4380  }
4381 
4382  Record.clear();
4383  StringRef Blob;
4384  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
4385  switch (RecCode) {
4386  case EXTENSION_METADATA: {
4387  ModuleFileExtensionMetadata Metadata;
4388  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
4389  return true;
4390 
4391  Listener.readModuleFileExtension(Metadata);
4392  break;
4393  }
4394  }
4395  }
4396  }
4397  }
4398 
4399  return false;
4400 }
4401 
4403  StringRef Filename, FileManager &FileMgr,
4404  const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts,
4405  const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts,
4406  std::string ExistingModuleCachePath) {
4407  SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts,
4408  ExistingModuleCachePath, FileMgr);
4409  return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr,
4410  /*FindModuleFileExtensions=*/false,
4411  validator);
4412 }
4413 
4415 ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
4416  // Enter the submodule block.
4417  if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) {
4418  Error("malformed submodule block record in AST file");
4419  return Failure;
4420  }
4421 
4422  ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
4423  bool First = true;
4424  Module *CurrentModule = nullptr;
4425  RecordData Record;
4426  while (true) {
4427  llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks();
4428 
4429  switch (Entry.Kind) {
4430  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
4432  Error("malformed block record in AST file");
4433  return Failure;
4434  case llvm::BitstreamEntry::EndBlock:
4435  return Success;
4436  case llvm::BitstreamEntry::Record:
4437  // The interesting case.
4438  break;
4439  }
4440 
4441  // Read a record.
4442  StringRef Blob;
4443  Record.clear();
4444  auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob);
4445 
4446  if ((Kind == SUBMODULE_METADATA) != First) {
4447  Error("submodule metadata record should be at beginning of block");
4448  return Failure;
4449  }
4450  First = false;
4451 
4452  // Submodule information is only valid if we have a current module.
4453  // FIXME: Should we error on these cases?
4454  if (!CurrentModule && Kind != SUBMODULE_METADATA &&
4456  continue;
4457 
4458  switch (Kind) {
4459  default: // Default behavior: ignore.
4460  break;
4461 
4462  case SUBMODULE_DEFINITION: {
4463  if (Record.size() < 8) {
4464  Error("malformed module definition");
4465  return Failure;
4466  }
4467 
4468  StringRef Name = Blob;
4469  unsigned Idx = 0;
4470  SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);
4471  SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);
4472  bool IsFramework = Record[Idx++];
4473  bool IsExplicit = Record[Idx++];
4474  bool IsSystem = Record[Idx++];
4475  bool IsExternC = Record[Idx++];
4476  bool InferSubmodules = Record[Idx++];
4477  bool InferExplicitSubmodules = Record[Idx++];
4478  bool InferExportWildcard = Record[Idx++];
4479  bool ConfigMacrosExhaustive = Record[Idx++];
4480 
4481  Module *ParentModule = nullptr;
4482  if (Parent)
4483  ParentModule = getSubmodule(Parent);
4484 
4485  // Retrieve this (sub)module from the module map, creating it if
4486  // necessary.
4487  CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, IsFramework,
4488  IsExplicit).first;
4489 
4490  // FIXME: set the definition loc for CurrentModule, or call
4491  // ModMap.setInferredModuleAllowedBy()
4492 
4493  SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS;
4494  if (GlobalIndex >= SubmodulesLoaded.size() ||
4495  SubmodulesLoaded[GlobalIndex]) {
4496  Error("too many submodules");
4497  return Failure;
4498  }
4499 
4500  if (!ParentModule) {
4501  if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
4502  if (CurFile != F.File) {
4503  if (!Diags.isDiagnosticInFlight()) {
4504  Diag(diag::err_module_file_conflict)
4505  << CurrentModule->getTopLevelModuleName()
4506  << CurFile->getName()
4507  << F.File->getName();
4508  }
4509  return Failure;
4510  }
4511  }
4512 
4513  CurrentModule->setASTFile(F.File);
4514  }
4515 
4516  CurrentModule->Signature = F.Signature;
4517  CurrentModule->IsFromModuleFile = true;
4518  CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
4519  CurrentModule->IsExternC = IsExternC;
4520  CurrentModule->InferSubmodules = InferSubmodules;
4521  CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules;
4522  CurrentModule->InferExportWildcard = InferExportWildcard;
4523  CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive;
4524  if (DeserializationListener)
4525  DeserializationListener->ModuleRead(GlobalID, CurrentModule);
4526 
4527  SubmodulesLoaded[GlobalIndex] = CurrentModule;
4528 
4529  // Clear out data that will be replaced by what is in the module file.
4530  CurrentModule->LinkLibraries.clear();
4531  CurrentModule->ConfigMacros.clear();
4532  CurrentModule->UnresolvedConflicts.clear();
4533  CurrentModule->Conflicts.clear();
4534 
4535  // The module is available unless it's missing a requirement; relevant
4536  // requirements will be (re-)added by SUBMODULE_REQUIRES records.
4537  // Missing headers that were present when the module was built do not
4538  // make it unavailable -- if we got this far, this must be an explicitly
4539  // imported module file.
4540  CurrentModule->Requirements.clear();
4541  CurrentModule->MissingHeaders.clear();
4542  CurrentModule->IsMissingRequirement =
4543  ParentModule && ParentModule->IsMissingRequirement;
4544  CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement;
4545  break;
4546  }
4547 
4549  std::string Filename = Blob;
4550  ResolveImportedPath(F, Filename);
4551  if (auto *Umbrella = PP.getFileManager().getFile(Filename)) {
4552  if (!CurrentModule->getUmbrellaHeader())
4553  ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob);
4554  else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) {
4555  // This can be a spurious difference caused by changing the VFS to
4556  // point to a different copy of the file, and it is too late to
4557  // to rebuild safely.
4558  // FIXME: If we wrote the virtual paths instead of the 'real' paths,
4559  // after input file validation only real problems would remain and we
4560  // could just error. For now, assume it's okay.
4561  break;
4562  }
4563  }
4564  break;
4565  }
4566 
4567  case SUBMODULE_HEADER:
4570  // We lazily associate headers with their modules via the HeaderInfo table.
4571  // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead
4572  // of complete filenames or remove it entirely.
4573  break;
4574 
4577  // FIXME: Textual headers are not marked in the HeaderInfo table. Load
4578  // them here.
4579  break;
4580 
4581  case SUBMODULE_TOPHEADER: {
4582  CurrentModule->addTopHeaderFilename(Blob);
4583  break;
4584  }
4585 
4586  case SUBMODULE_UMBRELLA_DIR: {
4587  std::string Dirname = Blob;
4588  ResolveImportedPath(F, Dirname);
4589  if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) {
4590  if (!CurrentModule->getUmbrellaDir())
4591  ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob);
4592  else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) {
4593  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
4594  Error("mismatched umbrella directories in submodule");
4595  return OutOfDate;
4596  }
4597  }
4598  break;
4599  }
4600 
4601  case SUBMODULE_METADATA: {
4602  F.BaseSubmoduleID = getTotalNumSubmodules();
4603  F.LocalNumSubmodules = Record[0];
4604  unsigned LocalBaseSubmoduleID = Record[1];
4605  if (F.LocalNumSubmodules > 0) {
4606  // Introduce the global -> local mapping for submodules within this
4607  // module.
4608  GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F));
4609 
4610  // Introduce the local -> global mapping for submodules within this
4611  // module.
4612  F.SubmoduleRemap.insertOrReplace(
4613  std::make_pair(LocalBaseSubmoduleID,
4614  F.BaseSubmoduleID - LocalBaseSubmoduleID));
4615 
4616  SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules);
4617  }
4618  break;
4619  }
4620 
4621  case SUBMODULE_IMPORTS: {
4622  for (unsigned Idx = 0; Idx != Record.size(); ++Idx) {
4623  UnresolvedModuleRef Unresolved;
4624  Unresolved.File = &F;
4625  Unresolved.Mod = CurrentModule;
4626  Unresolved.ID = Record[Idx];
4627  Unresolved.Kind = UnresolvedModuleRef::Import;
4628  Unresolved.IsWildcard = false;
4629  UnresolvedModuleRefs.push_back(Unresolved);
4630  }
4631  break;
4632  }
4633 
4634  case SUBMODULE_EXPORTS: {
4635  for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) {
4636  UnresolvedModuleRef Unresolved;
4637  Unresolved.File = &F;
4638  Unresolved.Mod = CurrentModule;
4639  Unresolved.ID = Record[Idx];
4640  Unresolved.Kind = UnresolvedModuleRef::Export;
4641  Unresolved.IsWildcard = Record[Idx + 1];
4642  UnresolvedModuleRefs.push_back(Unresolved);
4643  }
4644 
4645  // Once we've loaded the set of exports, there's no reason to keep
4646  // the parsed, unresolved exports around.
4647  CurrentModule->UnresolvedExports.clear();
4648  break;
4649  }
4650  case SUBMODULE_REQUIRES: {
4651  CurrentModule->addRequirement(Blob, Record[0], Context.getLangOpts(),
4653  break;
4654  }
4655 
4657  CurrentModule->LinkLibraries.push_back(
4658  Module::LinkLibrary(Blob, Record[0]));
4659  break;
4660 
4662  CurrentModule->ConfigMacros.push_back(Blob.str());
4663  break;
4664 
4665  case SUBMODULE_CONFLICT: {
4666  UnresolvedModuleRef Unresolved;
4667  Unresolved.File = &F;
4668  Unresolved.Mod = CurrentModule;
4669  Unresolved.ID = Record[0];
4670  Unresolved.Kind = UnresolvedModuleRef::Conflict;
4671  Unresolved.IsWildcard = false;
4672  Unresolved.String = Blob;
4673  UnresolvedModuleRefs.push_back(Unresolved);
4674  break;
4675  }
4676  }
4677  }
4678 }
4679 
4680 /// \brief Parse the record that corresponds to a LangOptions data
4681 /// structure.
4682 ///
4683 /// This routine parses the language options from the AST file and then gives
4684 /// them to the AST listener if one is set.
4685 ///
4686 /// \returns true if the listener deems the file unacceptable, false otherwise.
4687 bool ASTReader::ParseLanguageOptions(const RecordData &Record,
4688  bool Complain,
4689  ASTReaderListener &Listener,
4690  bool AllowCompatibleDifferences) {
4691  LangOptions LangOpts;
4692  unsigned Idx = 0;
4693 #define LANGOPT(Name, Bits, Default, Description) \
4694  LangOpts.Name = Record[Idx++];
4695 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
4696  LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
4697 #include "clang/Basic/LangOptions.def"
4698 #define SANITIZER(NAME, ID) \
4699  LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]);
4700 #include "clang/Basic/Sanitizers.def"
4701 
4702  for (unsigned N = Record[Idx++]; N; --N)
4703  LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx));
4704 
4705  ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++];
4706  VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx);
4707  LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion);
4708 
4709  LangOpts.CurrentModule = ReadString(Record, Idx);
4710 
4711  // Comment options.
4712  for (unsigned N = Record[Idx++]; N; --N) {
4713  LangOpts.CommentOpts.BlockCommandNames.push_back(
4714  ReadString(Record, Idx));
4715  }
4716  LangOpts.CommentOpts.ParseAllComments = Record[Idx++];
4717 
4718  // OpenMP offloading options.
4719  for (unsigned N = Record[Idx++]; N; --N) {
4720  LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx)));
4721  }
4722 
4723  LangOpts.OMPHostIRFile = ReadString(Record, Idx);
4724 
4725  return Listener.ReadLanguageOptions(LangOpts, Complain,
4726  AllowCompatibleDifferences);
4727 }
4728 
4729 bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain,
4730  ASTReaderListener &Listener,
4731  bool AllowCompatibleDifferences) {
4732  unsigned Idx = 0;
4733  TargetOptions TargetOpts;
4734  TargetOpts.Triple = ReadString(Record, Idx);
4735  TargetOpts.CPU = ReadString(Record, Idx);
4736  TargetOpts.ABI = ReadString(Record, Idx);
4737  for (unsigned N = Record[Idx++]; N; --N) {
4738  TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx));
4739  }
4740  for (unsigned N = Record[Idx++]; N; --N) {
4741  TargetOpts.Features.push_back(ReadString(Record, Idx));
4742  }
4743 
4744  return Listener.ReadTargetOptions(TargetOpts, Complain,
4745  AllowCompatibleDifferences);
4746 }
4747 
4748 bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain,
4749  ASTReaderListener &Listener) {
4751  unsigned Idx = 0;
4752 #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++];
4753 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
4754  DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));
4755 #include "clang/Basic/DiagnosticOptions.def"
4756 
4757  for (unsigned N = Record[Idx++]; N; --N)
4758  DiagOpts->Warnings.push_back(ReadString(Record, Idx));
4759  for (unsigned N = Record[Idx++]; N; --N)
4760  DiagOpts->Remarks.push_back(ReadString(Record, Idx));
4761 
4762  return Listener.ReadDiagnosticOptions(DiagOpts, Complain);
4763 }
4764 
4765 bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain,
4766  ASTReaderListener &Listener) {
4767  FileSystemOptions FSOpts;
4768  unsigned Idx = 0;
4769  FSOpts.WorkingDir = ReadString(Record, Idx);
4770  return Listener.ReadFileSystemOptions(FSOpts, Complain);
4771 }
4772 
4773 bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record,
4774  bool Complain,
4775  ASTReaderListener &Listener) {
4776  HeaderSearchOptions HSOpts;
4777  unsigned Idx = 0;
4778  HSOpts.Sysroot = ReadString(Record, Idx);
4779 
4780  // Include entries.
4781  for (unsigned N = Record[Idx++]; N; --N) {
4782  std::string Path = ReadString(Record, Idx);
4784  = static_cast<frontend::IncludeDirGroup>(Record[Idx++]);
4785  bool IsFramework = Record[Idx++];
4786  bool IgnoreSysRoot = Record[Idx++];
4787  HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework,
4788  IgnoreSysRoot);
4789  }
4790 
4791  // System header prefixes.
4792  for (unsigned N = Record[Idx++]; N; --N) {
4793  std::string Prefix = ReadString(Record, Idx);
4794  bool IsSystemHeader = Record[Idx++];
4795  HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
4796  }
4797 
4798  HSOpts.ResourceDir = ReadString(Record, Idx);
4799  HSOpts.ModuleCachePath = ReadString(Record, Idx);
4800  HSOpts.ModuleUserBuildPath = ReadString(Record, Idx);
4801  HSOpts.DisableModuleHash = Record[Idx++];
4802  HSOpts.UseBuiltinIncludes = Record[Idx++];
4803  HSOpts.UseStandardSystemIncludes = Record[Idx++];
4804  HSOpts.UseStandardCXXIncludes = Record[Idx++];
4805  HSOpts.UseLibcxx = Record[Idx++];
4806  std::string SpecificModuleCachePath = ReadString(Record, Idx);
4807 
4808  return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
4809  Complain);
4810 }
4811 
4812 bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
4813  bool Complain,
4814  ASTReaderListener &Listener,
4815  std::string &SuggestedPredefines) {
4816  PreprocessorOptions PPOpts;
4817  unsigned Idx = 0;
4818 
4819  // Macro definitions/undefs
4820  for (unsigned N = Record[Idx++]; N; --N) {
4821  std::string Macro = ReadString(Record, Idx);
4822  bool IsUndef = Record[Idx++];
4823  PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef));
4824  }
4825 
4826  // Includes
4827  for (unsigned N = Record[Idx++]; N; --N) {
4828  PPOpts.Includes.push_back(ReadString(Record, Idx));
4829  }
4830 
4831  // Macro Includes
4832  for (unsigned N = Record[Idx++]; N; --N) {
4833  PPOpts.MacroIncludes.push_back(ReadString(Record, Idx));
4834  }
4835 
4836  PPOpts.UsePredefines = Record[Idx++];
4837  PPOpts.DetailedRecord = Record[Idx++];
4838  PPOpts.ImplicitPCHInclude = ReadString(Record, Idx);
4839  PPOpts.ImplicitPTHInclude = ReadString(Record, Idx);
4840  PPOpts.ObjCXXARCStandardLibrary =
4841  static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]);
4842  SuggestedPredefines.clear();
4843  return Listener.ReadPreprocessorOptions(PPOpts, Complain,
4844  SuggestedPredefines);
4845 }
4846 
4847 std::pair<ModuleFile *, unsigned>
4848 ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) {
4850  I = GlobalPreprocessedEntityMap.find(GlobalIndex);
4851  assert(I != GlobalPreprocessedEntityMap.end() &&
4852  "Corrupted global preprocessed entity map");
4853  ModuleFile *M = I->second;
4854  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID;
4855  return std::make_pair(M, LocalIndex);
4856 }
4857 
4858 llvm::iterator_range<PreprocessingRecord::iterator>
4859 ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const {
4860  if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord())
4861  return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID,
4863 
4864  return llvm::make_range(PreprocessingRecord::iterator(),
4866 }
4867 
4868 llvm::iterator_range<ASTReader::ModuleDeclIterator>
4869 ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) {
4870  return llvm::make_range(
4871  ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls),
4872  ModuleDeclIterator(this, &Mod,
4873  Mod.FileSortedDecls + Mod.NumFileSortedDecls));
4874 }
4875 
4877  PreprocessedEntityID PPID = Index+1;
4878  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
4879  ModuleFile &M = *PPInfo.first;
4880  unsigned LocalIndex = PPInfo.second;
4881  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
4882 
4883  if (!PP.getPreprocessingRecord()) {
4884  Error("no preprocessing record");
4885  return nullptr;
4886  }
4887 
4889  M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset);
4890 
4891  llvm::BitstreamEntry Entry =
4892  M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
4893  if (Entry.Kind != llvm::BitstreamEntry::Record)
4894  return nullptr;
4895 
4896  // Read the record.
4897  SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()),
4898  TranslateSourceLocation(M, PPOffs.getEnd()));
4899  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
4900  StringRef Blob;
4901  RecordData Record;
4904  Entry.ID, Record, &Blob);
4905  switch (RecType) {
4906  case PPD_MACRO_EXPANSION: {
4907  bool isBuiltin = Record[0];
4908  IdentifierInfo *Name = nullptr;
4909  MacroDefinitionRecord *Def = nullptr;
4910  if (isBuiltin)
4911  Name = getLocalIdentifier(M, Record[1]);
4912  else {
4913  PreprocessedEntityID GlobalID =
4914  getGlobalPreprocessedEntityID(M, Record[1]);
4915  Def = cast<MacroDefinitionRecord>(
4916  PPRec.getLoadedPreprocessedEntity(GlobalID - 1));
4917  }
4918 
4919  MacroExpansion *ME;
4920  if (isBuiltin)
4921  ME = new (PPRec) MacroExpansion(Name, Range);
4922  else
4923  ME = new (PPRec) MacroExpansion(Def, Range);
4924 
4925  return ME;
4926  }
4927 
4928  case PPD_MACRO_DEFINITION: {
4929  // Decode the identifier info and then check again; if the macro is
4930  // still defined and associated with the identifier,
4931  IdentifierInfo *II = getLocalIdentifier(M, Record[0]);
4932  MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range);
4933 
4934  if (DeserializationListener)
4935  DeserializationListener->MacroDefinitionRead(PPID, MD);
4936 
4937  return MD;
4938  }
4939 
4940  case PPD_INCLUSION_DIRECTIVE: {
4941  const char *FullFileNameStart = Blob.data() + Record[0];
4942  StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
4943  const FileEntry *File = nullptr;
4944  if (!FullFileName.empty())
4945  File = PP.getFileManager().getFile(FullFileName);
4946 
4947  // FIXME: Stable encoding
4949  = static_cast<InclusionDirective::InclusionKind>(Record[2]);
4950  InclusionDirective *ID
4951  = new (PPRec) InclusionDirective(PPRec, Kind,
4952  StringRef(Blob.data(), Record[0]),
4953  Record[1], Record[3],
4954  File,
4955  Range);
4956  return ID;
4957  }
4958  }
4959 
4960  llvm_unreachable("Invalid PreprocessorDetailRecordTypes");
4961 }
4962 
4963 /// \brief \arg SLocMapI points at a chunk of a module that contains no
4964 /// preprocessed entities or the entities it contains are not the ones we are
4965 /// looking for. Find the next module that contains entities and return the ID
4966 /// of the first entry.
4967 PreprocessedEntityID ASTReader::findNextPreprocessedEntity(
4968  GlobalSLocOffsetMapType::const_iterator SLocMapI) const {
4969  ++SLocMapI;
4970  for (GlobalSLocOffsetMapType::const_iterator
4971  EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) {
4972  ModuleFile &M = *SLocMapI->second;
4973  if (M.NumPreprocessedEntities)
4974  return M.BasePreprocessedEntityID;
4975  }
4976 
4977  return getTotalNumPreprocessedEntities();
4978 }
4979 
4980 namespace {
4981 
4982 struct PPEntityComp {
4983  const ASTReader &Reader;
4984  ModuleFile &M;
4985 
4986  PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { }
4987 
4988  bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const {
4989  SourceLocation LHS = getLoc(L);
4990  SourceLocation RHS = getLoc(R);
4991  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
4992  }
4993 
4994  bool operator()(const PPEntityOffset &L, SourceLocation RHS) const {
4995  SourceLocation LHS = getLoc(L);
4996  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
4997  }
4998 
4999  bool operator()(SourceLocation LHS, const PPEntityOffset &R) const {
5000  SourceLocation RHS = getLoc(R);
5001  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5002  }
5003 
5004  SourceLocation getLoc(const PPEntityOffset &PPE) const {
5005  return Reader.TranslateSourceLocation(M, PPE.getBegin());
5006  }
5007 };
5008 
5009 }
5010 
5011 PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc,
5012  bool EndsAfter) const {
5013  if (SourceMgr.isLocalSourceLocation(Loc))
5014  return getTotalNumPreprocessedEntities();
5015 
5016  GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find(
5017  SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
5018  assert(SLocMapI != GlobalSLocOffsetMap.end() &&
5019  "Corrupted global sloc offset map");
5020 
5021  if (SLocMapI->second->NumPreprocessedEntities == 0)
5022  return findNextPreprocessedEntity(SLocMapI);
5023 
5024  ModuleFile &M = *SLocMapI->second;
5025  typedef const PPEntityOffset *pp_iterator;
5026  pp_iterator pp_begin = M.PreprocessedEntityOffsets;
5027  pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities;
5028 
5029  size_t Count = M.NumPreprocessedEntities;
5030  size_t Half;
5031  pp_iterator First = pp_begin;
5032  pp_iterator PPI;
5033 
5034  if (EndsAfter) {
5035  PPI = std::upper_bound(pp_begin, pp_end, Loc,
5036  PPEntityComp(*this, M));
5037  } else {
5038  // Do a binary search manually instead of using std::lower_bound because
5039  // The end locations of entities may be unordered (when a macro expansion
5040  // is inside another macro argument), but for this case it is not important
5041  // whether we get the first macro expansion or its containing macro.
5042  while (Count > 0) {
5043  Half = Count / 2;
5044  PPI = First;
5045  std::advance(PPI, Half);
5046  if (SourceMgr.isBeforeInTranslationUnit(
5047  TranslateSourceLocation(M, PPI->getEnd()), Loc)) {
5048  First = PPI;
5049  ++First;
5050  Count = Count - Half - 1;
5051  } else
5052  Count = Half;
5053  }
5054  }
5055 
5056  if (PPI == pp_end)
5057  return findNextPreprocessedEntity(SLocMapI);
5058 
5059  return M.BasePreprocessedEntityID + (PPI - pp_begin);
5060 }
5061 
5062 /// \brief Returns a pair of [Begin, End) indices of preallocated
5063 /// preprocessed entities that \arg Range encompasses.
5064 std::pair<unsigned, unsigned>
5066  if (Range.isInvalid())
5067  return std::make_pair(0,0);
5068  assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
5069 
5070  PreprocessedEntityID BeginID =
5071  findPreprocessedEntity(Range.getBegin(), false);
5072  PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true);
5073  return std::make_pair(BeginID, EndID);
5074 }
5075 
5076 /// \brief Optionally returns true or false if the preallocated preprocessed
5077 /// entity with index \arg Index came from file \arg FID.
5079  FileID FID) {
5080  if (FID.isInvalid())
5081  return false;
5082 
5083  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
5084  ModuleFile &M = *PPInfo.first;
5085  unsigned LocalIndex = PPInfo.second;
5086  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
5087 
5088  SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin());
5089  if (Loc.isInvalid())
5090  return false;
5091 
5092  if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID))
5093  return true;
5094  else
5095  return false;
5096 }
5097 
5098 namespace {
5099  /// \brief Visitor used to search for information about a header file.
5100  class HeaderFileInfoVisitor {
5101  const FileEntry *FE;
5102 
5104 
5105  public:
5106  explicit HeaderFileInfoVisitor(const FileEntry *FE)
5107  : FE(FE) { }
5108 
5109  bool operator()(ModuleFile &M) {
5111  = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable);
5112  if (!Table)
5113  return false;
5114 
5115  // Look in the on-disk hash table for an entry for this file name.
5116  HeaderFileInfoLookupTable::iterator Pos = Table->find(FE);
5117  if (Pos == Table->end())
5118  return false;
5119 
5120  HFI = *Pos;
5121  return true;
5122  }
5123 
5124  Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; }
5125  };
5126 }
5127 
5129  HeaderFileInfoVisitor Visitor(FE);
5130  ModuleMgr.visit(Visitor);
5131  if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo())
5132  return *HFI;
5133 
5134  return HeaderFileInfo();
5135 }
5136 
5138  // FIXME: Make it work properly with modules.
5140  for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) {
5141  ModuleFile &F = *(*I);
5142  unsigned Idx = 0;
5143  DiagStates.clear();
5144  assert(!Diag.DiagStates.empty());
5145  DiagStates.push_back(&Diag.DiagStates.front()); // the command-line one.
5146  while (Idx < F.PragmaDiagMappings.size()) {
5147  SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
5148  unsigned DiagStateID = F.PragmaDiagMappings[Idx++];
5149  if (DiagStateID != 0) {
5150  Diag.DiagStatePoints.push_back(
5151  DiagnosticsEngine::DiagStatePoint(DiagStates[DiagStateID-1],
5152  FullSourceLoc(Loc, SourceMgr)));
5153  continue;
5154  }
5155 
5156  assert(DiagStateID == 0);
5157  // A new DiagState was created here.
5158  Diag.DiagStates.push_back(*Diag.GetCurDiagState());
5159  DiagnosticsEngine::DiagState *NewState = &Diag.DiagStates.back();
5160  DiagStates.push_back(NewState);
5161  Diag.DiagStatePoints.push_back(
5162  DiagnosticsEngine::DiagStatePoint(NewState,
5163  FullSourceLoc(Loc, SourceMgr)));
5164  while (1) {
5165  assert(Idx < F.PragmaDiagMappings.size() &&
5166  "Invalid data, didn't find '-1' marking end of diag/map pairs");
5167  if (Idx >= F.PragmaDiagMappings.size()) {
5168  break; // Something is messed up but at least avoid infinite loop in
5169  // release build.
5170  }
5171  unsigned DiagID = F.PragmaDiagMappings[Idx++];
5172  if (DiagID == (unsigned)-1) {
5173  break; // no more diag/map pairs for this location.
5174  }
5176  DiagnosticMapping Mapping = Diag.makeUserMapping(Map, Loc);
5177  Diag.GetCurDiagState()->setMapping(DiagID, Mapping);
5178  }
5179  }
5180  }
5181 }
5182 
5183 /// \brief Get the correct cursor and offset for loading a type.
5184 ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
5185  GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index);
5186  assert(I != GlobalTypeMap.end() && "Corrupted global type map");
5187  ModuleFile *M = I->second;
5188  return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]);
5189 }
5190 
5191 /// \brief Read and return the type with the given index..
5192 ///
5193 /// The index is the type ID, shifted and minus the number of predefs. This
5194 /// routine actually reads the record corresponding to the type at the given
5195 /// location. It is a helper routine for GetType, which deals with reading type
5196 /// IDs.
5197 QualType ASTReader::readTypeRecord(unsigned Index) {
5198  RecordLocation Loc = TypeCursorForIndex(Index);
5199  BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
5200 
5201  // Keep track of where we are in the stream, then jump back there
5202  // after reading this type.
5203  SavedStreamPosition SavedPosition(DeclsCursor);
5204 
5205  ReadingKindTracker ReadingKind(Read_Type, *this);
5206 
5207  // Note that we are loading a type record.
5208  Deserializing AType(this);
5209 
5210  unsigned Idx = 0;
5211  DeclsCursor.JumpToBit(Loc.Offset);
5212  RecordData Record;
5213  unsigned Code = DeclsCursor.ReadCode();
5214  switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) {
5215  case TYPE_EXT_QUAL: {
5216  if (Record.size() != 2) {
5217  Error("Incorrect encoding of extended qualifier type");
5218  return QualType();
5219  }
5220  QualType Base = readType(*Loc.F, Record, Idx);
5221  Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]);
5222  return Context.getQualifiedType(Base, Quals);
5223  }
5224 
5225  case TYPE_COMPLEX: {
5226  if (Record.size() != 1) {
5227  Error("Incorrect encoding of complex type");
5228  return QualType();
5229  }
5230  QualType ElemType = readType(*Loc.F, Record, Idx);
5231  return Context.getComplexType(ElemType);
5232  }
5233 
5234  case TYPE_POINTER: {
5235  if (Record.size() != 1) {
5236  Error("Incorrect encoding of pointer type");
5237  return QualType();
5238  }
5239  QualType PointeeType = readType(*Loc.F, Record, Idx);
5240  return Context.getPointerType(PointeeType);
5241  }
5242 
5243  case TYPE_DECAYED: {
5244  if (Record.size() != 1) {
5245  Error("Incorrect encoding of decayed type");
5246  return QualType();
5247  }
5248  QualType OriginalType = readType(*Loc.F, Record, Idx);
5249  QualType DT = Context.getAdjustedParameterType(OriginalType);
5250  if (!isa<DecayedType>(DT))
5251  Error("Decayed type does not decay");
5252  return DT;
5253  }
5254 
5255  case TYPE_ADJUSTED: {
5256  if (Record.size() != 2) {
5257  Error("Incorrect encoding of adjusted type");
5258  return QualType();
5259  }
5260  QualType OriginalTy = readType(*Loc.F, Record, Idx);
5261  QualType AdjustedTy = readType(*Loc.F, Record, Idx);
5262  return Context.getAdjustedType(OriginalTy, AdjustedTy);
5263  }
5264 
5265  case TYPE_BLOCK_POINTER: {
5266  if (Record.size() != 1) {
5267  Error("Incorrect encoding of block pointer type");
5268  return QualType();
5269  }
5270  QualType PointeeType = readType(*Loc.F, Record, Idx);
5271  return Context.getBlockPointerType(PointeeType);
5272  }
5273 
5274  case TYPE_LVALUE_REFERENCE: {
5275  if (Record.size() != 2) {
5276  Error("Incorrect encoding of lvalue reference type");
5277  return QualType();
5278  }
5279  QualType PointeeType = readType(*Loc.F, Record, Idx);
5280  return Context.getLValueReferenceType(PointeeType, Record[1]);
5281  }
5282 
5283  case TYPE_RVALUE_REFERENCE: {
5284  if (Record.size() != 1) {
5285  Error("Incorrect encoding of rvalue reference type");
5286  return QualType();
5287  }
5288  QualType PointeeType = readType(*Loc.F, Record, Idx);
5289  return Context.getRValueReferenceType(PointeeType);
5290  }
5291 
5292  case TYPE_MEMBER_POINTER: {
5293  if (Record.size() != 2) {
5294  Error("Incorrect encoding of member pointer type");
5295  return QualType();
5296  }
5297  QualType PointeeType = readType(*Loc.F, Record, Idx);
5298  QualType ClassType = readType(*Loc.F, Record, Idx);
5299  if (PointeeType.isNull() || ClassType.isNull())
5300  return QualType();
5301 
5302  return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr());
5303  }
5304 
5305  case TYPE_CONSTANT_ARRAY: {
5306  QualType ElementType = readType(*Loc.F, Record, Idx);
5308  unsigned IndexTypeQuals = Record[2];
5309  unsigned Idx = 3;
5310  llvm::APInt Size = ReadAPInt(Record, Idx);
5311  return Context.getConstantArrayType(ElementType, Size,
5312  ASM, IndexTypeQuals);
5313  }
5314 
5315  case TYPE_INCOMPLETE_ARRAY: {
5316  QualType ElementType = readType(*Loc.F, Record, Idx);
5318  unsigned IndexTypeQuals = Record[2];
5319  return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
5320  }
5321 
5322  case TYPE_VARIABLE_ARRAY: {
5323  QualType ElementType = readType(*Loc.F, Record, Idx);
5325  unsigned IndexTypeQuals = Record[2];
5326  SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]);
5327  SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]);
5328  return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F),
5329  ASM, IndexTypeQuals,
5330  SourceRange(LBLoc, RBLoc));
5331  }
5332 
5333  case TYPE_VECTOR: {
5334  if (Record.size() != 3) {
5335  Error("incorrect encoding of vector type in AST file");
5336  return QualType();
5337  }
5338 
5339  QualType ElementType = readType(*Loc.F, Record, Idx);
5340  unsigned NumElements = Record[1];
5341  unsigned VecKind = Record[2];
5342  return Context.getVectorType(ElementType, NumElements,
5343  (VectorType::VectorKind)VecKind);
5344  }
5345 
5346  case TYPE_EXT_VECTOR: {
5347  if (Record.size() != 3) {
5348  Error("incorrect encoding of extended vector type in AST file");
5349  return QualType();
5350  }
5351 
5352  QualType ElementType = readType(*Loc.F, Record, Idx);
5353  unsigned NumElements = Record[1];
5354  return Context.getExtVectorType(ElementType, NumElements);
5355  }
5356 
5357  case TYPE_FUNCTION_NO_PROTO: {
5358  if (Record.size() != 6) {
5359  Error("incorrect encoding of no-proto function type");
5360  return QualType();
5361  }
5362  QualType ResultType = readType(*Loc.F, Record, Idx);
5363  FunctionType::ExtInfo Info(Record[1], Record[2], Record[3],
5364  (CallingConv)Record[4], Record[5]);
5365  return Context.getFunctionNoProtoType(ResultType, Info);
5366  }
5367 
5368  case TYPE_FUNCTION_PROTO: {
5369  QualType ResultType = readType(*Loc.F, Record, Idx);
5370 
5372  EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1],
5373  /*hasregparm*/ Record[2],
5374  /*regparm*/ Record[3],
5375  static_cast<CallingConv>(Record[4]),
5376  /*produces*/ Record[5]);
5377 
5378  unsigned Idx = 6;
5379 
5380  EPI.Variadic = Record[Idx++];
5381  EPI.HasTrailingReturn = Record[Idx++];
5382  EPI.TypeQuals = Record[Idx++];
5383  EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]);
5384  SmallVector<QualType, 8> ExceptionStorage;
5385  readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx);
5386 
5387  unsigned NumParams = Record[Idx++];
5388  SmallVector<QualType, 16> ParamTypes;
5389  for (unsigned I = 0; I != NumParams; ++I)
5390  ParamTypes.push_back(readType(*Loc.F, Record, Idx));
5391 
5393  if (Idx != Record.size()) {
5394  for (unsigned I = 0; I != NumParams; ++I)
5395  ExtParameterInfos.push_back(
5397  ::getFromOpaqueValue(Record[Idx++]));
5398  EPI.ExtParameterInfos = ExtParameterInfos.data();
5399  }
5400 
5401  assert(Idx == Record.size());
5402 
5403  return Context.getFunctionType(ResultType, ParamTypes, EPI);
5404  }
5405 
5406  case TYPE_UNRESOLVED_USING: {
5407  unsigned Idx = 0;
5408  return Context.getTypeDeclType(
5409  ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx));
5410  }
5411 
5412  case TYPE_TYPEDEF: {
5413  if (Record.size() != 2) {
5414  Error("incorrect encoding of typedef type");
5415  return QualType();
5416  }
5417  unsigned Idx = 0;
5418  TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx);
5419  QualType Canonical = readType(*Loc.F, Record, Idx);
5420  if (!Canonical.isNull())
5421  Canonical = Context.getCanonicalType(Canonical);
5422  return Context.getTypedefType(Decl, Canonical);
5423  }
5424 
5425  case TYPE_TYPEOF_EXPR:
5426  return Context.getTypeOfExprType(ReadExpr(*Loc.F));
5427 
5428  case TYPE_TYPEOF: {
5429  if (Record.size() != 1) {
5430  Error("incorrect encoding of typeof(type) in AST file");
5431  return QualType();
5432  }
5433  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
5434  return Context.getTypeOfType(UnderlyingType);
5435  }
5436 
5437  case TYPE_DECLTYPE: {
5438  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
5439  return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType);
5440  }
5441 
5442  case TYPE_UNARY_TRANSFORM: {
5443  QualType BaseType = readType(*Loc.F, Record, Idx);
5444  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
5446  return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind);
5447  }
5448 
5449  case TYPE_AUTO: {
5450  QualType Deduced = readType(*Loc.F, Record, Idx);
5451  AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++];
5452  bool IsDependent = Deduced.isNull() ? Record[Idx++] : false;
5453  return Context.getAutoType(Deduced, Keyword, IsDependent);
5454  }
5455 
5456  case TYPE_RECORD: {
5457  if (Record.size() != 2) {
5458  Error("incorrect encoding of record type");
5459  return QualType();
5460  }
5461  unsigned Idx = 0;
5462  bool IsDependent = Record[Idx++];
5463  RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx);
5464  RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl());
5465  QualType T = Context.getRecordType(RD);
5466  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
5467  return T;
5468  }
5469 
5470  case TYPE_ENUM: {
5471  if (Record.size() != 2) {
5472  Error("incorrect encoding of enum type");
5473  return QualType();
5474  }
5475  unsigned Idx = 0;
5476  bool IsDependent = Record[Idx++];
5477  QualType T
5478  = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx));
5479  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
5480  return T;
5481  }
5482 
5483  case TYPE_ATTRIBUTED: {
5484  if (Record.size() != 3) {
5485  Error("incorrect encoding of attributed type");
5486  return QualType();
5487  }
5488  QualType modifiedType = readType(*Loc.F, Record, Idx);
5489  QualType equivalentType = readType(*Loc.F, Record, Idx);
5490  AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]);
5491  return Context.getAttributedType(kind, modifiedType, equivalentType);
5492  }
5493 
5494  case TYPE_PAREN: {
5495  if (Record.size() != 1) {
5496  Error("incorrect encoding of paren type");
5497  return QualType();
5498  }
5499  QualType InnerType = readType(*Loc.F, Record, Idx);
5500  return Context.getParenType(InnerType);
5501  }
5502 
5503  case TYPE_PACK_EXPANSION: {
5504  if (Record.size() != 2) {
5505  Error("incorrect encoding of pack expansion type");
5506  return QualType();
5507  }
5508  QualType Pattern = readType(*Loc.F, Record, Idx);
5509  if (Pattern.isNull())
5510  return QualType();
5511  Optional<unsigned> NumExpansions;
5512  if (Record[1])
5513  NumExpansions = Record[1] - 1;
5514  return Context.getPackExpansionType(Pattern, NumExpansions);
5515  }
5516 
5517  case TYPE_ELABORATED: {
5518  unsigned Idx = 0;
5519  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
5520  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
5521  QualType NamedType = readType(*Loc.F, Record, Idx);
5522  return Context.getElaboratedType(Keyword, NNS, NamedType);
5523  }
5524 
5525  case TYPE_OBJC_INTERFACE: {
5526  unsigned Idx = 0;
5527  ObjCInterfaceDecl *ItfD
5528  = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx);
5530  }
5531 
5532  case TYPE_OBJC_OBJECT: {
5533  unsigned Idx = 0;
5534  QualType Base = readType(*Loc.F, Record, Idx);
5535  unsigned NumTypeArgs = Record[Idx++];
5536  SmallVector<QualType, 4> TypeArgs;
5537  for (unsigned I = 0; I != NumTypeArgs; ++I)
5538  TypeArgs.push_back(readType(*Loc.F, Record, Idx));
5539  unsigned NumProtos = Record[Idx++];
5541  for (unsigned I = 0; I != NumProtos; ++I)
5542  Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx));
5543  bool IsKindOf = Record[Idx++];
5544  return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf);
5545  }
5546 
5547  case TYPE_OBJC_OBJECT_POINTER: {
5548  unsigned Idx = 0;
5549  QualType Pointee = readType(*Loc.F, Record, Idx);
5550  return Context.getObjCObjectPointerType(Pointee);
5551  }
5552 
5554  unsigned Idx = 0;
5555  QualType Parm = readType(*Loc.F, Record, Idx);
5556  QualType Replacement = readType(*Loc.F, Record, Idx);
5558  cast<TemplateTypeParmType>(Parm),
5559  Context.getCanonicalType(Replacement));
5560  }
5561 
5563  unsigned Idx = 0;
5564  QualType Parm = readType(*Loc.F, Record, Idx);
5565  TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx);
5567  cast<TemplateTypeParmType>(Parm),
5568  ArgPack);
5569  }
5570 
5571  case TYPE_INJECTED_CLASS_NAME: {
5572  CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx);
5573  QualType TST = readType(*Loc.F, Record, Idx); // probably derivable
5574  // FIXME: ASTContext::getInjectedClassNameType is not currently suitable
5575  // for AST reading, too much interdependencies.
5576  const Type *T = nullptr;
5577  for (auto *DI = D; DI; DI = DI->getPreviousDecl()) {
5578  if (const Type *Existing = DI->getTypeForDecl()) {
5579  T = Existing;
5580  break;
5581  }
5582  }
5583  if (!T) {
5584  T = new (Context, TypeAlignment) InjectedClassNameType(D, TST);
5585  for (auto *DI = D; DI; DI = DI->getPreviousDecl())
5586  DI->setTypeForDecl(T);
5587  }
5588  return QualType(T, 0);
5589  }
5590 
5591  case TYPE_TEMPLATE_TYPE_PARM: {
5592  unsigned Idx = 0;
5593  unsigned Depth = Record[Idx++];
5594  unsigned Index = Record[Idx++];
5595  bool Pack = Record[Idx++];
5597  = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx);
5598  return Context.getTemplateTypeParmType(Depth, Index, Pack, D);
5599  }
5600 
5601  case TYPE_DEPENDENT_NAME: {
5602  unsigned Idx = 0;
5603  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
5604  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
5605  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
5606  QualType Canon = readType(*Loc.F, Record, Idx);
5607  if (!Canon.isNull())
5608  Canon = Context.getCanonicalType(Canon);
5609  return Context.getDependentNameType(Keyword, NNS, Name, Canon);
5610  }
5611 
5613  unsigned Idx = 0;
5614  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
5615  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
5616  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
5617  unsigned NumArgs = Record[Idx++];
5619  Args.reserve(NumArgs);
5620  while (NumArgs--)
5621  Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx));
5622  return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name,
5623  Args);
5624  }
5625 
5627  unsigned Idx = 0;
5628 
5629  // ArrayType
5630  QualType ElementType = readType(*Loc.F, Record, Idx);
5632  = (ArrayType::ArraySizeModifier)Record[Idx++];
5633  unsigned IndexTypeQuals = Record[Idx++];
5634 
5635  // DependentSizedArrayType
5636  Expr *NumElts = ReadExpr(*Loc.F);
5637  SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx);
5638 
5639  return Context.getDependentSizedArrayType(ElementType, NumElts, ASM,
5640  IndexTypeQuals, Brackets);
5641  }
5642 
5644  unsigned Idx = 0;
5645  bool IsDependent = Record[Idx++];
5646  TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
5648  ReadTemplateArgumentList(Args, *Loc.F, Record, Idx);
5649  QualType Underlying = readType(*Loc.F, Record, Idx);
5650  QualType T;
5651  if (Underlying.isNull())
5653  else
5654  T = Context.getTemplateSpecializationType(Name, Args, Underlying);
5655  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
5656  return T;
5657  }
5658 
5659  case TYPE_ATOMIC: {
5660  if (Record.size() != 1) {
5661  Error("Incorrect encoding of atomic type");
5662  return QualType();
5663  }
5664  QualType ValueType = readType(*Loc.F, Record, Idx);
5665  return Context.getAtomicType(ValueType);
5666  }
5667 
5668  case TYPE_PIPE: {
5669  if (Record.size() != 1) {
5670  Error("Incorrect encoding of pipe type");
5671  return QualType();
5672  }
5673 
5674  // Reading the pipe element type.
5675  QualType ElementType = readType(*Loc.F, Record, Idx);
5676  return Context.getPipeType(ElementType);
5677  }
5678  }
5679  llvm_unreachable("Invalid TypeCode!");
5680 }
5681 
5682 void ASTReader::readExceptionSpec(ModuleFile &ModuleFile,
5683  SmallVectorImpl<QualType> &Exceptions,
5685  const RecordData &Record, unsigned &Idx) {
5687  static_cast<ExceptionSpecificationType>(Record[Idx++]);
5688  ESI.Type = EST;
5689  if (EST == EST_Dynamic) {
5690  for (unsigned I = 0, N = Record[Idx++]; I != N; ++I)
5691  Exceptions.push_back(readType(ModuleFile, Record, Idx));
5692  ESI.Exceptions = Exceptions;
5693  } else if (EST == EST_ComputedNoexcept) {
5694  ESI.NoexceptExpr = ReadExpr(ModuleFile);
5695  } else if (EST == EST_Uninstantiated) {
5696  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
5697  ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
5698  } else if (EST == EST_Unevaluated) {
5699  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
5700  }
5701 }
5702 
5703 class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> {
5704  ASTReader &Reader;
5705  ModuleFile &F;
5706  const ASTReader::RecordData &Record;
5707  unsigned &Idx;
5708 
5709  SourceLocation ReadSourceLocation(const ASTReader::RecordData &R,
5710  unsigned &I) {
5711  return Reader.ReadSourceLocation(F, R, I);
5712  }
5713 
5714  template<typename T>
5715  T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) {
5716  return Reader.ReadDeclAs<T>(F, Record, Idx);
5717  }
5718 
5719 public:
5720  TypeLocReader(ASTReader &Reader, ModuleFile &F,
5721  const ASTReader::RecordData &Record, unsigned &Idx)
5722  : Reader(Reader), F(F), Record(Record), Idx(Idx)
5723  { }
5724 
5725  // We want compile-time assurance that we've enumerated all of
5726  // these, so unfortunately we have to declare them first, then
5727  // define them out-of-line.
5728 #define ABSTRACT_TYPELOC(CLASS, PARENT)
5729 #define TYPELOC(CLASS, PARENT) \
5730  void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
5731 #include "clang/AST/TypeLocNodes.def"
5732 
5733  void VisitFunctionTypeLoc(FunctionTypeLoc);
5734  void VisitArrayTypeLoc(ArrayTypeLoc);
5735 };
5736 
5737 void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
5738  // nothing to do
5739 }
5740 void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
5741  TL.setBuiltinLoc(ReadSourceLocation(Record, Idx));
5742  if (TL.needsExtraLocalData()) {
5743  TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++]));
5744  TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++]));
5745  TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++]));
5746  TL.setModeAttr(Record[Idx++]);
5747  }
5748 }
5749 void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) {
5750  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5751 }
5752 void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
5753  TL.setStarLoc(ReadSourceLocation(Record, Idx));
5754 }
5755 void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
5756  // nothing to do
5757 }
5758 void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
5759  // nothing to do
5760 }
5761 void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
5762  TL.setCaretLoc(ReadSourceLocation(Record, Idx));
5763 }
5764 void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
5765  TL.setAmpLoc(ReadSourceLocation(Record, Idx));
5766 }
5767 void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
5768  TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx));
5769 }
5770 void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
5771  TL.setStarLoc(ReadSourceLocation(Record, Idx));
5772  TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx));
5773 }
5775  TL.setLBracketLoc(ReadSourceLocation(Record, Idx));
5776  TL.setRBracketLoc(ReadSourceLocation(Record, Idx));
5777  if (Record[Idx++])
5778  TL.setSizeExpr(Reader.ReadExpr(F));
5779  else
5780  TL.setSizeExpr(nullptr);
5781 }
5782 void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
5783  VisitArrayTypeLoc(TL);
5784 }
5785 void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
5786  VisitArrayTypeLoc(TL);
5787 }
5788 void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
5789  VisitArrayTypeLoc(TL);
5790 }
5791 void TypeLocReader::VisitDependentSizedArrayTypeLoc(
5793  VisitArrayTypeLoc(TL);
5794 }
5795 void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
5797  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5798 }
5799 void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
5800  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5801 }
5802 void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
5803  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5804 }
5806  TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx));
5807  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5808  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5809  TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx));
5810  for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) {
5811  TL.setParam(i, ReadDeclAs<ParmVarDecl>(Record, Idx));
5812  }
5813 }
5814 void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
5815  VisitFunctionTypeLoc(TL);
5816 }
5817 void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
5818  VisitFunctionTypeLoc(TL);
5819 }
5820 void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
5821  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5822 }
5823 void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
5824  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5825 }
5826 void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
5827  TL.setTypeofLoc(ReadSourceLocation(Record, Idx));
5828  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5829  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5830 }
5831 void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
5832  TL.setTypeofLoc(ReadSourceLocation(Record, Idx));
5833  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5834  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5835  TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx));
5836 }
5837 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
5838  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5839 }
5840 void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
5841  TL.setKWLoc(ReadSourceLocation(Record, Idx));
5842  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5843  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5844  TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx));
5845 }
5846 void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) {
5847  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5848 }
5849 void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) {
5850  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5851 }
5852 void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) {
5853  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5854 }
5855 void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
5856  TL.setAttrNameLoc(ReadSourceLocation(Record, Idx));
5857  if (TL.hasAttrOperand()) {
5858  SourceRange range;
5859  range.setBegin(ReadSourceLocation(Record, Idx));
5860  range.setEnd(ReadSourceLocation(Record, Idx));
5861  TL.setAttrOperandParensRange(range);
5862  }
5863  if (TL.hasAttrExprOperand()) {
5864  if (Record[Idx++])
5865  TL.setAttrExprOperand(Reader.ReadExpr(F));
5866  else
5867  TL.setAttrExprOperand(nullptr);
5868  } else if (TL.hasAttrEnumOperand())
5869  TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx));
5870 }
5871 void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
5872  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5873 }
5874 void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc(
5876  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5877 }
5878 void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc(
5880  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5881 }
5882 void TypeLocReader::VisitTemplateSpecializationTypeLoc(
5884  TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx));
5885  TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx));
5886  TL.setLAngleLoc(ReadSourceLocation(Record, Idx));
5887  TL.setRAngleLoc(ReadSourceLocation(Record, Idx));
5888  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
5889  TL.setArgLocInfo(i,
5890  Reader.GetTemplateArgumentLocInfo(F,
5891  TL.getTypePtr()->getArg(i).getKind(),
5892  Record, Idx));
5893 }
5894 void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) {
5895  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5896  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5897 }
5898 void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
5899  TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx));
5900  TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx));
5901 }
5902 void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
5903  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5904 }
5905 void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
5906  TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx));
5907  TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx));
5908  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5909 }
5910 void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc(
5912  TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx));
5913  TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx));
5914  TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx));
5915  TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx));
5916  TL.setLAngleLoc(ReadSourceLocation(Record, Idx));
5917  TL.setRAngleLoc(ReadSourceLocation(Record, Idx));
5918  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
5919  TL.setArgLocInfo(I,
5920  Reader.GetTemplateArgumentLocInfo(F,
5921  TL.getTypePtr()->getArg(I).getKind(),
5922  Record, Idx));
5923 }
5924 void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
5925  TL.setEllipsisLoc(ReadSourceLocation(Record, Idx));
5926 }
5927 void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
5928  TL.setNameLoc(ReadSourceLocation(Record, Idx));
5929 }
5930 void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
5931  TL.setHasBaseTypeAsWritten(Record[Idx++]);
5932  TL.setTypeArgsLAngleLoc(ReadSourceLocation(Record, Idx));
5933  TL.setTypeArgsRAngleLoc(ReadSourceLocation(Record, Idx));
5934  for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i)
5935  TL.setTypeArgTInfo(i, Reader.GetTypeSourceInfo(F, Record, Idx));
5936  TL.setProtocolLAngleLoc(ReadSourceLocation(Record, Idx));
5937  TL.setProtocolRAngleLoc(ReadSourceLocation(Record, Idx));
5938  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
5939  TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx));
5940 }
5941 void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
5942  TL.setStarLoc(ReadSourceLocation(Record, Idx));
5943 }
5944 void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
5945  TL.setKWLoc(ReadSourceLocation(Record, Idx));
5946  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
5947  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
5948 }
5949 void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) {
5950  TL.setKWLoc(ReadSourceLocation(Record, Idx));
5951 }
5952 
5954  const RecordData &Record,
5955  unsigned &Idx) {
5956  QualType InfoTy = readType(F, Record, Idx);
5957  if (InfoTy.isNull())
5958  return nullptr;
5959 
5960  TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy);
5961  TypeLocReader TLR(*this, F, Record, Idx);
5962  for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
5963  TLR.Visit(TL);
5964  return TInfo;
5965 }
5966 
5968  unsigned FastQuals = ID & Qualifiers::FastMask;
5969  unsigned Index = ID >> Qualifiers::FastWidth;
5970 
5971  if (Index < NUM_PREDEF_TYPE_IDS) {
5972  QualType T;
5973  switch ((PredefinedTypeIDs)Index) {
5974  case PREDEF_TYPE_NULL_ID:
5975  return QualType();
5976  case PREDEF_TYPE_VOID_ID:
5977  T = Context.VoidTy;
5978  break;
5979  case PREDEF_TYPE_BOOL_ID:
5980  T = Context.BoolTy;
5981  break;
5982 
5983  case PREDEF_TYPE_CHAR_U_ID:
5984  case PREDEF_TYPE_CHAR_S_ID:
5985  // FIXME: Check that the signedness of CharTy is correct!
5986  T = Context.CharTy;
5987  break;
5988 
5989  case PREDEF_TYPE_UCHAR_ID:
5990  T = Context.UnsignedCharTy;
5991  break;
5992  case PREDEF_TYPE_USHORT_ID:
5994  break;
5995  case PREDEF_TYPE_UINT_ID:
5996  T = Context.UnsignedIntTy;
5997  break;
5998  case PREDEF_TYPE_ULONG_ID:
5999  T = Context.UnsignedLongTy;
6000  break;
6003  break;
6006  break;
6007  case PREDEF_TYPE_SCHAR_ID:
6008  T = Context.SignedCharTy;
6009  break;
6010  case PREDEF_TYPE_WCHAR_ID:
6011  T = Context.WCharTy;
6012  break;
6013  case PREDEF_TYPE_SHORT_ID:
6014  T = Context.ShortTy;
6015  break;
6016  case PREDEF_TYPE_INT_ID:
6017  T = Context.IntTy;
6018  break;
6019  case PREDEF_TYPE_LONG_ID:
6020  T = Context.LongTy;
6021  break;
6023  T = Context.LongLongTy;
6024  break;
6025  case PREDEF_TYPE_INT128_ID:
6026  T = Context.Int128Ty;
6027  break;
6028  case PREDEF_TYPE_HALF_ID:
6029  T = Context.HalfTy;
6030  break;
6031  case PREDEF_TYPE_FLOAT_ID:
6032  T = Context.FloatTy;
6033  break;
6034  case PREDEF_TYPE_DOUBLE_ID:
6035  T = Context.DoubleTy;
6036  break;
6038  T = Context.LongDoubleTy;
6039  break;
6041  T = Context.Float128Ty;
6042  break;
6044  T = Context.OverloadTy;
6045  break;
6047  T = Context.BoundMemberTy;
6048  break;
6050  T = Context.PseudoObjectTy;
6051  break;
6053  T = Context.DependentTy;
6054  break;
6056  T = Context.UnknownAnyTy;
6057  break;
6059  T = Context.NullPtrTy;
6060  break;
6061  case PREDEF_TYPE_CHAR16_ID:
6062  T = Context.Char16Ty;
6063  break;
6064  case PREDEF_TYPE_CHAR32_ID:
6065  T = Context.Char32Ty;
6066  break;
6067  case PREDEF_TYPE_OBJC_ID:
6069  break;
6072  break;
6073  case PREDEF_TYPE_OBJC_SEL:
6075  break;
6076 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6077  case PREDEF_TYPE_##Id##_ID: \
6078  T = Context.SingletonId; \
6079  break;
6080 #include "clang/Basic/OpenCLImageTypes.def"
6082  T = Context.OCLSamplerTy;
6083  break;
6084  case PREDEF_TYPE_EVENT_ID:
6085  T = Context.OCLEventTy;
6086  break;
6088  T = Context.OCLClkEventTy;
6089  break;
6090  case PREDEF_TYPE_QUEUE_ID:
6091  T = Context.OCLQueueTy;
6092  break;
6094  T = Context.OCLNDRangeTy;
6095  break;
6097  T = Context.OCLReserveIDTy;
6098  break;
6100  T = Context.getAutoDeductType();
6101  break;
6102 
6105  break;
6106 
6109  break;
6110 
6112  T = Context.BuiltinFnTy;
6113  break;
6114 
6117  break;
6118  }
6119 
6120  assert(!T.isNull() && "Unknown predefined type");
6121  return T.withFastQualifiers(FastQuals);
6122  }
6123 
6124  Index -= NUM_PREDEF_TYPE_IDS;
6125  assert(Index < TypesLoaded.size() && "Type index out-of-range");
6126  if (TypesLoaded[Index].isNull()) {
6127  TypesLoaded[Index] = readTypeRecord(Index);
6128  if (TypesLoaded[Index].isNull())
6129  return QualType();
6130 
6131  TypesLoaded[Index]->setFromAST();
6132  if (DeserializationListener)
6133  DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
6134  TypesLoaded[Index]);
6135  }
6136 
6137  return TypesLoaded[Index].withFastQualifiers(FastQuals);
6138 }
6139 
6140 QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) {
6141  return GetType(getGlobalTypeID(F, LocalID));
6142 }
6143 
6145 ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const {
6146  unsigned FastQuals = LocalID & Qualifiers::FastMask;
6147  unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
6148 
6149  if (LocalIndex < NUM_PREDEF_TYPE_IDS)
6150  return LocalID;
6151 
6153  = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS);
6154  assert(I != F.TypeRemap.end() && "Invalid index into type index remap");
6155 
6156  unsigned GlobalIndex = LocalIndex + I->second;
6157  return (GlobalIndex << Qualifiers::FastWidth) | FastQuals;
6158 }
6159 
6163  const RecordData &Record,
6164  unsigned &Index) {
6165  switch (Kind) {
6167  return ReadExpr(F);
6169  return GetTypeSourceInfo(F, Record, Index);
6171  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
6172  Index);
6173  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
6174  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
6175  SourceLocation());
6176  }
6178  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
6179  Index);
6180  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
6181  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index);
6182  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
6183  EllipsisLoc);
6184  }
6190  // FIXME: Is this right?
6191  return TemplateArgumentLocInfo();
6192  }
6193  llvm_unreachable("unexpected template argument loc");
6194 }
6195 
6198  const RecordData &Record, unsigned &Index) {
6199  TemplateArgument Arg = ReadTemplateArgument(F, Record, Index);
6200 
6201  if (Arg.getKind() == TemplateArgument::Expression) {
6202  if (Record[Index++]) // bool InfoHasSameExpr.
6204  }
6205  return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(),
6206  Record, Index));
6207 }
6208 
6211  const RecordData &Record,
6212  unsigned &Index) {
6213  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index);
6214  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index);
6215  unsigned NumArgsAsWritten = Record[Index++];
6216  TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
6217  for (unsigned i = 0; i != NumArgsAsWritten; ++i)
6218  TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index));
6219  return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo);
6220 }
6221 
6222 Decl *ASTReader::GetExternalDecl(uint32_t ID) {
6223  return GetDecl(ID);
6224 }
6225 
6226 template<typename TemplateSpecializationDecl>
6228  if (auto *TSD = dyn_cast<TemplateSpecializationDecl>(D))
6229  TSD->getSpecializedTemplate()->LoadLazySpecializations();
6230 }
6231 
6232 void ASTReader::CompleteRedeclChain(const Decl *D) {
6233  if (NumCurrentElementsDeserializing) {
6234  // We arrange to not care about the complete redeclaration chain while we're
6235  // deserializing. Just remember that the AST has marked this one as complete
6236  // but that it's not actually complete yet, so we know we still need to
6237  // complete it later.
6238  PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D));
6239  return;
6240  }
6241 
6242  const DeclContext *DC = D->getDeclContext()->getRedeclContext();
6243 
6244  // If this is a named declaration, complete it by looking it up
6245  // within its context.
6246  //
6247  // FIXME: Merging a function definition should merge
6248  // all mergeable entities within it.
6249  if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) ||
6250  isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) {
6251  if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) {
6252  if (!getContext().getLangOpts().CPlusPlus &&
6253  isa<TranslationUnitDecl>(DC)) {
6254  // Outside of C++, we don't have a lookup table for the TU, so update
6255  // the identifier instead. (For C++ modules, we don't store decls
6256  // in the serialized identifier table, so we do the lookup in the TU.)
6257  auto *II = Name.getAsIdentifierInfo();
6258  assert(II && "non-identifier name in C?");
6259  if (II->isOutOfDate())
6260  updateOutOfDateIdentifier(*II);
6261  } else
6262  DC->lookup(Name);
6263  } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) {
6264  // Find all declarations of this kind from the relevant context.
6265  for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) {
6266  auto *DC = cast<DeclContext>(DCDecl);
6267  SmallVector<Decl*, 8> Decls;
6268  FindExternalLexicalDecls(
6269  DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls);
6270  }
6271  }
6272  }
6273 
6274  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
6275  CTSD->getSpecializedTemplate()->LoadLazySpecializations();
6276  if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
6277  VTSD->getSpecializedTemplate()->LoadLazySpecializations();
6278  if (auto *FD = dyn_cast<FunctionDecl>(D)) {
6279  if (auto *Template = FD->getPrimaryTemplate())
6280  Template->LoadLazySpecializations();
6281  }
6282 }
6283 
6286  RecordLocation Loc = getLocalBitOffset(Offset);
6287  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
6288  SavedStreamPosition SavedPosition(Cursor);
6289  Cursor.JumpToBit(Loc.Offset);
6290  ReadingKindTracker ReadingKind(Read_Decl, *this);
6291 
6292  RecordData Record;
6293  unsigned Code = Cursor.ReadCode();
6294  unsigned RecCode = Cursor.readRecord(Code, Record);
6295  if (RecCode != DECL_CXX_CTOR_INITIALIZERS) {
6296  Error("malformed AST file: missing C++ ctor initializers");
6297  return nullptr;
6298  }
6299 
6300  unsigned Idx = 0;
6301  return ReadCXXCtorInitializers(*Loc.F, Record, Idx);
6302 }
6303 
6305  RecordLocation Loc = getLocalBitOffset(Offset);
6306  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
6307  SavedStreamPosition SavedPosition(Cursor);
6308  Cursor.JumpToBit(Loc.Offset);
6309  ReadingKindTracker ReadingKind(Read_Decl, *this);
6310  RecordData Record;
6311  unsigned Code = Cursor.ReadCode();
6312  unsigned RecCode = Cursor.readRecord(Code, Record);
6313  if (RecCode != DECL_CXX_BASE_SPECIFIERS) {
6314  Error("malformed AST file: missing C++ base specifiers");
6315  return nullptr;
6316  }
6317 
6318  unsigned Idx = 0;
6319  unsigned NumBases = Record[Idx++];
6320  void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases);
6321  CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases];
6322  for (unsigned I = 0; I != NumBases; ++I)
6323  Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx);
6324  return Bases;
6325 }
6326 
6328 ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const {
6329  if (LocalID < NUM_PREDEF_DECL_IDS)
6330  return LocalID;
6331 
6333  = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS);
6334  assert(I != F.DeclRemap.end() && "Invalid index into decl index remap");
6335 
6336  return LocalID + I->second;
6337 }
6338 
6340  ModuleFile &M) const {
6341  // Predefined decls aren't from any module.
6342  if (ID < NUM_PREDEF_DECL_IDS)
6343  return false;
6344 
6345  return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID &&
6346  ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls;
6347 }
6348 
6349 ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) {
6350  if (!D->isFromASTFile())
6351  return nullptr;
6352  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID());
6353  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
6354  return I->second;
6355 }
6356 
6358  if (ID < NUM_PREDEF_DECL_IDS)
6359  return SourceLocation();
6360 
6361  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
6362 
6363  if (Index > DeclsLoaded.size()) {
6364  Error("declaration ID out-of-range for AST file");
6365  return SourceLocation();
6366  }
6367 
6368  if (Decl *D = DeclsLoaded[Index])
6369  return D->getLocation();
6370 
6371  SourceLocation Loc;
6372  DeclCursorForID(ID, Loc);
6373  return Loc;
6374 }
6375 
6377  switch (ID) {
6378  case PREDEF_DECL_NULL_ID:
6379  return nullptr;
6380 
6382  return Context.getTranslationUnitDecl();
6383 
6385  return Context.getObjCIdDecl();
6386 
6388  return Context.getObjCSelDecl();
6389 
6391  return Context.getObjCClassDecl();
6392 
6394  return Context.getObjCProtocolDecl();
6395 
6397  return Context.getInt128Decl();
6398 
6400  return Context.getUInt128Decl();
6401 
6403  return Context.getObjCInstanceTypeDecl();
6404 
6406  return Context.getBuiltinVaListDecl();
6407 
6409  return Context.getVaListTagDecl();
6410 
6412  return Context.getBuiltinMSVaListDecl();
6413 
6415  return Context.getExternCContextDecl();
6416 
6418  return Context.getMakeIntegerSeqDecl();
6419 
6421  return Context.getCFConstantStringDecl();
6422 
6424  return Context.getCFConstantStringTagDecl();
6425 
6427  return Context.getTypePackElementDecl();
6428  }
6429  llvm_unreachable("PredefinedDeclIDs unknown enum value");
6430 }
6431 
6433  if (ID < NUM_PREDEF_DECL_IDS) {
6435  if (D) {
6436  // Track that we have merged the declaration with ID \p ID into the
6437  // pre-existing predefined declaration \p D.
6438  auto &Merged = KeyDecls[D->getCanonicalDecl()];
6439  if (Merged.empty())
6440  Merged.push_back(ID);
6441  }
6442  return D;
6443  }
6444 
6445  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
6446 
6447  if (Index >= DeclsLoaded.size()) {
6448  assert(0 && "declaration ID out-of-range for AST file");
6449  Error("declaration ID out-of-range for AST file");
6450  return nullptr;
6451  }
6452 
6453  return DeclsLoaded[Index];
6454 }
6455 
6457  if (ID < NUM_PREDEF_DECL_IDS)
6458  return GetExistingDecl(ID);
6459 
6460  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
6461 
6462  if (Index >= DeclsLoaded.size()) {
6463  assert(0 && "declaration ID out-of-range for AST file");
6464  Error("declaration ID out-of-range for AST file");
6465  return nullptr;
6466  }
6467 
6468  if (!DeclsLoaded[Index]) {
6469  ReadDeclRecord(ID);
6470  if (DeserializationListener)
6471  DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
6472  }
6473 
6474  return DeclsLoaded[Index];
6475 }
6476 
6478  DeclID GlobalID) {
6479  if (GlobalID < NUM_PREDEF_DECL_IDS)
6480  return GlobalID;
6481 
6482  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID);
6483  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
6484  ModuleFile *Owner = I->second;
6485 
6487  = M.GlobalToLocalDeclIDs.find(Owner);
6488  if (Pos == M.GlobalToLocalDeclIDs.end())
6489  return 0;
6490 
6491  return GlobalID - Owner->BaseDeclID + Pos->second;
6492 }
6493 
6495  const RecordData &Record,
6496  unsigned &Idx) {
6497  if (Idx >= Record.size()) {
6498  Error("Corrupted AST file");
6499  return 0;
6500  }
6501 
6502  return getGlobalDeclID(F, Record[Idx++]);
6503 }
6504 
6505 /// \brief Resolve the offset of a statement into a statement.
6506 ///
6507 /// This operation will read a new statement from the external
6508 /// source each time it is called, and is meant to be used via a
6509 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
6511  // Switch case IDs are per Decl.
6512  ClearSwitchCaseIDs();
6513 
6514  // Offset here is a global offset across the entire chain.
6515  RecordLocation Loc = getLocalBitOffset(Offset);
6516  Loc.F->DeclsCursor.JumpToBit(Loc.Offset);
6517  return ReadStmtFromStream(*Loc.F);
6518 }
6519 
6521  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
6522  SmallVectorImpl<Decl *> &Decls) {
6523  bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {};
6524 
6525  auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) {
6526  assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries");
6527  for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) {
6528  auto K = (Decl::Kind)+LexicalDecls[I];
6529  if (!IsKindWeWant(K))
6530  continue;
6531 
6532  auto ID = (serialization::DeclID)+LexicalDecls[I + 1];
6533 
6534  // Don't add predefined declarations to the lexical context more
6535  // than once.
6536  if (ID < NUM_PREDEF_DECL_IDS) {
6537  if (PredefsVisited[ID])
6538  continue;
6539 
6540  PredefsVisited[ID] = true;
6541  }
6542 
6543  if (Decl *D = GetLocalDecl(*M, ID)) {
6544  assert(D->getKind() == K && "wrong kind for lexical decl");
6545  if (!DC->isDeclInLexicalTraversal(D))
6546  Decls.push_back(D);
6547  }
6548  }
6549  };
6550 
6551  if (isa<TranslationUnitDecl>(DC)) {
6552  for (auto Lexical : TULexicalDecls)
6553  Visit(Lexical.first, Lexical.second);
6554  } else {
6555  auto I = LexicalDecls.find(DC);
6556  if (I != LexicalDecls.end())
6557  Visit(I->second.first, I->second.second);
6558  }
6559 
6560  ++NumLexicalDeclContextsRead;
6561 }
6562 
6563 namespace {
6564 
6565 class DeclIDComp {
6566  ASTReader &Reader;
6567  ModuleFile &Mod;
6568 
6569 public:
6570  DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {}
6571 
6572  bool operator()(LocalDeclID L, LocalDeclID R) const {
6573  SourceLocation LHS = getLocation(L);
6574  SourceLocation RHS = getLocation(R);
6575  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
6576  }
6577 
6578  bool operator()(SourceLocation LHS, LocalDeclID R) const {
6579  SourceLocation RHS = getLocation(R);
6580  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
6581  }
6582 
6583  bool operator()(LocalDeclID L, SourceLocation RHS) const {
6584  SourceLocation LHS = getLocation(L);
6585  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
6586  }
6587 
6588  SourceLocation getLocation(LocalDeclID ID) const {
6589  return Reader.getSourceManager().getFileLoc(
6590  Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID)));
6591  }
6592 };
6593 
6594 }
6595 
6597  unsigned Offset, unsigned Length,
6598  SmallVectorImpl<Decl *> &Decls) {
6599  SourceManager &SM = getSourceManager();
6600 
6601  llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File);
6602  if (I == FileDeclIDs.end())
6603  return;
6604 
6605  FileDeclsInfo &DInfo = I->second;
6606  if (DInfo.Decls.empty())
6607  return;
6608 
6610  BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset);
6611  SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length);
6612 
6613  DeclIDComp DIDComp(*this, *DInfo.Mod);
6615  BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
6616  BeginLoc, DIDComp);
6617  if (BeginIt != DInfo.Decls.begin())
6618  --BeginIt;
6619 
6620  // If we are pointing at a top-level decl inside an objc container, we need
6621  // to backtrack until we find it otherwise we will fail to report that the
6622  // region overlaps with an objc container.
6623  while (BeginIt != DInfo.Decls.begin() &&
6624  GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt))
6625  ->isTopLevelDeclInObjCContainer())
6626  --BeginIt;
6627 
6629  EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
6630  EndLoc, DIDComp);
6631  if (EndIt != DInfo.Decls.end())
6632  ++EndIt;
6633 
6635  DIt = BeginIt; DIt != EndIt; ++DIt)
6636  Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt)));
6637 }
6638 
6639 bool
6641  DeclarationName Name) {
6642  assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
6643  "DeclContext has no visible decls in storage");
6644  if (!Name)
6645  return false;
6646 
6647  auto It = Lookups.find(DC);
6648  if (It == Lookups.end())
6649  return false;
6650 
6651  Deserializing LookupResults(this);
6652 
6653  // Load the list of declarations.
6655  for (DeclID ID : It->second.Table.find(Name)) {
6656  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
6657  if (ND->getDeclName() == Name)
6658  Decls.push_back(ND);
6659  }
6660 
6661  ++NumVisibleDeclContextsRead;
6662  SetExternalVisibleDeclsForName(DC, Name, Decls);
6663  return !Decls.empty();
6664 }
6665 
6667  if (!DC->hasExternalVisibleStorage())
6668  return;
6669 
6670  auto It = Lookups.find(DC);
6671  assert(It != Lookups.end() &&
6672  "have external visible storage but no lookup tables");
6673 
6674  DeclsMap Decls;
6675 
6676  for (DeclID ID : It->second.Table.findAll()) {
6677  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
6678  Decls[ND->getDeclName()].push_back(ND);
6679  }
6680 
6681  ++NumVisibleDeclContextsRead;
6682 
6683  for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
6684  SetExternalVisibleDeclsForName(DC, I->first, I->second);
6685  }
6686  const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false);
6687 }
6688 
6691  auto I = Lookups.find(Primary);
6692  return I == Lookups.end() ? nullptr : &I->second;
6693 }
6694 
6695 /// \brief Under non-PCH compilation the consumer receives the objc methods
6696 /// before receiving the implementation, and codegen depends on this.
6697 /// We simulate this by deserializing and passing to consumer the methods of the
6698 /// implementation before passing the deserialized implementation decl.
6700  ASTConsumer *Consumer) {
6701  assert(ImplD && Consumer);
6702 
6703  for (auto *I : ImplD->methods())
6704  Consumer->HandleInterestingDecl(DeclGroupRef(I));
6705 
6706  Consumer->HandleInterestingDecl(DeclGroupRef(ImplD));
6707 }
6708 
6709 void ASTReader::PassInterestingDeclsToConsumer() {
6710  assert(Consumer);
6711 
6712  if (PassingDeclsToConsumer)
6713  return;
6714 
6715  // Guard variable to avoid recursively redoing the process of passing
6716  // decls to consumer.
6717  SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
6718  true);
6719 
6720  // Ensure that we've loaded all potentially-interesting declarations
6721  // that need to be eagerly loaded.
6722  for (auto ID : EagerlyDeserializedDecls)
6723  GetDecl(ID);
6724  EagerlyDeserializedDecls.clear();
6725 
6726  while (!InterestingDecls.empty()) {
6727  Decl *D = InterestingDecls.front();
6728  InterestingDecls.pop_front();
6729 
6730  PassInterestingDeclToConsumer(D);
6731  }
6732 }
6733 
6734 void ASTReader::PassInterestingDeclToConsumer(Decl *D) {
6735  if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
6736  PassObjCImplDeclToConsumer(ImplD, Consumer);
6737  else
6738  Consumer->HandleInterestingDecl(DeclGroupRef(D));
6739 }
6740 
6742  this->Consumer = Consumer;
6743 
6744  if (Consumer)
6745  PassInterestingDeclsToConsumer();
6746 
6747  if (DeserializationListener)
6748  DeserializationListener->ReaderInitialized(this);
6749 }
6750 
6752  std::fprintf(stderr, "*** AST File Statistics:\n");
6753 
6754  unsigned NumTypesLoaded
6755  = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(),
6756  QualType());
6757  unsigned NumDeclsLoaded
6758  = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(),
6759  (Decl *)nullptr);
6760  unsigned NumIdentifiersLoaded
6761  = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(),
6762  IdentifiersLoaded.end(),
6763  (IdentifierInfo *)nullptr);
6764  unsigned NumMacrosLoaded
6765  = MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
6766  MacrosLoaded.end(),
6767  (MacroInfo *)nullptr);
6768  unsigned NumSelectorsLoaded
6769  = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
6770  SelectorsLoaded.end(),
6771  Selector());
6772 
6773  if (unsigned TotalNumSLocEntries = getTotalNumSLocs())
6774  std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n",
6775  NumSLocEntriesRead, TotalNumSLocEntries,
6776  ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100));
6777  if (!TypesLoaded.empty())
6778  std::fprintf(stderr, " %u/%u types read (%f%%)\n",
6779  NumTypesLoaded, (unsigned)TypesLoaded.size(),
6780  ((float)NumTypesLoaded/TypesLoaded.size() * 100));
6781  if (!DeclsLoaded.empty())
6782  std::fprintf(stderr, " %u/%u declarations read (%f%%)\n",
6783  NumDeclsLoaded, (unsigned)DeclsLoaded.size(),
6784  ((float)NumDeclsLoaded/DeclsLoaded.size() * 100));
6785  if (!IdentifiersLoaded.empty())
6786  std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n",
6787  NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(),
6788  ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100));
6789  if (!MacrosLoaded.empty())
6790  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
6791  NumMacrosLoaded, (unsigned)MacrosLoaded.size(),
6792  ((float)NumMacrosLoaded/MacrosLoaded.size() * 100));
6793  if (!SelectorsLoaded.empty())
6794  std::fprintf(stderr, " %u/%u selectors read (%f%%)\n",
6795  NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(),
6796  ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100));
6797  if (TotalNumStatements)
6798  std::fprintf(stderr, " %u/%u statements read (%f%%)\n",
6799  NumStatementsRead, TotalNumStatements,
6800  ((float)NumStatementsRead/TotalNumStatements * 100));
6801  if (TotalNumMacros)
6802  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
6803  NumMacrosRead, TotalNumMacros,
6804  ((float)NumMacrosRead/TotalNumMacros * 100));
6805  if (TotalLexicalDeclContexts)
6806  std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n",
6807  NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
6808  ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
6809  * 100));
6810  if (TotalVisibleDeclContexts)
6811  std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n",
6812  NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
6813  ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
6814  * 100));
6815  if (TotalNumMethodPoolEntries) {
6816  std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n",
6817  NumMethodPoolEntriesRead, TotalNumMethodPoolEntries,
6818  ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries
6819  * 100));
6820  }
6821  if (NumMethodPoolLookups) {
6822  std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n",
6823  NumMethodPoolHits, NumMethodPoolLookups,
6824  ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0));
6825  }
6826  if (NumMethodPoolTableLookups) {
6827  std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n",
6828  NumMethodPoolTableHits, NumMethodPoolTableLookups,
6829  ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups
6830  * 100.0));
6831  }
6832 
6833  if (NumIdentifierLookupHits) {
6834  std::fprintf(stderr,
6835  " %u / %u identifier table lookups succeeded (%f%%)\n",
6836  NumIdentifierLookupHits, NumIdentifierLookups,
6837  (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
6838  }
6839 
6840  if (GlobalIndex) {
6841  std::fprintf(stderr, "\n");
6842  GlobalIndex->printStats();
6843  }
6844 
6845  std::fprintf(stderr, "\n");
6846  dump();
6847  std::fprintf(stderr, "\n");
6848 }
6849 
6850 template<typename Key, typename ModuleFile, unsigned InitialCapacity>
6851 static void
6852 dumpModuleIDMap(StringRef Name,
6853  const ContinuousRangeMap<Key, ModuleFile *,
6854  InitialCapacity> &Map) {
6855  if (Map.begin() == Map.end())
6856  return;
6857 
6859  llvm::errs() << Name << ":\n";
6860  for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
6861  I != IEnd; ++I) {
6862  llvm::errs() << " " << I->first << " -> " << I->second->FileName
6863  << "\n";
6864  }
6865 }
6866 
6867 LLVM_DUMP_METHOD void ASTReader::dump() {
6868  llvm::errs() << "*** PCH/ModuleFile Remappings:\n";
6869  dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
6870  dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
6871  dumpModuleIDMap("Global type map", GlobalTypeMap);
6872  dumpModuleIDMap("Global declaration map", GlobalDeclMap);
6873  dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
6874  dumpModuleIDMap("Global macro map", GlobalMacroMap);
6875  dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
6876  dumpModuleIDMap("Global selector map", GlobalSelectorMap);
6877  dumpModuleIDMap("Global preprocessed entity map",
6878  GlobalPreprocessedEntityMap);
6879 
6880  llvm::errs() << "\n*** PCH/Modules Loaded:";
6881  for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(),
6882  MEnd = ModuleMgr.end();
6883  M != MEnd; ++M)
6884  (*M)->dump();
6885 }
6886 
6887 /// Return the amount of memory used by memory buffers, breaking down
6888 /// by heap-backed versus mmap'ed memory.
6890  for (ModuleConstIterator I = ModuleMgr.begin(),
6891  E = ModuleMgr.end(); I != E; ++I) {
6892  if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) {
6893  size_t bytes = buf->getBufferSize();
6894  switch (buf->getBufferKind()) {
6895  case llvm::MemoryBuffer::MemoryBuffer_Malloc:
6896  sizes.malloc_bytes += bytes;
6897  break;
6898  case llvm::MemoryBuffer::MemoryBuffer_MMap:
6899  sizes.mmap_bytes += bytes;
6900  break;
6901  }
6902  }
6903  }
6904 }
6905 
6907  SemaObj = &S;
6908  S.addExternalSource(this);
6909 
6910  // Makes sure any declarations that were deserialized "too early"
6911  // still get added to the identifier's declaration chains.
6912  for (uint64_t ID : PreloadedDeclIDs) {
6913  NamedDecl *D = cast<NamedDecl>(GetDecl(ID));
6914  pushExternalDeclIntoScope(D, D->getDeclName());
6915  }
6916  PreloadedDeclIDs.clear();
6917 
6918  // FIXME: What happens if these are changed by a module import?
6919  if (!FPPragmaOptions.empty()) {
6920  assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
6921  SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0];
6922  }
6923 
6924  // FIXME: What happens if these are changed by a module import?
6925  if (!OpenCLExtensions.empty()) {
6926  unsigned I = 0;
6927 #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++];
6928 #include "clang/Basic/OpenCLExtensions.def"
6929 
6930  assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS");
6931  }
6932 
6933  UpdateSema();
6934 }
6935 
6937  assert(SemaObj && "no Sema to update");
6938 
6939  // Load the offsets of the declarations that Sema references.
6940  // They will be lazily deserialized when needed.
6941  if (!SemaDeclRefs.empty()) {
6942  assert(SemaDeclRefs.size() % 2 == 0);
6943  for (unsigned I = 0; I != SemaDeclRefs.size(); I += 2) {
6944  if (!SemaObj->StdNamespace)
6945  SemaObj->StdNamespace = SemaDeclRefs[I];
6946  if (!SemaObj->StdBadAlloc)
6947  SemaObj->StdBadAlloc = SemaDeclRefs[I+1];
6948  }
6949  SemaDeclRefs.clear();
6950  }
6951 
6952  // Update the state of pragmas. Use the same API as if we had encountered the
6953  // pragma in the source.
6954  if(OptimizeOffPragmaLocation.isValid())
6955  SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation);
6956  if (PragmaMSStructState != -1)
6957  SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState);
6958  if (PointersToMembersPragmaLocation.isValid()) {
6959  SemaObj->ActOnPragmaMSPointersToMembers(
6961  PragmaMSPointersToMembersState,
6962  PointersToMembersPragmaLocation);
6963  }
6964 }
6965 
6966 IdentifierInfo *ASTReader::get(StringRef Name) {
6967  // Note that we are loading an identifier.
6968  Deserializing AnIdentifier(this);
6969 
6970  IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0,
6971  NumIdentifierLookups,
6972  NumIdentifierLookupHits);
6973 
6974  // We don't need to do identifier table lookups in C++ modules (we preload
6975  // all interesting declarations, and don't need to use the scope for name
6976  // lookups). Perform the lookup in PCH files, though, since we don't build
6977  // a complete initial identifier table if we're carrying on from a PCH.
6978  if (Context.getLangOpts().CPlusPlus) {
6979  for (auto F : ModuleMgr.pch_modules())
6980  if (Visitor(*F))
6981  break;
6982  } else {
6983  // If there is a global index, look there first to determine which modules
6984  // provably do not have any results for this identifier.
6986  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
6987  if (!loadGlobalIndex()) {
6988  if (GlobalIndex->lookupIdentifier(Name, Hits)) {
6989  HitsPtr = &Hits;
6990  }
6991  }
6992 
6993  ModuleMgr.visit(Visitor, HitsPtr);
6994  }
6995 
6996  IdentifierInfo *II = Visitor.getIdentifierInfo();
6997  markIdentifierUpToDate(II);
6998  return II;
6999 }
7000 
7001 namespace clang {
7002  /// \brief An identifier-lookup iterator that enumerates all of the
7003  /// identifiers stored within a set of AST files.
7005  /// \brief The AST reader whose identifiers are being enumerated.
7006  const ASTReader &Reader;
7007 
7008  /// \brief The current index into the chain of AST files stored in
7009  /// the AST reader.
7010  unsigned Index;
7011 
7012  /// \brief The current position within the identifier lookup table
7013  /// of the current AST file.
7014  ASTIdentifierLookupTable::key_iterator Current;
7015 
7016  /// \brief The end position within the identifier lookup table of
7017  /// the current AST file.
7018  ASTIdentifierLookupTable::key_iterator End;
7019 
7020  /// \brief Whether to skip any modules in the ASTReader.
7021  bool SkipModules;
7022 
7023  public:
7024  explicit ASTIdentifierIterator(const ASTReader &Reader,
7025  bool SkipModules = false);
7026 
7027  StringRef Next() override;
7028  };
7029 }
7030 
7032  bool SkipModules)
7033  : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) {
7034 }
7035 
7037  while (Current == End) {
7038  // If we have exhausted all of our AST files, we're done.
7039  if (Index == 0)
7040  return StringRef();
7041 
7042  --Index;
7043  ModuleFile &F = Reader.ModuleMgr[Index];
7044  if (SkipModules && F.isModule())
7045  continue;
7046 
7047  ASTIdentifierLookupTable *IdTable =
7048  (ASTIdentifierLookupTable *)F.IdentifierLookupTable;
7049  Current = IdTable->key_begin();
7050  End = IdTable->key_end();
7051  }
7052 
7053  // We have any identifiers remaining in the current AST file; return
7054  // the next one.
7055  StringRef Result = *Current;
7056  ++Current;
7057  return Result;
7058 }
7059 
7060 namespace {
7061 /// A utility for appending two IdentifierIterators.
7062 class ChainedIdentifierIterator : public IdentifierIterator {
7063  std::unique_ptr<IdentifierIterator> Current;
7064  std::unique_ptr<IdentifierIterator> Queued;
7065 
7066 public:
7067  ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First,
7068  std::unique_ptr<IdentifierIterator> Second)
7069  : Current(std::move(First)), Queued(std::move(Second)) {}
7070 
7071  StringRef Next() override {
7072  if (!Current)
7073  return StringRef();
7074 
7075  StringRef result = Current->Next();
7076  if (!result.empty())
7077  return result;
7078 
7079  // Try the queued iterator, which may itself be empty.
7080  Current.reset();
7081  std::swap(Current, Queued);
7082  return Next();
7083  }
7084 };
7085 } // end anonymous namespace.
7086 
7088  if (!loadGlobalIndex()) {
7089  std::unique_ptr<IdentifierIterator> ReaderIter(
7090  new ASTIdentifierIterator(*this, /*SkipModules=*/true));
7091  std::unique_ptr<IdentifierIterator> ModulesIter(
7092  GlobalIndex->createIdentifierIterator());
7093  return new ChainedIdentifierIterator(std::move(ReaderIter),
7094  std::move(ModulesIter));
7095  }
7096 
7097  return new ASTIdentifierIterator(*this);
7098 }
7099 
7100 namespace clang { namespace serialization {
7102  ASTReader &Reader;
7103  Selector Sel;
7104  unsigned PriorGeneration;
7105  unsigned InstanceBits;
7106  unsigned FactoryBits;
7107  bool InstanceHasMoreThanOneDecl;
7108  bool FactoryHasMoreThanOneDecl;
7109  SmallVector<ObjCMethodDecl *, 4> InstanceMethods;
7110  SmallVector<ObjCMethodDecl *, 4> FactoryMethods;
7111 
7112  public:
7114  unsigned PriorGeneration)
7115  : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration),
7116  InstanceBits(0), FactoryBits(0), InstanceHasMoreThanOneDecl(false),
7117  FactoryHasMoreThanOneDecl(false) {}
7118 
7119  bool operator()(ModuleFile &M) {
7120  if (!M.SelectorLookupTable)
7121  return false;
7122 
7123  // If we've already searched this module file, skip it now.
7124  if (M.Generation <= PriorGeneration)
7125  return true;
7126 
7127  ++Reader.NumMethodPoolTableLookups;
7128  ASTSelectorLookupTable *PoolTable
7130  ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel);
7131  if (Pos == PoolTable->end())
7132  return false;
7133 
7134  ++Reader.NumMethodPoolTableHits;
7135  ++Reader.NumSelectorsRead;
7136  // FIXME: Not quite happy with the statistics here. We probably should
7137  // disable this tracking when called via LoadSelector.
7138  // Also, should entries without methods count as misses?
7139  ++Reader.NumMethodPoolEntriesRead;
7141  if (Reader.DeserializationListener)
7142  Reader.DeserializationListener->SelectorRead(Data.ID, Sel);
7143 
7144  InstanceMethods.append(Data.Instance.begin(), Data.Instance.end());
7145  FactoryMethods.append(Data.Factory.begin(), Data.Factory.end());
7146  InstanceBits = Data.InstanceBits;
7147  FactoryBits = Data.FactoryBits;
7148  InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl;
7149  FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl;
7150  return true;
7151  }
7152 
7153  /// \brief Retrieve the instance methods found by this visitor.
7155  return InstanceMethods;
7156  }
7157 
7158  /// \brief Retrieve the instance methods found by this visitor.
7160  return FactoryMethods;
7161  }
7162 
7163  unsigned getInstanceBits() const { return InstanceBits; }
7164  unsigned getFactoryBits() const { return FactoryBits; }
7166  return InstanceHasMoreThanOneDecl;
7167  }
7168  bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; }
7169  };
7170 } } // end namespace clang::serialization
7171 
7172 /// \brief Add the given set of methods to the method list.
7174  ObjCMethodList &List) {
7175  for (unsigned I = 0, N = Methods.size(); I != N; ++I) {
7176  S.addMethodToGlobalList(&List, Methods[I]);
7177  }
7178 }
7179 
7181  // Get the selector generation and update it to the current generation.
7182  unsigned &Generation = SelectorGeneration[Sel];
7183  unsigned PriorGeneration = Generation;
7184  Generation = getGeneration();
7185  SelectorOutOfDate[Sel] = false;
7186 
7187  // Search for methods defined with this selector.
7188  ++NumMethodPoolLookups;
7189  ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration);
7190  ModuleMgr.visit(Visitor);
7191 
7192  if (Visitor.getInstanceMethods().empty() &&
7193  Visitor.getFactoryMethods().empty())
7194  return;
7195 
7196  ++NumMethodPoolHits;
7197 
7198  if (!getSema())
7199  return;
7200 
7201  Sema &S = *getSema();
7203  = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first;
7204 
7205  Pos->second.first.setBits(Visitor.getInstanceBits());
7206  Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
7207  Pos->second.second.setBits(Visitor.getFactoryBits());
7208  Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl());
7209 
7210  // Add methods to the global pool *after* setting hasMoreThanOneDecl, since
7211  // when building a module we keep every method individually and may need to
7212  // update hasMoreThanOneDecl as we add the methods.
7213  addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first);
7214  addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second);
7215 }
7216 
7218  if (SelectorOutOfDate[Sel])
7219  ReadMethodPool(Sel);
7220 }
7221 
7223  SmallVectorImpl<NamespaceDecl *> &Namespaces) {
7224  Namespaces.clear();
7225 
7226  for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) {
7227  if (NamespaceDecl *Namespace
7228  = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I])))
7229  Namespaces.push_back(Namespace);
7230  }
7231 }
7232 
7234  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
7235  for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) {
7236  NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++]));
7237  SourceLocation Loc =
7238  SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]);
7239  Undefined.insert(std::make_pair(D, Loc));
7240  }
7241 }
7242 
7244  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
7245  Exprs) {
7246  for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) {
7247  FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++]));
7248  uint64_t Count = DelayedDeleteExprs[Idx++];
7249  for (uint64_t C = 0; C < Count; ++C) {
7250  SourceLocation DeleteLoc =
7251  SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]);
7252  const bool IsArrayForm = DelayedDeleteExprs[Idx++];
7253  Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm));
7254  }
7255  }
7256 }
7257 
7259  SmallVectorImpl<VarDecl *> &TentativeDefs) {
7260  for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
7261  VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I]));
7262  if (Var)
7263  TentativeDefs.push_back(Var);
7264  }
7265  TentativeDefinitions.clear();
7266 }
7267 
7270  for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
7271  DeclaratorDecl *D
7272  = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I]));
7273  if (D)
7274  Decls.push_back(D);
7275  }
7276  UnusedFileScopedDecls.clear();
7277 }
7278 
7281  for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) {
7283  = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I]));
7284  if (D)
7285  Decls.push_back(D);
7286  }
7287  DelegatingCtorDecls.clear();
7288 }
7289 
7291  for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) {
7292  TypedefNameDecl *D
7293  = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]));
7294  if (D)
7295  Decls.push_back(D);
7296  }
7297  ExtVectorDecls.clear();
7298 }
7299 
7302  for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N;
7303  ++I) {
7304  TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>(
7305  GetDecl(UnusedLocalTypedefNameCandidates[I]));
7306  if (D)
7307  Decls.insert(D);
7308  }
7309  UnusedLocalTypedefNameCandidates.clear();
7310 }
7311 
7313  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
7314  if (ReferencedSelectorsData.empty())
7315  return;
7316 
7317  // If there are @selector references added them to its pool. This is for
7318  // implementation of -Wselector.
7319  unsigned int DataSize = ReferencedSelectorsData.size()-1;
7320  unsigned I = 0;
7321  while (I < DataSize) {
7322  Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]);
7323  SourceLocation SelLoc
7324  = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]);
7325  Sels.push_back(std::make_pair(Sel, SelLoc));
7326  }
7327  ReferencedSelectorsData.clear();
7328 }
7329 
7331  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) {
7332  if (WeakUndeclaredIdentifiers.empty())
7333  return;
7334 
7335  for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) {
7336  IdentifierInfo *WeakId
7337  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
7338  IdentifierInfo *AliasId
7339  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
7340  SourceLocation Loc
7341  = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]);
7342  bool Used = WeakUndeclaredIdentifiers[I++];
7343  WeakInfo WI(AliasId, Loc);
7344  WI.setUsed(Used);
7345  WeakIDs.push_back(std::make_pair(WeakId, WI));
7346  }
7347  WeakUndeclaredIdentifiers.clear();
7348 }
7349 
7351  for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) {
7352  ExternalVTableUse VT;
7353  VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++]));
7354  VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]);
7355  VT.DefinitionRequired = VTableUses[Idx++];
7356  VTables.push_back(VT);
7357  }
7358 
7359  VTableUses.clear();
7360 }
7361 
7363  SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) {
7364  for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) {
7365  ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));
7366  SourceLocation Loc
7367  = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);
7368 
7369  Pending.push_back(std::make_pair(D, Loc));
7370  }
7371  PendingInstantiations.clear();
7372 }
7373 
7375  llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {
7376  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
7377  /* In loop */) {
7378  FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++]));
7379 
7381  LT->D = GetDecl(LateParsedTemplates[Idx++]);
7382 
7383  ModuleFile *F = getOwningModuleFile(LT->D);
7384  assert(F && "No module");
7385 
7386  unsigned TokN = LateParsedTemplates[Idx++];
7387  LT->Toks.reserve(TokN);
7388  for (unsigned T = 0; T < TokN; ++T)
7389  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
7390 
7391  LPTMap.insert(std::make_pair(FD, LT));
7392  }
7393 
7394  LateParsedTemplates.clear();
7395 }
7396 
7398  // It would be complicated to avoid reading the methods anyway. So don't.
7399  ReadMethodPool(Sel);
7400 }
7401 
7403  assert(ID && "Non-zero identifier ID required");
7404  assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range");
7405  IdentifiersLoaded[ID - 1] = II;
7406  if (DeserializationListener)
7407  DeserializationListener->IdentifierRead(ID, II);
7408 }
7409 
7410 /// \brief Set the globally-visible declarations associated with the given
7411 /// identifier.
7412 ///
7413 /// If the AST reader is currently in a state where the given declaration IDs
7414 /// cannot safely be resolved, they are queued until it is safe to resolve
7415 /// them.
7416 ///
7417 /// \param II an IdentifierInfo that refers to one or more globally-visible
7418 /// declarations.
7419 ///
7420 /// \param DeclIDs the set of declaration IDs with the name @p II that are
7421 /// visible at global scope.
7422 ///
7423 /// \param Decls if non-null, this vector will be populated with the set of
7424 /// deserialized declarations. These declarations will not be pushed into
7425 /// scope.
7426 void
7428  const SmallVectorImpl<uint32_t> &DeclIDs,
7429  SmallVectorImpl<Decl *> *Decls) {
7430  if (NumCurrentElementsDeserializing && !Decls) {
7431  PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end());
7432  return;
7433  }
7434 
7435  for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) {
7436  if (!SemaObj) {
7437  // Queue this declaration so that it will be added to the
7438  // translation unit scope and identifier's declaration chain
7439  // once a Sema object is known.
7440  PreloadedDeclIDs.push_back(DeclIDs[I]);
7441  continue;
7442  }
7443 
7444  NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I]));
7445 
7446  // If we're simply supposed to record the declarations, do so now.
7447  if (Decls) {
7448  Decls->push_back(D);
7449  continue;
7450  }
7451 
7452  // Introduce this declaration into the translation-unit scope
7453  // and add it to the declaration chain for this identifier, so
7454  // that (unqualified) name lookup will find it.
7455  pushExternalDeclIntoScope(D, II);
7456  }
7457 }
7458 
7460  if (ID == 0)
7461  return nullptr;
7462 
7463  if (IdentifiersLoaded.empty()) {
7464  Error("no identifier table in AST file");
7465  return nullptr;
7466  }
7467 
7468  ID -= 1;
7469  if (!IdentifiersLoaded[ID]) {
7470  GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
7471  assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
7472  ModuleFile *M = I->second;
7473  unsigned Index = ID - M->BaseIdentifierID;
7474  const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index];
7475 
7476  // All of the strings in the AST file are preceded by a 16-bit length.
7477  // Extract that 16-bit length to avoid having to execute strlen().
7478  // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as
7479  // unsigned integers. This is important to avoid integer overflow when
7480  // we cast them to 'unsigned'.
7481  const unsigned char *StrLenPtr = (const unsigned char*) Str - 2;
7482  unsigned StrLen = (((unsigned) StrLenPtr[0])
7483  | (((unsigned) StrLenPtr[1]) << 8)) - 1;
7484  auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen));
7485  IdentifiersLoaded[ID] = &II;
7486  markIdentifierFromAST(*this, II);
7487  if (DeserializationListener)
7488  DeserializationListener->IdentifierRead(ID + 1, &II);
7489  }
7490 
7491  return IdentifiersLoaded[ID];
7492 }
7493 
7494 IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
7495  return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
7496 }
7497 
7498 IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
7499  if (LocalID < NUM_PREDEF_IDENT_IDS)
7500  return LocalID;
7501 
7503  = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS);
7504  assert(I != M.IdentifierRemap.end()
7505  && "Invalid index into identifier index remap");
7506 
7507  return LocalID + I->second;
7508 }
7509 
7511  if (ID == 0)
7512  return nullptr;
7513 
7514  if (MacrosLoaded.empty()) {
7515  Error("no macro table in AST file");
7516  return nullptr;
7517  }
7518 
7519  ID -= NUM_PREDEF_MACRO_IDS;
7520  if (!MacrosLoaded[ID]) {
7522  = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS);
7523  assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
7524  ModuleFile *M = I->second;
7525  unsigned Index = ID - M->BaseMacroID;
7526  MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]);
7527 
7528  if (DeserializationListener)
7529  DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS,
7530  MacrosLoaded[ID]);
7531  }
7532 
7533  return MacrosLoaded[ID];
7534 }
7535 
7536 MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) {
7537  if (LocalID < NUM_PREDEF_MACRO_IDS)
7538  return LocalID;
7539 
7541  = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS);
7542  assert(I != M.MacroRemap.end() && "Invalid index into macro index remap");
7543 
7544  return LocalID + I->second;
7545 }
7546 
7548 ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) {
7549  if (LocalID < NUM_PREDEF_SUBMODULE_IDS)
7550  return LocalID;
7551 
7553  = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS);
7554  assert(I != M.SubmoduleRemap.end()
7555  && "Invalid index into submodule index remap");
7556 
7557  return LocalID + I->second;
7558 }
7559 
7561  if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) {
7562  assert(GlobalID == 0 && "Unhandled global submodule ID");
7563  return nullptr;
7564  }
7565 
7566  if (GlobalID > SubmodulesLoaded.size()) {
7567  Error("submodule ID out of range in AST file");
7568  return nullptr;
7569  }
7570 
7571  return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS];
7572 }
7573 
7575  return getSubmodule(ID);
7576 }
7577 
7578 ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) {
7579  if (ID & 1) {
7580  // It's a module, look it up by submodule ID.
7581  auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1));
7582  return I == GlobalSubmoduleMap.end() ? nullptr : I->second;
7583  } else {
7584  // It's a prefix (preamble, PCH, ...). Look it up by index.
7585  unsigned IndexFromEnd = ID >> 1;
7586  assert(IndexFromEnd && "got reference to unknown module file");
7587  return getModuleManager().pch_modules().end()[-IndexFromEnd];
7588  }
7589 }
7590 
7591 unsigned ASTReader::getModuleFileID(ModuleFile *F) {
7592  if (!F)
7593  return 1;
7594 
7595  // For a file representing a module, use the submodule ID of the top-level
7596  // module as the file ID. For any other kind of file, the number of such
7597  // files loaded beforehand will be the same on reload.
7598  // FIXME: Is this true even if we have an explicit module file and a PCH?
7599  if (F->isModule())
7600  return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1;
7601 
7602  auto PCHModules = getModuleManager().pch_modules();
7603  auto I = std::find(PCHModules.begin(), PCHModules.end(), F);
7604  assert(I != PCHModules.end() && "emitting reference to unknown file");
7605  return (I - PCHModules.end()) << 1;
7606 }
7607 
7610  if (const Module *M = getSubmodule(ID))
7612 
7613  // If there is only a single PCH, return it instead.
7614  // Chained PCH are not suported.
7615  if (ModuleMgr.size() == 1) {
7616  ModuleFile &MF = ModuleMgr.getPrimaryModule();
7617  StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName);
7618  StringRef FileName = llvm::sys::path::filename(MF.FileName);
7619  return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName,
7620  MF.Signature);
7621  }
7622  return None;
7623 }
7624 
7625 Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
7626  return DecodeSelector(getGlobalSelectorID(M, LocalID));
7627 }
7628 
7630  if (ID == 0)
7631  return Selector();
7632 
7633  if (ID > SelectorsLoaded.size()) {
7634  Error("selector ID out of range in AST file");
7635  return Selector();
7636  }
7637 
7638  if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) {
7639  // Load this selector from the selector table.
7640  GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
7641  assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
7642  ModuleFile &M = *I->second;
7643  ASTSelectorLookupTrait Trait(*this, M);
7644  unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS;
7645  SelectorsLoaded[ID - 1] =
7646  Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0);
7647  if (DeserializationListener)
7648  DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
7649  }
7650 
7651  return SelectorsLoaded[ID - 1];
7652 }
7653 
7655  return DecodeSelector(ID);
7656 }
7657 
7659  // ID 0 (the null selector) is considered an external selector.
7660  return getTotalNumSelectors() + 1;
7661 }
7662 
7664 ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const {
7665  if (LocalID < NUM_PREDEF_SELECTOR_IDS)
7666  return LocalID;
7667 
7670  assert(I != M.SelectorRemap.end()
7671  && "Invalid index into selector index remap");
7672 
7673  return LocalID + I->second;
7674 }
7675 
7678  const RecordData &Record, unsigned &Idx) {
7680  switch (Kind) {
7682  return DeclarationName(GetIdentifierInfo(F, Record, Idx));
7683 
7687  return DeclarationName(ReadSelector(F, Record, Idx));
7688 
7690  return Context.DeclarationNames.getCXXConstructorName(
7691  Context.getCanonicalType(readType(F, Record, Idx)));
7692 
7694  return Context.DeclarationNames.getCXXDestructorName(
7695  Context.getCanonicalType(readType(F, Record, Idx)));
7696 
7699  Context.getCanonicalType(readType(F, Record, Idx)));
7700 
7702  return Context.DeclarationNames.getCXXOperatorName(
7703  (OverloadedOperatorKind)Record[Idx++]);
7704 
7707  GetIdentifierInfo(F, Record, Idx));
7708 
7711  }
7712 
7713  llvm_unreachable("Invalid NameKind!");
7714 }
7715 
7717  DeclarationNameLoc &DNLoc,
7718  DeclarationName Name,
7719  const RecordData &Record, unsigned &Idx) {
7720  switch (Name.getNameKind()) {
7724  DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx);
7725  break;
7726 
7729  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
7731  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
7732  break;
7733 
7736  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
7737  break;
7738 
7744  break;
7745  }
7746 }
7747 
7749  DeclarationNameInfo &NameInfo,
7750  const RecordData &Record, unsigned &Idx) {
7751  NameInfo.setName(ReadDeclarationName(F, Record, Idx));
7752  NameInfo.setLoc(ReadSourceLocation(F, Record, Idx));
7753  DeclarationNameLoc DNLoc;
7754  ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx);
7755  NameInfo.setInfo(DNLoc);
7756 }
7757 
7759  const RecordData &Record, unsigned &Idx) {
7760  Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
7761  unsigned NumTPLists = Record[Idx++];
7762  Info.NumTemplParamLists = NumTPLists;
7763  if (NumTPLists) {
7764  Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists];
7765  for (unsigned i=0; i != NumTPLists; ++i)
7766  Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx);
7767  }
7768 }
7769 
7771 ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record,
7772  unsigned &Idx) {
7774  switch (Kind) {
7776  return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx));
7777 
7779  unsigned size = Record[Idx++];
7780  UnresolvedSet<8> Decls;
7781  while (size--)
7782  Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx));
7783 
7784  return Context.getOverloadedTemplateName(Decls.begin(), Decls.end());
7785  }
7786 
7788  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
7789  bool hasTemplKeyword = Record[Idx++];
7790  TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx);
7791  return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template);
7792  }
7793 
7795  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
7796  if (Record[Idx++]) // isIdentifier
7797  return Context.getDependentTemplateName(NNS,
7798  GetIdentifierInfo(F, Record,
7799  Idx));
7800  return Context.getDependentTemplateName(NNS,
7801  (OverloadedOperatorKind)Record[Idx++]);
7802  }
7803 
7806  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
7807  if (!param) return TemplateName();
7808  TemplateName replacement = ReadTemplateName(F, Record, Idx);
7809  return Context.getSubstTemplateTemplateParm(param, replacement);
7810  }
7811 
7813  TemplateTemplateParmDecl *Param
7814  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
7815  if (!Param)
7816  return TemplateName();
7817 
7818  TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx);
7819  if (ArgPack.getKind() != TemplateArgument::Pack)
7820  return TemplateName();
7821 
7822  return Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
7823  }
7824  }
7825 
7826  llvm_unreachable("Unhandled template name kind!");
7827 }
7828 
7830  const RecordData &Record,
7831  unsigned &Idx,
7832  bool Canonicalize) {
7833  if (Canonicalize) {
7834  // The caller wants a canonical template argument. Sometimes the AST only
7835  // wants template arguments in canonical form (particularly as the template
7836  // argument lists of template specializations) so ensure we preserve that
7837  // canonical form across serialization.
7838  TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false);
7839  return Context.getCanonicalTemplateArgument(Arg);
7840  }
7841 
7843  switch (Kind) {
7845  return TemplateArgument();
7847  return TemplateArgument(readType(F, Record, Idx));
7849  ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx);
7850  return TemplateArgument(D, readType(F, Record, Idx));
7851  }
7853  return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true);
7855  llvm::APSInt Value = ReadAPSInt(Record, Idx);
7856  QualType T = readType(F, Record, Idx);
7857  return TemplateArgument(Context, Value, T);
7858  }
7860  return TemplateArgument(ReadTemplateName(F, Record, Idx));
7862  TemplateName Name = ReadTemplateName(F, Record, Idx);
7863  Optional<unsigned> NumTemplateExpansions;
7864  if (unsigned NumExpansions = Record[Idx++])
7865  NumTemplateExpansions = NumExpansions - 1;
7866  return TemplateArgument(Name, NumTemplateExpansions);
7867  }
7869  return TemplateArgument(ReadExpr(F));
7870  case TemplateArgument::Pack: {
7871  unsigned NumArgs = Record[Idx++];
7872  TemplateArgument *Args = new (Context) TemplateArgument[NumArgs];
7873  for (unsigned I = 0; I != NumArgs; ++I)
7874  Args[I] = ReadTemplateArgument(F, Record, Idx);
7875  return TemplateArgument(llvm::makeArrayRef(Args, NumArgs));
7876  }
7877  }
7878 
7879  llvm_unreachable("Unhandled template argument kind!");
7880 }
7881 
7884  const RecordData &Record, unsigned &Idx) {
7885  SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx);
7886  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx);
7887  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx);
7888 
7889  unsigned NumParams = Record[Idx++];
7891  Params.reserve(NumParams);
7892  while (NumParams--)
7893  Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx));
7894 
7895  TemplateParameterList* TemplateParams =
7896  TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc,
7897  Params, RAngleLoc);
7898  return TemplateParams;
7899 }
7900 
7901 void
7904  ModuleFile &F, const RecordData &Record,
7905  unsigned &Idx, bool Canonicalize) {
7906  unsigned NumTemplateArgs = Record[Idx++];
7907  TemplArgs.reserve(NumTemplateArgs);
7908  while (NumTemplateArgs--)
7909  TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize));
7910 }
7911 
7912 /// \brief Read a UnresolvedSet structure.
7914  const RecordData &Record, unsigned &Idx) {
7915  unsigned NumDecls = Record[Idx++];
7916  Set.reserve(Context, NumDecls);
7917  while (NumDecls--) {
7918  DeclID ID = ReadDeclID(F, Record, Idx);
7919  AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
7920  Set.addLazyDecl(Context, ID, AS);
7921  }
7922 }
7923 
7926  const RecordData &Record, unsigned &Idx) {
7927  bool isVirtual = static_cast<bool>(Record[Idx++]);
7928  bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
7929  AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
7930  bool inheritConstructors = static_cast<bool>(Record[Idx++]);
7931  TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx);
7932  SourceRange Range = ReadSourceRange(F, Record, Idx);
7933  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx);
7934  CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo,
7935  EllipsisLoc);
7936  Result.setInheritConstructors(inheritConstructors);
7937  return Result;
7938 }
7939 
7941 ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
7942  unsigned &Idx) {
7943  unsigned NumInitializers = Record[Idx++];
7944  assert(NumInitializers && "wrote ctor initializers but have no inits");
7945  auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers];
7946  for (unsigned i = 0; i != NumInitializers; ++i) {
7947  TypeSourceInfo *TInfo = nullptr;
7948  bool IsBaseVirtual = false;
7949  FieldDecl *Member = nullptr;
7950  IndirectFieldDecl *IndirectMember = nullptr;
7951 
7952  CtorInitializerType Type = (CtorInitializerType)Record[Idx++];
7953  switch (Type) {
7954  case CTOR_INITIALIZER_BASE:
7955  TInfo = GetTypeSourceInfo(F, Record, Idx);
7956  IsBaseVirtual = Record[Idx++];
7957  break;
7958 
7960  TInfo = GetTypeSourceInfo(F, Record, Idx);
7961  break;
7962 
7964  Member = ReadDeclAs<FieldDecl>(F, Record, Idx);
7965  break;
7966 
7968  IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx);
7969  break;
7970  }
7971 
7972  SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx);
7973  Expr *Init = ReadExpr(F);
7974  SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx);
7975  SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx);
7976  bool IsWritten = Record[Idx++];
7977  unsigned SourceOrderOrNumArrayIndices;
7978  SmallVector<VarDecl *, 8> Indices;
7979  if (IsWritten) {
7980  SourceOrderOrNumArrayIndices = Record[Idx++];
7981  } else {
7982  SourceOrderOrNumArrayIndices = Record[Idx++];
7983  Indices.reserve(SourceOrderOrNumArrayIndices);
7984  for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
7985  Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx));
7986  }
7987 
7988  CXXCtorInitializer *BOMInit;
7989  if (Type == CTOR_INITIALIZER_BASE) {
7990  BOMInit = new (Context)
7991  CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init,
7992  RParenLoc, MemberOrEllipsisLoc);
7993  } else if (Type == CTOR_INITIALIZER_DELEGATING) {
7994  BOMInit = new (Context)
7995  CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc);
7996  } else if (IsWritten) {
7997  if (Member)
7998  BOMInit = new (Context) CXXCtorInitializer(
7999  Context, Member, MemberOrEllipsisLoc, LParenLoc, Init, RParenLoc);
8000  else
8001  BOMInit = new (Context)
8002  CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc,
8003  LParenLoc, Init, RParenLoc);
8004  } else {
8005  if (IndirectMember) {
8006  assert(Indices.empty() && "Indirect field improperly initialized");
8007  BOMInit = new (Context)
8008  CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc,
8009  LParenLoc, Init, RParenLoc);
8010  } else {
8011  BOMInit = CXXCtorInitializer::Create(
8012  Context, Member, MemberOrEllipsisLoc, LParenLoc, Init, RParenLoc,
8013  Indices.data(), Indices.size());
8014  }
8015  }
8016 
8017  if (IsWritten)
8018  BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices);
8019  CtorInitializers[i] = BOMInit;
8020  }
8021 
8022  return CtorInitializers;
8023 }
8024 
8027  const RecordData &Record, unsigned &Idx) {
8028  unsigned N = Record[Idx++];
8029  NestedNameSpecifier *NNS = nullptr, *Prev = nullptr;
8030  for (unsigned I = 0; I != N; ++I) {
8032  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
8033  switch (Kind) {
8035  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
8036  NNS = NestedNameSpecifier::Create(Context, Prev, II);
8037  break;
8038  }
8039 
8041  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
8042  NNS = NestedNameSpecifier::Create(Context, Prev, NS);
8043  break;
8044  }
8045 
8047  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
8048  NNS = NestedNameSpecifier::Create(Context, Prev, Alias);
8049  break;
8050  }
8051 
8054  const Type *T = readType(F, Record, Idx).getTypePtrOrNull();
8055  if (!T)
8056  return nullptr;
8057 
8058  bool Template = Record[Idx++];
8059  NNS = NestedNameSpecifier::Create(Context, Prev, Template, T);
8060  break;
8061  }
8062 
8064  NNS = NestedNameSpecifier::GlobalSpecifier(Context);
8065  // No associated value, and there can't be a prefix.
8066  break;
8067  }
8068 
8070  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
8071  NNS = NestedNameSpecifier::SuperSpecifier(Context, RD);
8072  break;
8073  }
8074  }
8075  Prev = NNS;
8076  }
8077  return NNS;
8078 }
8079 
8082  unsigned &Idx) {
8083  unsigned N = Record[Idx++];
8085  for (unsigned I = 0; I != N; ++I) {
8087  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
8088  switch (Kind) {
8090  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
8091  SourceRange Range = ReadSourceRange(F, Record, Idx);
8092  Builder.Extend(Context, II, Range.getBegin(), Range.getEnd());
8093  break;
8094  }
8095 
8097  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
8098  SourceRange Range = ReadSourceRange(F, Record, Idx);
8099  Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd());
8100  break;
8101  }
8102 
8104  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
8105  SourceRange Range = ReadSourceRange(F, Record, Idx);
8106  Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd());
8107  break;
8108  }
8109 
8112  bool Template = Record[Idx++];
8113  TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx);
8114  if (!T)
8115  return NestedNameSpecifierLoc();
8116  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
8117 
8118  // FIXME: 'template' keyword location not saved anywhere, so we fake it.
8119  Builder.Extend(Context,
8120  Template? T->getTypeLoc().getBeginLoc() : SourceLocation(),
8121  T->getTypeLoc(), ColonColonLoc);
8122  break;
8123  }
8124 
8126  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
8127  Builder.MakeGlobal(Context, ColonColonLoc);
8128  break;
8129  }
8130 
8132  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
8133  SourceRange Range = ReadSourceRange(F, Record, Idx);
8134  Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd());
8135  break;
8136  }
8137  }
8138  }
8139 
8140  return Builder.getWithLocInContext(Context);
8141 }
8142 
8144 ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record,
8145  unsigned &Idx) {
8146  SourceLocation beg = ReadSourceLocation(F, Record, Idx);
8147  SourceLocation end = ReadSourceLocation(F, Record, Idx);
8148  return SourceRange(beg, end);
8149 }
8150 
8151 /// \brief Read an integral value
8152 llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) {
8153  unsigned BitWidth = Record[Idx++];
8154  unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
8155  llvm::APInt Result(BitWidth, NumWords, &Record[Idx]);
8156  Idx += NumWords;
8157  return Result;
8158 }
8159 
8160 /// \brief Read a signed integral value
8161 llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) {
8162  bool isUnsigned = Record[Idx++];
8163  return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned);
8164 }
8165 
8166 /// \brief Read a floating-point value
8167 llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record,
8168  const llvm::fltSemantics &Sem,
8169  unsigned &Idx) {
8170  return llvm::APFloat(Sem, ReadAPInt(Record, Idx));
8171 }
8172 
8173 // \brief Read a string
8174 std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) {
8175  unsigned Len = Record[Idx++];
8176  std::string Result(Record.data() + Idx, Record.data() + Idx + Len);
8177  Idx += Len;
8178  return Result;
8179 }
8180 
8181 std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record,
8182  unsigned &Idx) {
8183  std::string Filename = ReadString(Record, Idx);
8184  ResolveImportedPath(F, Filename);
8185  return Filename;
8186 }
8187 
8189  unsigned &Idx) {
8190  unsigned Major = Record[Idx++];
8191  unsigned Minor = Record[Idx++];
8192  unsigned Subminor = Record[Idx++];
8193  if (Minor == 0)
8194  return VersionTuple(Major);
8195  if (Subminor == 0)
8196  return VersionTuple(Major, Minor - 1);
8197  return VersionTuple(Major, Minor - 1, Subminor - 1);
8198 }
8199 
8201  const RecordData &Record,
8202  unsigned &Idx) {
8203  CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx);
8204  return CXXTemporary::Create(Context, Decl);
8205 }
8206 
8208  return Diag(CurrentImportLoc, DiagID);
8209 }
8210 
8212  return Diags.Report(Loc, DiagID);
8213 }
8214 
8215 /// \brief Retrieve the identifier table associated with the
8216 /// preprocessor.
8218  return PP.getIdentifierTable();
8219 }
8220 
8221 /// \brief Record that the given ID maps to the given switch-case
8222 /// statement.
8224  assert((*CurrSwitchCaseStmts)[ID] == nullptr &&
8225  "Already have a SwitchCase with this ID");
8226  (*CurrSwitchCaseStmts)[ID] = SC;
8227 }
8228 
8229 /// \brief Retrieve the switch-case statement with the given ID.
8231  assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID");
8232  return (*CurrSwitchCaseStmts)[ID];
8233 }
8234 
8236  CurrSwitchCaseStmts->clear();
8237 }
8238 
8240  std::vector<RawComment *> Comments;
8241  for (SmallVectorImpl<std::pair<BitstreamCursor,
8243  I = CommentsCursors.begin(),
8244  E = CommentsCursors.end();
8245  I != E; ++I) {
8246  Comments.clear();
8247  BitstreamCursor &Cursor = I->first;
8248  serialization::ModuleFile &F = *I->second;
8249  SavedStreamPosition SavedPosition(Cursor);
8250 
8251  RecordData Record;
8252  while (true) {
8253  llvm::BitstreamEntry Entry =
8254  Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd);
8255 
8256  switch (Entry.Kind) {
8257  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
8259  Error("malformed block record in AST file");
8260  return;
8261  case llvm::BitstreamEntry::EndBlock:
8262  goto NextCursor;
8263  case llvm::BitstreamEntry::Record:
8264  // The interesting case.
8265  break;
8266  }
8267 
8268  // Read a record.
8269  Record.clear();
8270  switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
8271  case COMMENTS_RAW_COMMENT: {
8272  unsigned Idx = 0;
8273  SourceRange SR = ReadSourceRange(F, Record, Idx);
8275  (RawComment::CommentKind) Record[Idx++];
8276  bool IsTrailingComment = Record[Idx++];
8277  bool IsAlmostTrailingComment = Record[Idx++];
8278  Comments.push_back(new (Context) RawComment(
8279  SR, Kind, IsTrailingComment, IsAlmostTrailingComment,
8281  break;
8282  }
8283  }
8284  }
8285  NextCursor:
8286  Context.Comments.addDeserializedComments(Comments);
8287  }
8288 }
8289 
8291  // If we know the owning module, use it.
8292  if (Module *M = D->getImportedOwningModule())
8293  return M->getFullModuleName();
8294 
8295  // Otherwise, use the name of the top-level module the decl is within.
8296  if (ModuleFile *M = getOwningModuleFile(D))
8297  return M->ModuleName;
8298 
8299  // Not from a module.
8300  return "";
8301 }
8302 
8303 void ASTReader::finishPendingActions() {
8304  while (!PendingIdentifierInfos.empty() ||
8305  !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() ||
8306  !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
8307  !PendingUpdateRecords.empty()) {
8308  // If any identifiers with corresponding top-level declarations have
8309  // been loaded, load those declarations now.
8310  typedef llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2> >
8311  TopLevelDeclsMap;
8312  TopLevelDeclsMap TopLevelDecls;
8313 
8314  while (!PendingIdentifierInfos.empty()) {
8315  IdentifierInfo *II = PendingIdentifierInfos.back().first;
8316  SmallVector<uint32_t, 4> DeclIDs =
8317  std::move(PendingIdentifierInfos.back().second);
8318  PendingIdentifierInfos.pop_back();
8319 
8320  SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]);
8321  }
8322 
8323  // For each decl chain that we wanted to complete while deserializing, mark
8324  // it as "still needs to be completed".
8325  for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
8326  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
8327  }
8328  PendingIncompleteDeclChains.clear();
8329 
8330  // Load pending declaration chains.
8331  for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
8332  loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second);
8333  PendingDeclChains.clear();
8334 
8335  // Make the most recent of the top-level declarations visible.
8336  for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(),
8337  TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) {
8338  IdentifierInfo *II = TLD->first;
8339  for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) {
8340  pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II);
8341  }
8342  }
8343 
8344  // Load any pending macro definitions.
8345  for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
8346  IdentifierInfo *II = PendingMacroIDs.begin()[I].first;
8348  GlobalIDs.swap(PendingMacroIDs.begin()[I].second);
8349  // Initialize the macro history from chained-PCHs ahead of module imports.
8350  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
8351  ++IDIdx) {
8352  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
8353  if (Info.M->Kind != MK_ImplicitModule &&
8354  Info.M->Kind != MK_ExplicitModule)
8355  resolvePendingMacro(II, Info);
8356  }
8357  // Handle module imports.
8358  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
8359  ++IDIdx) {
8360  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
8361  if (Info.M->Kind == MK_ImplicitModule ||
8362  Info.M->Kind == MK_ExplicitModule)
8363  resolvePendingMacro(II, Info);
8364  }
8365  }
8366  PendingMacroIDs.clear();
8367 
8368  // Wire up the DeclContexts for Decls that we delayed setting until
8369  // recursive loading is completed.
8370  while (!PendingDeclContextInfos.empty()) {
8371  PendingDeclContextInfo Info = PendingDeclContextInfos.front();
8372  PendingDeclContextInfos.pop_front();
8373  DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC));
8374  DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC));
8375  Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext());
8376  }
8377 
8378  // Perform any pending declaration updates.
8379  while (!PendingUpdateRecords.empty()) {
8380  auto Update = PendingUpdateRecords.pop_back_val();
8381  ReadingKindTracker ReadingKind(Read_Decl, *this);
8382  loadDeclUpdateRecords(Update.first, Update.second);
8383  }
8384  }
8385 
8386  // At this point, all update records for loaded decls are in place, so any
8387  // fake class definitions should have become real.
8388  assert(PendingFakeDefinitionData.empty() &&
8389  "faked up a class definition but never saw the real one");
8390 
8391  // If we deserialized any C++ or Objective-C class definitions, any
8392  // Objective-C protocol definitions, or any redeclarable templates, make sure
8393  // that all redeclarations point to the definitions. Note that this can only
8394  // happen now, after the redeclaration chains have been fully wired.
8395  for (Decl *D : PendingDefinitions) {
8396  if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
8397  if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) {
8398  // Make sure that the TagType points at the definition.
8399  const_cast<TagType*>(TagT)->decl = TD;
8400  }
8401 
8402  if (auto RD = dyn_cast<CXXRecordDecl>(D)) {
8403  for (auto *R = getMostRecentExistingDecl(RD); R;
8404  R = R->getPreviousDecl()) {
8405  assert((R == D) ==
8406  cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() &&
8407  "declaration thinks it's the definition but it isn't");
8408  cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData;
8409  }
8410  }
8411 
8412  continue;
8413  }
8414 
8415  if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) {
8416  // Make sure that the ObjCInterfaceType points at the definition.
8417  const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl))
8418  ->Decl = ID;
8419 
8420  for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl())
8421  cast<ObjCInterfaceDecl>(R)->Data = ID->Data;
8422 
8423  continue;
8424  }
8425 
8426  if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) {
8427  for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl())
8428  cast<ObjCProtocolDecl>(R)->Data = PD->Data;
8429 
8430  continue;
8431  }
8432 
8433  auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl();
8434  for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl())
8435  cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common;
8436  }
8437  PendingDefinitions.clear();
8438 
8439  // Load the bodies of any functions or methods we've encountered. We do
8440  // this now (delayed) so that we can be sure that the declaration chains
8441  // have been fully wired up (hasBody relies on this).
8442  // FIXME: We shouldn't require complete redeclaration chains here.
8443  for (PendingBodiesMap::iterator PB = PendingBodies.begin(),
8444  PBEnd = PendingBodies.end();
8445  PB != PBEnd; ++PB) {
8446  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) {
8447  // FIXME: Check for =delete/=default?
8448  // FIXME: Complain about ODR violations here?
8449  if (!getContext().getLangOpts().Modules || !FD->hasBody())
8450  FD->setLazyBody(PB->second);
8451  continue;
8452  }
8453 
8454  ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first);
8455  if (!getContext().getLangOpts().Modules || !MD->hasBody())
8456  MD->setLazyBody(PB->second);
8457  }
8458  PendingBodies.clear();
8459 
8460  // Do some cleanup.
8461  for (auto *ND : PendingMergedDefinitionsToDeduplicate)
8463  PendingMergedDefinitionsToDeduplicate.clear();
8464 }
8465 
8466 void ASTReader::diagnoseOdrViolations() {
8467  if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty())
8468  return;
8469 
8470  // Trigger the import of the full definition of each class that had any
8471  // odr-merging problems, so we can produce better diagnostics for them.
8472  // These updates may in turn find and diagnose some ODR failures, so take
8473  // ownership of the set first.
8474  auto OdrMergeFailures = std::move(PendingOdrMergeFailures);
8475  PendingOdrMergeFailures.clear();
8476  for (auto &Merge : OdrMergeFailures) {
8477  Merge.first->buildLookup();
8478  Merge.first->decls_begin();
8479  Merge.first->bases_begin();
8480  Merge.first->vbases_begin();
8481  for (auto *RD : Merge.second) {
8482  RD->decls_begin();
8483  RD->bases_begin();
8484  RD->vbases_begin();
8485  }
8486  }
8487 
8488  // For each declaration from a merged context, check that the canonical
8489  // definition of that context also contains a declaration of the same
8490  // entity.
8491  //
8492  // Caution: this loop does things that might invalidate iterators into
8493  // PendingOdrMergeChecks. Don't turn this into a range-based for loop!
8494  while (!PendingOdrMergeChecks.empty()) {
8495  NamedDecl *D = PendingOdrMergeChecks.pop_back_val();
8496 
8497  // FIXME: Skip over implicit declarations for now. This matters for things
8498  // like implicitly-declared special member functions. This isn't entirely
8499  // correct; we can end up with multiple unmerged declarations of the same
8500  // implicit entity.
8501  if (D->isImplicit())
8502  continue;
8503 
8504  DeclContext *CanonDef = D->getDeclContext();
8505 
8506  bool Found = false;
8507  const Decl *DCanon = D->getCanonicalDecl();
8508 
8509  for (auto RI : D->redecls()) {
8510  if (RI->getLexicalDeclContext() == CanonDef) {
8511  Found = true;
8512  break;
8513  }
8514  }
8515  if (Found)
8516  continue;
8517 
8518  // Quick check failed, time to do the slow thing. Note, we can't just
8519  // look up the name of D in CanonDef here, because the member that is
8520  // in CanonDef might not be found by name lookup (it might have been
8521  // replaced by a more recent declaration in the lookup table), and we
8522  // can't necessarily find it in the redeclaration chain because it might
8523  // be merely mergeable, not redeclarable.
8525  for (auto *CanonMember : CanonDef->decls()) {
8526  if (CanonMember->getCanonicalDecl() == DCanon) {
8527  // This can happen if the declaration is merely mergeable and not
8528  // actually redeclarable (we looked for redeclarations earlier).
8529  //
8530  // FIXME: We should be able to detect this more efficiently, without
8531  // pulling in all of the members of CanonDef.
8532  Found = true;
8533  break;
8534  }
8535  if (auto *ND = dyn_cast<NamedDecl>(CanonMember))
8536  if (ND->getDeclName() == D->getDeclName())
8537  Candidates.push_back(ND);
8538  }
8539 
8540  if (!Found) {
8541  // The AST doesn't like TagDecls becoming invalid after they've been
8542  // completed. We only really need to mark FieldDecls as invalid here.
8543  if (!isa<TagDecl>(D))
8544  D->setInvalidDecl();
8545 
8546  // Ensure we don't accidentally recursively enter deserialization while
8547  // we're producing our diagnostic.
8548  Deserializing RecursionGuard(this);
8549 
8550  std::string CanonDefModule =
8551  getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef));
8552  Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl)
8554  << CanonDef << CanonDefModule.empty() << CanonDefModule;
8555 
8556  if (Candidates.empty())
8557  Diag(cast<Decl>(CanonDef)->getLocation(),
8558  diag::note_module_odr_violation_no_possible_decls) << D;
8559  else {
8560  for (unsigned I = 0, N = Candidates.size(); I != N; ++I)
8561  Diag(Candidates[I]->getLocation(),
8562  diag::note_module_odr_violation_possible_decl)
8563  << Candidates[I];
8564  }
8565 
8566  DiagnosedOdrMergeFailures.insert(CanonDef);
8567  }
8568  }
8569 
8570  if (OdrMergeFailures.empty())
8571  return;
8572 
8573  // Ensure we don't accidentally recursively enter deserialization while
8574  // we're producing our diagnostics.
8575  Deserializing RecursionGuard(this);
8576 
8577  // Issue any pending ODR-failure diagnostics.
8578  for (auto &Merge : OdrMergeFailures) {
8579  // If we've already pointed out a specific problem with this class, don't
8580  // bother issuing a general "something's different" diagnostic.
8581  if (!DiagnosedOdrMergeFailures.insert(Merge.first).second)
8582  continue;
8583 
8584  bool Diagnosed = false;
8585  for (auto *RD : Merge.second) {
8586  // Multiple different declarations got merged together; tell the user
8587  // where they came from.
8588  if (Merge.first != RD) {
8589  // FIXME: Walk the definition, figure out what's different,
8590  // and diagnose that.
8591  if (!Diagnosed) {
8592  std::string Module = getOwningModuleNameForDiagnostic(Merge.first);
8593  Diag(Merge.first->getLocation(),
8594  diag::err_module_odr_violation_different_definitions)
8595  << Merge.first << Module.empty() << Module;
8596  Diagnosed = true;
8597  }
8598 
8599  Diag(RD->getLocation(),
8600  diag::note_module_odr_violation_different_definitions)
8602  }
8603  }
8604 
8605  if (!Diagnosed) {
8606  // All definitions are updates to the same declaration. This happens if a
8607  // module instantiates the declaration of a class template specialization
8608  // and two or more other modules instantiate its definition.
8609  //
8610  // FIXME: Indicate which modules had instantiations of this definition.
8611  // FIXME: How can this even happen?
8612  Diag(Merge.first->getLocation(),
8613  diag::err_module_odr_violation_different_instantiations)
8614  << Merge.first;
8615  }
8616  }
8617 }
8618 
8620  if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get())
8621  ReadTimer->startTimer();
8622 }
8623 
8625  assert(NumCurrentElementsDeserializing &&
8626  "FinishedDeserializing not paired with StartedDeserializing");
8627  if (NumCurrentElementsDeserializing == 1) {
8628  // We decrease NumCurrentElementsDeserializing only after pending actions
8629  // are finished, to avoid recursively re-calling finishPendingActions().
8630  finishPendingActions();
8631  }
8632  --NumCurrentElementsDeserializing;
8633 
8634  if (NumCurrentElementsDeserializing == 0) {
8635  // Propagate exception specification updates along redeclaration chains.
8636  while (!PendingExceptionSpecUpdates.empty()) {
8637  auto Updates = std::move(PendingExceptionSpecUpdates);
8638  PendingExceptionSpecUpdates.clear();
8639  for (auto Update : Updates) {
8640  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
8641  auto *FPT = Update.second->getType()->castAs<FunctionProtoType>();
8642  auto ESI = FPT->getExtProtoInfo().ExceptionSpec;
8643  if (auto *Listener = Context.getASTMutationListener())
8644  Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second));
8645  for (auto *Redecl : Update.second->redecls())
8646  Context.adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
8647  }
8648  }
8649 
8650  if (ReadTimer)
8651  ReadTimer->stopTimer();
8652 
8653  diagnoseOdrViolations();
8654 
8655  // We are not in recursive loading, so it's safe to pass the "interesting"
8656  // decls to the consumer.
8657  if (Consumer)
8658  PassInterestingDeclsToConsumer();
8659  }
8660 }
8661 
8662 void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) {
8663  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
8664  // Remove any fake results before adding any real ones.
8665  auto It = PendingFakeLookupResults.find(II);
8666  if (It != PendingFakeLookupResults.end()) {
8667  for (auto *ND : It->second)
8668  SemaObj->IdResolver.RemoveDecl(ND);
8669  // FIXME: this works around module+PCH performance issue.
8670  // Rather than erase the result from the map, which is O(n), just clear
8671  // the vector of NamedDecls.
8672  It->second.clear();
8673  }
8674  }
8675 
8676  if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) {
8677  SemaObj->TUScope->AddDecl(D);
8678  } else if (SemaObj->TUScope) {
8679  // Adding the decl to IdResolver may have failed because it was already in
8680  // (even though it was not added in scope). If it is already in, make sure
8681  // it gets in the scope as well.
8682  if (std::find(SemaObj->IdResolver.begin(Name),
8683  SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end())
8684  SemaObj->TUScope->AddDecl(D);
8685  }
8686 }
8687 
8688 ASTReader::ASTReader(
8690  const PCHContainerReader &PCHContainerRdr,
8692  StringRef isysroot, bool DisableValidation,
8693  bool AllowASTWithCompilerErrors,
8694  bool AllowConfigurationMismatch, bool ValidateSystemInputs,
8695  bool UseGlobalIndex,
8696  std::unique_ptr<llvm::Timer> ReadTimer)
8697  : Listener(new PCHValidator(PP, *this)), DeserializationListener(nullptr),
8698  OwnsDeserializationListener(false), SourceMgr(PP.getSourceManager()),
8699  FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr),
8700  Diags(PP.getDiagnostics()), SemaObj(nullptr), PP(PP), Context(Context),
8701  Consumer(nullptr), ModuleMgr(PP.getFileManager(), PCHContainerRdr),
8702  DummyIdResolver(PP),
8703  ReadTimer(std::move(ReadTimer)),
8704  PragmaMSStructState(-1),
8705  PragmaMSPointersToMembersState(-1),
8706  isysroot(isysroot), DisableValidation(DisableValidation),
8707  AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
8708  AllowConfigurationMismatch(AllowConfigurationMismatch),
8709  ValidateSystemInputs(ValidateSystemInputs),
8710  UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false),
8711  ProcessingUpdateRecords(false),
8712  CurrSwitchCaseStmts(&SwitchCaseStmts), NumSLocEntriesRead(0),
8713  TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0),
8714  NumMacrosRead(0), TotalNumMacros(0), NumIdentifierLookups(0),
8715  NumIdentifierLookupHits(0), NumSelectorsRead(0),
8716  NumMethodPoolEntriesRead(0), NumMethodPoolLookups(0),
8717  NumMethodPoolHits(0), NumMethodPoolTableLookups(0),
8718  NumMethodPoolTableHits(0), TotalNumMethodPoolEntries(0),
8719  NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0),
8720  NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0),
8721  TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0),
8722  PassingDeclsToConsumer(false), ReadingKind(Read_None) {
8723  SourceMgr.setExternalSLocEntrySource(this);
8724 
8725  for (const auto &Ext : Extensions) {
8726  auto BlockName = Ext->getExtensionMetadata().BlockName;
8727  auto Known = ModuleFileExtensions.find(BlockName);
8728  if (Known != ModuleFileExtensions.end()) {
8729  Diags.Report(diag::warn_duplicate_module_file_extension)
8730  << BlockName;
8731  continue;
8732  }
8733 
8734  ModuleFileExtensions.insert({BlockName, Ext});
8735  }
8736 }
8737 
8739  if (OwnsDeserializationListener)
8740  delete DeserializationListener;
8741 }
8742 
8744  return SemaObj ? SemaObj->IdResolver : DummyIdResolver;
8745 }
llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx)
Read an integral value.
Definition: ASTReader.cpp:8152
Decl * GetExistingDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration.
Definition: ASTReader.cpp:6432
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Basic/Module.h:160
TypedefDecl * getObjCInstanceTypeDecl()
Retrieve the typedef declaration corresponding to the Objective-C "instancetype" type.
bool isPoisoned() const
Return true if this token has been poisoned.
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType) const
SmallVector< std::pair< llvm::BitstreamCursor, serialization::ModuleFile * >, 8 > CommentsCursors
Cursors for comments blocks.
Definition: ASTReader.h:2149
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
Definition: ASTReader.cpp:7217
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Finds all the visible declarations with a given name.
Definition: ASTReader.cpp:6640
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons...
Definition: ASTReader.h:326
Record code for the preprocessor options table.
Definition: ASTBitCodes.h:322
static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags, FileManager &FileMgr, std::string &SuggestedPredefines, const LangOptions &LangOpts)
Check the preprocessor options deserialized from the control block against the preprocessor options i...
Definition: ASTReader.cpp:499
std::vector< unsigned > PreloadIdentifierOffsets
Offsets of identifiers that we're going to preload within IdentifierTableData.
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Basic/Module.h:248
CanQualType LongLongTy
Definition: ASTContext.h:901
static const Decl * getCanonicalDecl(const Decl *D)
The client can handle an AST file that cannot load because it was built with a different version of C...
Definition: ASTReader.h:1369
void setInfo(const DeclarationNameLoc &Info)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
std::string Name
The name of this module.
Definition: Basic/Module.h:50
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:166
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Basic/Module.h:401
std::vector< std::pair< std::string, bool > > Macros
IdentifierIterator * getIdentifiers() override
Retrieve an iterator into the set of all identifiers in all loaded AST files.
Definition: ASTReader.cpp:7087
Record code for the signature that identifiers this AST file.
Definition: ASTBitCodes.h:292
void * IdentifierLookupTable
A pointer to an on-disk hash table of opaque type IdentifierHashTable.
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
Definition: ASTContext.h:1508
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
Definition: ASTReader.cpp:115
CanQualType OCLQueueTy
Definition: ASTContext.h:918
Record code for potentially unused local typedef names.
Definition: ASTBitCodes.h:572
Record code for map of Objective-C class definition IDs to the ObjC categories in a module that are a...
Definition: ASTBitCodes.h:530
Smart pointer class that efficiently represents Objective-C method names.
static void updateModuleTimestamp(ModuleFile &MF)
Definition: ASTReader.cpp:3434
static hash_value_type ComputeHash(Selector Sel)
Definition: ASTReader.cpp:667
unsigned Length
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system...
Definition: Basic/Module.h:138
static bool checkTargetOptions(const TargetOptions &TargetOpts, const TargetOptions &ExistingTargetOpts, DiagnosticsEngine *Diags, bool AllowCompatibleDifferences=true)
Compare the given set of target options against an existing set of target options.
Definition: ASTReader.cpp:259
A (possibly-)qualified type.
Definition: Type.h:598
A PointerType record.
Definition: ASTBitCodes.h:824
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
Definition: ASTReader.h:174
CtorInitializerType
The different kinds of data that can occur in a CtorInitializer.
Definition: ASTBitCodes.h:1509
TypedefDecl * getUInt128Decl() const
Retrieve the declaration for the 128-bit unsigned integer type.
Definition: ASTContext.cpp:970
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
Definition: MacroInfo.h:245
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1206
NameKind
NameKind - The kind of name this object contains.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
The macro directives history for a particular identifier.
Definition: ASTBitCodes.h:626
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
static bool startsWithASTFileMagic(BitstreamCursor &Stream)
Whether Stream starts with the AST/PCH file magic number 'CPCH'.
Definition: ASTReader.cpp:3699
void SetIdentifierInfo(unsigned ID, IdentifierInfo *II)
Definition: ASTReader.cpp:7402
virtual bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule)
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
Definition: ASTReader.h:200
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:117
The (signed) 'long long' type.
Definition: ASTBitCodes.h:740
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:36
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
Definition: ASTReader.h:185
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
QualType getAdjustedType(QualType Orig, QualType New) const
Return the uniqued reference to a type adjusted from the original type to a new type.
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Defines the clang::FileManager interface and associated types.
CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers...
Definition: ASTReader.cpp:6304
Record code for the source manager line table information, which stores information about #line direc...
Definition: ASTBitCodes.h:526
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
bool tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name)
Try to add the given declaration to the top level scope, if it (or a redeclaration of it) hasn't alre...
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
This header is part of the module (for layering purposes) but should be textually included...
Definition: ModuleMap.h:104
DeclarationName getCXXConstructorName(CanQualType Ty)
getCXXConstructorName - Returns the name of a C++ constructor for the given Type. ...
The 'bool' or '_Bool' type.
Definition: ASTBitCodes.h:714
std::string ModuleUserBuildPath
The directory used for a user build.
CanQualType Char32Ty
Definition: ASTContext.h:900
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1693
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:2048
unsigned getHash() const
Compute a fingerprint of this key for use in on-disk hash table.
Definition: ASTReader.cpp:897
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1284
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:810
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1246
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1140
Optional< bool > isPreprocessedEntityInFileID(unsigned Index, FileID FID) override
Optionally returns true or false if the preallocated preprocessed entity with index Index came from f...
Definition: ASTReader.cpp:5078
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1458
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1453
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
SourceLocation DirectImportLoc
The source location where the module was explicitly or implicitly imported in the local translation u...
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "...
Definition: Basic/Module.h:178
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
ControlRecordTypes
Record types that occur within the control block.
Definition: ASTBitCodes.h:259
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition: Basic/Module.h:420
unsigned Generation
The generation of which this module file is a part.
void ReadComments() override
Loads comments ranges.
Definition: ASTReader.cpp:8239
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Basic/Module.h:292
C Language Family Type Representation.
Defines the SourceManager interface.
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:123
The 'unknown any' placeholder type.
Definition: ASTBitCodes.h:768
void setWrittenWidthSpec(TypeSpecifierWidth written)
Definition: TypeLoc.h:581
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
Definition: ASTContext.h:1532
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
Definition: ASTReader.cpp:95
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
RawCommentList Comments
All comments in this translation unit.
Definition: ASTContext.h:617
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
getCXXConversionFunctionName - Returns the name of a C++ conversion function for the given Type...
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
Definition: ASTReader.cpp:7560
unsigned size() const
Number of modules loaded.
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:145
SmallVector< uint64_t, 4 > PreloadSLocEntries
SLocEntries that we're going to preload.
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
virtual void MacroRead(serialization::MacroID ID, MacroInfo *MI)
A macro was read from the AST file.
CanQualType ObjCBuiltinSelTy
Definition: ASTContext.h:912
RetTy Visit(TypeLoc TyLoc)
ModuleManager::ModuleConstIterator ModuleConstIterator
Definition: ASTReader.h:362
void VisitFunctionTypeLoc(FunctionTypeLoc)
Definition: ASTReader.cpp:5805
ModuleKind Kind
The type of this module.
virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value)
Receives COUNTER value.
Definition: ASTReader.h:181
Defines the C++ template declaration subclasses.
Describes a source location entry (SLocEntry) for a macro expansion.
Definition: ASTBitCodes.h:604
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition: Sema.h:713
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
Definition: ASTReader.h:1498
std::vector< std::string > Includes
An LValueReferenceType record.
Definition: ASTBitCodes.h:828
The placeholder type for builtin functions.
Definition: ASTBitCodes.h:782
void AddDecl(Decl *D)
Definition: Scope.h:275
static void completeRedeclChainForTemplateSpecialization(Decl *D)
Definition: ASTReader.cpp:6227
Defines the clang::MacroInfo and clang::MacroDirective classes.
Specifies the submodules that are imported by this submodule.
Definition: ASTBitCodes.h:664
std::string ModuleName
The name of the module.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
CanQualType ARCUnbridgedCastTy
Definition: ASTContext.h:911
A record that stores the set of declarations that are lexically stored within a given DeclContext...
Definition: ASTBitCodes.h:1070
The module file is out-of-date.
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
Specifies an umbrella directory.
Definition: ASTBitCodes.h:661
The base class of the type hierarchy.
Definition: Type.h:1281
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:63
IdentifierInfo * getLocalIdentifier(ModuleFile &M, unsigned LocalID)
Definition: ASTReader.cpp:7494
CanQualType LongTy
Definition: ASTContext.h:901
unsigned LocalNumObjCCategoriesInMap
The number of redeclaration info entries in ObjCCategoriesMap.
void setHasLineDirectives()
Set the flag that indicates that this FileID has line table entries associated with it...
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
Definition: ASTReader.h:1502
#define CHECK_TARGET_OPT(Field, Name)
A SubstTemplateTypeParmType record.
Definition: ASTBitCodes.h:866
QualType getRecordType(const RecordDecl *Decl) const
std::unique_ptr< llvm::MemoryBuffer > Buffer
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:6456
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1124
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1874
void setFlag(TokenFlags Flag)
Set the specified flag.
Definition: Token.h:233
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:471
Wrapper for source info for typedefs.
Definition: TypeLoc.h:620
static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II)
Definition: ASTReader.cpp:777
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:93
A container of type source information.
Definition: Decl.h:62
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
uint64_t GlobalBitOffset
The global bit offset (or base) of this module.
Record code for enabled OpenCL extensions.
Definition: ASTBitCodes.h:509
Record code for the module build directory.
Definition: ASTBitCodes.h:295
void * getAsOpaquePtr() const
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind NameVisibility, SourceLocation ImportLoc)
Make the entities in the given module and any of its (non-explicit) submodules visible to name lookup...
Definition: ASTReader.cpp:3361
An ElaboratedType record.
Definition: ASTBitCodes.h:864
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:305
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
virtual void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II)
An identifier was deserialized from the AST file.
An UnresolvedUsingType record.
Definition: ASTBitCodes.h:868
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
Wrapper for source info for pointers decayed from arrays and functions.
Definition: TypeLoc.h:1095
bool hasAttrEnumOperand() const
Definition: TypeLoc.h:738
ASTFileSignature Signature
The signature of the module file, which may be used along with size and modification time to identify...
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2187
TypeLoc getNextTypeLoc() const
Definition: TypeLoc.h:375
An IncompleteArrayType record.
Definition: ASTBitCodes.h:836
QualType getPipeType(QualType T) const
Return pipe type for the specified type.
The internal '__type_pack_element' template.
Definition: ASTBitCodes.h:988
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:201
void addPendingMacro(IdentifierInfo *II, ModuleFile *M, uint64_t MacroDirectivesOffset)
Add a macro to deserialize its macro directive history.
Definition: ASTReader.cpp:1643
Specifies a header that is part of the module but must be textually included.
Definition: ASTBitCodes.h:683
const uint32_t * SLocEntryOffsets
Offsets for all of the source location entries in the AST file.
bool RelocatablePCH
Whether this precompiled header is a relocatable PCH file.
CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a C++ base specifier.
Definition: ASTReader.cpp:7925
ARC's unbridged-cast placeholder type.
Definition: ASTBitCodes.h:778
CanQualType HalfTy
Definition: ASTContext.h:905
The client can handle an AST file that cannot load because it is out-of-date relative to its input fi...
Definition: ASTReader.h:1366
The AST file has errors.
Definition: ASTReader.h:343
void visit(llvm::function_ref< bool(ModuleFile &M)> Visitor, llvm::SmallPtrSetImpl< ModuleFile * > *ModuleFilesHit=nullptr)
Visit each of the modules.
ArrayRef< ObjCMethodDecl * > getInstanceMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:7154
bool getWarningsAsErrors() const
Definition: Diagnostic.h:453
uint32_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:55
An identifier, stored as an IdentifierInfo*.
The internal '__builtin_va_list' typedef.
Definition: ASTBitCodes.h:967
void addRequirement(StringRef Feature, bool RequiredState, const LangOptions &LangOpts, const TargetInfo &Target)
Add the given feature requirement to the list of features required by this module.
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:32
static Qualifiers fromOpaqueValue(unsigned opaque)
Definition: Type.h:225
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
Definition: ASTReader.cpp:7312
TypedefDecl * getBuiltinVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_va_list type...
std::string ImplicitPTHInclude
The implicit PTH input included at the start of the translation unit, or empty.
const FileEntry * getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Basic/Module.h:384
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Read the contents of a CXXCtorInitializer array.
Definition: ASTReader.cpp:6285
Wrapper for source info for member pointers.
Definition: TypeLoc.h:1163
void VisitArrayTypeLoc(ArrayTypeLoc)
Definition: ASTReader.cpp:5774
Options for controlling the target.
Definition: TargetOptions.h:25
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:247
serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const
Map a local type ID within a given AST file into a global type ID.
Definition: ASTReader.cpp:6145
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing)...
Definition: DiagnosticIDs.h:62
bool hasAttrExprOperand() const
Definition: TypeLoc.h:733
void CompleteRedeclChain(const Decl *D) override
If any redeclarations of D have been imported since it was last checked, this digs out those redeclar...
Definition: ASTReader.cpp:6232
CanQualType Float128Ty
Definition: ASTContext.h:904
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
Extra information about a function prototype.
Definition: Type.h:3167
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Definition: ASTReader.cpp:6906
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:995
The value of the next COUNTER to dispense.
Definition: ASTBitCodes.h:433
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
unsigned getLineTableFilenameID(StringRef Str)
Specifies the umbrella header used to create this module, if any.
Definition: ASTBitCodes.h:655
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:572
A namespace, stored as a NamespaceDecl*.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:78
Record code for header search information.
Definition: ASTBitCodes.h:503
data_type ReadData(Selector, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:702
BlockCommandNamesTy BlockCommandNames
Command names to treat as block commands in comments.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:49
void setBegin(SourceLocation b)
std::string ModuleCachePath
The directory used for the module cache.
Describes a source location entry (SLocEntry) for a buffer.
Definition: ASTBitCodes.h:593
Used to hold and unique data used to represent #line information.
Record code for the target options table.
Definition: ASTBitCodes.h:310
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:69
bool hasAttrOperand() const
Definition: TypeLoc.h:743
off_t getSize() const
Definition: FileManager.h:88
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
Definition: ASTReader.cpp:651
Record code for the array of eagerly deserialized decls.
Definition: ASTBitCodes.h:404
iterator begin() const
Definition: Type.h:4235
Defines the clang::Expr interface and subclasses for C++ expressions.
unsigned isImport
True if this is a #import'd or #pragma once file.
Definition: HeaderSearch.h:41
Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:1942
int SLocEntryBaseID
The base ID in the source manager's view of this module.
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
ContinuousRangeMap< uint32_t, int, 2 > DeclRemap
Remapping table for declaration IDs in this module.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1739
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
The collection of all-type qualifiers we support.
Definition: Type.h:117
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
Definition: TypeLoc.h:891
SourceLocation ImportLoc
The source location where this module was first imported.
Record code for the diagnostic options table.
Definition: ASTBitCodes.h:313
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &TentativeDefs) override
Read the set of tentative definitions known to the external Sema source.
Definition: ASTReader.cpp:7258
An UnresolvedSet-like class that might not have been loaded from the external AST source yet...
iterator begin(DeclarationName Name)
begin - Returns an iterator for decls with the name 'Name'.
The client can handle an AST file that cannot load because it is missing.
Definition: ASTReader.h:1363
CanQualType OCLSamplerTy
Definition: ASTContext.h:917
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage, or used but not defined internal functions.
Definition: ASTReader.cpp:7233
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
void setIsGNUVarargs()
Definition: MacroInfo.h:201
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
const unsigned VERSION_MAJOR
AST file major version number supported by this version of Clang.
Definition: ASTBitCodes.h:39
ObjCInterfaceDecl * getObjCProtocolDecl() const
Retrieve the Objective-C class declaration corresponding to the predefined Protocol class...
SourceLocation getBegin() const
Definition: ASTBitCodes.h:178
DeclarationName getName() const
getName - Returns the embedded declaration name.
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3182
One of these records is kept for each identifier that is lexed.
A macro directive exported by a module.
Definition: ASTBitCodes.h:630
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1270
void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS)
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
Definition: ASTReader.cpp:103
void disableFileContentsOverride(const FileEntry *File)
Disable overridding the contents of a file, previously enabled with overrideFileContents.
Specifies a top-level header that falls into this (sub)module.
Definition: ASTBitCodes.h:659
std::string ActualOriginalSourceFileName
The actual original source file name that was used to build this AST file.
The block containing comments.
Definition: ASTBitCodes.h:234
SmallVectorImpl< ModuleFile * >::const_iterator ModuleConstIterator
This table allows us to fully hide how we implement multi-keyword caching.
AddModuleResult
The result of attempting to add a new module.
bool isDeclInLexicalTraversal(const Decl *D) const
Determine whether the given declaration is stored in the list of declarations lexically within this c...
Definition: DeclBase.h:1778
A library or framework to link against when an entity from this module is used.
Definition: Basic/Module.h:258
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
bool isNull() const
Definition: TypeLoc.h:95
void finalizeForWriting()
Finalizes the AST reader's state before writing an AST file to disk.
Definition: ASTReader.cpp:4066
Iteration over the preprocessed entities.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:661
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
A C++ nested-name-specifier augmented with source location information.
Record the location of a macro definition.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:1756
The 'char' type, when it is signed.
Definition: ASTBitCodes.h:728
static std::string resolveFileRelativeToOriginalDir(const std::string &Filename, const std::string &OriginalDir, const std::string &CurrDir)
If a header file is not found at the path that we expect it to be and the PCH file was moved from its...
Definition: ASTReader.cpp:1175
serialization::SelectorID getGlobalSelectorID(ModuleFile &F, unsigned LocalID) const
Retrieve the global selector ID that corresponds to this the local selector ID in a given module...
Definition: ASTReader.cpp:7664
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
void setBuiltinLoc(SourceLocation Loc)
Definition: TypeLoc.h:525
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1472
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener)
Read the control block for the named AST file.
Definition: ASTReader.cpp:4194
Specifies a header that has been explicitly excluded from this submodule.
Definition: ASTBitCodes.h:672
void setRBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1373
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Basic/Module.h:148
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2293
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, LateParsedTemplate * > &LPTMap) override
Read the set of late parsed template functions for this source.
Definition: ASTReader.cpp:7374
The unsigned 128-bit integer type.
Definition: ASTBitCodes.h:961
ContinuousRangeMap< uint32_t, int, 2 > PreprocessedEntityRemap
Remapping table for preprocessed entity IDs in this module.
Record code for the module map file that was used to build this AST file.
Definition: ASTBitCodes.h:289
std::vector< Entry > UserEntries
User specified include entries.
An ExtVectorType record.
Definition: ASTBitCodes.h:842
QualType getCanonicalTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args) const
Delete expressions that will be analyzed later.
Definition: ASTBitCodes.h:577
std::vector< SystemHeaderPrefix > SystemHeaderPrefixes
User-specified system header prefixes.
llvm::SmallPtrSet< ModuleFile *, 4 > HitSet
A set of module files in which we found a result.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:283
Helper class that saves the current stream position and then restores it when destroyed.
Definition: ASTReader.h:2159
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
CanQualType OCLEventTy
Definition: ASTContext.h:917
static CXXCtorInitializer * Create(ASTContext &Context, FieldDecl *Member, SourceLocation MemberLoc, SourceLocation L, Expr *Init, SourceLocation R, VarDecl **Indices, unsigned NumIndices)
Creates a new member initializer that optionally contains array indices used to describe an elementwi...
Definition: DeclCXX.cpp:1768
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3094
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1788
TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template name.
Definition: ASTReader.cpp:7771
bool isFileOverridden(const FileEntry *File)
Returns true if the file contents have been overridden.
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
Definition: ASTReader.h:122
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
DeclarationName getCXXDestructorName(CanQualType Ty)
getCXXDestructorName - Returns the name of a C++ destructor for the given Type.
method_range methods() const
Definition: DeclObjC.h:964
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten)
Sets the umbrella directory of the given module to the given directory.
Definition: ModuleMap.cpp:771
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
QualType getTypeOfType(QualType t) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes...
unsigned getNumProtocols() const
Definition: TypeLoc.h:910
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:642
std::string OriginalDir
The directory that the PCH was originally created in.
void setKind(tok::TokenKind K)
Definition: Token.h:90
Sema * getSema()
Retrieve the semantic analysis object used to analyze the translation unit in which the precompiled h...
Definition: ASTReader.h:2127
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
Definition: ASTReader.cpp:7290
An AttributedType record.
Definition: ASTBitCodes.h:888
An object-like macro definition.
Definition: ASTBitCodes.h:614
void setUnderlyingTInfo(TypeSourceInfo *TInfo)
Definition: TypeLoc.h:1688
The client can handle an AST file that cannot load because it's compiled configuration doesn't match ...
Definition: ASTReader.h:1373
CanQualType OCLReserveIDTy
Definition: ASTContext.h:918
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
SourceLocation getEnd() const
Definition: ASTBitCodes.h:181
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1199
Describes one token.
Definition: ASTBitCodes.h:623
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:681
An AdjustedType record.
Definition: ASTBitCodes.h:900
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI) override
Read the set of weak, undeclared identifiers known to the external Sema source.
Definition: ASTReader.cpp:7330
Describes a module or submodule.
Definition: Basic/Module.h:47
void completeVisibleDeclsMap(const DeclContext *DC) override
Load all external visible decls in the given DeclContext.
Definition: ASTReader.cpp:6666
unsigned LocalNumHeaderFileInfos
The number of local HeaderFileInfo structures.
Record code for the set of ext_vector type names.
Definition: ASTBitCodes.h:448
iterator end()
end - Returns an iterator that has 'finished'.
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
Definition: ASTReader.cpp:8188
llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Return a descriptor for the corresponding module.
Definition: ASTReader.cpp:7609
static void collectMacroDefinitions(const PreprocessorOptions &PPOpts, MacroDefinitionsMap &Macros, SmallVectorImpl< StringRef > *MacroNames=nullptr)
Collect the macro definitions provided by the given preprocessor options.
Definition: ASTReader.cpp:460
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
const PPEntityOffset * PreprocessedEntityOffsets
Specifies the submodules that are re-exported from this submodule.
Definition: ASTBitCodes.h:667
TemplateParameterList ** TemplParamLists
TemplParamLists - A new-allocated array of size NumTemplParamLists, containing pointers to the "outer...
Definition: Decl.h:627
std::string UserInfo
A string containing additional user information that will be stored with the metadata.
serialization::MacroID BaseMacroID
Base macro ID for macros local to this module.
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:160
QualType getParenType(QualType NamedType) const
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2006
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
Definition: Basic/Module.h:195
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:496
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:195
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:588
virtual void HandleInterestingDecl(DeclGroupRef D)
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: ASTConsumer.cpp:23
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
PreprocessedEntity * ReadPreprocessedEntity(unsigned Index) override
Read a preallocated preprocessed entity from the external source.
Definition: ASTReader.cpp:4876
void setCaretLoc(SourceLocation Loc)
Definition: TypeLoc.h:1153
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1895
const LangOptions & getLangOpts() const
Definition: ASTContext.h:604
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:631
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Definition: Basic/Module.h:314
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
TypeSourceInfo * GetTypeSourceInfo(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a declarator info from the given record.
Definition: ASTReader.cpp:5953
const unsigned NumSpecialTypeIDs
The number of special type IDs.
Definition: ASTBitCodes.h:930
A convenient class for passing around template argument information.
Definition: TemplateBase.h:523
void setcudaConfigureCallDecl(FunctionDecl *FD)
Definition: ASTContext.h:1098
uint32_t Offset
Definition: CacheTokens.cpp:44
Describes a blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:598
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Record code for the language options table.
Definition: ASTBitCodes.h:307
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition: ASTReader.h:1495
void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:7758
std::string Message
The message provided to the user when there is a conflict.
Definition: Basic/Module.h:300
Wrapper for source info for functions.
Definition: TypeLoc.h:1255
Specifies a conflict with another module.
Definition: ASTBitCodes.h:678
The signed 128-bit integer type.
Definition: ASTBitCodes.h:958
CXXCtorInitializer ** ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a CXXCtorInitializer array.
Definition: ASTReader.cpp:7941
llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx)
Read a signed integral value.
Definition: ASTReader.cpp:8161
A UnaryTransformType record.
Definition: ASTBitCodes.h:894
An ObjCObjectType record.
Definition: ASTBitCodes.h:872
A ConstantArrayType record.
Definition: ASTBitCodes.h:834
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8181
void RemoveDecl(NamedDecl *D)
RemoveDecl - Unlink the decl from its shadowed decl chain.
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
Definition: ASTReader.cpp:609
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:704
std::string getOwningModuleNameForDiagnostic(const Decl *D)
Get the best name we know for the module that owns the given declaration, or an empty string if the d...
Definition: ASTReader.cpp:8290
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName replacement) const
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID)
Retrieve the global submodule ID given a module and its local ID number.
Definition: ASTReader.cpp:7548
Record code for #pragma optimize options.
Definition: ASTBitCodes.h:569
uint32_t BitOffset
Offset in the AST file.
Definition: ASTBitCodes.h:172
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8200
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Definition: Sema.h:1000
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
Specifies a header that is private to this submodule but must be textually included.
Definition: ASTBitCodes.h:686
Record code for pending implicit instantiations.
Definition: ASTBitCodes.h:478
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:697
TypeLocReader(ASTReader &Reader, ModuleFile &F, const ASTReader::RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:5720
CanQualType PseudoObjectTy
Definition: ASTContext.h:911
The internal '__make_integer_seq' template.
Definition: ASTBitCodes.h:979
bool needsExtraLocalData() const
Definition: TypeLoc.h:538
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1604
void setLazyBody(uint64_t Offset)
Definition: DeclObjC.h:486
TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument.
Definition: ASTReader.cpp:7829
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Definition: ASTReader.h:2118
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
Record code for #pragma diagnostic mappings.
Definition: ASTBitCodes.h:497
An ExtQualType record.
Definition: ASTBitCodes.h:820
TypedefDecl * getObjCIdDecl() const
Retrieve the typedef corresponding to the predefined id type in Objective-C.
Record code for floating point #pragma options.
Definition: ASTBitCodes.h:506
CommentRecordTypes
Record types used within a comments block.
Definition: ASTBitCodes.h:690
static internal_key_type ReadKey(const unsigned char *d, unsigned n)
Definition: ASTReader.cpp:749
CanQualType LongDoubleTy
Definition: ASTContext.h:904
void setMustBuildLookupTable()
Mark that there are external lexical declarations that we need to include in our lookup table (and th...
Definition: DeclBase.h:1741
void addExternalSource(ExternalSemaSource *E)
Registers an external source.
Definition: Sema.cpp:326
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition: Basic/Module.h:163
std::string OriginalSourceFileName
The original source file name that was used to build the primary AST file, which may have been modifi...
Wrapper for source info for ObjC interfaces.
Definition: TypeLoc.h:981
Record code for the set of known namespaces, which are used for typo correction.
Definition: ASTBitCodes.h:516
static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps)
Definition: ASTReader.cpp:2069
Record code for an array of all of the (sub)modules that were imported by the AST file...
Definition: ASTBitCodes.h:537
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
Present this diagnostic as an error.
ModuleManager::ModuleIterator ModuleIterator
Definition: ASTReader.h:361
SourceLocation FirstLoc
The first source location in this module.
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending) override
Read the set of pending instantiations known to the external Sema source.
Definition: ASTReader.cpp:7362
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:354
A BlockPointerType record.
Definition: ASTBitCodes.h:826
void setProtocolLoc(unsigned i, SourceLocation Loc)
Definition: TypeLoc.h:918
iterator end() const
A MemberPointerType record.
Definition: ASTBitCodes.h:832
ContinuousRangeMap< uint32_t, int, 2 > SLocRemap
Remapping table for source locations in this module.
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1263
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag)
Definition: ASTReader.cpp:5137
Represents an ObjC class declaration.
Definition: DeclObjC.h:1091
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
The AST file itself appears corrupted.
Definition: ASTReader.h:331
detail::InMemoryDirectory::const_iterator I
void dump()
Dump information about the AST reader to standard error.
Definition: ASTReader.cpp:6867
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3160
unsigned getNumParams() const
Definition: TypeLoc.h:1301
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 >> &Exprs) override
Definition: ASTReader.cpp:7243
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:39
uint64_t PreprocessorDetailStartOffset
The offset of the start of the preprocessor detail cursor.
TypedefDecl * getObjCClassDecl() const
Retrieve the typedef declaration corresponding to the predefined Objective-C 'Class' type...
CanQualType UnsignedCharTy
Definition: ASTContext.h:902
Record code for the table of offsets into the block of source-location information.
Definition: ASTBitCodes.h:437
bool isInvalid() const
friend class ASTIdentifierIterator
Definition: ASTReader.h:350
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:1677
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.h:190
A SubstTemplateTypeParmPackType record.
Definition: ASTBitCodes.h:890
Objective-C "id" redefinition type.
Definition: ASTBitCodes.h:920
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls) override
Read the set of delegating constructors known to the external Sema source.
Definition: ASTReader.cpp:7279
static std::string ReadString(const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8174
TypeCode
Record codes for each kind of type.
Definition: ASTBitCodes.h:818
Records the location of a macro expansion.
DiagnosticsEngine & getDiagnostics() const
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel)
A selector was read from the AST file.
virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain)
Receives the file system options.
Definition: ASTReader.h:151
void setUnderlyingTInfo(TypeSourceInfo *TI) const
Definition: TypeLoc.h:1649
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:113
Class that aids in the construction of nested-name-specifiers along with source-location information ...
unsigned getObjCOrBuiltinID() const
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
Definition: Basic/Module.h:173
The block containing information about the source manager.
Definition: ASTBitCodes.h:217
IdentifierInfo * GetIdentifierInfo(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:1876
The placeholder type for OpenMP array section.
Definition: ASTBitCodes.h:796
A VariableArrayType record.
Definition: ASTBitCodes.h:838
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
diag::Severity getExtensionHandlingBehavior() const
Definition: Diagnostic.h:523
const unsigned int NUM_PREDEF_PP_ENTITY_IDS
The number of predefined preprocessed entity IDs.
Definition: ASTBitCodes.h:206
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
void setUsedForHeaderGuard(bool Val)
Definition: MacroInfo.h:274
ASTRecordTypes
Record types that occur within the AST block itself.
Definition: ASTBitCodes.h:342
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:873
static bool parseModuleFileExtensionMetadata(const SmallVectorImpl< uint64_t > &Record, StringRef Blob, ModuleFileExtensionMetadata &Metadata)
Parse a record and blob containing module file extension metadata.
Definition: ASTReader.cpp:3860
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement into a statement.
Definition: ASTReader.cpp:6510
unsigned NumTemplParamLists
NumTemplParamLists - The number of "outer" template parameter lists.
Definition: Decl.h:620
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3073
Defines the major attributes of a submodule, including its name and parent.
Definition: ASTBitCodes.h:652
llvm::BitstreamCursor Stream
The main bitstream cursor for the main block.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:107
llvm::DenseMap< ModuleFile *, serialization::DeclID > GlobalToLocalDeclIDs
Mapping from the module files that this module file depends on to the base declaration ID for that mo...
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:646
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:97
ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, unsigned PriorGeneration)
Definition: ASTReader.cpp:7113
ModuleKind
Specifies the kind of module that has been loaded.
StringRef Filename
Definition: Format.cpp:1194
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:198
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:462
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2462
void SetGloballyVisibleDecls(IdentifierInfo *II, const SmallVectorImpl< uint32_t > &DeclIDs, SmallVectorImpl< Decl * > *Decls=nullptr)
Set the globally-visible declarations associated with the given identifier.
Definition: ASTReader.cpp:7427
ASTContext * Context
std::vector< bool > & Stack
void ReadModuleMapFile(StringRef ModuleMapPath) override
Definition: ASTReader.cpp:82
void setSizeExpr(Expr *Size)
Definition: TypeLoc.h:1384
unsigned LocalNumSLocEntries
The number of source location entries in this AST file.
void setCFConstantStringType(QualType T)
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
Captures information about a #pragma weak directive.
Definition: Weak.h:25
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1903
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, std::string ExistingModuleCachePath)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
Definition: ASTReader.cpp:4402
Record code for the table of offsets of each macro ID.
Definition: ASTBitCodes.h:554
const DirectoryEntry * Entry
Definition: Basic/Module.h:120
const uint32_t * TypeOffsets
Offset of each type within the bitstream, indexed by the type ID, or the representation of a Type*...
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo)
Definition: ASTReader.cpp:1791
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
CanQualType OCLNDRangeTy
Definition: ASTContext.h:918
unsigned UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1881
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
serialization::PreprocessedEntityID getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const
Determine the global preprocessed entity ID that corresponds to the given local ID within the given m...
Definition: ASTReader.cpp:1521
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, const TemplateArgumentListInfo &Args) const
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1143
ASTReaderListener implementation to validate the information of the PCH file against an initialized P...
Definition: ASTReader.h:263
int * Depth
uint64_t Signature
The module signature.
Definition: Basic/Module.h:68
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:116
An TemplateSpecializationType record.
Definition: ASTBitCodes.h:876
An ObjCObjectPointerType record.
Definition: ASTBitCodes.h:860
Type source information for an attributed type.
Definition: TypeLoc.h:724
An ObjCInterfaceType record.
Definition: ASTBitCodes.h:858
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
const Type * getTypePtrOrNull() const
Definition: Type.h:5263
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1855
HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override
Read the header file information for the given file entry.
Definition: ASTReader.cpp:5128
Describes a zlib-compressed blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:601
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:590
Expr - This represents one expression.
Definition: Expr.h:105
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Definition: ASTReader.cpp:7591
StringRef getName() const
Return the actual identifier string.
Record code for the array of VTable uses.
Definition: ASTBitCodes.h:458
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
The 'char' type, when it is unsigned.
Definition: ASTBitCodes.h:716
void setHasCommaPasting()
Definition: MacroInfo.h:215
static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, bool IsModule)
Whether the given identifier is "interesting".
Definition: ASTReader.cpp:755
void setModeAttr(bool written)
Definition: TypeLoc.h:601
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
Definition: ASTReader.cpp:8230
serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID)
Retrieve the global macro ID corresponding to the given local ID within the given module file...
Definition: ASTReader.cpp:7536
The directory that the PCH was originally created in.
Definition: ASTBitCodes.h:274
DiagnosticBuilder Diag(unsigned DiagID)
Report a diagnostic.
Definition: ASTReader.cpp:8207
QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a type from the current position in the given record, which was read from the given AST file...
Definition: ASTReader.h:1635
Declaration of a template type parameter.
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
unsigned LocalNumIdentifiers
The number of identifiers in this AST file.
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
Definition: ASTReader.cpp:7350
The placeholder type for overloaded function sets.
Definition: ASTBitCodes.h:748
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:127
Implements an efficient mapping from strings to IdentifierInfo nodes.
Defines implementation details of the clang::SourceManager class.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:4357
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:54
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
Definition: ASTReader.h:213
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Basic/Module.h:202
Record code for the table of offsets to entries in the preprocessing record.
Definition: ASTBitCodes.h:455
std::unique_ptr< llvm::MemoryBuffer > Buffer
The memory buffer that stores the data associated with this AST file.
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2414
ContinuousRangeMap< uint32_t, int, 2 > IdentifierRemap
Remapping table for identifier IDs in this module.
CanQualType OMPArraySectionTy
Definition: ASTContext.h:919
llvm::BitstreamCursor SLocEntryCursor
Cursor used to read source location entries.
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:886
Defines version macros and version-related utility functions for Clang.
The OpenCL 'half' / ARM NEON __fp16 type.
Definition: ASTBitCodes.h:776
Defines the clang::Preprocessor interface.
ArgKind
The kind of template argument we're storing.
Definition: TemplateBase.h:43
serialization::DeclID getGlobalDeclID(ModuleFile &F, serialization::LocalDeclID LocalID) const
Map from a local declaration ID within a given module to a global declaration ID. ...
Definition: ASTReader.cpp:6328
The block containing the detailed preprocessing record.
Definition: ASTBitCodes.h:228
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:216
std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID) override
Retrieve the module import location and module name for the given source manager entry ID...
Definition: ASTReader.cpp:1343
static LineEntry get(unsigned Offs, unsigned Line, int Filename, SrcMgr::CharacteristicKind FileKind, unsigned IncludeOffset)
void setWrittenSignSpec(TypeSpecifierSign written)
Definition: TypeLoc.h:567
llvm::BitstreamCursor InputFilesCursor
The cursor to the start of the input-files block.
unsigned LocalNumMacros
The number of macros in this AST file.
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a source range.
Definition: ASTReader.cpp:8144
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1145
CanQualType ShortTy
Definition: ASTContext.h:901
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
struct ExtInfo * ExtInfo
Definition: CGCleanup.h:260
Record code for the original file that was used to generate the AST file, including both its file ID ...
Definition: ASTBitCodes.h:271
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2013
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
Definition: Basic/Module.h:275
QualType getLocalType(ModuleFile &F, unsigned LocalID)
Resolve a local type ID within a given AST file into a type.
Definition: ASTReader.cpp:6140
Information about a module that has been loaded by the ASTReader.
A namespace alias, stored as a NamespaceAliasDecl*.
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
Definition: ASTReader.cpp:130
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:903
An iterator that walks over all of the known identifiers in the lookup table.
SmallVector< uint64_t, 1 > ObjCCategories
The Objective-C category lists for categories known to this module.
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:994
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1597
FileID OriginalSourceFileID
The file ID for the original source file that was used to build this AST file.
A FunctionProtoType record.
Definition: ASTBitCodes.h:846
void setInheritConstructors(bool Inherit=true)
Set that this base class's constructors should be inherited.
Definition: DeclCXX.h:221
bool HasTimestamps
Whether timestamps are included in this module file.
Describes a source location entry (SLocEntry) for a file.
Definition: ASTBitCodes.h:590
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
Wrapper for source info for enum types.
Definition: TypeLoc.h:680
A block containing a module file extension.
Definition: ASTBitCodes.h:255
bool isInstanceMethod() const
Definition: DeclObjC.h:414
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:93
std::string FileName
The file name of the module file.
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten)
Sets the umbrella header of the given module to the given header.
Definition: ModuleMap.cpp:759
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:1960
Record code for an update to a decl context's lookup table.
Definition: ASTBitCodes.h:485
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition: TypeLoc.h:937
Record the location of an inclusion directive, such as an #include or #import statement.
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
Definition: ASTReader.cpp:329
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:580
InclusionKind
The kind of inclusion directives known to the preprocessor.
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:807
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
struct CXXOpName CXXOperatorName
a DecltypeType record.
Definition: ASTBitCodes.h:862
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Trait class used to search the on-disk hash table containing all of the header search information...
QualType getSubstTemplateTypeParmPackType(const TemplateTypeParmType *Replaced, const TemplateArgument &ArgPack)
Retrieve a.
void insertOrReplace(const value_type &Val)
void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method)
Add the given method to the list of globally-known methods.
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4154
void deduplicateMergedDefinitonsFor(NamedDecl *ND)
Clean up the merged definition list.
Definition: ASTContext.cpp:892
void StartedDeserializing() override
Notify ASTReader that we started deserialization of a decl or type so until FinishedDeserializing is ...
Definition: ASTReader.cpp:8619
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
void setArgumentList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the argument list for this macro.
Definition: MacroInfo.h:161
Information about a header directive as found in the module map file.
Definition: Basic/Module.h:109
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
Definition: ASTContext.cpp:923
The result type of a method or function.
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1680
unsigned SLocEntryBaseOffset
The base offset in the source manager's view of this module.
Record code for the table of offsets of each identifier ID.
Definition: ASTBitCodes.h:375
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1797
SmallVector< uint64_t, 16 > PreloadedDeclIDs
Definition: ASTReader.h:2122
Record code for undefined but used functions and variables that need a definition in this TU...
Definition: ASTBitCodes.h:563
void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:7748
A DependentNameType record.
Definition: ASTBitCodes.h:878
const SourceManager & SM
Definition: Format.cpp:1184
unsigned MajorVersion
The major version of the extension data.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:231
CanQualType SignedCharTy
Definition: ASTContext.h:901
Record code for the identifier table.
Definition: ASTBitCodes.h:394
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateDecl *Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Basic/Module.h:379
The AST file was missing.
Definition: ASTReader.h:333
uint64_t BuildSessionTimestamp
The time in seconds when the build session started.
unsigned MinorVersion
The minor version of the extension data.
NestedNameSpecifier * ReadNestedNameSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8026
void AddEntry(FileID FID, const std::vector< LineEntry > &Entries)
Add a new line entry that has already been encoded into the internal representation of the line table...
The placeholder type for bound member functions.
Definition: ASTBitCodes.h:770
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Definition: MacroInfo.h:149
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:36
bool getSuppressSystemWarnings() const
Definition: Diagnostic.h:467
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1170
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
std::vector< std::unique_ptr< ModuleFileExtensionReader > > ExtensionReaders
The list of extension readers that are attached to this module file.
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:126
void setTypeofLoc(SourceLocation Loc)
Definition: TypeLoc.h:1590
SpecifierKind
The kind of specifier that completes this nested name specifier.
std::pair< Module *, bool > findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Find a new module or submodule, or create it if it does not already exist.
Definition: ModuleMap.cpp:544
void makeNamesVisible(const HiddenNames &Names, Module *Owner)
Make the names within this set of hidden names visible.
Definition: ASTReader.cpp:3347
StringRef Next() override
Retrieve the next string in the identifier table and advances the iterator for the following string...
Definition: ASTReader.cpp:7036
The 'unsigned long long' type.
Definition: ASTBitCodes.h:726
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:205
Wrapper for source info for arrays.
Definition: TypeLoc.h:1358
virtual void ExtractPCH(llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const =0
Initialize an llvm::BitstreamReader with the serialized AST inside the PCH container Buffer...
Record code for the set of source location entries that need to be preloaded by the AST reader...
Definition: ASTBitCodes.h:445
QualifierInfo - A struct with extended info about a syntactic name qualifier, to be used for the case...
Definition: Decl.h:613
CanQualType OverloadTy
Definition: ASTContext.h:909
The control block was read successfully.
Definition: ASTReader.h:329
The list of delegating constructor declarations.
Definition: ASTBitCodes.h:512
Information about a FileID, basically just the logical file that it represents and include stack info...
void setSourceOrder(int pos)
Set the source order of this initializer.
Definition: DeclCXX.h:2115
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
void setAttrOperandParensRange(SourceRange range)
Definition: TypeLoc.h:801
static bool readBit(unsigned &Bits)
Definition: ASTReader.cpp:765
void setIsFunctionLike()
Function/Object-likeness.
Definition: MacroInfo.h:195
const unsigned char * SelectorLookupTableData
A pointer to the character data that comprises the selector table.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Definition: MacroInfo.h:307
bool ReadFullVersionInformation(StringRef FullVersion) override
Receives the full Clang version information.
Definition: ASTReader.cpp:74
#define false
Definition: stdbool.h:33
serialization::TypeID BaseTypeIndex
Base type ID for types local to this module as represented in the global type ID space.
CanQualType BuiltinFnTy
Definition: ASTContext.h:910
StringRef FileName
Definition: Format.cpp:1313
ContinuousRangeMap< uint32_t, int, 2 > SelectorRemap
Remapping table for selector IDs in this module.
Kind
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:42
void setASTFile(const FileEntry *File)
Set the serialized AST file for the top-level module of this module.
Definition: Basic/Module.h:389
bool isGlobalIndexUnavailable() const
Determine whether we tried to load the global index, but failed, e.g., because it is out-of-date or d...
Definition: ASTReader.cpp:3429
bool hasRevertedBuiltin() const
True if setNotBuiltin() was called.
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3153
void LoadSelector(Selector Sel)
Load a selector from disk, registering its ID if it exists.
Definition: ASTReader.cpp:7397
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1888
SmallVectorImpl< AnnotatedLine * >::const_iterator Next
serialization::IdentID BaseIdentifierID
Base identifier ID for identifiers local to this module.
MacroInfo * ReadMacroRecord(ModuleFile &F, uint64_t Offset)
Reads the macro record located at the given offset.
Definition: ASTReader.cpp:1410
File is a PCH file treated as the preamble.
ContinuousRangeMap< unsigned, int, 2 > SLocRemap
Definition: ASTUnit.cpp:2526
const char * getName() const
Definition: FileManager.h:85
static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method)
Move the given method to the back of the global list of methods.
Definition: ASTReader.cpp:3319
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3188
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
ExternCContextDecl * getExternCContextDecl() const
Definition: ASTContext.cpp:905
Encodes a location in the source.
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, StringRef ExistingModuleCachePath, DiagnosticsEngine *Diags, const LangOptions &LangOpts)
Check the header search options deserialized from the control block against the header search options...
Definition: ASTReader.cpp:625
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
Definition: ASTReader.cpp:6690
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5259
const TemplateArgument * iterator
Definition: Type.h:4233
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1078
File is a PCH file treated as such.
CanQualType Int128Ty
Definition: ASTContext.h:901
IdentifierInfo * get(StringRef Name) override
Retrieve the IdentifierInfo for the named identifier.
Definition: ASTReader.cpp:6966
void setLength(unsigned Len)
Definition: Token.h:132
Specifies a library or framework to link against.
Definition: ASTBitCodes.h:674
Record code for file ID of the file or buffer that was used to generate the AST file.
Definition: ASTBitCodes.h:278
Represents a C++ temporary.
Definition: ExprCXX.h:1088
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:4936
void InitializeContext()
Initializes the ASTContext.
Definition: ASTReader.cpp:3930
Specifies a header that falls into this (sub)module.
Definition: ASTBitCodes.h:657
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
ContinuousRangeMap< uint32_t, int, 2 > SubmoduleRemap
Remapping table for submodule IDs in this module.
void setUsed(bool Used=true)
Definition: Weak.h:36
A ComplexType record.
Definition: ASTBitCodes.h:822
Record code for special CUDA declarations.
Definition: ASTBitCodes.h:500
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
Options for controlling the compiler diagnostics engine.
A list of "interesting" identifiers.
Definition: ASTBitCodes.h:559
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition: Basic/Module.h:214
An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files...
Definition: ASTReader.cpp:7004
The block of configuration options, used to check that a module is being used in a configuration comp...
Definition: ASTBitCodes.h:252
const std::string ID
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2727
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply...
void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces) override
Load the set of namespaces that are known to the external source, which will be used during typo corr...
Definition: ASTReader.cpp:7222
PredefinedTypeIDs
Predefined type IDs.
Definition: ASTBitCodes.h:708
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
llvm::BitstreamReader StreamFile
The bitstream reader from which we'll read the AST file.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
All of the names in this module are hidden.
Definition: Basic/Module.h:208
File is an implicitly-loaded module.
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:697
void setProtocolRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:906
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
Metadata describing this particular extension.
Definition: ASTBitCodes.h:328
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
Definition: ASTReader.cpp:123
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
Definition: MacroInfo.h:200
MacroInfo * getMacro(serialization::MacroID ID)
Retrieve the macro with the given ID.
Definition: ASTReader.cpp:7510
uint64_t SizeInBits
The size of this file, in bits.
TemplateParameterList * ReadTemplateParameterList(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template parameter list.
Definition: ASTReader.cpp:7883
void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, bool ReportDiags=true)
ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...
Definition: Warnings.cpp:44
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
Definition: ASTReader.cpp:6339
ModuleReverseIterator rbegin()
Reverse iterator to traverse all loaded modules.
Record code for the offsets of each decl.
Definition: ASTBitCodes.h:367
void setIdentifierInfo(IdentifierInfo *II)
Definition: Token.h:185
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
Definition: ASTReader.cpp:7180
void * SelectorLookupTable
A pointer to an on-disk hash table of opaque type ASTSelectorLookupTable.
Metadata for submodules as a whole.
Definition: ASTBitCodes.h:649
const uint32_t * IdentifierOffsets
Offsets into the identifier table data.
The width of the "fast" qualifier mask.
Definition: Type.h:160
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Class that performs lookup for a selector's entries in the global method pool stored in an AST file...
A TypeOfExprType record.
Definition: ASTBitCodes.h:850
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
Record code for late parsed template functions.
Definition: ASTBitCodes.h:566
CanQualType FloatTy
Definition: ASTContext.h:904
const FileEntry * Entry
Definition: Basic/Module.h:111
Defines the clang::TargetOptions class.
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
QualType getIncompleteArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type...
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
Definition: MacroInfo.h:123
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:112
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings starting...
Definition: TargetOptions.h:55
unsigned LocalNumDecls
The number of declarations in this AST file.
The internal 'instancetype' typedef.
Definition: ASTBitCodes.h:964
CanQualType VoidTy
Definition: ASTContext.h:893
OptionsRecordTypes
Record types that occur within the options block inside the control block.
Definition: ASTBitCodes.h:300
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:82
unsigned getNumTypeArgs() const
Definition: TypeLoc.h:882
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:1543
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:129
The AST block, which acts as a container around the full AST block.
Definition: ASTBitCodes.h:213
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1236
IdentID ReadIdentifierID(const unsigned char *d)
Definition: ASTReader.cpp:771
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1843
void setWrittenTypeSpec(TypeSpecifierType written)
Definition: TypeLoc.h:590
Objective-C "SEL" redefinition type.
Definition: ASTBitCodes.h:924
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:51
SourceLocation getBegin() const
void setAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1228
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1407
void setLBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1366
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
static bool checkLanguageOptions(const LangOptions &LangOpts, const LangOptions &ExistingLangOpts, DiagnosticsEngine *Diags, bool AllowCompatibleDifferences=true)
Compare the given set of language options against an existing set of language options.
Definition: ASTReader.cpp:184
Updates[]
Definition: OpenMPClause.h:312
An InjectedClassNameType record.
Definition: ASTBitCodes.h:870
const serialization::DeclID * FileSortedDecls
Array of file-level DeclIDs sorted by file.
Record code for the extra statistics we gather while generating an AST file.
Definition: ASTBitCodes.h:417
bool getEnableAllWarnings() const
Definition: Diagnostic.h:449
static Decl * getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID)
Definition: ASTReader.cpp:6376
TypedefDecl * getInt128Decl() const
Retrieve the declaration for the 128-bit signed integer type.
Definition: ASTContext.cpp:964
virtual void visitImport(StringRef Filename)
If needsImportVisitation returns true, this is called for each AST file imported by this AST file...
Definition: ASTReader.h:210
static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool Complain)
Definition: ASTReader.cpp:345
std::vector< InputFile > InputFilesLoaded
The input files that have been loaded from this AST file.
The module file was just loaded in response to this call.
DeclarationName ReadDeclarationName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a declaration name.
Definition: ASTReader.cpp:7677
ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, unsigned ClientLoadCapabilities)
Load the AST file designated by the given file name.
Definition: ASTReader.cpp:3474
HashTableTy::const_iterator iterator
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:167
The AST file was writtten with a different language/target configuration.
Definition: ASTReader.h:341
ArrayRef< ObjCMethodDecl * > getFactoryMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:7159
const char * HeaderFileInfoTableData
Actual data for the on-disk hash table of header file information.
void markIdentifierUpToDate(IdentifierInfo *II)
Note that this identifier is up-to-date.
Definition: ASTReader.cpp:1780
const llvm::support::unaligned_uint64_t * InputFileOffsets
Offsets for all of the input file entries in the AST file.
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:563
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
Definition: ModuleMap.cpp:792
File is a PCH file treated as the actual main file.
llvm::APFloat ReadAPFloat(const RecordData &Record, const llvm::fltSemantics &Sem, unsigned &Idx)
Read a floating-point value.
Definition: ASTReader.cpp:8167
Record code for referenced selector pool.
Definition: ASTBitCodes.h:463
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
std::vector< std::string > MacroIncludes
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4294
ModuleFile * getLocalModuleFile(ModuleFile &M, unsigned ID)
Retrieve the module file with a given local ID within the specified ModuleFile.
Definition: ASTReader.cpp:7578
Record code for the set of non-builtin, special types.
Definition: ASTBitCodes.h:413
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1277
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1451
void setTypeArgsLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:871
uint64_t InputFilesValidationTimestamp
If non-zero, specifies the time when we last validated input files.
CanQualType UnsignedShortTy
Definition: ASTContext.h:902
const uint32_t * MacroOffsets
Offsets of macros in the preprocessor block.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2609
unsigned LocalNumSelectors
The number of selectors new to this file.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
CanQualType CharTy
Definition: ASTContext.h:895
unsigned NextIndex
Represents a template argument.
Definition: TemplateBase.h:40
Record code for the list of other AST files imported by this AST file.
Definition: ASTBitCodes.h:266
Selector getLocalSelector(ModuleFile &M, unsigned LocalID)
Retrieve a selector from the given module with its local ID number.
Definition: ASTReader.cpp:7625
Describes a macro definition within the preprocessing record.
Definition: ASTBitCodes.h:639
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
const ASTTemplateArgumentListInfo * ReadASTTemplateArgumentListInfo(ModuleFile &F, const RecordData &Record, unsigned &Index)
Definition: ASTReader.cpp:6210
A conflict between two modules.
Definition: Basic/Module.h:295
void setClassTInfo(TypeSourceInfo *TI)
Definition: TypeLoc.h:1180
bool ReadSLocEntry(int ID) override
Read the source location entry with index ID.
Definition: ASTReader.cpp:1203
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
Definition: ASTReader.cpp:642
The internal '__NSConstantString' typedef.
Definition: ASTBitCodes.h:982
Record code for the module name.
Definition: ASTBitCodes.h:285
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:912
void ResolveImportedPath(ModuleFile &M, std::string &Filename)
If we are loading a relocatable PCH or module file, and the filename is not an absolute path...
Definition: ASTReader.cpp:2054
void setDeserializationListener(ASTDeserializationListener *Listener, bool TakeOwnership=false)
Set the AST deserialization listener.
Definition: ASTReader.cpp:659
Describes an inclusion directive within the preprocessing record.
Definition: ASTBitCodes.h:643
The internal '__builtin_ms_va_list' typedef.
Definition: ASTBitCodes.h:973
llvm::BitstreamCursor DeclsCursor
DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.
unsigned IsMissingRequirement
Whether this module is missing a feature from Requirements.
Definition: Basic/Module.h:151
not evaluated yet, for special member function
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
Record code for a file sorted array of DeclIDs in a module.
Definition: ASTBitCodes.h:533
void setAmpAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1241
CanQualType NullPtrTy
Definition: ASTContext.h:908
Record code for the array of Objective-C categories (including extensions).
Definition: ASTBitCodes.h:547
void updateOutOfDateIdentifier(IdentifierInfo &II) override
Update an out-of-date identifier.
Definition: ASTReader.cpp:1755
void reserve(ASTContext &C, unsigned N)
Specifies a configuration macro for this module.
Definition: ASTBitCodes.h:676
void ReadDefinedMacros() override
Read the set of macros defined by this external macro source.
Definition: ASTReader.cpp:1650
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:330
PreprocessorDetailRecordTypes
Record types used within a preprocessor detail block.
Definition: ASTBitCodes.h:634
static std::pair< GlobalModuleIndex *, ErrorCode > readIndex(StringRef Path)
Read a global index file for the given directory.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
static unsigned moduleKindForDiagnostic(ModuleKind Kind)
Definition: ASTReader.cpp:3706
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) override
Receives the file system options.
Definition: ASTReader.cpp:109
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:25
uint64_t MacroStartOffset
The offset of the start of the set of defined macros.
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
Record code for the array of unused file scoped decls.
Definition: ASTBitCodes.h:451
A FunctionNoProtoType record.
Definition: ASTBitCodes.h:844
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
Definition: LangOptions.h:123
static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID)
Given a cursor at the start of an AST file, scan ahead and drop the cursor into the start of the give...
Definition: ASTReader.cpp:3447
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:312
File is an explicitly-loaded module.
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2521
Expr * ReadExpr(ModuleFile &F)
Reads an expression.
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:320
ModuleFile & getPrimaryModule()
Returns the primary module associated with the manager, that is, the first module loaded...
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:903
bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule) override
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
Definition: ASTReader.cpp:148
QualType getEnumType(const EnumDecl *Decl) const
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DeclarationName - The name of a declaration.
Record code for the Objective-C method pool,.
Definition: ASTBitCodes.h:429
virtual void ReadModuleMapFile(StringRef ModuleMapPath)
Definition: ASTReader.h:117
Specifies a header that is private to this submodule.
Definition: ASTBitCodes.h:680
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
bool needsInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.cpp:135
Describes a macro expansion within the preprocessing record.
Definition: ASTBitCodes.h:636
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
Selector getSelector() const
Definition: DeclObjC.h:328
void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Decls) override
Read all of the declarations lexically stored in a declaration context.
Definition: ASTReader.cpp:6520
An EnumType record.
Definition: ASTBitCodes.h:856
detail::InMemoryDirectory::const_iterator E
IdentifierTable & getIdentifierTable()
Retrieve the identifier table associated with the preprocessor.
Definition: ASTReader.cpp:8217
IdentifierResolver IdResolver
Definition: Sema.h:708
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1966
A map from continuous integer ranges to some value, with a very specialized interface.
Class that performs lookup for an identifier stored in an AST file.
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
ContinuousRangeMap< uint32_t, int, 2 > MacroRemap
Remapping table for macro IDs in this module.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
An RValueReferenceType record.
Definition: ASTBitCodes.h:830
void ReadDeclarationNameLoc(ModuleFile &F, DeclarationNameLoc &DNLoc, DeclarationName Name, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:7716
A type that was preceded by the 'template' keyword, stored as a Type*.
void ClearSwitchCaseIDs()
Definition: ASTReader.cpp:8235
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const
Read a source location from raw form.
Definition: ASTReader.h:2013
std::string BlockName
The name used to identify this particular extension block within the resulting module file...
void setHasExternalLexicalStorage(bool ES=true)
State whether this DeclContext has external storage for declarations lexically in this context...
Definition: DeclBase.h:1760
unsigned getTotalNumSelectors() const
Returns the number of selectors found in the chain.
Definition: ASTReader.h:1588
unsigned Map[Count]
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
Definition: AddressSpaces.h:45
An AtomicType record.
Definition: ASTBitCodes.h:896
BuiltinTemplateDecl * getTypePackElementDecl() const
Definition: ASTContext.cpp:931
static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, ASTConsumer *Consumer)
Under non-PCH compilation the consumer receives the objc methods before receiving the implementation...
Definition: ASTReader.cpp:6699
The placeholder type for dependent types.
Definition: ASTBitCodes.h:750
All of the names in this module are visible.
Definition: Basic/Module.h:210
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1807
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:34
Decl * GetExternalDecl(uint32_t ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:6222
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope...
Definition: ASTReader.cpp:8743
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:741
uint32_t getGeneration() const
Get the current generation of this AST source.
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3163
time_t getModificationTime() const
Definition: FileManager.h:92
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, const RecordData &Record, unsigned &Idx)
Read a UnresolvedSet structure.
Definition: ASTReader.cpp:7913
void setAttrEnumOperandLoc(SourceLocation loc)
Definition: TypeLoc.h:788
struct CXXLitOpName CXXLiteralOperatorName
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:104
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:427
CanQualType UnknownAnyTy
Definition: ASTContext.h:909
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Basic/Module.h:304
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8081
std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range) override
Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses...
Definition: ASTReader.cpp:5065
Record code for the table of offsets into the Objective-C method pool.
Definition: ASTBitCodes.h:426
Represents a C++ base or member initializer.
Definition: DeclCXX.h:1922
llvm::iterator_range< ModuleConstIterator > pch_modules() const
A range covering the PCH and preamble module files loaded.
A DependentSizedArrayType record.
Definition: ASTBitCodes.h:882
CanQualType UnsignedLongTy
Definition: ASTContext.h:902
Record code for the remapping information used to relate loaded modules to the various offsets and ID...
Definition: ASTBitCodes.h:522
bool isInvalid() const
virtual bool needsImportVisitation() const
Returns true if this ASTReaderListener wants to receive the imports of the AST file via visitImport...
Definition: ASTReader.h:207
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:1573
void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata) override
Indicates that a particular module file extension has been read.
Definition: ASTReader.cpp:164
Record code for declarations that Sema keeps references of.
Definition: ASTBitCodes.h:472
void ReadTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument array.
Definition: ASTReader.cpp:7903
CanQualType DependentTy
Definition: ASTContext.h:909
void * HeaderFileInfoTable
The on-disk hash table that contains information about each of the header files.
CanQualType WCharTy
Definition: ASTContext.h:896
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:139
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:481
Offsets into the input-files block where input files reside.
Definition: ASTBitCodes.h:282
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:87
CanQualType ObjCBuiltinClassTy
Definition: ASTContext.h:912
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:673
PreprocessorRecordTypes
Record types used within a preprocessor block.
Definition: ASTBitCodes.h:608
static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags)
Definition: ASTReader.cpp:375
CanQualType BoundMemberTy
Definition: ASTContext.h:909
The block containing the submodule structure.
Definition: ASTBitCodes.h:231
void setTypeArgsRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:878
Wrapper for source info for record types.
Definition: TypeLoc.h:672
std::string BaseDirectory
The base directory of the module.
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1815
The template argument is a type.
Definition: TemplateBase.h:48
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
PragmaMSStructKind
Definition: PragmaKinds.h:24
Wraps an ObjCPointerType with source location information.
Definition: TypeLoc.h:1198
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:379
ContinuousRangeMap< uint32_t, int, 2 > TypeRemap
Remapping table for type IDs in this module.
Selector DecodeSelector(serialization::SelectorID Idx)
Definition: ASTReader.cpp:7629
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
bool isInvalid() const
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
Represents a base class of a C++ class.
Definition: DeclCXX.h:159
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:40
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any...
Definition: ASTContext.h:958
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
Definition: ASTReader.cpp:7658
const Expr * Replacement
Definition: AttributeList.h:58
void PrintStats() override
Print some statistics about AST usage.
Definition: ASTReader.cpp:6751
void insert(const value_type &Val)
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
Metadata for a module file extension.
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3155
Keeps track of options that affect how file operations are performed.
A TypedefType record.
Definition: ASTBitCodes.h:848
static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID)
ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the specified cursor.
Definition: ASTReader.cpp:1380
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
Definition: ASTReader.cpp:5967
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
IdentifierInfo * DecodeIdentifierInfo(serialization::IdentifierID ID)
Definition: ASTReader.cpp:7459
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3157
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:614
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
Definition: ASTReader.h:160
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Canon=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getTypeOfExprType(Expr *e) const
GCC extension.
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II)
getCXXLiteralOperatorName - Get the name of the literal operator function with II as the identifier...
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:1999
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:157
void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) override
Get the decls that are contained in a file in the Offset/Length range.
Definition: ASTReader.cpp:6596
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type...
FormatToken * Current
TemplateArgumentLoc ReadTemplateArgumentLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a TemplateArgumentLoc.
Definition: ASTReader.cpp:6197
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Basic/Module.h:187
void setEnd(SourceLocation e)
TemplateArgumentLocInfo GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, const RecordData &Record, unsigned &Idx)
Reads a TemplateArgumentLocInfo appropriate for the given TemplateArgument kind.
Definition: ASTReader.cpp:6161
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
BoundNodesTreeBuilder *const Builder
Selector GetExternalSelector(serialization::SelectorID ID) override
Resolve a selector ID into a selector.
Definition: ASTReader.cpp:7654
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:142
serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a declaration ID from the given position in a record in the given module.
Definition: ASTReader.cpp:6494
static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile)
Reads and return the signature record from StreamFile's control block, or else returns 0...
Definition: ASTReader.cpp:4072
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.h:193
An TemplateTypeParmType record.
Definition: ASTBitCodes.h:874
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Basic/Module.h:227
Decl * D
The template function declaration to be late parsed.
Definition: Sema.h:9646
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
bool needsSystemInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.cpp:139
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:704
SmallVector< uint64_t, 8 > PragmaDiagMappings
Diagnostic IDs and their mappings that the user changed.
Record code for the filesystem options table.
Definition: ASTBitCodes.h:316
static hash_value_type ComputeHash(const internal_key_type &a)
Definition: ASTReader.cpp:736
Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx)
Reads a token out of a record.
Definition: ASTReader.cpp:1397
const char * IdentifierTableData
Actual data for the on-disk hash table of identifiers.
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1307
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:323
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:568
const FileEntry * getFile() const
CanQualType Char16Ty
Definition: ASTContext.h:899
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:141
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source...
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1031
const DeclOffset * DeclOffsets
Offset of each declaration within the bitstream, indexed by the declaration ID (-1).
Location information for a TemplateArgument.
Definition: TemplateBase.h:368
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
Definition: ASTReader.h:132
Record code for the offsets of each type.
Definition: ASTBitCodes.h:355
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
The block containing the definitions of all of the types and decls used within the AST file...
Definition: ASTBitCodes.h:225
The internal '__va_list_tag' struct, if any.
Definition: ASTBitCodes.h:970
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:43
virtual void ReadModuleName(StringRef ModuleName)
Definition: ASTReader.h:116
The fast qualifier mask.
Definition: Type.h:163
TypedefDecl * getCFConstantStringDecl() const
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
Definition: ASTReader.cpp:420
ASTIdentifierIterator(const ASTReader &Reader, bool SkipModules=false)
Definition: ASTReader.cpp:7031
The module file had already been loaded.
Defines the clang::TargetInfo interface.
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition: ASTReader.h:336
A SourceLocation and its associated SourceManager.
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Basic/Module.h:206
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition: MacroInfo.h:339
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1683
a linked list of methods with the same selector name but different signatures.
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1465
std::pair< ObjCMethodList, ObjCMethodList > GlobalMethods
Definition: Sema.h:991
data_type ReadData(const internal_key_type &k, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:786
Specifies a required feature.
Definition: ASTBitCodes.h:669
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
void adjustExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI, bool AsWritten=false)
Change the exception specification on a function once it is delay-parsed, instantiated, or computed.
SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID)
Returns the source location for the decl ID.
Definition: ASTReader.cpp:6357
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Basic/Module.h:279
TagDecl * getDecl() const
Definition: Type.cpp:2960
CanQualType IntTy
Definition: ASTContext.h:901
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
The AST file was written by a different version of Clang.
Definition: ASTReader.h:338
Record for offsets of DECL_UPDATES records for declarations that were modified after being deserializ...
Definition: ASTBitCodes.h:489
static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool IsSystem, bool Complain)
Definition: ASTReader.cpp:382
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
static void dumpModuleIDMap(StringRef Name, const ContinuousRangeMap< Key, ModuleFile *, InitialCapacity > &Map)
Definition: ASTReader.cpp:6852
llvm::BitstreamCursor PreprocessorDetailCursor
The cursor to the start of the (optional) detailed preprocessing record block.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
void setProtocolLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:899
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:991
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
ModuleFile * getOwningModuleFile(const Decl *D)
Retrieve the module file that owns the given declaration, or NULL if the declaration is not from a mo...
Definition: ASTReader.cpp:6349
Contains a late templated function.
Definition: Sema.h:9643
RecordDecl * getCFConstantStringTagDecl() const
Record code for weak undeclared identifiers.
Definition: ASTBitCodes.h:475
The block containing information about the preprocessor.
Definition: ASTBitCodes.h:221
TypedefDecl * getObjCSelDecl() const
Retrieve the typedef corresponding to the predefined 'SEL' type in Objective-C.
TypedefDecl * getBuiltinMSVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_ms_va_list type...
void StartTranslationUnit(ASTConsumer *Consumer) override
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
Definition: ASTReader.cpp:6741
A DecayedType record.
Definition: ASTBitCodes.h:898
void setLocation(SourceLocation L)
Definition: Token.h:131
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:80
Wrapper for source info for builtin types.
Definition: TypeLoc.h:517
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1034
A set of overloaded template declarations.
Definition: TemplateName.h:192
Wrapper for template type parameters.
Definition: TypeLoc.h:688
Record code for the headers search options table.
Definition: ASTBitCodes.h:319
Module * Other
The module that this module conflicts with.
Definition: Basic/Module.h:297
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
Definition: ASTContext.h:1520
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
Definition: ASTContext.h:1498
AST file metadata, including the AST file version number and information about the compiler used to b...
Definition: ASTBitCodes.h:262
The block of input files, which were used as inputs to create this AST file.
Definition: ASTBitCodes.h:245
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.
Present this diagnostic as a warning.
ObjCMethodList * getNext() const
llvm::BitstreamCursor MacroCursor
The cursor to the start of the preprocessor block, which stores all of the macro definitions.
const uint32_t * SelectorOffsets
Offsets into the selector lookup table's data array where each selector resides.
CanQualType BoolTy
Definition: ASTContext.h:894
void UpdateSema()
Update the state of Sema after loading some additional modules.
Definition: ASTReader.cpp:6936
unsigned LocalNumTypes
The number of types in this AST file.
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const
Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...
Definition: Diagnostic.h:667
Represents a C++ namespace alias.
Definition: DeclCXX.h:2718
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1486
Kind
The basic Objective-C runtimes that we know about.
Definition: ObjCRuntime.h:28
bool isValid() const
The internal '__NSConstantString' tag type.
Definition: ASTBitCodes.h:985
static TypeIdx fromTypeID(TypeID ID)
Definition: ASTBitCodes.h:96
serialization::DeclID mapGlobalIDToModuleFileGlobalID(ModuleFile &M, serialization::DeclID GlobalID)
Map a global declaration ID into the declaration ID used to refer to this declaration within the give...
Definition: ASTReader.cpp:6477
InputFileRecordTypes
Record types that occur within the input-files block inside the control block.
Definition: ASTBitCodes.h:336
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls) override
Read the set of unused file-scope declarations known to the external Sema source. ...
Definition: ASTReader.cpp:7268
void FinishedDeserializing() override
Notify ASTReader that we finished the deserialization of a decl or type.
Definition: ASTReader.cpp:8624
CanQualType DoubleTy
Definition: ASTContext.h:904
A function-like macro definition.
Definition: ASTBitCodes.h:619
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
~ASTReader() override
Definition: ASTReader.cpp:8738
The Objective-C 'Protocol' type.
Definition: ASTBitCodes.h:955
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, QualType Replacement) const
Retrieve a substitution-result type.
The global specifier '::'. There is no stored value.
T * getFETokenInfo() const
getFETokenInfo/setFETokenInfo - The language front-end is allowed to associate arbitrary metadata wit...
The control block, which contains all of the information that needs to be validated prior to committi...
Definition: ASTBitCodes.h:239
Wrapper for source info for pointers.
Definition: TypeLoc.h:1134
std::string Triple
If given, the name of the target triple to compile for.
Definition: TargetOptions.h:29
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1147
void ReadModuleName(StringRef ModuleName) override
Definition: ASTReader.cpp:78
This class handles loading and caching of source files into memory.
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3187
PredefinedDeclIDs
Predefined declaration IDs.
Definition: ASTBitCodes.h:938
Record code for an update to the TU's lexically contained declarations.
Definition: ASTBitCodes.h:467
A class which abstracts out some details necessary for making a call.
Definition: Type.h:2904
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1730
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:187
void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override
This is called for each AST file loaded.
Definition: ASTReader.cpp:143
const serialization::ObjCCategoriesInfo * ObjCCategoriesMap
Array of category list location information within this module file, sorted by the definition ID...
bool loadGlobalIndex()
Attempts to load the global index.
Definition: ASTReader.cpp:3407
void startToken()
Reset all flags to cleared.
Definition: Token.h:168
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
Definition: ASTReader.cpp:7574
Objective-C "Class" redefinition type.
Definition: ASTBitCodes.h:922
A PackExpansionType record.
Definition: ASTBitCodes.h:886
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
Definition: ASTReader.cpp:7300
A single template declaration.
Definition: TemplateName.h:190
CanQualType OCLClkEventTy
Definition: ASTContext.h:917
The pseudo-object placeholder type.
Definition: ASTBitCodes.h:780
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:163
virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain)
Receives the diagnostic options.
Definition: ASTReader.h:142
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Basic/Module.h:191
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:583
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
Definition: ASTReader.cpp:8223
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:97
A DependentTemplateSpecializationType record.
Definition: ASTBitCodes.h:880
CanQualType UnsignedIntTy
Definition: ASTContext.h:902
bool ParseAllComments
Treat ordinary comments as documentation comments.
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, unsigned LocalID)
Definition: ASTReader.cpp:7498
Record code for the array of tentative definitions.
Definition: ASTBitCodes.h:420
static void addMethodsToPool(Sema &S, ArrayRef< ObjCMethodDecl * > Methods, ObjCMethodList &List)
Add the given set of methods to the method list.
Definition: ASTReader.cpp:7173
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
getCXXOperatorName - Get the name of the overloadable C++ operator corresponding to Op...
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:1766
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.