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