clang  8.0.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"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/DeclBase.h"
23 #include "clang/AST/DeclCXX.h"
24 #include "clang/AST/DeclFriend.h"
25 #include "clang/AST/DeclGroup.h"
26 #include "clang/AST/DeclObjC.h"
27 #include "clang/AST/DeclTemplate.h"
29 #include "clang/AST/Expr.h"
30 #include "clang/AST/ExprCXX.h"
33 #include "clang/AST/ODRHash.h"
35 #include "clang/AST/TemplateBase.h"
36 #include "clang/AST/TemplateName.h"
37 #include "clang/AST/Type.h"
38 #include "clang/AST/TypeLoc.h"
42 #include "clang/Basic/Diagnostic.h"
48 #include "clang/Basic/LLVM.h"
51 #include "clang/Basic/Module.h"
55 #include "clang/Basic/Sanitizers.h"
59 #include "clang/Basic/Specifiers.h"
60 #include "clang/Basic/TargetInfo.h"
62 #include "clang/Basic/TokenKinds.h"
63 #include "clang/Basic/Version.h"
64 #include "clang/Lex/HeaderSearch.h"
66 #include "clang/Lex/MacroInfo.h"
67 #include "clang/Lex/ModuleMap.h"
69 #include "clang/Lex/Preprocessor.h"
71 #include "clang/Lex/Token.h"
73 #include "clang/Sema/Scope.h"
74 #include "clang/Sema/Sema.h"
75 #include "clang/Sema/Weak.h"
85 #include "llvm/ADT/APFloat.h"
86 #include "llvm/ADT/APInt.h"
87 #include "llvm/ADT/APSInt.h"
88 #include "llvm/ADT/ArrayRef.h"
89 #include "llvm/ADT/DenseMap.h"
90 #include "llvm/ADT/FoldingSet.h"
91 #include "llvm/ADT/Hashing.h"
92 #include "llvm/ADT/IntrusiveRefCntPtr.h"
93 #include "llvm/ADT/None.h"
94 #include "llvm/ADT/Optional.h"
95 #include "llvm/ADT/STLExtras.h"
96 #include "llvm/ADT/SmallPtrSet.h"
97 #include "llvm/ADT/SmallString.h"
98 #include "llvm/ADT/SmallVector.h"
99 #include "llvm/ADT/StringExtras.h"
100 #include "llvm/ADT/StringMap.h"
101 #include "llvm/ADT/StringRef.h"
102 #include "llvm/ADT/Triple.h"
103 #include "llvm/ADT/iterator_range.h"
104 #include "llvm/Bitcode/BitstreamReader.h"
105 #include "llvm/Support/Casting.h"
106 #include "llvm/Support/Compiler.h"
107 #include "llvm/Support/Compression.h"
108 #include "llvm/Support/DJB.h"
109 #include "llvm/Support/Endian.h"
110 #include "llvm/Support/Error.h"
111 #include "llvm/Support/ErrorHandling.h"
112 #include "llvm/Support/FileSystem.h"
113 #include "llvm/Support/MemoryBuffer.h"
114 #include "llvm/Support/Path.h"
115 #include "llvm/Support/SaveAndRestore.h"
116 #include "llvm/Support/Timer.h"
117 #include "llvm/Support/VersionTuple.h"
118 #include "llvm/Support/raw_ostream.h"
119 #include <algorithm>
120 #include <cassert>
121 #include <cstddef>
122 #include <cstdint>
123 #include <cstdio>
124 #include <ctime>
125 #include <iterator>
126 #include <limits>
127 #include <map>
128 #include <memory>
129 #include <string>
130 #include <system_error>
131 #include <tuple>
132 #include <utility>
133 #include <vector>
134 
135 using namespace clang;
136 using namespace clang::serialization;
137 using namespace clang::serialization::reader;
138 using llvm::BitstreamCursor;
139 
140 //===----------------------------------------------------------------------===//
141 // ChainedASTReaderListener implementation
142 //===----------------------------------------------------------------------===//
143 
144 bool
146  return First->ReadFullVersionInformation(FullVersion) ||
147  Second->ReadFullVersionInformation(FullVersion);
148 }
149 
150 void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) {
151  First->ReadModuleName(ModuleName);
152  Second->ReadModuleName(ModuleName);
153 }
154 
155 void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) {
156  First->ReadModuleMapFile(ModuleMapPath);
157  Second->ReadModuleMapFile(ModuleMapPath);
158 }
159 
160 bool
162  bool Complain,
163  bool AllowCompatibleDifferences) {
164  return First->ReadLanguageOptions(LangOpts, Complain,
165  AllowCompatibleDifferences) ||
166  Second->ReadLanguageOptions(LangOpts, Complain,
167  AllowCompatibleDifferences);
168 }
169 
171  const TargetOptions &TargetOpts, bool Complain,
172  bool AllowCompatibleDifferences) {
173  return First->ReadTargetOptions(TargetOpts, Complain,
174  AllowCompatibleDifferences) ||
175  Second->ReadTargetOptions(TargetOpts, Complain,
176  AllowCompatibleDifferences);
177 }
178 
180  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) {
181  return First->ReadDiagnosticOptions(DiagOpts, Complain) ||
182  Second->ReadDiagnosticOptions(DiagOpts, Complain);
183 }
184 
185 bool
187  bool Complain) {
188  return First->ReadFileSystemOptions(FSOpts, Complain) ||
189  Second->ReadFileSystemOptions(FSOpts, Complain);
190 }
191 
193  const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath,
194  bool Complain) {
195  return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
196  Complain) ||
197  Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
198  Complain);
199 }
200 
202  const PreprocessorOptions &PPOpts, bool Complain,
203  std::string &SuggestedPredefines) {
204  return First->ReadPreprocessorOptions(PPOpts, Complain,
205  SuggestedPredefines) ||
206  Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines);
207 }
208 
210  unsigned Value) {
211  First->ReadCounter(M, Value);
212  Second->ReadCounter(M, Value);
213 }
214 
216  return First->needsInputFileVisitation() ||
217  Second->needsInputFileVisitation();
218 }
219 
221  return First->needsSystemInputFileVisitation() ||
222  Second->needsSystemInputFileVisitation();
223 }
224 
226  ModuleKind Kind) {
227  First->visitModuleFile(Filename, Kind);
228  Second->visitModuleFile(Filename, Kind);
229 }
230 
232  bool isSystem,
233  bool isOverridden,
234  bool isExplicitModule) {
235  bool Continue = false;
236  if (First->needsInputFileVisitation() &&
237  (!isSystem || First->needsSystemInputFileVisitation()))
238  Continue |= First->visitInputFile(Filename, isSystem, isOverridden,
239  isExplicitModule);
240  if (Second->needsInputFileVisitation() &&
241  (!isSystem || Second->needsSystemInputFileVisitation()))
242  Continue |= Second->visitInputFile(Filename, isSystem, isOverridden,
243  isExplicitModule);
244  return Continue;
245 }
246 
248  const ModuleFileExtensionMetadata &Metadata) {
249  First->readModuleFileExtension(Metadata);
250  Second->readModuleFileExtension(Metadata);
251 }
252 
253 //===----------------------------------------------------------------------===//
254 // PCH validator implementation
255 //===----------------------------------------------------------------------===//
256 
258 
259 /// Compare the given set of language options against an existing set of
260 /// language options.
261 ///
262 /// \param Diags If non-NULL, diagnostics will be emitted via this engine.
263 /// \param AllowCompatibleDifferences If true, differences between compatible
264 /// language options will be permitted.
265 ///
266 /// \returns true if the languagae options mis-match, false otherwise.
267 static bool checkLanguageOptions(const LangOptions &LangOpts,
268  const LangOptions &ExistingLangOpts,
269  DiagnosticsEngine *Diags,
270  bool AllowCompatibleDifferences = true) {
271 #define LANGOPT(Name, Bits, Default, Description) \
272  if (ExistingLangOpts.Name != LangOpts.Name) { \
273  if (Diags) \
274  Diags->Report(diag::err_pch_langopt_mismatch) \
275  << Description << LangOpts.Name << ExistingLangOpts.Name; \
276  return true; \
277  }
278 
279 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
280  if (ExistingLangOpts.Name != LangOpts.Name) { \
281  if (Diags) \
282  Diags->Report(diag::err_pch_langopt_value_mismatch) \
283  << Description; \
284  return true; \
285  }
286 
287 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
288  if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \
289  if (Diags) \
290  Diags->Report(diag::err_pch_langopt_value_mismatch) \
291  << Description; \
292  return true; \
293  }
294 
295 #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \
296  if (!AllowCompatibleDifferences) \
297  LANGOPT(Name, Bits, Default, Description)
298 
299 #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \
300  if (!AllowCompatibleDifferences) \
301  ENUM_LANGOPT(Name, Bits, Default, Description)
302 
303 #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \
304  if (!AllowCompatibleDifferences) \
305  VALUE_LANGOPT(Name, Bits, Default, Description)
306 
307 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
308 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
309 #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description)
310 #include "clang/Basic/LangOptions.def"
311 
312  if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) {
313  if (Diags)
314  Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features";
315  return true;
316  }
317 
318  if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) {
319  if (Diags)
320  Diags->Report(diag::err_pch_langopt_value_mismatch)
321  << "target Objective-C runtime";
322  return true;
323  }
324 
325  if (ExistingLangOpts.CommentOpts.BlockCommandNames !=
326  LangOpts.CommentOpts.BlockCommandNames) {
327  if (Diags)
328  Diags->Report(diag::err_pch_langopt_value_mismatch)
329  << "block command names";
330  return true;
331  }
332 
333  // Sanitizer feature mismatches are treated as compatible differences. If
334  // compatible differences aren't allowed, we still only want to check for
335  // mismatches of non-modular sanitizers (the only ones which can affect AST
336  // generation).
337  if (!AllowCompatibleDifferences) {
338  SanitizerMask ModularSanitizers = getPPTransparentSanitizers();
339  SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize;
340  SanitizerSet ImportedSanitizers = LangOpts.Sanitize;
341  ExistingSanitizers.clear(ModularSanitizers);
342  ImportedSanitizers.clear(ModularSanitizers);
343  if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) {
344  const std::string Flag = "-fsanitize=";
345  if (Diags) {
346 #define SANITIZER(NAME, ID) \
347  { \
348  bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \
349  bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \
350  if (InExistingModule != InImportedModule) \
351  Diags->Report(diag::err_pch_targetopt_feature_mismatch) \
352  << InExistingModule << (Flag + NAME); \
353  }
354 #include "clang/Basic/Sanitizers.def"
355  }
356  return true;
357  }
358  }
359 
360  return false;
361 }
362 
363 /// Compare the given set of target options against an existing set of
364 /// target options.
365 ///
366 /// \param Diags If non-NULL, diagnostics will be emitted via this engine.
367 ///
368 /// \returns true if the target options mis-match, false otherwise.
369 static bool checkTargetOptions(const TargetOptions &TargetOpts,
370  const TargetOptions &ExistingTargetOpts,
371  DiagnosticsEngine *Diags,
372  bool AllowCompatibleDifferences = true) {
373 #define CHECK_TARGET_OPT(Field, Name) \
374  if (TargetOpts.Field != ExistingTargetOpts.Field) { \
375  if (Diags) \
376  Diags->Report(diag::err_pch_targetopt_mismatch) \
377  << Name << TargetOpts.Field << ExistingTargetOpts.Field; \
378  return true; \
379  }
380 
381  // The triple and ABI must match exactly.
382  CHECK_TARGET_OPT(Triple, "target");
383  CHECK_TARGET_OPT(ABI, "target ABI");
384 
385  // We can tolerate different CPUs in many cases, notably when one CPU
386  // supports a strict superset of another. When allowing compatible
387  // differences skip this check.
388  if (!AllowCompatibleDifferences)
389  CHECK_TARGET_OPT(CPU, "target CPU");
390 
391 #undef CHECK_TARGET_OPT
392 
393  // Compare feature sets.
394  SmallVector<StringRef, 4> ExistingFeatures(
395  ExistingTargetOpts.FeaturesAsWritten.begin(),
396  ExistingTargetOpts.FeaturesAsWritten.end());
397  SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(),
398  TargetOpts.FeaturesAsWritten.end());
399  llvm::sort(ExistingFeatures);
400  llvm::sort(ReadFeatures);
401 
402  // We compute the set difference in both directions explicitly so that we can
403  // diagnose the differences differently.
404  SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures;
405  std::set_difference(
406  ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(),
407  ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures));
408  std::set_difference(ReadFeatures.begin(), ReadFeatures.end(),
409  ExistingFeatures.begin(), ExistingFeatures.end(),
410  std::back_inserter(UnmatchedReadFeatures));
411 
412  // If we are allowing compatible differences and the read feature set is
413  // a strict subset of the existing feature set, there is nothing to diagnose.
414  if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty())
415  return false;
416 
417  if (Diags) {
418  for (StringRef Feature : UnmatchedReadFeatures)
419  Diags->Report(diag::err_pch_targetopt_feature_mismatch)
420  << /* is-existing-feature */ false << Feature;
421  for (StringRef Feature : UnmatchedExistingFeatures)
422  Diags->Report(diag::err_pch_targetopt_feature_mismatch)
423  << /* is-existing-feature */ true << Feature;
424  }
425 
426  return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty();
427 }
428 
429 bool
431  bool Complain,
432  bool AllowCompatibleDifferences) {
433  const LangOptions &ExistingLangOpts = PP.getLangOpts();
434  return checkLanguageOptions(LangOpts, ExistingLangOpts,
435  Complain ? &Reader.Diags : nullptr,
436  AllowCompatibleDifferences);
437 }
438 
440  bool Complain,
441  bool AllowCompatibleDifferences) {
442  const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts();
443  return checkTargetOptions(TargetOpts, ExistingTargetOpts,
444  Complain ? &Reader.Diags : nullptr,
445  AllowCompatibleDifferences);
446 }
447 
448 namespace {
449 
450 using MacroDefinitionsMap =
451  llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>;
452 using DeclsMap = llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8>>;
453 
454 } // namespace
455 
457  DiagnosticsEngine &Diags,
458  bool Complain) {
460 
461  // Check current mappings for new -Werror mappings, and the stored mappings
462  // for cases that were explicitly mapped to *not* be errors that are now
463  // errors because of options like -Werror.
464  DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags };
465 
466  for (DiagnosticsEngine *MappingSource : MappingSources) {
467  for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) {
468  diag::kind DiagID = DiagIDMappingPair.first;
469  Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation());
470  if (CurLevel < DiagnosticsEngine::Error)
471  continue; // not significant
472  Level StoredLevel =
473  StoredDiags.getDiagnosticLevel(DiagID, SourceLocation());
474  if (StoredLevel < DiagnosticsEngine::Error) {
475  if (Complain)
476  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" +
477  Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str();
478  return true;
479  }
480  }
481  }
482 
483  return false;
484 }
485 
488  if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors())
489  return true;
490  return Ext >= diag::Severity::Error;
491 }
492 
494  DiagnosticsEngine &Diags,
495  bool IsSystem, bool Complain) {
496  // Top-level options
497  if (IsSystem) {
498  if (Diags.getSuppressSystemWarnings())
499  return false;
500  // If -Wsystem-headers was not enabled before, be conservative
501  if (StoredDiags.getSuppressSystemWarnings()) {
502  if (Complain)
503  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers";
504  return true;
505  }
506  }
507 
508  if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) {
509  if (Complain)
510  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror";
511  return true;
512  }
513 
514  if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() &&
515  !StoredDiags.getEnableAllWarnings()) {
516  if (Complain)
517  Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror";
518  return true;
519  }
520 
521  if (isExtHandlingFromDiagsError(Diags) &&
522  !isExtHandlingFromDiagsError(StoredDiags)) {
523  if (Complain)
524  Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors";
525  return true;
526  }
527 
528  return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain);
529 }
530 
531 /// Return the top import module if it is implicit, nullptr otherwise.
533  Preprocessor &PP) {
534  // If the original import came from a file explicitly generated by the user,
535  // don't check the diagnostic mappings.
536  // FIXME: currently this is approximated by checking whether this is not a
537  // module import of an implicitly-loaded module file.
538  // Note: ModuleMgr.rbegin() may not be the current module, but it must be in
539  // the transitive closure of its imports, since unrelated modules cannot be
540  // imported until after this module finishes validation.
541  ModuleFile *TopImport = &*ModuleMgr.rbegin();
542  while (!TopImport->ImportedBy.empty())
543  TopImport = TopImport->ImportedBy[0];
544  if (TopImport->Kind != MK_ImplicitModule)
545  return nullptr;
546 
547  StringRef ModuleName = TopImport->ModuleName;
548  assert(!ModuleName.empty() && "diagnostic options read before module name");
549 
550  Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName);
551  assert(M && "missing module");
552  return M;
553 }
554 
556  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) {
557  DiagnosticsEngine &ExistingDiags = PP.getDiagnostics();
558  IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs());
560  new DiagnosticsEngine(DiagIDs, DiagOpts.get()));
561  // This should never fail, because we would have processed these options
562  // before writing them to an ASTFile.
563  ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false);
564 
565  ModuleManager &ModuleMgr = Reader.getModuleManager();
566  assert(ModuleMgr.size() >= 1 && "what ASTFile is this then");
567 
568  Module *TopM = getTopImportImplicitModule(ModuleMgr, PP);
569  if (!TopM)
570  return false;
571 
572  // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that
573  // contains the union of their flags.
574  return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem,
575  Complain);
576 }
577 
578 /// Collect the macro definitions provided by the given preprocessor
579 /// options.
580 static void
582  MacroDefinitionsMap &Macros,
583  SmallVectorImpl<StringRef> *MacroNames = nullptr) {
584  for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) {
585  StringRef Macro = PPOpts.Macros[I].first;
586  bool IsUndef = PPOpts.Macros[I].second;
587 
588  std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
589  StringRef MacroName = MacroPair.first;
590  StringRef MacroBody = MacroPair.second;
591 
592  // For an #undef'd macro, we only care about the name.
593  if (IsUndef) {
594  if (MacroNames && !Macros.count(MacroName))
595  MacroNames->push_back(MacroName);
596 
597  Macros[MacroName] = std::make_pair("", true);
598  continue;
599  }
600 
601  // For a #define'd macro, figure out the actual definition.
602  if (MacroName.size() == Macro.size())
603  MacroBody = "1";
604  else {
605  // Note: GCC drops anything following an end-of-line character.
606  StringRef::size_type End = MacroBody.find_first_of("\n\r");
607  MacroBody = MacroBody.substr(0, End);
608  }
609 
610  if (MacroNames && !Macros.count(MacroName))
611  MacroNames->push_back(MacroName);
612  Macros[MacroName] = std::make_pair(MacroBody, false);
613  }
614 }
615 
616 /// Check the preprocessor options deserialized from the control block
617 /// against the preprocessor options in an existing preprocessor.
618 ///
619 /// \param Diags If non-null, produce diagnostics for any mismatches incurred.
620 /// \param Validate If true, validate preprocessor options. If false, allow
621 /// macros defined by \p ExistingPPOpts to override those defined by
622 /// \p PPOpts in SuggestedPredefines.
624  const PreprocessorOptions &ExistingPPOpts,
625  DiagnosticsEngine *Diags,
626  FileManager &FileMgr,
627  std::string &SuggestedPredefines,
628  const LangOptions &LangOpts,
629  bool Validate = true) {
630  // Check macro definitions.
631  MacroDefinitionsMap ASTFileMacros;
632  collectMacroDefinitions(PPOpts, ASTFileMacros);
633  MacroDefinitionsMap ExistingMacros;
634  SmallVector<StringRef, 4> ExistingMacroNames;
635  collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
636 
637  for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
638  // Dig out the macro definition in the existing preprocessor options.
639  StringRef MacroName = ExistingMacroNames[I];
640  std::pair<StringRef, bool> Existing = ExistingMacros[MacroName];
641 
642  // Check whether we know anything about this macro name or not.
643  llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>::iterator Known =
644  ASTFileMacros.find(MacroName);
645  if (!Validate || Known == ASTFileMacros.end()) {
646  // FIXME: Check whether this identifier was referenced anywhere in the
647  // AST file. If so, we should reject the AST file. Unfortunately, this
648  // information isn't in the control block. What shall we do about it?
649 
650  if (Existing.second) {
651  SuggestedPredefines += "#undef ";
652  SuggestedPredefines += MacroName.str();
653  SuggestedPredefines += '\n';
654  } else {
655  SuggestedPredefines += "#define ";
656  SuggestedPredefines += MacroName.str();
657  SuggestedPredefines += ' ';
658  SuggestedPredefines += Existing.first.str();
659  SuggestedPredefines += '\n';
660  }
661  continue;
662  }
663 
664  // If the macro was defined in one but undef'd in the other, we have a
665  // conflict.
666  if (Existing.second != Known->second.second) {
667  if (Diags) {
668  Diags->Report(diag::err_pch_macro_def_undef)
669  << MacroName << Known->second.second;
670  }
671  return true;
672  }
673 
674  // If the macro was #undef'd in both, or if the macro bodies are identical,
675  // it's fine.
676  if (Existing.second || Existing.first == Known->second.first)
677  continue;
678 
679  // The macro bodies differ; complain.
680  if (Diags) {
681  Diags->Report(diag::err_pch_macro_def_conflict)
682  << MacroName << Known->second.first << Existing.first;
683  }
684  return true;
685  }
686 
687  // Check whether we're using predefines.
688  if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) {
689  if (Diags) {
690  Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines;
691  }
692  return true;
693  }
694 
695  // Detailed record is important since it is used for the module cache hash.
696  if (LangOpts.Modules &&
697  PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) {
698  if (Diags) {
699  Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord;
700  }
701  return true;
702  }
703 
704  // Compute the #include and #include_macros lines we need.
705  for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) {
706  StringRef File = ExistingPPOpts.Includes[I];
707 
708  if (!ExistingPPOpts.ImplicitPCHInclude.empty() &&
709  !ExistingPPOpts.PCHThroughHeader.empty()) {
710  // In case the through header is an include, we must add all the includes
711  // to the predefines so the start point can be determined.
712  SuggestedPredefines += "#include \"";
713  SuggestedPredefines += File;
714  SuggestedPredefines += "\"\n";
715  continue;
716  }
717 
718  if (File == ExistingPPOpts.ImplicitPCHInclude)
719  continue;
720 
721  if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File)
722  != PPOpts.Includes.end())
723  continue;
724 
725  SuggestedPredefines += "#include \"";
726  SuggestedPredefines += File;
727  SuggestedPredefines += "\"\n";
728  }
729 
730  for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) {
731  StringRef File = ExistingPPOpts.MacroIncludes[I];
732  if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(),
733  File)
734  != PPOpts.MacroIncludes.end())
735  continue;
736 
737  SuggestedPredefines += "#__include_macros \"";
738  SuggestedPredefines += File;
739  SuggestedPredefines += "\"\n##\n";
740  }
741 
742  return false;
743 }
744 
746  bool Complain,
747  std::string &SuggestedPredefines) {
748  const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts();
749 
750  return checkPreprocessorOptions(PPOpts, ExistingPPOpts,
751  Complain? &Reader.Diags : nullptr,
752  PP.getFileManager(),
753  SuggestedPredefines,
754  PP.getLangOpts());
755 }
756 
758  const PreprocessorOptions &PPOpts,
759  bool Complain,
760  std::string &SuggestedPredefines) {
761  return checkPreprocessorOptions(PPOpts,
762  PP.getPreprocessorOpts(),
763  nullptr,
764  PP.getFileManager(),
765  SuggestedPredefines,
766  PP.getLangOpts(),
767  false);
768 }
769 
770 /// Check the header search options deserialized from the control block
771 /// against the header search options in an existing preprocessor.
772 ///
773 /// \param Diags If non-null, produce diagnostics for any mismatches incurred.
775  StringRef SpecificModuleCachePath,
776  StringRef ExistingModuleCachePath,
777  DiagnosticsEngine *Diags,
778  const LangOptions &LangOpts) {
779  if (LangOpts.Modules) {
780  if (SpecificModuleCachePath != ExistingModuleCachePath) {
781  if (Diags)
782  Diags->Report(diag::err_pch_modulecache_mismatch)
783  << SpecificModuleCachePath << ExistingModuleCachePath;
784  return true;
785  }
786  }
787 
788  return false;
789 }
790 
792  StringRef SpecificModuleCachePath,
793  bool Complain) {
794  return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
795  PP.getHeaderSearchInfo().getModuleCachePath(),
796  Complain ? &Reader.Diags : nullptr,
797  PP.getLangOpts());
798 }
799 
800 void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) {
801  PP.setCounterValue(Value);
802 }
803 
804 //===----------------------------------------------------------------------===//
805 // AST reader implementation
806 //===----------------------------------------------------------------------===//
807 
809  bool TakeOwnership) {
810  DeserializationListener = Listener;
811  OwnsDeserializationListener = TakeOwnership;
812 }
813 
815  return serialization::ComputeHash(Sel);
816 }
817 
818 std::pair<unsigned, unsigned>
820  using namespace llvm::support;
821 
822  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
823  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
824  return std::make_pair(KeyLen, DataLen);
825 }
826 
828 ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
829  using namespace llvm::support;
830 
831  SelectorTable &SelTable = Reader.getContext().Selectors;
832  unsigned N = endian::readNext<uint16_t, little, unaligned>(d);
833  IdentifierInfo *FirstII = Reader.getLocalIdentifier(
834  F, endian::readNext<uint32_t, little, unaligned>(d));
835  if (N == 0)
836  return SelTable.getNullarySelector(FirstII);
837  else if (N == 1)
838  return SelTable.getUnarySelector(FirstII);
839 
841  Args.push_back(FirstII);
842  for (unsigned I = 1; I != N; ++I)
843  Args.push_back(Reader.getLocalIdentifier(
844  F, endian::readNext<uint32_t, little, unaligned>(d)));
845 
846  return SelTable.getSelector(N, Args.data());
847 }
848 
851  unsigned DataLen) {
852  using namespace llvm::support;
853 
854  data_type Result;
855 
856  Result.ID = Reader.getGlobalSelectorID(
857  F, endian::readNext<uint32_t, little, unaligned>(d));
858  unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d);
859  unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d);
860  Result.InstanceBits = FullInstanceBits & 0x3;
861  Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1;
862  Result.FactoryBits = FullFactoryBits & 0x3;
863  Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1;
864  unsigned NumInstanceMethods = FullInstanceBits >> 3;
865  unsigned NumFactoryMethods = FullFactoryBits >> 3;
866 
867  // Load instance methods
868  for (unsigned I = 0; I != NumInstanceMethods; ++I) {
869  if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
870  F, endian::readNext<uint32_t, little, unaligned>(d)))
871  Result.Instance.push_back(Method);
872  }
873 
874  // Load factory methods
875  for (unsigned I = 0; I != NumFactoryMethods; ++I) {
876  if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
877  F, endian::readNext<uint32_t, little, unaligned>(d)))
878  Result.Factory.push_back(Method);
879  }
880 
881  return Result;
882 }
883 
885  return llvm::djbHash(a);
886 }
887 
888 std::pair<unsigned, unsigned>
890  using namespace llvm::support;
891 
892  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
893  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
894  return std::make_pair(KeyLen, DataLen);
895 }
896 
898 ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) {
899  assert(n >= 2 && d[n-1] == '\0');
900  return StringRef((const char*) d, n-1);
901 }
902 
903 /// Whether the given identifier is "interesting".
905  bool IsModule) {
906  return II.hadMacroDefinition() ||
907  II.isPoisoned() ||
908  (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) ||
910  (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) &&
911  II.getFETokenInfo());
912 }
913 
914 static bool readBit(unsigned &Bits) {
915  bool Value = Bits & 0x1;
916  Bits >>= 1;
917  return Value;
918 }
919 
921  using namespace llvm::support;
922 
923  unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
924  return Reader.getGlobalIdentifierID(F, RawID >> 1);
925 }
926 
927 static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) {
928  if (!II.isFromAST()) {
929  II.setIsFromAST();
930  bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr;
931  if (isInterestingIdentifier(Reader, II, IsModule))
933  }
934 }
935 
937  const unsigned char* d,
938  unsigned DataLen) {
939  using namespace llvm::support;
940 
941  unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
942  bool IsInteresting = RawID & 0x01;
943 
944  // Wipe out the "is interesting" bit.
945  RawID = RawID >> 1;
946 
947  // Build the IdentifierInfo and link the identifier ID with it.
948  IdentifierInfo *II = KnownII;
949  if (!II) {
950  II = &Reader.getIdentifierTable().getOwn(k);
951  KnownII = II;
952  }
953  markIdentifierFromAST(Reader, *II);
954  Reader.markIdentifierUpToDate(II);
955 
956  IdentID ID = Reader.getGlobalIdentifierID(F, RawID);
957  if (!IsInteresting) {
958  // For uninteresting identifiers, there's nothing else to do. Just notify
959  // the reader that we've finished loading this identifier.
960  Reader.SetIdentifierInfo(ID, II);
961  return II;
962  }
963 
964  unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d);
965  unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d);
966  bool CPlusPlusOperatorKeyword = readBit(Bits);
967  bool HasRevertedTokenIDToIdentifier = readBit(Bits);
968  bool HasRevertedBuiltin = readBit(Bits);
969  bool Poisoned = readBit(Bits);
970  bool ExtensionToken = readBit(Bits);
971  bool HadMacroDefinition = readBit(Bits);
972 
973  assert(Bits == 0 && "Extra bits in the identifier?");
974  DataLen -= 8;
975 
976  // Set or check the various bits in the IdentifierInfo structure.
977  // Token IDs are read-only.
978  if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier)
980  if (!F.isModule())
981  II->setObjCOrBuiltinID(ObjCOrBuiltinID);
982  else if (HasRevertedBuiltin && II->getBuiltinID()) {
983  II->revertBuiltin();
984  assert((II->hasRevertedBuiltin() ||
985  II->getObjCOrBuiltinID() == ObjCOrBuiltinID) &&
986  "Incorrect ObjC keyword or builtin ID");
987  }
988  assert(II->isExtensionToken() == ExtensionToken &&
989  "Incorrect extension token flag");
990  (void)ExtensionToken;
991  if (Poisoned)
992  II->setIsPoisoned(true);
993  assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword &&
994  "Incorrect C++ operator keyword flag");
995  (void)CPlusPlusOperatorKeyword;
996 
997  // If this identifier is a macro, deserialize the macro
998  // definition.
999  if (HadMacroDefinition) {
1000  uint32_t MacroDirectivesOffset =
1001  endian::readNext<uint32_t, little, unaligned>(d);
1002  DataLen -= 4;
1003 
1004  Reader.addPendingMacro(II, &F, MacroDirectivesOffset);
1005  }
1006 
1007  Reader.SetIdentifierInfo(ID, II);
1008 
1009  // Read all of the declarations visible at global scope with this
1010  // name.
1011  if (DataLen > 0) {
1012  SmallVector<uint32_t, 4> DeclIDs;
1013  for (; DataLen > 0; DataLen -= 4)
1014  DeclIDs.push_back(Reader.getGlobalDeclID(
1015  F, endian::readNext<uint32_t, little, unaligned>(d)));
1016  Reader.SetGloballyVisibleDecls(II, DeclIDs);
1017  }
1018 
1019  return II;
1020 }
1021 
1023  : Kind(Name.getNameKind()) {
1024  switch (Kind) {
1026  Data = (uint64_t)Name.getAsIdentifierInfo();
1027  break;
1031  Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr();
1032  break;
1034  Data = Name.getCXXOverloadedOperator();
1035  break;
1037  Data = (uint64_t)Name.getCXXLiteralIdentifier();
1038  break;
1040  Data = (uint64_t)Name.getCXXDeductionGuideTemplate()
1042  break;
1047  Data = 0;
1048  break;
1049  }
1050 }
1051 
1053  llvm::FoldingSetNodeID ID;
1054  ID.AddInteger(Kind);
1055 
1056  switch (Kind) {
1060  ID.AddString(((IdentifierInfo*)Data)->getName());
1061  break;
1065  ID.AddInteger(serialization::ComputeHash(Selector(Data)));
1066  break;
1068  ID.AddInteger((OverloadedOperatorKind)Data);
1069  break;
1074  break;
1075  }
1076 
1077  return ID.ComputeHash();
1078 }
1079 
1080 ModuleFile *
1081 ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) {
1082  using namespace llvm::support;
1083 
1084  uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d);
1085  return Reader.getLocalModuleFile(F, ModuleFileID);
1086 }
1087 
1088 std::pair<unsigned, unsigned>
1089 ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) {
1090  using namespace llvm::support;
1091 
1092  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
1093  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
1094  return std::make_pair(KeyLen, DataLen);
1095 }
1096 
1098 ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
1099  using namespace llvm::support;
1100 
1101  auto Kind = (DeclarationName::NameKind)*d++;
1102  uint64_t Data;
1103  switch (Kind) {
1107  Data = (uint64_t)Reader.getLocalIdentifier(
1108  F, endian::readNext<uint32_t, little, unaligned>(d));
1109  break;
1113  Data =
1114  (uint64_t)Reader.getLocalSelector(
1115  F, endian::readNext<uint32_t, little, unaligned>(
1116  d)).getAsOpaquePtr();
1117  break;
1119  Data = *d++; // OverloadedOperatorKind
1120  break;
1125  Data = 0;
1126  break;
1127  }
1128 
1129  return DeclarationNameKey(Kind, Data);
1130 }
1131 
1132 void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type,
1133  const unsigned char *d,
1134  unsigned DataLen,
1135  data_type_builder &Val) {
1136  using namespace llvm::support;
1137 
1138  for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) {
1139  uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d);
1140  Val.insert(Reader.getGlobalDeclID(F, LocalID));
1141  }
1142 }
1143 
1144 bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
1145  BitstreamCursor &Cursor,
1146  uint64_t Offset,
1147  DeclContext *DC) {
1148  assert(Offset != 0);
1149 
1150  SavedStreamPosition SavedPosition(Cursor);
1151  Cursor.JumpToBit(Offset);
1152 
1153  RecordData Record;
1154  StringRef Blob;
1155  unsigned Code = Cursor.ReadCode();
1156  unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
1157  if (RecCode != DECL_CONTEXT_LEXICAL) {
1158  Error("Expected lexical block");
1159  return true;
1160  }
1161 
1162  assert(!isa<TranslationUnitDecl>(DC) &&
1163  "expected a TU_UPDATE_LEXICAL record for TU");
1164  // If we are handling a C++ class template instantiation, we can see multiple
1165  // lexical updates for the same record. It's important that we select only one
1166  // of them, so that field numbering works properly. Just pick the first one we
1167  // see.
1168  auto &Lex = LexicalDecls[DC];
1169  if (!Lex.first) {
1170  Lex = std::make_pair(
1171  &M, llvm::makeArrayRef(
1172  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
1173  Blob.data()),
1174  Blob.size() / 4));
1175  }
1176  DC->setHasExternalLexicalStorage(true);
1177  return false;
1178 }
1179 
1180 bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
1181  BitstreamCursor &Cursor,
1182  uint64_t Offset,
1183  DeclID ID) {
1184  assert(Offset != 0);
1185 
1186  SavedStreamPosition SavedPosition(Cursor);
1187  Cursor.JumpToBit(Offset);
1188 
1189  RecordData Record;
1190  StringRef Blob;
1191  unsigned Code = Cursor.ReadCode();
1192  unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
1193  if (RecCode != DECL_CONTEXT_VISIBLE) {
1194  Error("Expected visible lookup table block");
1195  return true;
1196  }
1197 
1198  // We can't safely determine the primary context yet, so delay attaching the
1199  // lookup table until we're done with recursive deserialization.
1200  auto *Data = (const unsigned char*)Blob.data();
1201  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data});
1202  return false;
1203 }
1204 
1205 void ASTReader::Error(StringRef Msg) const {
1206  Error(diag::err_fe_pch_malformed, Msg);
1207  if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() &&
1208  !PP.getHeaderSearchInfo().getModuleCachePath().empty()) {
1209  Diag(diag::note_module_cache_path)
1210  << PP.getHeaderSearchInfo().getModuleCachePath();
1211  }
1212 }
1213 
1214 void ASTReader::Error(unsigned DiagID,
1215  StringRef Arg1, StringRef Arg2) const {
1216  if (Diags.isDiagnosticInFlight())
1217  Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2);
1218  else
1219  Diag(DiagID) << Arg1 << Arg2;
1220 }
1221 
1222 //===----------------------------------------------------------------------===//
1223 // Source Manager Deserialization
1224 //===----------------------------------------------------------------------===//
1225 
1226 /// Read the line table in the source manager block.
1227 /// \returns true if there was an error.
1228 bool ASTReader::ParseLineTable(ModuleFile &F,
1229  const RecordData &Record) {
1230  unsigned Idx = 0;
1231  LineTableInfo &LineTable = SourceMgr.getLineTable();
1232 
1233  // Parse the file names
1234  std::map<int, int> FileIDs;
1235  FileIDs[-1] = -1; // For unspecified filenames.
1236  for (unsigned I = 0; Record[Idx]; ++I) {
1237  // Extract the file name
1238  auto Filename = ReadPath(F, Record, Idx);
1239  FileIDs[I] = LineTable.getLineTableFilenameID(Filename);
1240  }
1241  ++Idx;
1242 
1243  // Parse the line entries
1244  std::vector<LineEntry> Entries;
1245  while (Idx < Record.size()) {
1246  int FID = Record[Idx++];
1247  assert(FID >= 0 && "Serialized line entries for non-local file.");
1248  // Remap FileID from 1-based old view.
1249  FID += F.SLocEntryBaseID - 1;
1250 
1251  // Extract the line entries
1252  unsigned NumEntries = Record[Idx++];
1253  assert(NumEntries && "no line entries for file ID");
1254  Entries.clear();
1255  Entries.reserve(NumEntries);
1256  for (unsigned I = 0; I != NumEntries; ++I) {
1257  unsigned FileOffset = Record[Idx++];
1258  unsigned LineNo = Record[Idx++];
1259  int FilenameID = FileIDs[Record[Idx++]];
1261  = (SrcMgr::CharacteristicKind)Record[Idx++];
1262  unsigned IncludeOffset = Record[Idx++];
1263  Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID,
1264  FileKind, IncludeOffset));
1265  }
1266  LineTable.AddEntry(FileID::get(FID), Entries);
1267  }
1268 
1269  return false;
1270 }
1271 
1272 /// Read a source manager block
1273 bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
1274  using namespace SrcMgr;
1275 
1276  BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
1277 
1278  // Set the source-location entry cursor to the current position in
1279  // the stream. This cursor will be used to read the contents of the
1280  // source manager block initially, and then lazily read
1281  // source-location entries as needed.
1282  SLocEntryCursor = F.Stream;
1283 
1284  // The stream itself is going to skip over the source manager block.
1285  if (F.Stream.SkipBlock()) {
1286  Error("malformed block record in AST file");
1287  return true;
1288  }
1289 
1290  // Enter the source manager block.
1291  if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) {
1292  Error("malformed source manager block record in AST file");
1293  return true;
1294  }
1295 
1296  RecordData Record;
1297  while (true) {
1298  llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks();
1299 
1300  switch (E.Kind) {
1301  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1303  Error("malformed block record in AST file");
1304  return true;
1305  case llvm::BitstreamEntry::EndBlock:
1306  return false;
1307  case llvm::BitstreamEntry::Record:
1308  // The interesting case.
1309  break;
1310  }
1311 
1312  // Read a record.
1313  Record.clear();
1314  StringRef Blob;
1315  switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) {
1316  default: // Default behavior: ignore.
1317  break;
1318 
1319  case SM_SLOC_FILE_ENTRY:
1320  case SM_SLOC_BUFFER_ENTRY:
1322  // Once we hit one of the source location entries, we're done.
1323  return false;
1324  }
1325  }
1326 }
1327 
1328 /// If a header file is not found at the path that we expect it to be
1329 /// and the PCH file was moved from its original location, try to resolve the
1330 /// file by assuming that header+PCH were moved together and the header is in
1331 /// the same place relative to the PCH.
1332 static std::string
1334  const std::string &OriginalDir,
1335  const std::string &CurrDir) {
1336  assert(OriginalDir != CurrDir &&
1337  "No point trying to resolve the file if the PCH dir didn't change");
1338 
1339  using namespace llvm::sys;
1340 
1341  SmallString<128> filePath(Filename);
1342  fs::make_absolute(filePath);
1343  assert(path::is_absolute(OriginalDir));
1344  SmallString<128> currPCHPath(CurrDir);
1345 
1346  path::const_iterator fileDirI = path::begin(path::parent_path(filePath)),
1347  fileDirE = path::end(path::parent_path(filePath));
1348  path::const_iterator origDirI = path::begin(OriginalDir),
1349  origDirE = path::end(OriginalDir);
1350  // Skip the common path components from filePath and OriginalDir.
1351  while (fileDirI != fileDirE && origDirI != origDirE &&
1352  *fileDirI == *origDirI) {
1353  ++fileDirI;
1354  ++origDirI;
1355  }
1356  for (; origDirI != origDirE; ++origDirI)
1357  path::append(currPCHPath, "..");
1358  path::append(currPCHPath, fileDirI, fileDirE);
1359  path::append(currPCHPath, path::filename(Filename));
1360  return currPCHPath.str();
1361 }
1362 
1364  if (ID == 0)
1365  return false;
1366 
1367  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1368  Error("source location entry ID out-of-range for AST file");
1369  return true;
1370  }
1371 
1372  // Local helper to read the (possibly-compressed) buffer data following the
1373  // entry record.
1374  auto ReadBuffer = [this](
1375  BitstreamCursor &SLocEntryCursor,
1376  StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> {
1377  RecordData Record;
1378  StringRef Blob;
1379  unsigned Code = SLocEntryCursor.ReadCode();
1380  unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob);
1381 
1382  if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
1383  if (!llvm::zlib::isAvailable()) {
1384  Error("zlib is not available");
1385  return nullptr;
1386  }
1387  SmallString<0> Uncompressed;
1388  if (llvm::Error E =
1389  llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) {
1390  Error("could not decompress embedded file contents: " +
1391  llvm::toString(std::move(E)));
1392  return nullptr;
1393  }
1394  return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name);
1395  } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
1396  return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
1397  } else {
1398  Error("AST record has invalid code");
1399  return nullptr;
1400  }
1401  };
1402 
1403  ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
1404  F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
1405  BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
1406  unsigned BaseOffset = F->SLocEntryBaseOffset;
1407 
1408  ++NumSLocEntriesRead;
1409  llvm::BitstreamEntry Entry = SLocEntryCursor.advance();
1410  if (Entry.Kind != llvm::BitstreamEntry::Record) {
1411  Error("incorrectly-formatted source location entry in AST file");
1412  return true;
1413  }
1414 
1415  RecordData Record;
1416  StringRef Blob;
1417  switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) {
1418  default:
1419  Error("incorrectly-formatted source location entry in AST file");
1420  return true;
1421 
1422  case SM_SLOC_FILE_ENTRY: {
1423  // We will detect whether a file changed and return 'Failure' for it, but
1424  // we will also try to fail gracefully by setting up the SLocEntry.
1425  unsigned InputID = Record[4];
1426  InputFile IF = getInputFile(*F, InputID);
1427  const FileEntry *File = IF.getFile();
1428  bool OverriddenBuffer = IF.isOverridden();
1429 
1430  // Note that we only check if a File was returned. If it was out-of-date
1431  // we have complained but we will continue creating a FileID to recover
1432  // gracefully.
1433  if (!File)
1434  return true;
1435 
1436  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1437  if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) {
1438  // This is the module's main file.
1439  IncludeLoc = getImportLocation(F);
1440  }
1442  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1443  FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter,
1444  ID, BaseOffset + Record[0]);
1445  SrcMgr::FileInfo &FileInfo =
1446  const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
1447  FileInfo.NumCreatedFIDs = Record[5];
1448  if (Record[3])
1449  FileInfo.setHasLineDirectives();
1450 
1451  const DeclID *FirstDecl = F->FileSortedDecls + Record[6];
1452  unsigned NumFileDecls = Record[7];
1453  if (NumFileDecls && ContextObj) {
1454  assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?");
1455  FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl,
1456  NumFileDecls));
1457  }
1458 
1459  const SrcMgr::ContentCache *ContentCache
1460  = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
1461  if (OverriddenBuffer && !ContentCache->BufferOverridden &&
1462  ContentCache->ContentsEntry == ContentCache->OrigEntry &&
1463  !ContentCache->getRawBuffer()) {
1464  auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
1465  if (!Buffer)
1466  return true;
1467  SourceMgr.overrideFileContents(File, std::move(Buffer));
1468  }
1469 
1470  break;
1471  }
1472 
1473  case SM_SLOC_BUFFER_ENTRY: {
1474  const char *Name = Blob.data();
1475  unsigned Offset = Record[0];
1477  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1478  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1479  if (IncludeLoc.isInvalid() && F->isModule()) {
1480  IncludeLoc = getImportLocation(F);
1481  }
1482 
1483  auto Buffer = ReadBuffer(SLocEntryCursor, Name);
1484  if (!Buffer)
1485  return true;
1486  SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
1487  BaseOffset + Offset, IncludeLoc);
1488  break;
1489  }
1490 
1491  case SM_SLOC_EXPANSION_ENTRY: {
1492  SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]);
1493  SourceMgr.createExpansionLoc(SpellingLoc,
1494  ReadSourceLocation(*F, Record[2]),
1495  ReadSourceLocation(*F, Record[3]),
1496  Record[5],
1497  Record[4],
1498  ID,
1499  BaseOffset + Record[0]);
1500  break;
1501  }
1502  }
1503 
1504  return false;
1505 }
1506 
1507 std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) {
1508  if (ID == 0)
1509  return std::make_pair(SourceLocation(), "");
1510 
1511  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1512  Error("source location entry ID out-of-range for AST file");
1513  return std::make_pair(SourceLocation(), "");
1514  }
1515 
1516  // Find which module file this entry lands in.
1517  ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second;
1518  if (!M->isModule())
1519  return std::make_pair(SourceLocation(), "");
1520 
1521  // FIXME: Can we map this down to a particular submodule? That would be
1522  // ideal.
1523  return std::make_pair(M->ImportLoc, StringRef(M->ModuleName));
1524 }
1525 
1526 /// Find the location where the module F is imported.
1527 SourceLocation ASTReader::getImportLocation(ModuleFile *F) {
1528  if (F->ImportLoc.isValid())
1529  return F->ImportLoc;
1530 
1531  // Otherwise we have a PCH. It's considered to be "imported" at the first
1532  // location of its includer.
1533  if (F->ImportedBy.empty() || !F->ImportedBy[0]) {
1534  // Main file is the importer.
1535  assert(SourceMgr.getMainFileID().isValid() && "missing main file");
1536  return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
1537  }
1538  return F->ImportedBy[0]->FirstLoc;
1539 }
1540 
1541 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1542 /// specified cursor. Read the abbreviations that are at the top of the block
1543 /// and then leave the cursor pointing into the block.
1544 bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) {
1545  if (Cursor.EnterSubBlock(BlockID))
1546  return true;
1547 
1548  while (true) {
1549  uint64_t Offset = Cursor.GetCurrentBitNo();
1550  unsigned Code = Cursor.ReadCode();
1551 
1552  // We expect all abbrevs to be at the start of the block.
1553  if (Code != llvm::bitc::DEFINE_ABBREV) {
1554  Cursor.JumpToBit(Offset);
1555  return false;
1556  }
1557  Cursor.ReadAbbrevRecord();
1558  }
1559 }
1560 
1562  unsigned &Idx) {
1563  Token Tok;
1564  Tok.startToken();
1565  Tok.setLocation(ReadSourceLocation(F, Record, Idx));
1566  Tok.setLength(Record[Idx++]);
1567  if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++]))
1568  Tok.setIdentifierInfo(II);
1569  Tok.setKind((tok::TokenKind)Record[Idx++]);
1570  Tok.setFlag((Token::TokenFlags)Record[Idx++]);
1571  return Tok;
1572 }
1573 
1575  BitstreamCursor &Stream = F.MacroCursor;
1576 
1577  // Keep track of where we are in the stream, then jump back there
1578  // after reading this macro.
1579  SavedStreamPosition SavedPosition(Stream);
1580 
1581  Stream.JumpToBit(Offset);
1582  RecordData Record;
1584  MacroInfo *Macro = nullptr;
1585 
1586  while (true) {
1587  // Advance to the next record, but if we get to the end of the block, don't
1588  // pop it (removing all the abbreviations from the cursor) since we want to
1589  // be able to reseek within the block and read entries.
1590  unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd;
1591  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags);
1592 
1593  switch (Entry.Kind) {
1594  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1596  Error("malformed block record in AST file");
1597  return Macro;
1598  case llvm::BitstreamEntry::EndBlock:
1599  return Macro;
1600  case llvm::BitstreamEntry::Record:
1601  // The interesting case.
1602  break;
1603  }
1604 
1605  // Read a record.
1606  Record.clear();
1607  PreprocessorRecordTypes RecType =
1608  (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record);
1609  switch (RecType) {
1610  case PP_MODULE_MACRO:
1612  return Macro;
1613 
1614  case PP_MACRO_OBJECT_LIKE:
1615  case PP_MACRO_FUNCTION_LIKE: {
1616  // If we already have a macro, that means that we've hit the end
1617  // of the definition of the macro we were looking for. We're
1618  // done.
1619  if (Macro)
1620  return Macro;
1621 
1622  unsigned NextIndex = 1; // Skip identifier ID.
1623  SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
1624  MacroInfo *MI = PP.AllocateMacroInfo(Loc);
1625  MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
1626  MI->setIsUsed(Record[NextIndex++]);
1627  MI->setUsedForHeaderGuard(Record[NextIndex++]);
1628 
1629  if (RecType == PP_MACRO_FUNCTION_LIKE) {
1630  // Decode function-like macro info.
1631  bool isC99VarArgs = Record[NextIndex++];
1632  bool isGNUVarArgs = Record[NextIndex++];
1633  bool hasCommaPasting = Record[NextIndex++];
1634  MacroParams.clear();
1635  unsigned NumArgs = Record[NextIndex++];
1636  for (unsigned i = 0; i != NumArgs; ++i)
1637  MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++]));
1638 
1639  // Install function-like macro info.
1640  MI->setIsFunctionLike();
1641  if (isC99VarArgs) MI->setIsC99Varargs();
1642  if (isGNUVarArgs) MI->setIsGNUVarargs();
1643  if (hasCommaPasting) MI->setHasCommaPasting();
1644  MI->setParameterList(MacroParams, PP.getPreprocessorAllocator());
1645  }
1646 
1647  // Remember that we saw this macro last so that we add the tokens that
1648  // form its body to it.
1649  Macro = MI;
1650 
1651  if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() &&
1652  Record[NextIndex]) {
1653  // We have a macro definition. Register the association
1655  GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]);
1656  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
1657  PreprocessingRecord::PPEntityID PPID =
1658  PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true);
1659  MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>(
1660  PPRec.getPreprocessedEntity(PPID));
1661  if (PPDef)
1662  PPRec.RegisterMacroDefinition(Macro, PPDef);
1663  }
1664 
1665  ++NumMacrosRead;
1666  break;
1667  }
1668 
1669  case PP_TOKEN: {
1670  // If we see a TOKEN before a PP_MACRO_*, then the file is
1671  // erroneous, just pretend we didn't see this.
1672  if (!Macro) break;
1673 
1674  unsigned Idx = 0;
1675  Token Tok = ReadToken(F, Record, Idx);
1676  Macro->AddTokenToBody(Tok);
1677  break;
1678  }
1679  }
1680  }
1681 }
1682 
1685  unsigned LocalID) const {
1686  if (!M.ModuleOffsetMap.empty())
1687  ReadModuleOffsetMap(M);
1688 
1691  assert(I != M.PreprocessedEntityRemap.end()
1692  && "Invalid index into preprocessed entity index remap");
1693 
1694  return LocalID + I->second;
1695 }
1696 
1698  return llvm::hash_combine(ikey.Size, ikey.ModTime);
1699 }
1700 
1702 HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) {
1703  internal_key_type ikey = {FE->getSize(),
1704  M.HasTimestamps ? FE->getModificationTime() : 0,
1705  FE->getName(), /*Imported*/ false};
1706  return ikey;
1707 }
1708 
1709 bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
1710  if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime))
1711  return false;
1712 
1713  if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename)
1714  return true;
1715 
1716  // Determine whether the actual files are equivalent.
1717  FileManager &FileMgr = Reader.getFileManager();
1718  auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* {
1719  if (!Key.Imported)
1720  return FileMgr.getFile(Key.Filename);
1721 
1722  std::string Resolved = Key.Filename;
1723  Reader.ResolveImportedPath(M, Resolved);
1724  return FileMgr.getFile(Resolved);
1725  };
1726 
1727  const FileEntry *FEA = GetFile(a);
1728  const FileEntry *FEB = GetFile(b);
1729  return FEA && FEA == FEB;
1730 }
1731 
1732 std::pair<unsigned, unsigned>
1733 HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) {
1734  using namespace llvm::support;
1735 
1736  unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d);
1737  unsigned DataLen = (unsigned) *d++;
1738  return std::make_pair(KeyLen, DataLen);
1739 }
1740 
1742 HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) {
1743  using namespace llvm::support;
1744 
1745  internal_key_type ikey;
1746  ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d));
1747  ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d));
1748  ikey.Filename = (const char *)d;
1749  ikey.Imported = true;
1750  return ikey;
1751 }
1752 
1754 HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
1755  unsigned DataLen) {
1756  using namespace llvm::support;
1757 
1758  const unsigned char *End = d + DataLen;
1759  HeaderFileInfo HFI;
1760  unsigned Flags = *d++;
1761  // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
1762  HFI.isImport |= (Flags >> 5) & 0x01;
1763  HFI.isPragmaOnce |= (Flags >> 4) & 0x01;
1764  HFI.DirInfo = (Flags >> 1) & 0x07;
1765  HFI.IndexHeaderMapHeader = Flags & 0x01;
1766  // FIXME: Find a better way to handle this. Maybe just store a
1767  // "has been included" flag?
1768  HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d),
1769  HFI.NumIncludes);
1770  HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
1771  M, endian::readNext<uint32_t, little, unaligned>(d));
1772  if (unsigned FrameworkOffset =
1773  endian::readNext<uint32_t, little, unaligned>(d)) {
1774  // The framework offset is 1 greater than the actual offset,
1775  // since 0 is used as an indicator for "no framework name".
1776  StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1);
1777  HFI.Framework = HS->getUniqueFrameworkName(FrameworkName);
1778  }
1779 
1780  assert((End - d) % 4 == 0 &&
1781  "Wrong data length in HeaderFileInfo deserialization");
1782  while (d != End) {
1783  uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d);
1784  auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3);
1785  LocalSMID >>= 2;
1786 
1787  // This header is part of a module. Associate it with the module to enable
1788  // implicit module import.
1789  SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
1790  Module *Mod = Reader.getSubmodule(GlobalSMID);
1791  FileManager &FileMgr = Reader.getFileManager();
1792  ModuleMap &ModMap =
1793  Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
1794 
1795  std::string Filename = key.Filename;
1796  if (key.Imported)
1797  Reader.ResolveImportedPath(M, Filename);
1798  // FIXME: This is not always the right filename-as-written, but we're not
1799  // going to use this information to rebuild the module, so it doesn't make
1800  // a lot of difference.
1801  Module::Header H = { key.Filename, FileMgr.getFile(Filename) };
1802  ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
1803  HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
1804  }
1805 
1806  // This HeaderFileInfo was externally loaded.
1807  HFI.External = true;
1808  HFI.IsValid = true;
1809  return HFI;
1810 }
1811 
1813  ModuleFile *M,
1814  uint64_t MacroDirectivesOffset) {
1815  assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
1816  PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset));
1817 }
1818 
1820  // Note that we are loading defined macros.
1821  Deserializing Macros(this);
1822 
1823  for (ModuleFile &I : llvm::reverse(ModuleMgr)) {
1824  BitstreamCursor &MacroCursor = I.MacroCursor;
1825 
1826  // If there was no preprocessor block, skip this file.
1827  if (MacroCursor.getBitcodeBytes().empty())
1828  continue;
1829 
1830  BitstreamCursor Cursor = MacroCursor;
1831  Cursor.JumpToBit(I.MacroStartOffset);
1832 
1833  RecordData Record;
1834  while (true) {
1835  llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks();
1836 
1837  switch (E.Kind) {
1838  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1840  Error("malformed block record in AST file");
1841  return;
1842  case llvm::BitstreamEntry::EndBlock:
1843  goto NextCursor;
1844 
1845  case llvm::BitstreamEntry::Record:
1846  Record.clear();
1847  switch (Cursor.readRecord(E.ID, Record)) {
1848  default: // Default behavior: ignore.
1849  break;
1850 
1851  case PP_MACRO_OBJECT_LIKE:
1852  case PP_MACRO_FUNCTION_LIKE: {
1853  IdentifierInfo *II = getLocalIdentifier(I, Record[0]);
1854  if (II->isOutOfDate())
1855  updateOutOfDateIdentifier(*II);
1856  break;
1857  }
1858 
1859  case PP_TOKEN:
1860  // Ignore tokens.
1861  break;
1862  }
1863  break;
1864  }
1865  }
1866  NextCursor: ;
1867  }
1868 }
1869 
1870 namespace {
1871 
1872  /// Visitor class used to look up identifirs in an AST file.
1873  class IdentifierLookupVisitor {
1874  StringRef Name;
1875  unsigned NameHash;
1876  unsigned PriorGeneration;
1877  unsigned &NumIdentifierLookups;
1878  unsigned &NumIdentifierLookupHits;
1879  IdentifierInfo *Found = nullptr;
1880 
1881  public:
1882  IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration,
1883  unsigned &NumIdentifierLookups,
1884  unsigned &NumIdentifierLookupHits)
1885  : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)),
1886  PriorGeneration(PriorGeneration),
1887  NumIdentifierLookups(NumIdentifierLookups),
1888  NumIdentifierLookupHits(NumIdentifierLookupHits) {}
1889 
1890  bool operator()(ModuleFile &M) {
1891  // If we've already searched this module file, skip it now.
1892  if (M.Generation <= PriorGeneration)
1893  return true;
1894 
1895  ASTIdentifierLookupTable *IdTable
1897  if (!IdTable)
1898  return false;
1899 
1900  ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M,
1901  Found);
1902  ++NumIdentifierLookups;
1903  ASTIdentifierLookupTable::iterator Pos =
1904  IdTable->find_hashed(Name, NameHash, &Trait);
1905  if (Pos == IdTable->end())
1906  return false;
1907 
1908  // Dereferencing the iterator has the effect of building the
1909  // IdentifierInfo node and populating it with the various
1910  // declarations it needs.
1911  ++NumIdentifierLookupHits;
1912  Found = *Pos;
1913  return true;
1914  }
1915 
1916  // Retrieve the identifier info found within the module
1917  // files.
1918  IdentifierInfo *getIdentifierInfo() const { return Found; }
1919  };
1920 
1921 } // namespace
1922 
1924  // Note that we are loading an identifier.
1925  Deserializing AnIdentifier(this);
1926 
1927  unsigned PriorGeneration = 0;
1928  if (getContext().getLangOpts().Modules)
1929  PriorGeneration = IdentifierGeneration[&II];
1930 
1931  // If there is a global index, look there first to determine which modules
1932  // provably do not have any results for this identifier.
1934  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
1935  if (!loadGlobalIndex()) {
1936  if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) {
1937  HitsPtr = &Hits;
1938  }
1939  }
1940 
1941  IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration,
1942  NumIdentifierLookups,
1943  NumIdentifierLookupHits);
1944  ModuleMgr.visit(Visitor, HitsPtr);
1945  markIdentifierUpToDate(&II);
1946 }
1947 
1949  if (!II)
1950  return;
1951 
1952  II->setOutOfDate(false);
1953 
1954  // Update the generation for this identifier.
1955  if (getContext().getLangOpts().Modules)
1956  IdentifierGeneration[II] = getGeneration();
1957 }
1958 
1960  const PendingMacroInfo &PMInfo) {
1961  ModuleFile &M = *PMInfo.M;
1962 
1963  BitstreamCursor &Cursor = M.MacroCursor;
1964  SavedStreamPosition SavedPosition(Cursor);
1965  Cursor.JumpToBit(PMInfo.MacroDirectivesOffset);
1966 
1967  struct ModuleMacroRecord {
1968  SubmoduleID SubModID;
1969  MacroInfo *MI;
1970  SmallVector<SubmoduleID, 8> Overrides;
1971  };
1973 
1974  // We expect to see a sequence of PP_MODULE_MACRO records listing exported
1975  // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete
1976  // macro histroy.
1977  RecordData Record;
1978  while (true) {
1979  llvm::BitstreamEntry Entry =
1980  Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
1981  if (Entry.Kind != llvm::BitstreamEntry::Record) {
1982  Error("malformed block record in AST file");
1983  return;
1984  }
1985 
1986  Record.clear();
1987  switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
1989  break;
1990 
1991  case PP_MODULE_MACRO: {
1992  ModuleMacros.push_back(ModuleMacroRecord());
1993  auto &Info = ModuleMacros.back();
1994  Info.SubModID = getGlobalSubmoduleID(M, Record[0]);
1995  Info.MI = getMacro(getGlobalMacroID(M, Record[1]));
1996  for (int I = 2, N = Record.size(); I != N; ++I)
1997  Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I]));
1998  continue;
1999  }
2000 
2001  default:
2002  Error("malformed block record in AST file");
2003  return;
2004  }
2005 
2006  // We found the macro directive history; that's the last record
2007  // for this macro.
2008  break;
2009  }
2010 
2011  // Module macros are listed in reverse dependency order.
2012  {
2013  std::reverse(ModuleMacros.begin(), ModuleMacros.end());
2015  for (auto &MMR : ModuleMacros) {
2016  Overrides.clear();
2017  for (unsigned ModID : MMR.Overrides) {
2018  Module *Mod = getSubmodule(ModID);
2019  auto *Macro = PP.getModuleMacro(Mod, II);
2020  assert(Macro && "missing definition for overridden macro");
2021  Overrides.push_back(Macro);
2022  }
2023 
2024  bool Inserted = false;
2025  Module *Owner = getSubmodule(MMR.SubModID);
2026  PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted);
2027  }
2028  }
2029 
2030  // Don't read the directive history for a module; we don't have anywhere
2031  // to put it.
2032  if (M.isModule())
2033  return;
2034 
2035  // Deserialize the macro directives history in reverse source-order.
2036  MacroDirective *Latest = nullptr, *Earliest = nullptr;
2037  unsigned Idx = 0, N = Record.size();
2038  while (Idx < N) {
2039  MacroDirective *MD = nullptr;
2040  SourceLocation Loc = ReadSourceLocation(M, Record, Idx);
2041  MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++];
2042  switch (K) {
2044  MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++]));
2045  MD = PP.AllocateDefMacroDirective(MI, Loc);
2046  break;
2047  }
2049  MD = PP.AllocateUndefMacroDirective(Loc);
2050  break;
2052  bool isPublic = Record[Idx++];
2053  MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic);
2054  break;
2055  }
2056 
2057  if (!Latest)
2058  Latest = MD;
2059  if (Earliest)
2060  Earliest->setPrevious(MD);
2061  Earliest = MD;
2062  }
2063 
2064  if (Latest)
2065  PP.setLoadedMacroDirective(II, Earliest, Latest);
2066 }
2067 
2068 ASTReader::InputFileInfo
2069 ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
2070  // Go find this input file.
2071  BitstreamCursor &Cursor = F.InputFilesCursor;
2072  SavedStreamPosition SavedPosition(Cursor);
2073  Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
2074 
2075  unsigned Code = Cursor.ReadCode();
2076  RecordData Record;
2077  StringRef Blob;
2078 
2079  unsigned Result = Cursor.readRecord(Code, Record, &Blob);
2080  assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE &&
2081  "invalid record type for input file");
2082  (void)Result;
2083 
2084  assert(Record[0] == ID && "Bogus stored ID or offset");
2085  InputFileInfo R;
2086  R.StoredSize = static_cast<off_t>(Record[1]);
2087  R.StoredTime = static_cast<time_t>(Record[2]);
2088  R.Overridden = static_cast<bool>(Record[3]);
2089  R.Transient = static_cast<bool>(Record[4]);
2090  R.TopLevelModuleMap = static_cast<bool>(Record[5]);
2091  R.Filename = Blob;
2092  ResolveImportedPath(F, R.Filename);
2093  return R;
2094 }
2095 
2096 static unsigned moduleKindForDiagnostic(ModuleKind Kind);
2097 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
2098  // If this ID is bogus, just return an empty input file.
2099  if (ID == 0 || ID > F.InputFilesLoaded.size())
2100  return InputFile();
2101 
2102  // If we've already loaded this input file, return it.
2103  if (F.InputFilesLoaded[ID-1].getFile())
2104  return F.InputFilesLoaded[ID-1];
2105 
2106  if (F.InputFilesLoaded[ID-1].isNotFound())
2107  return InputFile();
2108 
2109  // Go find this input file.
2110  BitstreamCursor &Cursor = F.InputFilesCursor;
2111  SavedStreamPosition SavedPosition(Cursor);
2112  Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
2113 
2114  InputFileInfo FI = readInputFileInfo(F, ID);
2115  off_t StoredSize = FI.StoredSize;
2116  time_t StoredTime = FI.StoredTime;
2117  bool Overridden = FI.Overridden;
2118  bool Transient = FI.Transient;
2119  StringRef Filename = FI.Filename;
2120 
2121  const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false);
2122  // If we didn't find the file, resolve it relative to the
2123  // original directory from which this AST file was created.
2124  if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
2125  F.OriginalDir != F.BaseDirectory) {
2126  std::string Resolved = resolveFileRelativeToOriginalDir(
2127  Filename, F.OriginalDir, F.BaseDirectory);
2128  if (!Resolved.empty())
2129  File = FileMgr.getFile(Resolved);
2130  }
2131 
2132  // For an overridden file, create a virtual file with the stored
2133  // size/timestamp.
2134  if ((Overridden || Transient) && File == nullptr)
2135  File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime);
2136 
2137  if (File == nullptr) {
2138  if (Complain) {
2139  std::string ErrorStr = "could not find file '";
2140  ErrorStr += Filename;
2141  ErrorStr += "' referenced by AST file '";
2142  ErrorStr += F.FileName;
2143  ErrorStr += "'";
2144  Error(ErrorStr);
2145  }
2146  // Record that we didn't find the file.
2148  return InputFile();
2149  }
2150 
2151  // Check if there was a request to override the contents of the file
2152  // that was part of the precompiled header. Overriding such a file
2153  // can lead to problems when lexing using the source locations from the
2154  // PCH.
2155  SourceManager &SM = getSourceManager();
2156  // FIXME: Reject if the overrides are different.
2157  if ((!Overridden && !Transient) && SM.isFileOverridden(File)) {
2158  if (Complain)
2159  Error(diag::err_fe_pch_file_overridden, Filename);
2160  // After emitting the diagnostic, recover by disabling the override so
2161  // that the original file will be used.
2162  //
2163  // FIXME: This recovery is just as broken as the original state; there may
2164  // be another precompiled module that's using the overridden contents, or
2165  // we might be half way through parsing it. Instead, we should treat the
2166  // overridden contents as belonging to a separate FileEntry.
2167  SM.disableFileContentsOverride(File);
2168  // The FileEntry is a virtual file entry with the size of the contents
2169  // that would override the original contents. Set it to the original's
2170  // size/time.
2171  FileMgr.modifyFileEntry(const_cast<FileEntry*>(File),
2172  StoredSize, StoredTime);
2173  }
2174 
2175  bool IsOutOfDate = false;
2176 
2177  // For an overridden file, there is nothing to validate.
2178  if (!Overridden && //
2179  (StoredSize != File->getSize() ||
2180  (StoredTime && StoredTime != File->getModificationTime() &&
2181  !DisableValidation)
2182  )) {
2183  if (Complain) {
2184  // Build a list of the PCH imports that got us here (in reverse).
2185  SmallVector<ModuleFile *, 4> ImportStack(1, &F);
2186  while (!ImportStack.back()->ImportedBy.empty())
2187  ImportStack.push_back(ImportStack.back()->ImportedBy[0]);
2188 
2189  // The top-level PCH is stale.
2190  StringRef TopLevelPCHName(ImportStack.back()->FileName);
2191  unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
2192  if (DiagnosticKind == 0)
2193  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
2194  else if (DiagnosticKind == 1)
2195  Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
2196  else
2197  Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
2198 
2199  // Print the import stack.
2200  if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
2201  Diag(diag::note_pch_required_by)
2202  << Filename << ImportStack[0]->FileName;
2203  for (unsigned I = 1; I < ImportStack.size(); ++I)
2204  Diag(diag::note_pch_required_by)
2205  << ImportStack[I-1]->FileName << ImportStack[I]->FileName;
2206  }
2207 
2208  if (!Diags.isDiagnosticInFlight())
2209  Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
2210  }
2211 
2212  IsOutOfDate = true;
2213  }
2214  // FIXME: If the file is overridden and we've already opened it,
2215  // issue an error (or split it into a separate FileEntry).
2216 
2217  InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate);
2218 
2219  // Note that we've loaded this input file.
2220  F.InputFilesLoaded[ID-1] = IF;
2221  return IF;
2222 }
2223 
2224 /// If we are loading a relocatable PCH or module file, and the filename
2225 /// is not an absolute path, add the system or module root to the beginning of
2226 /// the file name.
2228  // Resolve relative to the base directory, if we have one.
2229  if (!M.BaseDirectory.empty())
2230  return ResolveImportedPath(Filename, M.BaseDirectory);
2231 }
2232 
2233 void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) {
2234  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
2235  return;
2236 
2237  SmallString<128> Buffer;
2238  llvm::sys::path::append(Buffer, Prefix, Filename);
2239  Filename.assign(Buffer.begin(), Buffer.end());
2240 }
2241 
2242 static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) {
2243  switch (ARR) {
2244  case ASTReader::Failure: return true;
2245  case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing);
2246  case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate);
2249  return !(Caps & ASTReader::ARR_ConfigurationMismatch);
2250  case ASTReader::HadErrors: return true;
2251  case ASTReader::Success: return false;
2252  }
2253 
2254  llvm_unreachable("unknown ASTReadResult");
2255 }
2256 
2257 ASTReader::ASTReadResult ASTReader::ReadOptionsBlock(
2258  BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
2259  bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
2260  std::string &SuggestedPredefines) {
2261  if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID))
2262  return Failure;
2263 
2264  // Read all of the records in the options block.
2265  RecordData Record;
2266  ASTReadResult Result = Success;
2267  while (true) {
2268  llvm::BitstreamEntry Entry = Stream.advance();
2269 
2270  switch (Entry.Kind) {
2272  case llvm::BitstreamEntry::SubBlock:
2273  return Failure;
2274 
2275  case llvm::BitstreamEntry::EndBlock:
2276  return Result;
2277 
2278  case llvm::BitstreamEntry::Record:
2279  // The interesting case.
2280  break;
2281  }
2282 
2283  // Read and process a record.
2284  Record.clear();
2285  switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) {
2286  case LANGUAGE_OPTIONS: {
2287  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2288  if (ParseLanguageOptions(Record, Complain, Listener,
2289  AllowCompatibleConfigurationMismatch))
2290  Result = ConfigurationMismatch;
2291  break;
2292  }
2293 
2294  case TARGET_OPTIONS: {
2295  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2296  if (ParseTargetOptions(Record, Complain, Listener,
2297  AllowCompatibleConfigurationMismatch))
2298  Result = ConfigurationMismatch;
2299  break;
2300  }
2301 
2302  case FILE_SYSTEM_OPTIONS: {
2303  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2304  if (!AllowCompatibleConfigurationMismatch &&
2305  ParseFileSystemOptions(Record, Complain, Listener))
2306  Result = ConfigurationMismatch;
2307  break;
2308  }
2309 
2310  case HEADER_SEARCH_OPTIONS: {
2311  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2312  if (!AllowCompatibleConfigurationMismatch &&
2313  ParseHeaderSearchOptions(Record, Complain, Listener))
2314  Result = ConfigurationMismatch;
2315  break;
2316  }
2317 
2318  case PREPROCESSOR_OPTIONS:
2319  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2320  if (!AllowCompatibleConfigurationMismatch &&
2321  ParsePreprocessorOptions(Record, Complain, Listener,
2322  SuggestedPredefines))
2323  Result = ConfigurationMismatch;
2324  break;
2325  }
2326  }
2327 }
2328 
2330 ASTReader::ReadControlBlock(ModuleFile &F,
2332  const ModuleFile *ImportedBy,
2333  unsigned ClientLoadCapabilities) {
2334  BitstreamCursor &Stream = F.Stream;
2335  ASTReadResult Result = Success;
2336 
2337  if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
2338  Error("malformed block record in AST file");
2339  return Failure;
2340  }
2341 
2342  // Lambda to read the unhashed control block the first time it's called.
2343  //
2344  // For PCM files, the unhashed control block cannot be read until after the
2345  // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still
2346  // need to look ahead before reading the IMPORTS record. For consistency,
2347  // this block is always read somehow (see BitstreamEntry::EndBlock).
2348  bool HasReadUnhashedControlBlock = false;
2349  auto readUnhashedControlBlockOnce = [&]() {
2350  if (!HasReadUnhashedControlBlock) {
2351  HasReadUnhashedControlBlock = true;
2352  if (ASTReadResult Result =
2353  readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities))
2354  return Result;
2355  }
2356  return Success;
2357  };
2358 
2359  // Read all of the records and blocks in the control block.
2360  RecordData Record;
2361  unsigned NumInputs = 0;
2362  unsigned NumUserInputs = 0;
2363  while (true) {
2364  llvm::BitstreamEntry Entry = Stream.advance();
2365 
2366  switch (Entry.Kind) {
2368  Error("malformed block record in AST file");
2369  return Failure;
2370  case llvm::BitstreamEntry::EndBlock: {
2371  // Validate the module before returning. This call catches an AST with
2372  // no module name and no imports.
2373  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2374  return Result;
2375 
2376  // Validate input files.
2377  const HeaderSearchOptions &HSOpts =
2378  PP.getHeaderSearchInfo().getHeaderSearchOpts();
2379 
2380  // All user input files reside at the index range [0, NumUserInputs), and
2381  // system input files reside at [NumUserInputs, NumInputs). For explicitly
2382  // loaded module files, ignore missing inputs.
2383  if (!DisableValidation && F.Kind != MK_ExplicitModule &&
2384  F.Kind != MK_PrebuiltModule) {
2385  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
2386 
2387  // If we are reading a module, we will create a verification timestamp,
2388  // so we verify all input files. Otherwise, verify only user input
2389  // files.
2390 
2391  unsigned N = NumUserInputs;
2392  if (ValidateSystemInputs ||
2395  F.Kind == MK_ImplicitModule))
2396  N = NumInputs;
2397 
2398  for (unsigned I = 0; I < N; ++I) {
2399  InputFile IF = getInputFile(F, I+1, Complain);
2400  if (!IF.getFile() || IF.isOutOfDate())
2401  return OutOfDate;
2402  }
2403  }
2404 
2405  if (Listener)
2406  Listener->visitModuleFile(F.FileName, F.Kind);
2407 
2408  if (Listener && Listener->needsInputFileVisitation()) {
2409  unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs
2410  : NumUserInputs;
2411  for (unsigned I = 0; I < N; ++I) {
2412  bool IsSystem = I >= NumUserInputs;
2413  InputFileInfo FI = readInputFileInfo(F, I+1);
2414  Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden,
2415  F.Kind == MK_ExplicitModule ||
2416  F.Kind == MK_PrebuiltModule);
2417  }
2418  }
2419 
2420  return Result;
2421  }
2422 
2423  case llvm::BitstreamEntry::SubBlock:
2424  switch (Entry.ID) {
2425  case INPUT_FILES_BLOCK_ID:
2426  F.InputFilesCursor = Stream;
2427  if (Stream.SkipBlock() || // Skip with the main cursor
2428  // Read the abbreviations
2429  ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) {
2430  Error("malformed block record in AST file");
2431  return Failure;
2432  }
2433  continue;
2434 
2435  case OPTIONS_BLOCK_ID:
2436  // If we're reading the first module for this group, check its options
2437  // are compatible with ours. For modules it imports, no further checking
2438  // is required, because we checked them when we built it.
2439  if (Listener && !ImportedBy) {
2440  // Should we allow the configuration of the module file to differ from
2441  // the configuration of the current translation unit in a compatible
2442  // way?
2443  //
2444  // FIXME: Allow this for files explicitly specified with -include-pch.
2445  bool AllowCompatibleConfigurationMismatch =
2447 
2448  Result = ReadOptionsBlock(Stream, ClientLoadCapabilities,
2449  AllowCompatibleConfigurationMismatch,
2450  *Listener, SuggestedPredefines);
2451  if (Result == Failure) {
2452  Error("malformed block record in AST file");
2453  return Result;
2454  }
2455 
2456  if (DisableValidation ||
2457  (AllowConfigurationMismatch && Result == ConfigurationMismatch))
2458  Result = Success;
2459 
2460  // If we can't load the module, exit early since we likely
2461  // will rebuild the module anyway. The stream may be in the
2462  // middle of a block.
2463  if (Result != Success)
2464  return Result;
2465  } else if (Stream.SkipBlock()) {
2466  Error("malformed block record in AST file");
2467  return Failure;
2468  }
2469  continue;
2470 
2471  default:
2472  if (Stream.SkipBlock()) {
2473  Error("malformed block record in AST file");
2474  return Failure;
2475  }
2476  continue;
2477  }
2478 
2479  case llvm::BitstreamEntry::Record:
2480  // The interesting case.
2481  break;
2482  }
2483 
2484  // Read and process a record.
2485  Record.clear();
2486  StringRef Blob;
2487  switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) {
2488  case METADATA: {
2489  if (Record[0] != VERSION_MAJOR && !DisableValidation) {
2490  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2491  Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old
2492  : diag::err_pch_version_too_new);
2493  return VersionMismatch;
2494  }
2495 
2496  bool hasErrors = Record[7];
2497  if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) {
2498  Diag(diag::err_pch_with_compiler_errors);
2499  return HadErrors;
2500  }
2501  if (hasErrors) {
2502  Diags.ErrorOccurred = true;
2503  Diags.UncompilableErrorOccurred = true;
2504  Diags.UnrecoverableErrorOccurred = true;
2505  }
2506 
2507  F.RelocatablePCH = Record[4];
2508  // Relative paths in a relocatable PCH are relative to our sysroot.
2509  if (F.RelocatablePCH)
2510  F.BaseDirectory = isysroot.empty() ? "/" : isysroot;
2511 
2512  F.HasTimestamps = Record[5];
2513 
2514  F.PCHHasObjectFile = Record[6];
2515 
2516  const std::string &CurBranch = getClangFullRepositoryVersion();
2517  StringRef ASTBranch = Blob;
2518  if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
2519  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2520  Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch;
2521  return VersionMismatch;
2522  }
2523  break;
2524  }
2525 
2526  case IMPORTS: {
2527  // Validate the AST before processing any imports (otherwise, untangling
2528  // them can be error-prone and expensive). A module will have a name and
2529  // will already have been validated, but this catches the PCH case.
2530  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2531  return Result;
2532 
2533  // Load each of the imported PCH files.
2534  unsigned Idx = 0, N = Record.size();
2535  while (Idx < N) {
2536  // Read information about the AST file.
2537  ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
2538  // The import location will be the local one for now; we will adjust
2539  // all import locations of module imports after the global source
2540  // location info are setup, in ReadAST.
2541  SourceLocation ImportLoc =
2542  ReadUntranslatedSourceLocation(Record[Idx++]);
2543  off_t StoredSize = (off_t)Record[Idx++];
2544  time_t StoredModTime = (time_t)Record[Idx++];
2545  ASTFileSignature StoredSignature = {
2546  {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
2547  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
2548  (uint32_t)Record[Idx++]}}};
2549 
2550  std::string ImportedName = ReadString(Record, Idx);
2551  std::string ImportedFile;
2552 
2553  // For prebuilt and explicit modules first consult the file map for
2554  // an override. Note that here we don't search prebuilt module
2555  // directories, only the explicit name to file mappings. Also, we will
2556  // still verify the size/signature making sure it is essentially the
2557  // same file but perhaps in a different location.
2558  if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule)
2559  ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName(
2560  ImportedName, /*FileMapOnly*/ true);
2561 
2562  if (ImportedFile.empty())
2563  ImportedFile = ReadPath(F, Record, Idx);
2564  else
2565  SkipPath(Record, Idx);
2566 
2567  // If our client can't cope with us being out of date, we can't cope with
2568  // our dependency being missing.
2569  unsigned Capabilities = ClientLoadCapabilities;
2570  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2571  Capabilities &= ~ARR_Missing;
2572 
2573  // Load the AST file.
2574  auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F,
2575  Loaded, StoredSize, StoredModTime,
2576  StoredSignature, Capabilities);
2577 
2578  // If we diagnosed a problem, produce a backtrace.
2579  if (isDiagnosedResult(Result, Capabilities))
2580  Diag(diag::note_module_file_imported_by)
2581  << F.FileName << !F.ModuleName.empty() << F.ModuleName;
2582 
2583  switch (Result) {
2584  case Failure: return Failure;
2585  // If we have to ignore the dependency, we'll have to ignore this too.
2586  case Missing:
2587  case OutOfDate: return OutOfDate;
2588  case VersionMismatch: return VersionMismatch;
2589  case ConfigurationMismatch: return ConfigurationMismatch;
2590  case HadErrors: return HadErrors;
2591  case Success: break;
2592  }
2593  }
2594  break;
2595  }
2596 
2597  case ORIGINAL_FILE:
2598  F.OriginalSourceFileID = FileID::get(Record[0]);
2601  ResolveImportedPath(F, F.OriginalSourceFileName);
2602  break;
2603 
2604  case ORIGINAL_FILE_ID:
2605  F.OriginalSourceFileID = FileID::get(Record[0]);
2606  break;
2607 
2608  case ORIGINAL_PCH_DIR:
2609  F.OriginalDir = Blob;
2610  break;
2611 
2612  case MODULE_NAME:
2613  F.ModuleName = Blob;
2614  if (Listener)
2615  Listener->ReadModuleName(F.ModuleName);
2616 
2617  // Validate the AST as soon as we have a name so we can exit early on
2618  // failure.
2619  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2620  return Result;
2621 
2622  break;
2623 
2624  case MODULE_DIRECTORY: {
2625  assert(!F.ModuleName.empty() &&
2626  "MODULE_DIRECTORY found before MODULE_NAME");
2627  // If we've already loaded a module map file covering this module, we may
2628  // have a better path for it (relative to the current build).
2629  Module *M = PP.getHeaderSearchInfo().lookupModule(
2630  F.ModuleName, /*AllowSearch*/ true,
2631  /*AllowExtraModuleMapSearch*/ true);
2632  if (M && M->Directory) {
2633  // If we're implicitly loading a module, the base directory can't
2634  // change between the build and use.
2635  // Don't emit module relocation error if we have -fno-validate-pch
2636  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
2638  const DirectoryEntry *BuildDir =
2639  PP.getFileManager().getDirectory(Blob);
2640  if (!BuildDir || BuildDir != M->Directory) {
2641  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2642  Diag(diag::err_imported_module_relocated)
2643  << F.ModuleName << Blob << M->Directory->getName();
2644  return OutOfDate;
2645  }
2646  }
2647  F.BaseDirectory = M->Directory->getName();
2648  } else {
2649  F.BaseDirectory = Blob;
2650  }
2651  break;
2652  }
2653 
2654  case MODULE_MAP_FILE:
2655  if (ASTReadResult Result =
2656  ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities))
2657  return Result;
2658  break;
2659 
2660  case INPUT_FILE_OFFSETS:
2661  NumInputs = Record[0];
2662  NumUserInputs = Record[1];
2663  F.InputFileOffsets =
2664  (const llvm::support::unaligned_uint64_t *)Blob.data();
2665  F.InputFilesLoaded.resize(NumInputs);
2666  F.NumUserInputFiles = NumUserInputs;
2667  break;
2668  }
2669  }
2670 }
2671 
2673 ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
2674  BitstreamCursor &Stream = F.Stream;
2675 
2676  if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
2677  Error("malformed block record in AST file");
2678  return Failure;
2679  }
2680 
2681  // Read all of the records and blocks for the AST file.
2682  RecordData Record;
2683  while (true) {
2684  llvm::BitstreamEntry Entry = Stream.advance();
2685 
2686  switch (Entry.Kind) {
2688  Error("error at end of module block in AST file");
2689  return Failure;
2690  case llvm::BitstreamEntry::EndBlock:
2691  // Outside of C++, we do not store a lookup map for the translation unit.
2692  // Instead, mark it as needing a lookup map to be built if this module
2693  // contains any declarations lexically within it (which it always does!).
2694  // This usually has no cost, since we very rarely need the lookup map for
2695  // the translation unit outside C++.
2696  if (ASTContext *Ctx = ContextObj) {
2697  DeclContext *DC = Ctx->getTranslationUnitDecl();
2698  if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus)
2700  }
2701 
2702  return Success;
2703  case llvm::BitstreamEntry::SubBlock:
2704  switch (Entry.ID) {
2705  case DECLTYPES_BLOCK_ID:
2706  // We lazily load the decls block, but we want to set up the
2707  // DeclsCursor cursor to point into it. Clone our current bitcode
2708  // cursor to it, enter the block and read the abbrevs in that block.
2709  // With the main cursor, we just skip over it.
2710  F.DeclsCursor = Stream;
2711  if (Stream.SkipBlock() || // Skip with the main cursor.
2712  // Read the abbrevs.
2713  ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) {
2714  Error("malformed block record in AST file");
2715  return Failure;
2716  }
2717  break;
2718 
2719  case PREPROCESSOR_BLOCK_ID:
2720  F.MacroCursor = Stream;
2721  if (!PP.getExternalSource())
2722  PP.setExternalSource(this);
2723 
2724  if (Stream.SkipBlock() ||
2725  ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) {
2726  Error("malformed block record in AST file");
2727  return Failure;
2728  }
2729  F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo();
2730  break;
2731 
2733  F.PreprocessorDetailCursor = Stream;
2734  if (Stream.SkipBlock() ||
2735  ReadBlockAbbrevs(F.PreprocessorDetailCursor,
2737  Error("malformed preprocessor detail record in AST file");
2738  return Failure;
2739  }
2741  = F.PreprocessorDetailCursor.GetCurrentBitNo();
2742 
2743  if (!PP.getPreprocessingRecord())
2744  PP.createPreprocessingRecord();
2745  if (!PP.getPreprocessingRecord()->getExternalSource())
2746  PP.getPreprocessingRecord()->SetExternalSource(*this);
2747  break;
2748 
2750  if (ReadSourceManagerBlock(F))
2751  return Failure;
2752  break;
2753 
2754  case SUBMODULE_BLOCK_ID:
2755  if (ASTReadResult Result =
2756  ReadSubmoduleBlock(F, ClientLoadCapabilities))
2757  return Result;
2758  break;
2759 
2760  case COMMENTS_BLOCK_ID: {
2761  BitstreamCursor C = Stream;
2762  if (Stream.SkipBlock() ||
2763  ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) {
2764  Error("malformed comments block in AST file");
2765  return Failure;
2766  }
2767  CommentsCursors.push_back(std::make_pair(C, &F));
2768  break;
2769  }
2770 
2771  default:
2772  if (Stream.SkipBlock()) {
2773  Error("malformed block record in AST file");
2774  return Failure;
2775  }
2776  break;
2777  }
2778  continue;
2779 
2780  case llvm::BitstreamEntry::Record:
2781  // The interesting case.
2782  break;
2783  }
2784 
2785  // Read and process a record.
2786  Record.clear();
2787  StringRef Blob;
2788  auto RecordType =
2789  (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob);
2790 
2791  // If we're not loading an AST context, we don't care about most records.
2792  if (!ContextObj) {
2793  switch (RecordType) {
2794  case IDENTIFIER_TABLE:
2795  case IDENTIFIER_OFFSET:
2797  case STATISTICS:
2798  case PP_CONDITIONAL_STACK:
2799  case PP_COUNTER_VALUE:
2801  case MODULE_OFFSET_MAP:
2804  case PPD_ENTITIES_OFFSETS:
2805  case HEADER_SEARCH_TABLE:
2806  case IMPORTED_MODULES:
2807  case MACRO_OFFSET:
2808  break;
2809  default:
2810  continue;
2811  }
2812  }
2813 
2814  switch (RecordType) {
2815  default: // Default behavior: ignore.
2816  break;
2817 
2818  case TYPE_OFFSET: {
2819  if (F.LocalNumTypes != 0) {
2820  Error("duplicate TYPE_OFFSET record in AST file");
2821  return Failure;
2822  }
2823  F.TypeOffsets = (const uint32_t *)Blob.data();
2824  F.LocalNumTypes = Record[0];
2825  unsigned LocalBaseTypeIndex = Record[1];
2826  F.BaseTypeIndex = getTotalNumTypes();
2827 
2828  if (F.LocalNumTypes > 0) {
2829  // Introduce the global -> local mapping for types within this module.
2830  GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F));
2831 
2832  // Introduce the local -> global mapping for types within this module.
2834  std::make_pair(LocalBaseTypeIndex,
2835  F.BaseTypeIndex - LocalBaseTypeIndex));
2836 
2837  TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
2838  }
2839  break;
2840  }
2841 
2842  case DECL_OFFSET: {
2843  if (F.LocalNumDecls != 0) {
2844  Error("duplicate DECL_OFFSET record in AST file");
2845  return Failure;
2846  }
2847  F.DeclOffsets = (const DeclOffset *)Blob.data();
2848  F.LocalNumDecls = Record[0];
2849  unsigned LocalBaseDeclID = Record[1];
2850  F.BaseDeclID = getTotalNumDecls();
2851 
2852  if (F.LocalNumDecls > 0) {
2853  // Introduce the global -> local mapping for declarations within this
2854  // module.
2855  GlobalDeclMap.insert(
2856  std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F));
2857 
2858  // Introduce the local -> global mapping for declarations within this
2859  // module.
2861  std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID));
2862 
2863  // Introduce the global -> local mapping for declarations within this
2864  // module.
2865  F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID;
2866 
2867  DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
2868  }
2869  break;
2870  }
2871 
2872  case TU_UPDATE_LEXICAL: {
2873  DeclContext *TU = ContextObj->getTranslationUnitDecl();
2874  LexicalContents Contents(
2875  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
2876  Blob.data()),
2877  static_cast<unsigned int>(Blob.size() / 4));
2878  TULexicalDecls.push_back(std::make_pair(&F, Contents));
2879  TU->setHasExternalLexicalStorage(true);
2880  break;
2881  }
2882 
2883  case UPDATE_VISIBLE: {
2884  unsigned Idx = 0;
2885  serialization::DeclID ID = ReadDeclID(F, Record, Idx);
2886  auto *Data = (const unsigned char*)Blob.data();
2887  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data});
2888  // If we've already loaded the decl, perform the updates when we finish
2889  // loading this block.
2890  if (Decl *D = GetExistingDecl(ID))
2891  PendingUpdateRecords.push_back(
2892  PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
2893  break;
2894  }
2895 
2896  case IDENTIFIER_TABLE:
2897  F.IdentifierTableData = Blob.data();
2898  if (Record[0]) {
2900  (const unsigned char *)F.IdentifierTableData + Record[0],
2901  (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t),
2902  (const unsigned char *)F.IdentifierTableData,
2903  ASTIdentifierLookupTrait(*this, F));
2904 
2905  PP.getIdentifierTable().setExternalIdentifierLookup(this);
2906  }
2907  break;
2908 
2909  case IDENTIFIER_OFFSET: {
2910  if (F.LocalNumIdentifiers != 0) {
2911  Error("duplicate IDENTIFIER_OFFSET record in AST file");
2912  return Failure;
2913  }
2914  F.IdentifierOffsets = (const uint32_t *)Blob.data();
2915  F.LocalNumIdentifiers = Record[0];
2916  unsigned LocalBaseIdentifierID = Record[1];
2917  F.BaseIdentifierID = getTotalNumIdentifiers();
2918 
2919  if (F.LocalNumIdentifiers > 0) {
2920  // Introduce the global -> local mapping for identifiers within this
2921  // module.
2922  GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1,
2923  &F));
2924 
2925  // Introduce the local -> global mapping for identifiers within this
2926  // module.
2928  std::make_pair(LocalBaseIdentifierID,
2929  F.BaseIdentifierID - LocalBaseIdentifierID));
2930 
2931  IdentifiersLoaded.resize(IdentifiersLoaded.size()
2932  + F.LocalNumIdentifiers);
2933  }
2934  break;
2935  }
2936 
2938  F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end());
2939  break;
2940 
2942  // FIXME: Skip reading this record if our ASTConsumer doesn't care
2943  // about "interesting" decls (for instance, if we're building a module).
2944  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2945  EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
2946  break;
2947 
2948  case MODULAR_CODEGEN_DECLS:
2949  // FIXME: Skip reading this record if our ASTConsumer doesn't care about
2950  // them (ie: if we're not codegenerating this module).
2951  if (F.Kind == MK_MainFile)
2952  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2953  EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
2954  break;
2955 
2956  case SPECIAL_TYPES:
2957  if (SpecialTypes.empty()) {
2958  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2959  SpecialTypes.push_back(getGlobalTypeID(F, Record[I]));
2960  break;
2961  }
2962 
2963  if (SpecialTypes.size() != Record.size()) {
2964  Error("invalid special-types record");
2965  return Failure;
2966  }
2967 
2968  for (unsigned I = 0, N = Record.size(); I != N; ++I) {
2969  serialization::TypeID ID = getGlobalTypeID(F, Record[I]);
2970  if (!SpecialTypes[I])
2971  SpecialTypes[I] = ID;
2972  // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate
2973  // merge step?
2974  }
2975  break;
2976 
2977  case STATISTICS:
2978  TotalNumStatements += Record[0];
2979  TotalNumMacros += Record[1];
2980  TotalLexicalDeclContexts += Record[2];
2981  TotalVisibleDeclContexts += Record[3];
2982  break;
2983 
2985  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2986  UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I]));
2987  break;
2988 
2989  case DELEGATING_CTORS:
2990  for (unsigned I = 0, N = Record.size(); I != N; ++I)
2991  DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I]));
2992  break;
2993 
2995  if (Record.size() % 4 != 0) {
2996  Error("invalid weak identifiers record");
2997  return Failure;
2998  }
2999 
3000  // FIXME: Ignore weak undeclared identifiers from non-original PCH
3001  // files. This isn't the way to do it :)
3002  WeakUndeclaredIdentifiers.clear();
3003 
3004  // Translate the weak, undeclared identifiers into global IDs.
3005  for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) {
3006  WeakUndeclaredIdentifiers.push_back(
3007  getGlobalIdentifierID(F, Record[I++]));
3008  WeakUndeclaredIdentifiers.push_back(
3009  getGlobalIdentifierID(F, Record[I++]));
3010  WeakUndeclaredIdentifiers.push_back(
3011  ReadSourceLocation(F, Record, I).getRawEncoding());
3012  WeakUndeclaredIdentifiers.push_back(Record[I++]);
3013  }
3014  break;
3015 
3016  case SELECTOR_OFFSETS: {
3017  F.SelectorOffsets = (const uint32_t *)Blob.data();
3018  F.LocalNumSelectors = Record[0];
3019  unsigned LocalBaseSelectorID = Record[1];
3020  F.BaseSelectorID = getTotalNumSelectors();
3021 
3022  if (F.LocalNumSelectors > 0) {
3023  // Introduce the global -> local mapping for selectors within this
3024  // module.
3025  GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F));
3026 
3027  // Introduce the local -> global mapping for selectors within this
3028  // module.
3030  std::make_pair(LocalBaseSelectorID,
3031  F.BaseSelectorID - LocalBaseSelectorID));
3032 
3033  SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
3034  }
3035  break;
3036  }
3037 
3038  case METHOD_POOL:
3039  F.SelectorLookupTableData = (const unsigned char *)Blob.data();
3040  if (Record[0])
3043  F.SelectorLookupTableData + Record[0],
3045  ASTSelectorLookupTrait(*this, F));
3046  TotalNumMethodPoolEntries += Record[1];
3047  break;
3048 
3050  if (!Record.empty()) {
3051  for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) {
3052  ReferencedSelectorsData.push_back(getGlobalSelectorID(F,
3053  Record[Idx++]));
3054  ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx).
3055  getRawEncoding());
3056  }
3057  }
3058  break;
3059 
3060  case PP_CONDITIONAL_STACK:
3061  if (!Record.empty()) {
3062  unsigned Idx = 0, End = Record.size() - 1;
3063  bool ReachedEOFWhileSkipping = Record[Idx++];
3065  if (ReachedEOFWhileSkipping) {
3066  SourceLocation HashToken = ReadSourceLocation(F, Record, Idx);
3067  SourceLocation IfTokenLoc = ReadSourceLocation(F, Record, Idx);
3068  bool FoundNonSkipPortion = Record[Idx++];
3069  bool FoundElse = Record[Idx++];
3070  SourceLocation ElseLoc = ReadSourceLocation(F, Record, Idx);
3071  SkipInfo.emplace(HashToken, IfTokenLoc, FoundNonSkipPortion,
3072  FoundElse, ElseLoc);
3073  }
3074  SmallVector<PPConditionalInfo, 4> ConditionalStack;
3075  while (Idx < End) {
3076  auto Loc = ReadSourceLocation(F, Record, Idx);
3077  bool WasSkipping = Record[Idx++];
3078  bool FoundNonSkip = Record[Idx++];
3079  bool FoundElse = Record[Idx++];
3080  ConditionalStack.push_back(
3081  {Loc, WasSkipping, FoundNonSkip, FoundElse});
3082  }
3083  PP.setReplayablePreambleConditionalStack(ConditionalStack, SkipInfo);
3084  }
3085  break;
3086 
3087  case PP_COUNTER_VALUE:
3088  if (!Record.empty() && Listener)
3089  Listener->ReadCounter(F, Record[0]);
3090  break;
3091 
3092  case FILE_SORTED_DECLS:
3093  F.FileSortedDecls = (const DeclID *)Blob.data();
3094  F.NumFileSortedDecls = Record[0];
3095  break;
3096 
3097  case SOURCE_LOCATION_OFFSETS: {
3098  F.SLocEntryOffsets = (const uint32_t *)Blob.data();
3099  F.LocalNumSLocEntries = Record[0];
3100  unsigned SLocSpaceSize = Record[1];
3101  std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
3102  SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries,
3103  SLocSpaceSize);
3104  if (!F.SLocEntryBaseID) {
3105  Error("ran out of source locations");
3106  break;
3107  }
3108  // Make our entry in the range map. BaseID is negative and growing, so
3109  // we invert it. Because we invert it, though, we need the other end of
3110  // the range.
3111  unsigned RangeStart =
3112  unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1;
3113  GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F));
3115 
3116  // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing.
3117  assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0);
3118  GlobalSLocOffsetMap.insert(
3119  std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset
3120  - SLocSpaceSize,&F));
3121 
3122  // Initialize the remapping table.
3123  // Invalid stays invalid.
3124  F.SLocRemap.insertOrReplace(std::make_pair(0U, 0));
3125  // This module. Base was 2 when being compiled.
3126  F.SLocRemap.insertOrReplace(std::make_pair(2U,
3127  static_cast<int>(F.SLocEntryBaseOffset - 2)));
3128 
3129  TotalNumSLocEntries += F.LocalNumSLocEntries;
3130  break;
3131  }
3132 
3133  case MODULE_OFFSET_MAP:
3134  F.ModuleOffsetMap = Blob;
3135  break;
3136 
3138  if (ParseLineTable(F, Record))
3139  return Failure;
3140  break;
3141 
3142  case SOURCE_LOCATION_PRELOADS: {
3143  // Need to transform from the local view (1-based IDs) to the global view,
3144  // which is based off F.SLocEntryBaseID.
3145  if (!F.PreloadSLocEntries.empty()) {
3146  Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file");
3147  return Failure;
3148  }
3149 
3150  F.PreloadSLocEntries.swap(Record);
3151  break;
3152  }
3153 
3154  case EXT_VECTOR_DECLS:
3155  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3156  ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I]));
3157  break;
3158 
3159  case VTABLE_USES:
3160  if (Record.size() % 3 != 0) {
3161  Error("Invalid VTABLE_USES record");
3162  return Failure;
3163  }
3164 
3165  // Later tables overwrite earlier ones.
3166  // FIXME: Modules will have some trouble with this. This is clearly not
3167  // the right way to do this.
3168  VTableUses.clear();
3169 
3170  for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) {
3171  VTableUses.push_back(getGlobalDeclID(F, Record[Idx++]));
3172  VTableUses.push_back(
3173  ReadSourceLocation(F, Record, Idx).getRawEncoding());
3174  VTableUses.push_back(Record[Idx++]);
3175  }
3176  break;
3177 
3179  if (PendingInstantiations.size() % 2 != 0) {
3180  Error("Invalid existing PendingInstantiations");
3181  return Failure;
3182  }
3183 
3184  if (Record.size() % 2 != 0) {
3185  Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block");
3186  return Failure;
3187  }
3188 
3189  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3190  PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++]));
3191  PendingInstantiations.push_back(
3192  ReadSourceLocation(F, Record, I).getRawEncoding());
3193  }
3194  break;
3195 
3196  case SEMA_DECL_REFS:
3197  if (Record.size() != 3) {
3198  Error("Invalid SEMA_DECL_REFS block");
3199  return Failure;
3200  }
3201  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3202  SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
3203  break;
3204 
3205  case PPD_ENTITIES_OFFSETS: {
3206  F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data();
3207  assert(Blob.size() % sizeof(PPEntityOffset) == 0);
3208  F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset);
3209 
3210  unsigned LocalBasePreprocessedEntityID = Record[0];
3211 
3212  unsigned StartingID;
3213  if (!PP.getPreprocessingRecord())
3214  PP.createPreprocessingRecord();
3215  if (!PP.getPreprocessingRecord()->getExternalSource())
3216  PP.getPreprocessingRecord()->SetExternalSource(*this);
3217  StartingID
3218  = PP.getPreprocessingRecord()
3219  ->allocateLoadedEntities(F.NumPreprocessedEntities);
3220  F.BasePreprocessedEntityID = StartingID;
3221 
3222  if (F.NumPreprocessedEntities > 0) {
3223  // Introduce the global -> local mapping for preprocessed entities in
3224  // this module.
3225  GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F));
3226 
3227  // Introduce the local -> global mapping for preprocessed entities in
3228  // this module.
3230  std::make_pair(LocalBasePreprocessedEntityID,
3231  F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID));
3232  }
3233 
3234  break;
3235  }
3236 
3237  case PPD_SKIPPED_RANGES: {
3238  F.PreprocessedSkippedRangeOffsets = (const PPSkippedRange*)Blob.data();
3239  assert(Blob.size() % sizeof(PPSkippedRange) == 0);
3240  F.NumPreprocessedSkippedRanges = Blob.size() / sizeof(PPSkippedRange);
3241 
3242  if (!PP.getPreprocessingRecord())
3243  PP.createPreprocessingRecord();
3244  if (!PP.getPreprocessingRecord()->getExternalSource())
3245  PP.getPreprocessingRecord()->SetExternalSource(*this);
3246  F.BasePreprocessedSkippedRangeID = PP.getPreprocessingRecord()
3247  ->allocateSkippedRanges(F.NumPreprocessedSkippedRanges);
3248 
3249  if (F.NumPreprocessedSkippedRanges > 0)
3250  GlobalSkippedRangeMap.insert(
3251  std::make_pair(F.BasePreprocessedSkippedRangeID, &F));
3252  break;
3253  }
3254 
3255  case DECL_UPDATE_OFFSETS:
3256  if (Record.size() % 2 != 0) {
3257  Error("invalid DECL_UPDATE_OFFSETS block in AST file");
3258  return Failure;
3259  }
3260  for (unsigned I = 0, N = Record.size(); I != N; I += 2) {
3261  GlobalDeclID ID = getGlobalDeclID(F, Record[I]);
3262  DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1]));
3263 
3264  // If we've already loaded the decl, perform the updates when we finish
3265  // loading this block.
3266  if (Decl *D = GetExistingDecl(ID))
3267  PendingUpdateRecords.push_back(
3268  PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
3269  }
3270  break;
3271 
3272  case OBJC_CATEGORIES_MAP:
3273  if (F.LocalNumObjCCategoriesInMap != 0) {
3274  Error("duplicate OBJC_CATEGORIES_MAP record in AST file");
3275  return Failure;
3276  }
3277 
3278  F.LocalNumObjCCategoriesInMap = Record[0];
3279  F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data();
3280  break;
3281 
3282  case OBJC_CATEGORIES:
3283  F.ObjCCategories.swap(Record);
3284  break;
3285 
3287  // Later tables overwrite earlier ones.
3288  // FIXME: Modules will have trouble with this.
3289  CUDASpecialDeclRefs.clear();
3290  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3291  CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
3292  break;
3293 
3294  case HEADER_SEARCH_TABLE:
3295  F.HeaderFileInfoTableData = Blob.data();
3296  F.LocalNumHeaderFileInfos = Record[1];
3297  if (Record[0]) {
3300  (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
3301  (const unsigned char *)F.HeaderFileInfoTableData,
3302  HeaderFileInfoTrait(*this, F,
3303  &PP.getHeaderSearchInfo(),
3304  Blob.data() + Record[2]));
3305 
3306  PP.getHeaderSearchInfo().SetExternalSource(this);
3307  if (!PP.getHeaderSearchInfo().getExternalLookup())
3308  PP.getHeaderSearchInfo().SetExternalLookup(this);
3309  }
3310  break;
3311 
3312  case FP_PRAGMA_OPTIONS:
3313  // Later tables overwrite earlier ones.
3314  FPPragmaOptions.swap(Record);
3315  break;
3316 
3317  case OPENCL_EXTENSIONS:
3318  for (unsigned I = 0, E = Record.size(); I != E; ) {
3319  auto Name = ReadString(Record, I);
3320  auto &Opt = OpenCLExtensions.OptMap[Name];
3321  Opt.Supported = Record[I++] != 0;
3322  Opt.Enabled = Record[I++] != 0;
3323  Opt.Avail = Record[I++];
3324  Opt.Core = Record[I++];
3325  }
3326  break;
3327 
3329  for (unsigned I = 0, E = Record.size(); I != E;) {
3330  auto TypeID = static_cast<::TypeID>(Record[I++]);
3331  auto *Type = GetType(TypeID).getTypePtr();
3332  auto NumExt = static_cast<unsigned>(Record[I++]);
3333  for (unsigned II = 0; II != NumExt; ++II) {
3334  auto Ext = ReadString(Record, I);
3335  OpenCLTypeExtMap[Type].insert(Ext);
3336  }
3337  }
3338  break;
3339 
3341  for (unsigned I = 0, E = Record.size(); I != E;) {
3342  auto DeclID = static_cast<::DeclID>(Record[I++]);
3343  auto *Decl = GetDecl(DeclID);
3344  auto NumExt = static_cast<unsigned>(Record[I++]);
3345  for (unsigned II = 0; II != NumExt; ++II) {
3346  auto Ext = ReadString(Record, I);
3347  OpenCLDeclExtMap[Decl].insert(Ext);
3348  }
3349  }
3350  break;
3351 
3352  case TENTATIVE_DEFINITIONS:
3353  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3354  TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I]));
3355  break;
3356 
3357  case KNOWN_NAMESPACES:
3358  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3359  KnownNamespaces.push_back(getGlobalDeclID(F, Record[I]));
3360  break;
3361 
3362  case UNDEFINED_BUT_USED:
3363  if (UndefinedButUsed.size() % 2 != 0) {
3364  Error("Invalid existing UndefinedButUsed");
3365  return Failure;
3366  }
3367 
3368  if (Record.size() % 2 != 0) {
3369  Error("invalid undefined-but-used record");
3370  return Failure;
3371  }
3372  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3373  UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++]));
3374  UndefinedButUsed.push_back(
3375  ReadSourceLocation(F, Record, I).getRawEncoding());
3376  }
3377  break;
3378 
3380  for (unsigned I = 0, N = Record.size(); I != N;) {
3381  DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++]));
3382  const uint64_t Count = Record[I++];
3383  DelayedDeleteExprs.push_back(Count);
3384  for (uint64_t C = 0; C < Count; ++C) {
3385  DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding());
3386  bool IsArrayForm = Record[I++] == 1;
3387  DelayedDeleteExprs.push_back(IsArrayForm);
3388  }
3389  }
3390  break;
3391 
3392  case IMPORTED_MODULES:
3393  if (!F.isModule()) {
3394  // If we aren't loading a module (which has its own exports), make
3395  // all of the imported modules visible.
3396  // FIXME: Deal with macros-only imports.
3397  for (unsigned I = 0, N = Record.size(); I != N; /**/) {
3398  unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]);
3399  SourceLocation Loc = ReadSourceLocation(F, Record, I);
3400  if (GlobalID) {
3401  ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc));
3402  if (DeserializationListener)
3403  DeserializationListener->ModuleImportRead(GlobalID, Loc);
3404  }
3405  }
3406  }
3407  break;
3408 
3409  case MACRO_OFFSET: {
3410  if (F.LocalNumMacros != 0) {
3411  Error("duplicate MACRO_OFFSET record in AST file");
3412  return Failure;
3413  }
3414  F.MacroOffsets = (const uint32_t *)Blob.data();
3415  F.LocalNumMacros = Record[0];
3416  unsigned LocalBaseMacroID = Record[1];
3417  F.BaseMacroID = getTotalNumMacros();
3418 
3419  if (F.LocalNumMacros > 0) {
3420  // Introduce the global -> local mapping for macros within this module.
3421  GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F));
3422 
3423  // Introduce the local -> global mapping for macros within this module.
3425  std::make_pair(LocalBaseMacroID,
3426  F.BaseMacroID - LocalBaseMacroID));
3427 
3428  MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros);
3429  }
3430  break;
3431  }
3432 
3433  case LATE_PARSED_TEMPLATE:
3434  LateParsedTemplates.append(Record.begin(), Record.end());
3435  break;
3436 
3438  if (Record.size() != 1) {
3439  Error("invalid pragma optimize record");
3440  return Failure;
3441  }
3442  OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]);
3443  break;
3444 
3446  if (Record.size() != 1) {
3447  Error("invalid pragma ms_struct record");
3448  return Failure;
3449  }
3450  PragmaMSStructState = Record[0];
3451  break;
3452 
3454  if (Record.size() != 2) {
3455  Error("invalid pragma ms_struct record");
3456  return Failure;
3457  }
3458  PragmaMSPointersToMembersState = Record[0];
3459  PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]);
3460  break;
3461 
3463  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3464  UnusedLocalTypedefNameCandidates.push_back(
3465  getGlobalDeclID(F, Record[I]));
3466  break;
3467 
3469  if (Record.size() != 1) {
3470  Error("invalid cuda pragma options record");
3471  return Failure;
3472  }
3473  ForceCUDAHostDeviceDepth = Record[0];
3474  break;
3475 
3476  case PACK_PRAGMA_OPTIONS: {
3477  if (Record.size() < 3) {
3478  Error("invalid pragma pack record");
3479  return Failure;
3480  }
3481  PragmaPackCurrentValue = Record[0];
3482  PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]);
3483  unsigned NumStackEntries = Record[2];
3484  unsigned Idx = 3;
3485  // Reset the stack when importing a new module.
3486  PragmaPackStack.clear();
3487  for (unsigned I = 0; I < NumStackEntries; ++I) {
3488  PragmaPackStackEntry Entry;
3489  Entry.Value = Record[Idx++];
3490  Entry.Location = ReadSourceLocation(F, Record[Idx++]);
3491  Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
3492  PragmaPackStrings.push_back(ReadString(Record, Idx));
3493  Entry.SlotLabel = PragmaPackStrings.back();
3494  PragmaPackStack.push_back(Entry);
3495  }
3496  break;
3497  }
3498  }
3499  }
3500 }
3501 
3502 void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
3503  assert(!F.ModuleOffsetMap.empty() && "no module offset map to read");
3504 
3505  // Additional remapping information.
3506  const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data();
3507  const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size();
3508  F.ModuleOffsetMap = StringRef();
3509 
3510  // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders.
3511  if (F.SLocRemap.find(0) == F.SLocRemap.end()) {
3512  F.SLocRemap.insert(std::make_pair(0U, 0));
3513  F.SLocRemap.insert(std::make_pair(2U, 1));
3514  }
3515 
3516  // Continuous range maps we may be updating in our module.
3517  using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder;
3518  RemapBuilder SLocRemap(F.SLocRemap);
3519  RemapBuilder IdentifierRemap(F.IdentifierRemap);
3520  RemapBuilder MacroRemap(F.MacroRemap);
3521  RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
3522  RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
3523  RemapBuilder SelectorRemap(F.SelectorRemap);
3524  RemapBuilder DeclRemap(F.DeclRemap);
3525  RemapBuilder TypeRemap(F.TypeRemap);
3526 
3527  while (Data < DataEnd) {
3528  // FIXME: Looking up dependency modules by filename is horrible. Let's
3529  // start fixing this with prebuilt and explicit modules and see how it
3530  // goes...
3531  using namespace llvm::support;
3532  ModuleKind Kind = static_cast<ModuleKind>(
3533  endian::readNext<uint8_t, little, unaligned>(Data));
3534  uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data);
3535  StringRef Name = StringRef((const char*)Data, Len);
3536  Data += Len;
3537  ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule
3538  ? ModuleMgr.lookupByModuleName(Name)
3539  : ModuleMgr.lookupByFileName(Name));
3540  if (!OM) {
3541  std::string Msg =
3542  "SourceLocation remap refers to unknown module, cannot find ";
3543  Msg.append(Name);
3544  Error(Msg);
3545  return;
3546  }
3547 
3548  uint32_t SLocOffset =
3549  endian::readNext<uint32_t, little, unaligned>(Data);
3550  uint32_t IdentifierIDOffset =
3551  endian::readNext<uint32_t, little, unaligned>(Data);
3552  uint32_t MacroIDOffset =
3553  endian::readNext<uint32_t, little, unaligned>(Data);
3554  uint32_t PreprocessedEntityIDOffset =
3555  endian::readNext<uint32_t, little, unaligned>(Data);
3556  uint32_t SubmoduleIDOffset =
3557  endian::readNext<uint32_t, little, unaligned>(Data);
3558  uint32_t SelectorIDOffset =
3559  endian::readNext<uint32_t, little, unaligned>(Data);
3560  uint32_t DeclIDOffset =
3561  endian::readNext<uint32_t, little, unaligned>(Data);
3562  uint32_t TypeIndexOffset =
3563  endian::readNext<uint32_t, little, unaligned>(Data);
3564 
3565  uint32_t None = std::numeric_limits<uint32_t>::max();
3566 
3567  auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset,
3568  RemapBuilder &Remap) {
3569  if (Offset != None)
3570  Remap.insert(std::make_pair(Offset,
3571  static_cast<int>(BaseOffset - Offset)));
3572  };
3573  mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap);
3574  mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap);
3575  mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
3576  mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
3577  PreprocessedEntityRemap);
3578  mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap);
3579  mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap);
3580  mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap);
3581  mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap);
3582 
3583  // Global -> local mappings.
3584  F.GlobalToLocalDeclIDs[OM] = DeclIDOffset;
3585  }
3586 }
3587 
3589 ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
3590  const ModuleFile *ImportedBy,
3591  unsigned ClientLoadCapabilities) {
3592  unsigned Idx = 0;
3593  F.ModuleMapPath = ReadPath(F, Record, Idx);
3594 
3595  // Try to resolve ModuleName in the current header search context and
3596  // verify that it is found in the same module map file as we saved. If the
3597  // top-level AST file is a main file, skip this check because there is no
3598  // usable header search context.
3599  assert(!F.ModuleName.empty() &&
3600  "MODULE_NAME should come before MODULE_MAP_FILE");
3601  if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) {
3602  // An implicitly-loaded module file should have its module listed in some
3603  // module map file that we've already loaded.
3604  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
3605  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
3606  const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
3607  // Don't emit module relocation error if we have -fno-validate-pch
3608  if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
3609  assert(ImportedBy && "top-level import should be verified");
3610  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
3611  if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
3612  // This module was defined by an imported (explicit) module.
3613  Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName
3614  << ASTFE->getName();
3615  } else {
3616  // This module was built with a different module map.
3617  Diag(diag::err_imported_module_not_found)
3618  << F.ModuleName << F.FileName << ImportedBy->FileName
3619  << F.ModuleMapPath;
3620  // In case it was imported by a PCH, there's a chance the user is
3621  // just missing to include the search path to the directory containing
3622  // the modulemap.
3623  if (ImportedBy->Kind == MK_PCH)
3624  Diag(diag::note_imported_by_pch_module_not_found)
3625  << llvm::sys::path::parent_path(F.ModuleMapPath);
3626  }
3627  }
3628  return OutOfDate;
3629  }
3630 
3631  assert(M->Name == F.ModuleName && "found module with different name");
3632 
3633  // Check the primary module map file.
3634  const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath);
3635  if (StoredModMap == nullptr || StoredModMap != ModMap) {
3636  assert(ModMap && "found module is missing module map file");
3637  assert(ImportedBy && "top-level import should be verified");
3638  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3639  Diag(diag::err_imported_module_modmap_changed)
3640  << F.ModuleName << ImportedBy->FileName
3641  << ModMap->getName() << F.ModuleMapPath;
3642  return OutOfDate;
3643  }
3644 
3645  llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps;
3646  for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) {
3647  // FIXME: we should use input files rather than storing names.
3648  std::string Filename = ReadPath(F, Record, Idx);
3649  const FileEntry *F =
3650  FileMgr.getFile(Filename, false, false);
3651  if (F == nullptr) {
3652  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3653  Error("could not find file '" + Filename +"' referenced by AST file");
3654  return OutOfDate;
3655  }
3656  AdditionalStoredMaps.insert(F);
3657  }
3658 
3659  // Check any additional module map files (e.g. module.private.modulemap)
3660  // that are not in the pcm.
3661  if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) {
3662  for (const FileEntry *ModMap : *AdditionalModuleMaps) {
3663  // Remove files that match
3664  // Note: SmallPtrSet::erase is really remove
3665  if (!AdditionalStoredMaps.erase(ModMap)) {
3666  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3667  Diag(diag::err_module_different_modmap)
3668  << F.ModuleName << /*new*/0 << ModMap->getName();
3669  return OutOfDate;
3670  }
3671  }
3672  }
3673 
3674  // Check any additional module map files that are in the pcm, but not
3675  // found in header search. Cases that match are already removed.
3676  for (const FileEntry *ModMap : AdditionalStoredMaps) {
3677  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3678  Diag(diag::err_module_different_modmap)
3679  << F.ModuleName << /*not new*/1 << ModMap->getName();
3680  return OutOfDate;
3681  }
3682  }
3683 
3684  if (Listener)
3685  Listener->ReadModuleMapFile(F.ModuleMapPath);
3686  return Success;
3687 }
3688 
3689 /// Move the given method to the back of the global list of methods.
3691  // Find the entry for this selector in the method pool.
3692  Sema::GlobalMethodPool::iterator Known
3693  = S.MethodPool.find(Method->getSelector());
3694  if (Known == S.MethodPool.end())
3695  return;
3696 
3697  // Retrieve the appropriate method list.
3698  ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first
3699  : Known->second.second;
3700  bool Found = false;
3701  for (ObjCMethodList *List = &Start; List; List = List->getNext()) {
3702  if (!Found) {
3703  if (List->getMethod() == Method) {
3704  Found = true;
3705  } else {
3706  // Keep searching.
3707  continue;
3708  }
3709  }
3710 
3711  if (List->getNext())
3712  List->setMethod(List->getNext()->getMethod());
3713  else
3714  List->setMethod(Method);
3715  }
3716 }
3717 
3718 void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) {
3719  assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?");
3720  for (Decl *D : Names) {
3721  bool wasHidden = D->isHidden();
3722  D->setVisibleDespiteOwningModule();
3723 
3724  if (wasHidden && SemaObj) {
3725  if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) {
3726  moveMethodToBackOfGlobalList(*SemaObj, Method);
3727  }
3728  }
3729  }
3730 }
3731 
3733  Module::NameVisibilityKind NameVisibility,
3734  SourceLocation ImportLoc) {
3735  llvm::SmallPtrSet<Module *, 4> Visited;
3737  Stack.push_back(Mod);
3738  while (!Stack.empty()) {
3739  Mod = Stack.pop_back_val();
3740 
3741  if (NameVisibility <= Mod->NameVisibility) {
3742  // This module already has this level of visibility (or greater), so
3743  // there is nothing more to do.
3744  continue;
3745  }
3746 
3747  if (!Mod->isAvailable()) {
3748  // Modules that aren't available cannot be made visible.
3749  continue;
3750  }
3751 
3752  // Update the module's name visibility.
3753  Mod->NameVisibility = NameVisibility;
3754 
3755  // If we've already deserialized any names from this module,
3756  // mark them as visible.
3757  HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod);
3758  if (Hidden != HiddenNamesMap.end()) {
3759  auto HiddenNames = std::move(*Hidden);
3760  HiddenNamesMap.erase(Hidden);
3761  makeNamesVisible(HiddenNames.second, HiddenNames.first);
3762  assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() &&
3763  "making names visible added hidden names");
3764  }
3765 
3766  // Push any exported modules onto the stack to be marked as visible.
3767  SmallVector<Module *, 16> Exports;
3768  Mod->getExportedModules(Exports);
3770  I = Exports.begin(), E = Exports.end(); I != E; ++I) {
3771  Module *Exported = *I;
3772  if (Visited.insert(Exported).second)
3773  Stack.push_back(Exported);
3774  }
3775  }
3776 }
3777 
3778 /// We've merged the definition \p MergedDef into the existing definition
3779 /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made
3780 /// visible.
3782  NamedDecl *MergedDef) {
3783  if (Def->isHidden()) {
3784  // If MergedDef is visible or becomes visible, make the definition visible.
3785  if (!MergedDef->isHidden())
3787  else {
3788  getContext().mergeDefinitionIntoModule(
3789  Def, MergedDef->getImportedOwningModule(),
3790  /*NotifyListeners*/ false);
3791  PendingMergedDefinitionsToDeduplicate.insert(Def);
3792  }
3793  }
3794 }
3795 
3797  if (GlobalIndex)
3798  return false;
3799 
3800  if (TriedLoadingGlobalIndex || !UseGlobalIndex ||
3801  !PP.getLangOpts().Modules)
3802  return true;
3803 
3804  // Try to load the global index.
3805  TriedLoadingGlobalIndex = true;
3806  StringRef ModuleCachePath
3807  = getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
3808  std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result
3809  = GlobalModuleIndex::readIndex(ModuleCachePath);
3810  if (!Result.first)
3811  return true;
3812 
3813  GlobalIndex.reset(Result.first);
3814  ModuleMgr.setGlobalIndex(GlobalIndex.get());
3815  return false;
3816 }
3817 
3819  return PP.getLangOpts().Modules && UseGlobalIndex &&
3820  !hasGlobalIndex() && TriedLoadingGlobalIndex;
3821 }
3822 
3824  // Overwrite the timestamp file contents so that file's mtime changes.
3825  std::string TimestampFilename = MF.getTimestampFilename();
3826  std::error_code EC;
3827  llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
3828  if (EC)
3829  return;
3830  OS << "Timestamp file\n";
3831  OS.close();
3832  OS.clear_error(); // Avoid triggering a fatal error.
3833 }
3834 
3835 /// Given a cursor at the start of an AST file, scan ahead and drop the
3836 /// cursor into the start of the given block ID, returning false on success and
3837 /// true on failure.
3838 static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) {
3839  while (true) {
3840  llvm::BitstreamEntry Entry = Cursor.advance();
3841  switch (Entry.Kind) {
3843  case llvm::BitstreamEntry::EndBlock:
3844  return true;
3845 
3846  case llvm::BitstreamEntry::Record:
3847  // Ignore top-level records.
3848  Cursor.skipRecord(Entry.ID);
3849  break;
3850 
3851  case llvm::BitstreamEntry::SubBlock:
3852  if (Entry.ID == BlockID) {
3853  if (Cursor.EnterSubBlock(BlockID))
3854  return true;
3855  // Found it!
3856  return false;
3857  }
3858 
3859  if (Cursor.SkipBlock())
3860  return true;
3861  }
3862  }
3863 }
3864 
3866  ModuleKind Type,
3867  SourceLocation ImportLoc,
3868  unsigned ClientLoadCapabilities,
3871  SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
3872 
3873  // Defer any pending actions until we get to the end of reading the AST file.
3874  Deserializing AnASTFile(this);
3875 
3876  // Bump the generation number.
3877  unsigned PreviousGeneration = 0;
3878  if (ContextObj)
3879  PreviousGeneration = incrementGeneration(*ContextObj);
3880 
3881  unsigned NumModules = ModuleMgr.size();
3883  switch (ASTReadResult ReadResult =
3884  ReadASTCore(FileName, Type, ImportLoc,
3885  /*ImportedBy=*/nullptr, Loaded, 0, 0,
3886  ASTFileSignature(), ClientLoadCapabilities)) {
3887  case Failure:
3888  case Missing:
3889  case OutOfDate:
3890  case VersionMismatch:
3891  case ConfigurationMismatch:
3892  case HadErrors: {
3893  llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet;
3894  for (const ImportedModule &IM : Loaded)
3895  LoadedSet.insert(IM.Mod);
3896 
3897  ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet,
3898  PP.getLangOpts().Modules
3899  ? &PP.getHeaderSearchInfo().getModuleMap()
3900  : nullptr);
3901 
3902  // If we find that any modules are unusable, the global index is going
3903  // to be out-of-date. Just remove it.
3904  GlobalIndex.reset();
3905  ModuleMgr.setGlobalIndex(nullptr);
3906  return ReadResult;
3907  }
3908  case Success:
3909  break;
3910  }
3911 
3912  // Here comes stuff that we only do once the entire chain is loaded.
3913 
3914  // Load the AST blocks of all of the modules that we loaded.
3915  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
3916  MEnd = Loaded.end();
3917  M != MEnd; ++M) {
3918  ModuleFile &F = *M->Mod;
3919 
3920  // Read the AST block.
3921  if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities))
3922  return Result;
3923 
3924  // Read the extension blocks.
3926  if (ASTReadResult Result = ReadExtensionBlock(F))
3927  return Result;
3928  }
3929 
3930  // Once read, set the ModuleFile bit base offset and update the size in
3931  // bits of all files we've seen.
3932  F.GlobalBitOffset = TotalModulesSizeInBits;
3933  TotalModulesSizeInBits += F.SizeInBits;
3934  GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F));
3935 
3936  // Preload SLocEntries.
3937  for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) {
3938  int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID;
3939  // Load it through the SourceManager and don't call ReadSLocEntry()
3940  // directly because the entry may have already been loaded in which case
3941  // calling ReadSLocEntry() directly would trigger an assertion in
3942  // SourceManager.
3943  SourceMgr.getLoadedSLocEntryByID(Index);
3944  }
3945 
3946  // Map the original source file ID into the ID space of the current
3947  // compilation.
3948  if (F.OriginalSourceFileID.isValid()) {
3949  F.OriginalSourceFileID = FileID::get(
3950  F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1);
3951  }
3952 
3953  // Preload all the pending interesting identifiers by marking them out of
3954  // date.
3955  for (auto Offset : F.PreloadIdentifierOffsets) {
3956  const unsigned char *Data = reinterpret_cast<const unsigned char *>(
3958 
3959  ASTIdentifierLookupTrait Trait(*this, F);
3960  auto KeyDataLen = Trait.ReadKeyDataLength(Data);
3961  auto Key = Trait.ReadKey(Data, KeyDataLen.first);
3962  auto &II = PP.getIdentifierTable().getOwn(Key);
3963  II.setOutOfDate(true);
3964 
3965  // Mark this identifier as being from an AST file so that we can track
3966  // whether we need to serialize it.
3967  markIdentifierFromAST(*this, II);
3968 
3969  // Associate the ID with the identifier so that the writer can reuse it.
3970  auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
3971  SetIdentifierInfo(ID, &II);
3972  }
3973  }
3974 
3975  // Setup the import locations and notify the module manager that we've
3976  // committed to these module files.
3977  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
3978  MEnd = Loaded.end();
3979  M != MEnd; ++M) {
3980  ModuleFile &F = *M->Mod;
3981 
3982  ModuleMgr.moduleFileAccepted(&F);
3983 
3984  // Set the import location.
3985  F.DirectImportLoc = ImportLoc;
3986  // FIXME: We assume that locations from PCH / preamble do not need
3987  // any translation.
3988  if (!M->ImportedBy)
3989  F.ImportLoc = M->ImportLoc;
3990  else
3991  F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc);
3992  }
3993 
3994  if (!PP.getLangOpts().CPlusPlus ||
3995  (Type != MK_ImplicitModule && Type != MK_ExplicitModule &&
3996  Type != MK_PrebuiltModule)) {
3997  // Mark all of the identifiers in the identifier table as being out of date,
3998  // so that various accessors know to check the loaded modules when the
3999  // identifier is used.
4000  //
4001  // For C++ modules, we don't need information on many identifiers (just
4002  // those that provide macros or are poisoned), so we mark all of
4003  // the interesting ones via PreloadIdentifierOffsets.
4004  for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(),
4005  IdEnd = PP.getIdentifierTable().end();
4006  Id != IdEnd; ++Id)
4007  Id->second->setOutOfDate(true);
4008  }
4009  // Mark selectors as out of date.
4010  for (auto Sel : SelectorGeneration)
4011  SelectorOutOfDate[Sel.first] = true;
4012 
4013  // Resolve any unresolved module exports.
4014  for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) {
4015  UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I];
4016  SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID);
4017  Module *ResolvedMod = getSubmodule(GlobalID);
4018 
4019  switch (Unresolved.Kind) {
4020  case UnresolvedModuleRef::Conflict:
4021  if (ResolvedMod) {
4022  Module::Conflict Conflict;
4023  Conflict.Other = ResolvedMod;
4024  Conflict.Message = Unresolved.String.str();
4025  Unresolved.Mod->Conflicts.push_back(Conflict);
4026  }
4027  continue;
4028 
4029  case UnresolvedModuleRef::Import:
4030  if (ResolvedMod)
4031  Unresolved.Mod->Imports.insert(ResolvedMod);
4032  continue;
4033 
4034  case UnresolvedModuleRef::Export:
4035  if (ResolvedMod || Unresolved.IsWildcard)
4036  Unresolved.Mod->Exports.push_back(
4037  Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard));
4038  continue;
4039  }
4040  }
4041  UnresolvedModuleRefs.clear();
4042 
4043  if (Imported)
4044  Imported->append(ImportedModules.begin(),
4045  ImportedModules.end());
4046 
4047  // FIXME: How do we load the 'use'd modules? They may not be submodules.
4048  // Might be unnecessary as use declarations are only used to build the
4049  // module itself.
4050 
4051  if (ContextObj)
4052  InitializeContext();
4053 
4054  if (SemaObj)
4055  UpdateSema();
4056 
4057  if (DeserializationListener)
4058  DeserializationListener->ReaderInitialized(this);
4059 
4060  ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule();
4061  if (PrimaryModule.OriginalSourceFileID.isValid()) {
4062  // If this AST file is a precompiled preamble, then set the
4063  // preamble file ID of the source manager to the file source file
4064  // from which the preamble was built.
4065  if (Type == MK_Preamble) {
4066  SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID);
4067  } else if (Type == MK_MainFile) {
4068  SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID);
4069  }
4070  }
4071 
4072  // For any Objective-C class definitions we have already loaded, make sure
4073  // that we load any additional categories.
4074  if (ContextObj) {
4075  for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) {
4076  loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(),
4077  ObjCClassesLoaded[I],
4078  PreviousGeneration);
4079  }
4080  }
4081 
4082  if (PP.getHeaderSearchInfo()
4083  .getHeaderSearchOpts()
4084  .ModulesValidateOncePerBuildSession) {
4085  // Now we are certain that the module and all modules it depends on are
4086  // up to date. Create or update timestamp files for modules that are
4087  // located in the module cache (not for PCH files that could be anywhere
4088  // in the filesystem).
4089  for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
4090  ImportedModule &M = Loaded[I];
4091  if (M.Mod->Kind == MK_ImplicitModule) {
4092  updateModuleTimestamp(*M.Mod);
4093  }
4094  }
4095  }
4096 
4097  return Success;
4098 }
4099 
4100 static ASTFileSignature readASTFileSignature(StringRef PCH);
4101 
4102 /// Whether \p Stream starts with the AST/PCH file magic number 'CPCH'.
4103 static bool startsWithASTFileMagic(BitstreamCursor &Stream) {
4104  return Stream.canSkipToPos(4) &&
4105  Stream.Read(8) == 'C' &&
4106  Stream.Read(8) == 'P' &&
4107  Stream.Read(8) == 'C' &&
4108  Stream.Read(8) == 'H';
4109 }
4110 
4112  switch (Kind) {
4113  case MK_PCH:
4114  return 0; // PCH
4115  case MK_ImplicitModule:
4116  case MK_ExplicitModule:
4117  case MK_PrebuiltModule:
4118  return 1; // module
4119  case MK_MainFile:
4120  case MK_Preamble:
4121  return 2; // main source file
4122  }
4123  llvm_unreachable("unknown module kind");
4124 }
4125 
4127 ASTReader::ReadASTCore(StringRef FileName,
4128  ModuleKind Type,
4129  SourceLocation ImportLoc,
4130  ModuleFile *ImportedBy,
4132  off_t ExpectedSize, time_t ExpectedModTime,
4133  ASTFileSignature ExpectedSignature,
4134  unsigned ClientLoadCapabilities) {
4135  ModuleFile *M;
4136  std::string ErrorStr;
4138  = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy,
4139  getGeneration(), ExpectedSize, ExpectedModTime,
4140  ExpectedSignature, readASTFileSignature,
4141  M, ErrorStr);
4142 
4143  switch (AddResult) {
4145  return Success;
4146 
4148  // Load module file below.
4149  break;
4150 
4152  // The module file was missing; if the client can handle that, return
4153  // it.
4154  if (ClientLoadCapabilities & ARR_Missing)
4155  return Missing;
4156 
4157  // Otherwise, return an error.
4158  Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type)
4159  << FileName << !ErrorStr.empty()
4160  << ErrorStr;
4161  return Failure;
4162 
4164  // We couldn't load the module file because it is out-of-date. If the
4165  // client can handle out-of-date, return it.
4166  if (ClientLoadCapabilities & ARR_OutOfDate)
4167  return OutOfDate;
4168 
4169  // Otherwise, return an error.
4170  Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type)
4171  << FileName << !ErrorStr.empty()
4172  << ErrorStr;
4173  return Failure;
4174  }
4175 
4176  assert(M && "Missing module file");
4177 
4178  ModuleFile &F = *M;
4179  BitstreamCursor &Stream = F.Stream;
4180  Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer));
4181  F.SizeInBits = F.Buffer->getBufferSize() * 8;
4182 
4183  // Sniff for the signature.
4184  if (!startsWithASTFileMagic(Stream)) {
4185  Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type)
4186  << FileName;
4187  return Failure;
4188  }
4189 
4190  // This is used for compatibility with older PCH formats.
4191  bool HaveReadControlBlock = false;
4192  while (true) {
4193  llvm::BitstreamEntry Entry = Stream.advance();
4194 
4195  switch (Entry.Kind) {
4197  case llvm::BitstreamEntry::Record:
4198  case llvm::BitstreamEntry::EndBlock:
4199  Error("invalid record at top-level of AST file");
4200  return Failure;
4201 
4202  case llvm::BitstreamEntry::SubBlock:
4203  break;
4204  }
4205 
4206  switch (Entry.ID) {
4207  case CONTROL_BLOCK_ID:
4208  HaveReadControlBlock = true;
4209  switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) {
4210  case Success:
4211  // Check that we didn't try to load a non-module AST file as a module.
4212  //
4213  // FIXME: Should we also perform the converse check? Loading a module as
4214  // a PCH file sort of works, but it's a bit wonky.
4215  if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule ||
4216  Type == MK_PrebuiltModule) &&
4217  F.ModuleName.empty()) {
4218  auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure;
4219  if (Result != OutOfDate ||
4220  (ClientLoadCapabilities & ARR_OutOfDate) == 0)
4221  Diag(diag::err_module_file_not_module) << FileName;
4222  return Result;
4223  }
4224  break;
4225 
4226  case Failure: return Failure;
4227  case Missing: return Missing;
4228  case OutOfDate: return OutOfDate;
4229  case VersionMismatch: return VersionMismatch;
4230  case ConfigurationMismatch: return ConfigurationMismatch;
4231  case HadErrors: return HadErrors;
4232  }
4233  break;
4234 
4235  case AST_BLOCK_ID:
4236  if (!HaveReadControlBlock) {
4237  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
4238  Diag(diag::err_pch_version_too_old);
4239  return VersionMismatch;
4240  }
4241 
4242  // Record that we've loaded this module.
4243  Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc));
4244  return Success;
4245 
4247  // This block is handled using look-ahead during ReadControlBlock. We
4248  // shouldn't get here!
4249  Error("malformed block record in AST file");
4250  return Failure;
4251 
4252  default:
4253  if (Stream.SkipBlock()) {
4254  Error("malformed block record in AST file");
4255  return Failure;
4256  }
4257  break;
4258  }
4259  }
4260 
4261  return Success;
4262 }
4263 
4265 ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
4266  unsigned ClientLoadCapabilities) {
4267  const HeaderSearchOptions &HSOpts =
4268  PP.getHeaderSearchInfo().getHeaderSearchOpts();
4269  bool AllowCompatibleConfigurationMismatch =
4271 
4272  ASTReadResult Result = readUnhashedControlBlockImpl(
4273  &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch,
4274  Listener.get(),
4275  WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions);
4276 
4277  // If F was directly imported by another module, it's implicitly validated by
4278  // the importing module.
4279  if (DisableValidation || WasImportedBy ||
4280  (AllowConfigurationMismatch && Result == ConfigurationMismatch))
4281  return Success;
4282 
4283  if (Result == Failure) {
4284  Error("malformed block record in AST file");
4285  return Failure;
4286  }
4287 
4288  if (Result == OutOfDate && F.Kind == MK_ImplicitModule) {
4289  // If this module has already been finalized in the PCMCache, we're stuck
4290  // with it; we can only load a single version of each module.
4291  //
4292  // This can happen when a module is imported in two contexts: in one, as a
4293  // user module; in another, as a system module (due to an import from
4294  // another module marked with the [system] flag). It usually indicates a
4295  // bug in the module map: this module should also be marked with [system].
4296  //
4297  // If -Wno-system-headers (the default), and the first import is as a
4298  // system module, then validation will fail during the as-user import,
4299  // since -Werror flags won't have been validated. However, it's reasonable
4300  // to treat this consistently as a system module.
4301  //
4302  // If -Wsystem-headers, the PCM on disk was built with
4303  // -Wno-system-headers, and the first import is as a user module, then
4304  // validation will fail during the as-system import since the PCM on disk
4305  // doesn't guarantee that -Werror was respected. However, the -Werror
4306  // flags were checked during the initial as-user import.
4307  if (PCMCache.isBufferFinal(F.FileName)) {
4308  Diag(diag::warn_module_system_bit_conflict) << F.FileName;
4309  return Success;
4310  }
4311  }
4312 
4313  return Result;
4314 }
4315 
4316 ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl(
4317  ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities,
4318  bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
4319  bool ValidateDiagnosticOptions) {
4320  // Initialize a stream.
4321  BitstreamCursor Stream(StreamData);
4322 
4323  // Sniff for the signature.
4324  if (!startsWithASTFileMagic(Stream))
4325  return Failure;
4326 
4327  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
4329  return Failure;
4330 
4331  // Read all of the records in the options block.
4332  RecordData Record;
4333  ASTReadResult Result = Success;
4334  while (true) {
4335  llvm::BitstreamEntry Entry = Stream.advance();
4336 
4337  switch (Entry.Kind) {
4339  case llvm::BitstreamEntry::SubBlock:
4340  return Failure;
4341 
4342  case llvm::BitstreamEntry::EndBlock:
4343  return Result;
4344 
4345  case llvm::BitstreamEntry::Record:
4346  // The interesting case.
4347  break;
4348  }
4349 
4350  // Read and process a record.
4351  Record.clear();
4352  switch (
4353  (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) {
4354  case SIGNATURE:
4355  if (F)
4356  std::copy(Record.begin(), Record.end(), F->Signature.data());
4357  break;
4358  case DIAGNOSTIC_OPTIONS: {
4359  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
4360  if (Listener && ValidateDiagnosticOptions &&
4361  !AllowCompatibleConfigurationMismatch &&
4362  ParseDiagnosticOptions(Record, Complain, *Listener))
4363  Result = OutOfDate; // Don't return early. Read the signature.
4364  break;
4365  }
4366  case DIAG_PRAGMA_MAPPINGS:
4367  if (!F)
4368  break;
4369  if (F->PragmaDiagMappings.empty())
4370  F->PragmaDiagMappings.swap(Record);
4371  else
4372  F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(),
4373  Record.begin(), Record.end());
4374  break;
4375  }
4376  }
4377 }
4378 
4379 /// Parse a record and blob containing module file extension metadata.
4381  const SmallVectorImpl<uint64_t> &Record,
4382  StringRef Blob,
4383  ModuleFileExtensionMetadata &Metadata) {
4384  if (Record.size() < 4) return true;
4385 
4386  Metadata.MajorVersion = Record[0];
4387  Metadata.MinorVersion = Record[1];
4388 
4389  unsigned BlockNameLen = Record[2];
4390  unsigned UserInfoLen = Record[3];
4391 
4392  if (BlockNameLen + UserInfoLen > Blob.size()) return true;
4393 
4394  Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen);
4395  Metadata.UserInfo = std::string(Blob.data() + BlockNameLen,
4396  Blob.data() + BlockNameLen + UserInfoLen);
4397  return false;
4398 }
4399 
4400 ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) {
4401  BitstreamCursor &Stream = F.Stream;
4402 
4403  RecordData Record;
4404  while (true) {
4405  llvm::BitstreamEntry Entry = Stream.advance();
4406  switch (Entry.Kind) {
4407  case llvm::BitstreamEntry::SubBlock:
4408  if (Stream.SkipBlock())
4409  return Failure;
4410 
4411  continue;
4412 
4413  case llvm::BitstreamEntry::EndBlock:
4414  return Success;
4415 
4417  return HadErrors;
4418 
4419  case llvm::BitstreamEntry::Record:
4420  break;
4421  }
4422 
4423  Record.clear();
4424  StringRef Blob;
4425  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
4426  switch (RecCode) {
4427  case EXTENSION_METADATA: {
4428  ModuleFileExtensionMetadata Metadata;
4429  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
4430  return Failure;
4431 
4432  // Find a module file extension with this block name.
4433  auto Known = ModuleFileExtensions.find(Metadata.BlockName);
4434  if (Known == ModuleFileExtensions.end()) break;
4435 
4436  // Form a reader.
4437  if (auto Reader = Known->second->createExtensionReader(Metadata, *this,
4438  F, Stream)) {
4439  F.ExtensionReaders.push_back(std::move(Reader));
4440  }
4441 
4442  break;
4443  }
4444  }
4445  }
4446 
4447  return Success;
4448 }
4449 
4451  assert(ContextObj && "no context to initialize");
4452  ASTContext &Context = *ContextObj;
4453 
4454  // If there's a listener, notify them that we "read" the translation unit.
4455  if (DeserializationListener)
4456  DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID,
4457  Context.getTranslationUnitDecl());
4458 
4459  // FIXME: Find a better way to deal with collisions between these
4460  // built-in types. Right now, we just ignore the problem.
4461 
4462  // Load the special types.
4463  if (SpecialTypes.size() >= NumSpecialTypeIDs) {
4464  if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
4465  if (!Context.CFConstantStringTypeDecl)
4466  Context.setCFConstantStringType(GetType(String));
4467  }
4468 
4469  if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
4470  QualType FileType = GetType(File);
4471  if (FileType.isNull()) {
4472  Error("FILE type is NULL");
4473  return;
4474  }
4475 
4476  if (!Context.FILEDecl) {
4477  if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
4478  Context.setFILEDecl(Typedef->getDecl());
4479  else {
4480  const TagType *Tag = FileType->getAs<TagType>();
4481  if (!Tag) {
4482  Error("Invalid FILE type in AST file");
4483  return;
4484  }
4485  Context.setFILEDecl(Tag->getDecl());
4486  }
4487  }
4488  }
4489 
4490  if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
4491  QualType Jmp_bufType = GetType(Jmp_buf);
4492  if (Jmp_bufType.isNull()) {
4493  Error("jmp_buf type is NULL");
4494  return;
4495  }
4496 
4497  if (!Context.jmp_bufDecl) {
4498  if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
4499  Context.setjmp_bufDecl(Typedef->getDecl());
4500  else {
4501  const TagType *Tag = Jmp_bufType->getAs<TagType>();
4502  if (!Tag) {
4503  Error("Invalid jmp_buf type in AST file");
4504  return;
4505  }
4506  Context.setjmp_bufDecl(Tag->getDecl());
4507  }
4508  }
4509  }
4510 
4511  if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
4512  QualType Sigjmp_bufType = GetType(Sigjmp_buf);
4513  if (Sigjmp_bufType.isNull()) {
4514  Error("sigjmp_buf type is NULL");
4515  return;
4516  }
4517 
4518  if (!Context.sigjmp_bufDecl) {
4519  if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
4520  Context.setsigjmp_bufDecl(Typedef->getDecl());
4521  else {
4522  const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
4523  assert(Tag && "Invalid sigjmp_buf type in AST file");
4524  Context.setsigjmp_bufDecl(Tag->getDecl());
4525  }
4526  }
4527  }
4528 
4529  if (unsigned ObjCIdRedef
4530  = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
4531  if (Context.ObjCIdRedefinitionType.isNull())
4532  Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef);
4533  }
4534 
4535  if (unsigned ObjCClassRedef
4536  = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
4537  if (Context.ObjCClassRedefinitionType.isNull())
4538  Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef);
4539  }
4540 
4541  if (unsigned ObjCSelRedef
4542  = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
4543  if (Context.ObjCSelRedefinitionType.isNull())
4544  Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef);
4545  }
4546 
4547  if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
4548  QualType Ucontext_tType = GetType(Ucontext_t);
4549  if (Ucontext_tType.isNull()) {
4550  Error("ucontext_t type is NULL");
4551  return;
4552  }
4553 
4554  if (!Context.ucontext_tDecl) {
4555  if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>())
4556  Context.setucontext_tDecl(Typedef->getDecl());
4557  else {
4558  const TagType *Tag = Ucontext_tType->getAs<TagType>();
4559  assert(Tag && "Invalid ucontext_t type in AST file");
4560  Context.setucontext_tDecl(Tag->getDecl());
4561  }
4562  }
4563  }
4564  }
4565 
4566  ReadPragmaDiagnosticMappings(Context.getDiagnostics());
4567 
4568  // If there were any CUDA special declarations, deserialize them.
4569  if (!CUDASpecialDeclRefs.empty()) {
4570  assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!");
4571  Context.setcudaConfigureCallDecl(
4572  cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0])));
4573  }
4574 
4575  // Re-export any modules that were imported by a non-module AST file.
4576  // FIXME: This does not make macro-only imports visible again.
4577  for (auto &Import : ImportedModules) {
4578  if (Module *Imported = getSubmodule(Import.ID)) {
4579  makeModuleVisible(Imported, Module::AllVisible,
4580  /*ImportLoc=*/Import.ImportLoc);
4581  if (Import.ImportLoc.isValid())
4582  PP.makeModuleVisible(Imported, Import.ImportLoc);
4583  // FIXME: should we tell Sema to make the module visible too?
4584  }
4585  }
4586  ImportedModules.clear();
4587 }
4588 
4590  // Nothing to do for now.
4591 }
4592 
4593 /// Reads and return the signature record from \p PCH's control block, or
4594 /// else returns 0.
4596  BitstreamCursor Stream(PCH);
4597  if (!startsWithASTFileMagic(Stream))
4598  return ASTFileSignature();
4599 
4600  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
4602  return ASTFileSignature();
4603 
4604  // Scan for SIGNATURE inside the diagnostic options block.
4605  ASTReader::RecordData Record;
4606  while (true) {
4607  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
4608  if (Entry.Kind != llvm::BitstreamEntry::Record)
4609  return ASTFileSignature();
4610 
4611  Record.clear();
4612  StringRef Blob;
4613  if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob))
4614  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
4615  (uint32_t)Record[3], (uint32_t)Record[4]}}};
4616  }
4617 }
4618 
4619 /// Retrieve the name of the original source file name
4620 /// directly from the AST file, without actually loading the AST
4621 /// file.
4623  const std::string &ASTFileName, FileManager &FileMgr,
4624  const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) {
4625  // Open the AST file.
4626  auto Buffer = FileMgr.getBufferForFile(ASTFileName);
4627  if (!Buffer) {
4628  Diags.Report(diag::err_fe_unable_to_read_pch_file)
4629  << ASTFileName << Buffer.getError().message();
4630  return std::string();
4631  }
4632 
4633  // Initialize the stream
4634  BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer));
4635 
4636  // Sniff for the signature.
4637  if (!startsWithASTFileMagic(Stream)) {
4638  Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName;
4639  return std::string();
4640  }
4641 
4642  // Scan for the CONTROL_BLOCK_ID block.
4643  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) {
4644  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4645  return std::string();
4646  }
4647 
4648  // Scan for ORIGINAL_FILE inside the control block.
4649  RecordData Record;
4650  while (true) {
4651  llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
4652  if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
4653  return std::string();
4654 
4655  if (Entry.Kind != llvm::BitstreamEntry::Record) {
4656  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4657  return std::string();
4658  }
4659 
4660  Record.clear();
4661  StringRef Blob;
4662  if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE)
4663  return Blob.str();
4664  }
4665 }
4666 
4667 namespace {
4668 
4669  class SimplePCHValidator : public ASTReaderListener {
4670  const LangOptions &ExistingLangOpts;
4671  const TargetOptions &ExistingTargetOpts;
4672  const PreprocessorOptions &ExistingPPOpts;
4673  std::string ExistingModuleCachePath;
4674  FileManager &FileMgr;
4675 
4676  public:
4677  SimplePCHValidator(const LangOptions &ExistingLangOpts,
4678  const TargetOptions &ExistingTargetOpts,
4679  const PreprocessorOptions &ExistingPPOpts,
4680  StringRef ExistingModuleCachePath,
4681  FileManager &FileMgr)
4682  : ExistingLangOpts(ExistingLangOpts),
4683  ExistingTargetOpts(ExistingTargetOpts),
4684  ExistingPPOpts(ExistingPPOpts),
4685  ExistingModuleCachePath(ExistingModuleCachePath),
4686  FileMgr(FileMgr) {}
4687 
4688  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
4689  bool AllowCompatibleDifferences) override {
4690  return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr,
4691  AllowCompatibleDifferences);
4692  }
4693 
4694  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
4695  bool AllowCompatibleDifferences) override {
4696  return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr,
4697  AllowCompatibleDifferences);
4698  }
4699 
4700  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
4701  StringRef SpecificModuleCachePath,
4702  bool Complain) override {
4703  return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
4704  ExistingModuleCachePath,
4705  nullptr, ExistingLangOpts);
4706  }
4707 
4708  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
4709  bool Complain,
4710  std::string &SuggestedPredefines) override {
4711  return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr,
4712  SuggestedPredefines, ExistingLangOpts);
4713  }
4714  };
4715 
4716 } // namespace
4717 
4719  StringRef Filename, FileManager &FileMgr,
4720  const PCHContainerReader &PCHContainerRdr,
4721  bool FindModuleFileExtensions,
4722  ASTReaderListener &Listener, bool ValidateDiagnosticOptions) {
4723  // Open the AST file.
4724  // FIXME: This allows use of the VFS; we do not allow use of the
4725  // VFS when actually loading a module.
4726  auto Buffer = FileMgr.getBufferForFile(Filename);
4727  if (!Buffer) {
4728  return true;
4729  }
4730 
4731  // Initialize the stream
4732  StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer);
4733  BitstreamCursor Stream(Bytes);
4734 
4735  // Sniff for the signature.
4736  if (!startsWithASTFileMagic(Stream))
4737  return true;
4738 
4739  // Scan for the CONTROL_BLOCK_ID block.
4740  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID))
4741  return true;
4742 
4743  bool NeedsInputFiles = Listener.needsInputFileVisitation();
4744  bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation();
4745  bool NeedsImports = Listener.needsImportVisitation();
4746  BitstreamCursor InputFilesCursor;
4747 
4748  RecordData Record;
4749  std::string ModuleDir;
4750  bool DoneWithControlBlock = false;
4751  while (!DoneWithControlBlock) {
4752  llvm::BitstreamEntry Entry = Stream.advance();
4753 
4754  switch (Entry.Kind) {
4755  case llvm::BitstreamEntry::SubBlock: {
4756  switch (Entry.ID) {
4757  case OPTIONS_BLOCK_ID: {
4758  std::string IgnoredSuggestedPredefines;
4759  if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate,
4760  /*AllowCompatibleConfigurationMismatch*/ false,
4761  Listener, IgnoredSuggestedPredefines) != Success)
4762  return true;
4763  break;
4764  }
4765 
4766  case INPUT_FILES_BLOCK_ID:
4767  InputFilesCursor = Stream;
4768  if (Stream.SkipBlock() ||
4769  (NeedsInputFiles &&
4770  ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID)))
4771  return true;
4772  break;
4773 
4774  default:
4775  if (Stream.SkipBlock())
4776  return true;
4777  break;
4778  }
4779 
4780  continue;
4781  }
4782 
4783  case llvm::BitstreamEntry::EndBlock:
4784  DoneWithControlBlock = true;
4785  break;
4786 
4788  return true;
4789 
4790  case llvm::BitstreamEntry::Record:
4791  break;
4792  }
4793 
4794  if (DoneWithControlBlock) break;
4795 
4796  Record.clear();
4797  StringRef Blob;
4798  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
4799  switch ((ControlRecordTypes)RecCode) {
4800  case METADATA:
4801  if (Record[0] != VERSION_MAJOR)
4802  return true;
4803  if (Listener.ReadFullVersionInformation(Blob))
4804  return true;
4805  break;
4806  case MODULE_NAME:
4807  Listener.ReadModuleName(Blob);
4808  break;
4809  case MODULE_DIRECTORY:
4810  ModuleDir = Blob;
4811  break;
4812  case MODULE_MAP_FILE: {
4813  unsigned Idx = 0;
4814  auto Path = ReadString(Record, Idx);
4815  ResolveImportedPath(Path, ModuleDir);
4816  Listener.ReadModuleMapFile(Path);
4817  break;
4818  }
4819  case INPUT_FILE_OFFSETS: {
4820  if (!NeedsInputFiles)
4821  break;
4822 
4823  unsigned NumInputFiles = Record[0];
4824  unsigned NumUserFiles = Record[1];
4825  const llvm::support::unaligned_uint64_t *InputFileOffs =
4826  (const llvm::support::unaligned_uint64_t *)Blob.data();
4827  for (unsigned I = 0; I != NumInputFiles; ++I) {
4828  // Go find this input file.
4829  bool isSystemFile = I >= NumUserFiles;
4830 
4831  if (isSystemFile && !NeedsSystemInputFiles)
4832  break; // the rest are system input files
4833 
4834  BitstreamCursor &Cursor = InputFilesCursor;
4835  SavedStreamPosition SavedPosition(Cursor);
4836  Cursor.JumpToBit(InputFileOffs[I]);
4837 
4838  unsigned Code = Cursor.ReadCode();
4839  RecordData Record;
4840  StringRef Blob;
4841  bool shouldContinue = false;
4842  switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) {
4843  case INPUT_FILE:
4844  bool Overridden = static_cast<bool>(Record[3]);
4845  std::string Filename = Blob;
4846  ResolveImportedPath(Filename, ModuleDir);
4847  shouldContinue = Listener.visitInputFile(
4848  Filename, isSystemFile, Overridden, /*IsExplicitModule*/false);
4849  break;
4850  }
4851  if (!shouldContinue)
4852  break;
4853  }
4854  break;
4855  }
4856 
4857  case IMPORTS: {
4858  if (!NeedsImports)
4859  break;
4860 
4861  unsigned Idx = 0, N = Record.size();
4862  while (Idx < N) {
4863  // Read information about the AST file.
4864  Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
4865  std::string ModuleName = ReadString(Record, Idx);
4866  std::string Filename = ReadString(Record, Idx);
4867  ResolveImportedPath(Filename, ModuleDir);
4868  Listener.visitImport(ModuleName, Filename);
4869  }
4870  break;
4871  }
4872 
4873  default:
4874  // No other validation to perform.
4875  break;
4876  }
4877  }
4878 
4879  // Look for module file extension blocks, if requested.
4880  if (FindModuleFileExtensions) {
4881  BitstreamCursor SavedStream = Stream;
4882  while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) {
4883  bool DoneWithExtensionBlock = false;
4884  while (!DoneWithExtensionBlock) {
4885  llvm::BitstreamEntry Entry = Stream.advance();
4886 
4887  switch (Entry.Kind) {
4888  case llvm::BitstreamEntry::SubBlock:
4889  if (Stream.SkipBlock())
4890  return true;
4891 
4892  continue;
4893 
4894  case llvm::BitstreamEntry::EndBlock:
4895  DoneWithExtensionBlock = true;
4896  continue;
4897 
4899  return true;
4900 
4901  case llvm::BitstreamEntry::Record:
4902  break;
4903  }
4904 
4905  Record.clear();
4906  StringRef Blob;
4907  unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
4908  switch (RecCode) {
4909  case EXTENSION_METADATA: {
4910  ModuleFileExtensionMetadata Metadata;
4911  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
4912  return true;
4913 
4914  Listener.readModuleFileExtension(Metadata);
4915  break;
4916  }
4917  }
4918  }
4919  }
4920  Stream = SavedStream;
4921  }
4922 
4923  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
4924  if (readUnhashedControlBlockImpl(
4925  nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate,
4926  /*AllowCompatibleConfigurationMismatch*/ false, &Listener,
4927  ValidateDiagnosticOptions) != Success)
4928  return true;
4929 
4930  return false;
4931 }
4932 
4934  const PCHContainerReader &PCHContainerRdr,
4935  const LangOptions &LangOpts,
4936  const TargetOptions &TargetOpts,
4937  const PreprocessorOptions &PPOpts,
4938  StringRef ExistingModuleCachePath) {
4939  SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts,
4940  ExistingModuleCachePath, FileMgr);
4941  return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr,
4942  /*FindModuleFileExtensions=*/false,
4943  validator,
4944  /*ValidateDiagnosticOptions=*/true);
4945 }
4946 
4948 ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
4949  // Enter the submodule block.
4950  if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) {
4951  Error("malformed submodule block record in AST file");
4952  return Failure;
4953  }
4954 
4955  ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
4956  bool First = true;
4957  Module *CurrentModule = nullptr;
4958  RecordData Record;
4959  while (true) {
4960  llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks();
4961 
4962  switch (Entry.Kind) {
4963  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
4965  Error("malformed block record in AST file");
4966  return Failure;
4967  case llvm::BitstreamEntry::EndBlock:
4968  return Success;
4969  case llvm::BitstreamEntry::Record:
4970  // The interesting case.
4971  break;
4972  }
4973 
4974  // Read a record.
4975  StringRef Blob;
4976  Record.clear();
4977  auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob);
4978 
4979  if ((Kind == SUBMODULE_METADATA) != First) {
4980  Error("submodule metadata record should be at beginning of block");
4981  return Failure;
4982  }
4983  First = false;
4984 
4985  // Submodule information is only valid if we have a current module.
4986  // FIXME: Should we error on these cases?
4987  if (!CurrentModule && Kind != SUBMODULE_METADATA &&
4989  continue;
4990 
4991  switch (Kind) {
4992  default: // Default behavior: ignore.
4993  break;
4994 
4995  case SUBMODULE_DEFINITION: {
4996  if (Record.size() < 12) {
4997  Error("malformed module definition");
4998  return Failure;
4999  }
5000 
5001  StringRef Name = Blob;
5002  unsigned Idx = 0;
5003  SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);
5004  SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);
5005  Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++];
5006  bool IsFramework = Record[Idx++];
5007  bool IsExplicit = Record[Idx++];
5008  bool IsSystem = Record[Idx++];
5009  bool IsExternC = Record[Idx++];
5010  bool InferSubmodules = Record[Idx++];
5011  bool InferExplicitSubmodules = Record[Idx++];
5012  bool InferExportWildcard = Record[Idx++];
5013  bool ConfigMacrosExhaustive = Record[Idx++];
5014  bool ModuleMapIsPrivate = Record[Idx++];
5015 
5016  Module *ParentModule = nullptr;
5017  if (Parent)
5018  ParentModule = getSubmodule(Parent);
5019 
5020  // Retrieve this (sub)module from the module map, creating it if
5021  // necessary.
5022  CurrentModule =
5023  ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit)
5024  .first;
5025 
5026  // FIXME: set the definition loc for CurrentModule, or call
5027  // ModMap.setInferredModuleAllowedBy()
5028 
5029  SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS;
5030  if (GlobalIndex >= SubmodulesLoaded.size() ||
5031  SubmodulesLoaded[GlobalIndex]) {
5032  Error("too many submodules");
5033  return Failure;
5034  }
5035 
5036  if (!ParentModule) {
5037  if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
5038  // Don't emit module relocation error if we have -fno-validate-pch
5039  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
5040  CurFile != F.File) {
5041  if (!Diags.isDiagnosticInFlight()) {
5042  Diag(diag::err_module_file_conflict)
5043  << CurrentModule->getTopLevelModuleName()
5044  << CurFile->getName()
5045  << F.File->getName();
5046  }
5047  return Failure;
5048  }
5049  }
5050 
5051  CurrentModule->setASTFile(F.File);
5052  CurrentModule->PresumedModuleMapFile = F.ModuleMapPath;
5053  }
5054 
5055  CurrentModule->Kind = Kind;
5056  CurrentModule->Signature = F.Signature;
5057  CurrentModule->IsFromModuleFile = true;
5058  CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
5059  CurrentModule->IsExternC = IsExternC;
5060  CurrentModule->InferSubmodules = InferSubmodules;
5061  CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules;
5062  CurrentModule->InferExportWildcard = InferExportWildcard;
5063  CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive;
5064  CurrentModule->ModuleMapIsPrivate = ModuleMapIsPrivate;
5065  if (DeserializationListener)
5066  DeserializationListener->ModuleRead(GlobalID, CurrentModule);
5067 
5068  SubmodulesLoaded[GlobalIndex] = CurrentModule;
5069 
5070  // Clear out data that will be replaced by what is in the module file.
5071  CurrentModule->LinkLibraries.clear();
5072  CurrentModule->ConfigMacros.clear();
5073  CurrentModule->UnresolvedConflicts.clear();
5074  CurrentModule->Conflicts.clear();
5075 
5076  // The module is available unless it's missing a requirement; relevant
5077  // requirements will be (re-)added by SUBMODULE_REQUIRES records.
5078  // Missing headers that were present when the module was built do not
5079  // make it unavailable -- if we got this far, this must be an explicitly
5080  // imported module file.
5081  CurrentModule->Requirements.clear();
5082  CurrentModule->MissingHeaders.clear();
5083  CurrentModule->IsMissingRequirement =
5084  ParentModule && ParentModule->IsMissingRequirement;
5085  CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement;
5086  break;
5087  }
5088 
5090  std::string Filename = Blob;
5091  ResolveImportedPath(F, Filename);
5092  if (auto *Umbrella = PP.getFileManager().getFile(Filename)) {
5093  if (!CurrentModule->getUmbrellaHeader())
5094  ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob);
5095  else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) {
5096  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
5097  Error("mismatched umbrella headers in submodule");
5098  return OutOfDate;
5099  }
5100  }
5101  break;
5102  }
5103 
5104  case SUBMODULE_HEADER:
5107  // We lazily associate headers with their modules via the HeaderInfo table.
5108  // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead
5109  // of complete filenames or remove it entirely.
5110  break;
5111 
5114  // FIXME: Textual headers are not marked in the HeaderInfo table. Load
5115  // them here.
5116  break;
5117 
5118  case SUBMODULE_TOPHEADER:
5119  CurrentModule->addTopHeaderFilename(Blob);
5120  break;
5121 
5122  case SUBMODULE_UMBRELLA_DIR: {
5123  std::string Dirname = Blob;
5124  ResolveImportedPath(F, Dirname);
5125  if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) {
5126  if (!CurrentModule->getUmbrellaDir())
5127  ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob);
5128  else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) {
5129  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
5130  Error("mismatched umbrella directories in submodule");
5131  return OutOfDate;
5132  }
5133  }
5134  break;
5135  }
5136 
5137  case SUBMODULE_METADATA: {
5138  F.BaseSubmoduleID = getTotalNumSubmodules();
5139  F.LocalNumSubmodules = Record[0];
5140  unsigned LocalBaseSubmoduleID = Record[1];
5141  if (F.LocalNumSubmodules > 0) {
5142  // Introduce the global -> local mapping for submodules within this
5143  // module.
5144  GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F));
5145 
5146  // Introduce the local -> global mapping for submodules within this
5147  // module.
5149  std::make_pair(LocalBaseSubmoduleID,
5150  F.BaseSubmoduleID - LocalBaseSubmoduleID));
5151 
5152  SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules);
5153  }
5154  break;
5155  }
5156 
5157  case SUBMODULE_IMPORTS:
5158  for (unsigned Idx = 0; Idx != Record.size(); ++Idx) {
5159  UnresolvedModuleRef Unresolved;
5160  Unresolved.File = &F;
5161  Unresolved.Mod = CurrentModule;
5162  Unresolved.ID = Record[Idx];
5163  Unresolved.Kind = UnresolvedModuleRef::Import;
5164  Unresolved.IsWildcard = false;
5165  UnresolvedModuleRefs.push_back(Unresolved);
5166  }
5167  break;
5168 
5169  case SUBMODULE_EXPORTS:
5170  for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) {
5171  UnresolvedModuleRef Unresolved;
5172  Unresolved.File = &F;
5173  Unresolved.Mod = CurrentModule;
5174  Unresolved.ID = Record[Idx];
5175  Unresolved.Kind = UnresolvedModuleRef::Export;
5176  Unresolved.IsWildcard = Record[Idx + 1];
5177  UnresolvedModuleRefs.push_back(Unresolved);
5178  }
5179 
5180  // Once we've loaded the set of exports, there's no reason to keep
5181  // the parsed, unresolved exports around.
5182  CurrentModule->UnresolvedExports.clear();
5183  break;
5184 
5185  case SUBMODULE_REQUIRES:
5186  CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(),
5187  PP.getTargetInfo());
5188  break;
5189 
5191  ModMap.resolveLinkAsDependencies(CurrentModule);
5192  CurrentModule->LinkLibraries.push_back(
5193  Module::LinkLibrary(Blob, Record[0]));
5194  break;
5195 
5197  CurrentModule->ConfigMacros.push_back(Blob.str());
5198  break;
5199 
5200  case SUBMODULE_CONFLICT: {
5201  UnresolvedModuleRef Unresolved;
5202  Unresolved.File = &F;
5203  Unresolved.Mod = CurrentModule;
5204  Unresolved.ID = Record[0];
5205  Unresolved.Kind = UnresolvedModuleRef::Conflict;
5206  Unresolved.IsWildcard = false;
5207  Unresolved.String = Blob;
5208  UnresolvedModuleRefs.push_back(Unresolved);
5209  break;
5210  }
5211 
5212  case SUBMODULE_INITIALIZERS: {
5213  if (!ContextObj)
5214  break;
5216  for (auto &ID : Record)
5217  Inits.push_back(getGlobalDeclID(F, ID));
5218  ContextObj->addLazyModuleInitializers(CurrentModule, Inits);
5219  break;
5220  }
5221 
5222  case SUBMODULE_EXPORT_AS:
5223  CurrentModule->ExportAsModule = Blob.str();
5224  ModMap.addLinkAsDependency(CurrentModule);
5225  break;
5226  }
5227  }
5228 }
5229 
5230 /// Parse the record that corresponds to a LangOptions data
5231 /// structure.
5232 ///
5233 /// This routine parses the language options from the AST file and then gives
5234 /// them to the AST listener if one is set.
5235 ///
5236 /// \returns true if the listener deems the file unacceptable, false otherwise.
5237 bool ASTReader::ParseLanguageOptions(const RecordData &Record,
5238  bool Complain,
5239  ASTReaderListener &Listener,
5240  bool AllowCompatibleDifferences) {
5241  LangOptions LangOpts;
5242  unsigned Idx = 0;
5243 #define LANGOPT(Name, Bits, Default, Description) \
5244  LangOpts.Name = Record[Idx++];
5245 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
5246  LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
5247 #include "clang/Basic/LangOptions.def"
5248 #define SANITIZER(NAME, ID) \
5249  LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]);
5250 #include "clang/Basic/Sanitizers.def"
5251 
5252  for (unsigned N = Record[Idx++]; N; --N)
5253  LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx));
5254 
5255  ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++];
5256  VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx);
5257  LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion);
5258 
5259  LangOpts.CurrentModule = ReadString(Record, Idx);
5260 
5261  // Comment options.
5262  for (unsigned N = Record[Idx++]; N; --N) {
5263  LangOpts.CommentOpts.BlockCommandNames.push_back(
5264  ReadString(Record, Idx));
5265  }
5266  LangOpts.CommentOpts.ParseAllComments = Record[Idx++];
5267 
5268  // OpenMP offloading options.
5269  for (unsigned N = Record[Idx++]; N; --N) {
5270  LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx)));
5271  }
5272 
5273  LangOpts.OMPHostIRFile = ReadString(Record, Idx);
5274 
5275  return Listener.ReadLanguageOptions(LangOpts, Complain,
5276  AllowCompatibleDifferences);
5277 }
5278 
5279 bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain,
5280  ASTReaderListener &Listener,
5281  bool AllowCompatibleDifferences) {
5282  unsigned Idx = 0;
5283  TargetOptions TargetOpts;
5284  TargetOpts.Triple = ReadString(Record, Idx);
5285  TargetOpts.CPU = ReadString(Record, Idx);
5286  TargetOpts.ABI = ReadString(Record, Idx);
5287  for (unsigned N = Record[Idx++]; N; --N) {
5288  TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx));
5289  }
5290  for (unsigned N = Record[Idx++]; N; --N) {
5291  TargetOpts.Features.push_back(ReadString(Record, Idx));
5292  }
5293 
5294  return Listener.ReadTargetOptions(TargetOpts, Complain,
5295  AllowCompatibleDifferences);
5296 }
5297 
5298 bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain,
5299  ASTReaderListener &Listener) {
5301  unsigned Idx = 0;
5302 #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++];
5303 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
5304  DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));
5305 #include "clang/Basic/DiagnosticOptions.def"
5306 
5307  for (unsigned N = Record[Idx++]; N; --N)
5308  DiagOpts->Warnings.push_back(ReadString(Record, Idx));
5309  for (unsigned N = Record[Idx++]; N; --N)
5310  DiagOpts->Remarks.push_back(ReadString(Record, Idx));
5311 
5312  return Listener.ReadDiagnosticOptions(DiagOpts, Complain);
5313 }
5314 
5315 bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain,
5316  ASTReaderListener &Listener) {
5317  FileSystemOptions FSOpts;
5318  unsigned Idx = 0;
5319  FSOpts.WorkingDir = ReadString(Record, Idx);
5320  return Listener.ReadFileSystemOptions(FSOpts, Complain);
5321 }
5322 
5323 bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record,
5324  bool Complain,
5325  ASTReaderListener &Listener) {
5326  HeaderSearchOptions HSOpts;
5327  unsigned Idx = 0;
5328  HSOpts.Sysroot = ReadString(Record, Idx);
5329 
5330  // Include entries.
5331  for (unsigned N = Record[Idx++]; N; --N) {
5332  std::string Path = ReadString(Record, Idx);
5334  = static_cast<frontend::IncludeDirGroup>(Record[Idx++]);
5335  bool IsFramework = Record[Idx++];
5336  bool IgnoreSysRoot = Record[Idx++];
5337  HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework,
5338  IgnoreSysRoot);
5339  }
5340 
5341  // System header prefixes.
5342  for (unsigned N = Record[Idx++]; N; --N) {
5343  std::string Prefix = ReadString(Record, Idx);
5344  bool IsSystemHeader = Record[Idx++];
5345  HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
5346  }
5347 
5348  HSOpts.ResourceDir = ReadString(Record, Idx);
5349  HSOpts.ModuleCachePath = ReadString(Record, Idx);
5350  HSOpts.ModuleUserBuildPath = ReadString(Record, Idx);
5351  HSOpts.DisableModuleHash = Record[Idx++];
5352  HSOpts.ImplicitModuleMaps = Record[Idx++];
5353  HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++];
5354  HSOpts.UseBuiltinIncludes = Record[Idx++];
5355  HSOpts.UseStandardSystemIncludes = Record[Idx++];
5356  HSOpts.UseStandardCXXIncludes = Record[Idx++];
5357  HSOpts.UseLibcxx = Record[Idx++];
5358  std::string SpecificModuleCachePath = ReadString(Record, Idx);
5359 
5360  return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
5361  Complain);
5362 }
5363 
5364 bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
5365  bool Complain,
5366  ASTReaderListener &Listener,
5367  std::string &SuggestedPredefines) {
5368  PreprocessorOptions PPOpts;
5369  unsigned Idx = 0;
5370 
5371  // Macro definitions/undefs
5372  for (unsigned N = Record[Idx++]; N; --N) {
5373  std::string Macro = ReadString(Record, Idx);
5374  bool IsUndef = Record[Idx++];
5375  PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef));
5376  }
5377 
5378  // Includes
5379  for (unsigned N = Record[Idx++]; N; --N) {
5380  PPOpts.Includes.push_back(ReadString(Record, Idx));
5381  }
5382 
5383  // Macro Includes
5384  for (unsigned N = Record[Idx++]; N; --N) {
5385  PPOpts.MacroIncludes.push_back(ReadString(Record, Idx));
5386  }
5387 
5388  PPOpts.UsePredefines = Record[Idx++];
5389  PPOpts.DetailedRecord = Record[Idx++];
5390  PPOpts.ImplicitPCHInclude = ReadString(Record, Idx);
5391  PPOpts.ObjCXXARCStandardLibrary =
5392  static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]);
5393  SuggestedPredefines.clear();
5394  return Listener.ReadPreprocessorOptions(PPOpts, Complain,
5395  SuggestedPredefines);
5396 }
5397 
5398 std::pair<ModuleFile *, unsigned>
5399 ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) {
5401  I = GlobalPreprocessedEntityMap.find(GlobalIndex);
5402  assert(I != GlobalPreprocessedEntityMap.end() &&
5403  "Corrupted global preprocessed entity map");
5404  ModuleFile *M = I->second;
5405  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID;
5406  return std::make_pair(M, LocalIndex);
5407 }
5408 
5409 llvm::iterator_range<PreprocessingRecord::iterator>
5410 ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const {
5411  if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord())
5412  return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID,
5414 
5415  return llvm::make_range(PreprocessingRecord::iterator(),
5417 }
5418 
5419 llvm::iterator_range<ASTReader::ModuleDeclIterator>
5421  return llvm::make_range(
5422  ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls),
5423  ModuleDeclIterator(this, &Mod,
5424  Mod.FileSortedDecls + Mod.NumFileSortedDecls));
5425 }
5426 
5428  auto I = GlobalSkippedRangeMap.find(GlobalIndex);
5429  assert(I != GlobalSkippedRangeMap.end() &&
5430  "Corrupted global skipped range map");
5431  ModuleFile *M = I->second;
5432  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedSkippedRangeID;
5433  assert(LocalIndex < M->NumPreprocessedSkippedRanges);
5434  PPSkippedRange RawRange = M->PreprocessedSkippedRangeOffsets[LocalIndex];
5435  SourceRange Range(TranslateSourceLocation(*M, RawRange.getBegin()),
5436  TranslateSourceLocation(*M, RawRange.getEnd()));
5437  assert(Range.isValid());
5438  return Range;
5439 }
5440 
5442  PreprocessedEntityID PPID = Index+1;
5443  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
5444  ModuleFile &M = *PPInfo.first;
5445  unsigned LocalIndex = PPInfo.second;
5446  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
5447 
5448  if (!PP.getPreprocessingRecord()) {
5449  Error("no preprocessing record");
5450  return nullptr;
5451  }
5452 
5454  M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset);
5455 
5456  llvm::BitstreamEntry Entry =
5457  M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
5458  if (Entry.Kind != llvm::BitstreamEntry::Record)
5459  return nullptr;
5460 
5461  // Read the record.
5462  SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()),
5463  TranslateSourceLocation(M, PPOffs.getEnd()));
5464  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
5465  StringRef Blob;
5466  RecordData Record;
5469  Entry.ID, Record, &Blob);
5470  switch (RecType) {
5471  case PPD_MACRO_EXPANSION: {
5472  bool isBuiltin = Record[0];
5473  IdentifierInfo *Name = nullptr;
5474  MacroDefinitionRecord *Def = nullptr;
5475  if (isBuiltin)
5476  Name = getLocalIdentifier(M, Record[1]);
5477  else {
5478  PreprocessedEntityID GlobalID =
5479  getGlobalPreprocessedEntityID(M, Record[1]);
5480  Def = cast<MacroDefinitionRecord>(
5481  PPRec.getLoadedPreprocessedEntity(GlobalID - 1));
5482  }
5483 
5484  MacroExpansion *ME;
5485  if (isBuiltin)
5486  ME = new (PPRec) MacroExpansion(Name, Range);
5487  else
5488  ME = new (PPRec) MacroExpansion(Def, Range);
5489 
5490  return ME;
5491  }
5492 
5493  case PPD_MACRO_DEFINITION: {
5494  // Decode the identifier info and then check again; if the macro is
5495  // still defined and associated with the identifier,
5496  IdentifierInfo *II = getLocalIdentifier(M, Record[0]);
5497  MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range);
5498 
5499  if (DeserializationListener)
5500  DeserializationListener->MacroDefinitionRead(PPID, MD);
5501 
5502  return MD;
5503  }
5504 
5505  case PPD_INCLUSION_DIRECTIVE: {
5506  const char *FullFileNameStart = Blob.data() + Record[0];
5507  StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
5508  const FileEntry *File = nullptr;
5509  if (!FullFileName.empty())
5510  File = PP.getFileManager().getFile(FullFileName);
5511 
5512  // FIXME: Stable encoding
5514  = static_cast<InclusionDirective::InclusionKind>(Record[2]);
5516  = new (PPRec) InclusionDirective(PPRec, Kind,
5517  StringRef(Blob.data(), Record[0]),
5518  Record[1], Record[3],
5519  File,
5520  Range);
5521  return ID;
5522  }
5523  }
5524 
5525  llvm_unreachable("Invalid PreprocessorDetailRecordTypes");
5526 }
5527 
5528 /// Find the next module that contains entities and return the ID
5529 /// of the first entry.
5530 ///
5531 /// \param SLocMapI points at a chunk of a module that contains no
5532 /// preprocessed entities or the entities it contains are not the ones we are
5533 /// looking for.
5534 PreprocessedEntityID ASTReader::findNextPreprocessedEntity(
5535  GlobalSLocOffsetMapType::const_iterator SLocMapI) const {
5536  ++SLocMapI;
5538  EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) {
5539  ModuleFile &M = *SLocMapI->second;
5541  return M.BasePreprocessedEntityID;
5542  }
5543 
5544  return getTotalNumPreprocessedEntities();
5545 }
5546 
5547 namespace {
5548 
5549 struct PPEntityComp {
5550  const ASTReader &Reader;
5551  ModuleFile &M;
5552 
5553  PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) {}
5554 
5555  bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const {
5556  SourceLocation LHS = getLoc(L);
5557  SourceLocation RHS = getLoc(R);
5558  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5559  }
5560 
5561  bool operator()(const PPEntityOffset &L, SourceLocation RHS) const {
5562  SourceLocation LHS = getLoc(L);
5563  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5564  }
5565 
5566  bool operator()(SourceLocation LHS, const PPEntityOffset &R) const {
5567  SourceLocation RHS = getLoc(R);
5568  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5569  }
5570 
5571  SourceLocation getLoc(const PPEntityOffset &PPE) const {
5572  return Reader.TranslateSourceLocation(M, PPE.getBegin());
5573  }
5574 };
5575 
5576 } // namespace
5577 
5578 PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc,
5579  bool EndsAfter) const {
5580  if (SourceMgr.isLocalSourceLocation(Loc))
5581  return getTotalNumPreprocessedEntities();
5582 
5583  GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find(
5584  SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
5585  assert(SLocMapI != GlobalSLocOffsetMap.end() &&
5586  "Corrupted global sloc offset map");
5587 
5588  if (SLocMapI->second->NumPreprocessedEntities == 0)
5589  return findNextPreprocessedEntity(SLocMapI);
5590 
5591  ModuleFile &M = *SLocMapI->second;
5592 
5593  using pp_iterator = const PPEntityOffset *;
5594 
5595  pp_iterator pp_begin = M.PreprocessedEntityOffsets;
5596  pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities;
5597 
5598  size_t Count = M.NumPreprocessedEntities;
5599  size_t Half;
5600  pp_iterator First = pp_begin;
5601  pp_iterator PPI;
5602 
5603  if (EndsAfter) {
5604  PPI = std::upper_bound(pp_begin, pp_end, Loc,
5605  PPEntityComp(*this, M));
5606  } else {
5607  // Do a binary search manually instead of using std::lower_bound because
5608  // The end locations of entities may be unordered (when a macro expansion
5609  // is inside another macro argument), but for this case it is not important
5610  // whether we get the first macro expansion or its containing macro.
5611  while (Count > 0) {
5612  Half = Count / 2;
5613  PPI = First;
5614  std::advance(PPI, Half);
5615  if (SourceMgr.isBeforeInTranslationUnit(
5616  TranslateSourceLocation(M, PPI->getEnd()), Loc)) {
5617  First = PPI;
5618  ++First;
5619  Count = Count - Half - 1;
5620  } else
5621  Count = Half;
5622  }
5623  }
5624 
5625  if (PPI == pp_end)
5626  return findNextPreprocessedEntity(SLocMapI);
5627 
5628  return M.BasePreprocessedEntityID + (PPI - pp_begin);
5629 }
5630 
5631 /// Returns a pair of [Begin, End) indices of preallocated
5632 /// preprocessed entities that \arg Range encompasses.
5633 std::pair<unsigned, unsigned>
5635  if (Range.isInvalid())
5636  return std::make_pair(0,0);
5637  assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
5638 
5639  PreprocessedEntityID BeginID =
5640  findPreprocessedEntity(Range.getBegin(), false);
5641  PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true);
5642  return std::make_pair(BeginID, EndID);
5643 }
5644 
5645 /// Optionally returns true or false if the preallocated preprocessed
5646 /// entity with index \arg Index came from file \arg FID.
5648  FileID FID) {
5649  if (FID.isInvalid())
5650  return false;
5651 
5652  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
5653  ModuleFile &M = *PPInfo.first;
5654  unsigned LocalIndex = PPInfo.second;
5655  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
5656 
5657  SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin());
5658  if (Loc.isInvalid())
5659  return false;
5660 
5661  if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID))
5662  return true;
5663  else
5664  return false;
5665 }
5666 
5667 namespace {
5668 
5669  /// Visitor used to search for information about a header file.
5670  class HeaderFileInfoVisitor {
5671  const FileEntry *FE;
5673 
5674  public:
5675  explicit HeaderFileInfoVisitor(const FileEntry *FE) : FE(FE) {}
5676 
5677  bool operator()(ModuleFile &M) {
5679  = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable);
5680  if (!Table)
5681  return false;
5682 
5683  // Look in the on-disk hash table for an entry for this file name.
5684  HeaderFileInfoLookupTable::iterator Pos = Table->find(FE);
5685  if (Pos == Table->end())
5686  return false;
5687 
5688  HFI = *Pos;
5689  return true;
5690  }
5691 
5692  Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; }
5693  };
5694 
5695 } // namespace
5696 
5698  HeaderFileInfoVisitor Visitor(FE);
5699  ModuleMgr.visit(Visitor);
5700  if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo())
5701  return *HFI;
5702 
5703  return HeaderFileInfo();
5704 }
5705 
5707  using DiagState = DiagnosticsEngine::DiagState;
5708  SmallVector<DiagState *, 32> DiagStates;
5709 
5710  for (ModuleFile &F : ModuleMgr) {
5711  unsigned Idx = 0;
5712  auto &Record = F.PragmaDiagMappings;
5713  if (Record.empty())
5714  continue;
5715 
5716  DiagStates.clear();
5717 
5718  auto ReadDiagState =
5719  [&](const DiagState &BasedOn, SourceLocation Loc,
5720  bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * {
5721  unsigned BackrefID = Record[Idx++];
5722  if (BackrefID != 0)
5723  return DiagStates[BackrefID - 1];
5724 
5725  // A new DiagState was created here.
5726  Diag.DiagStates.push_back(BasedOn);
5727  DiagState *NewState = &Diag.DiagStates.back();
5728  DiagStates.push_back(NewState);
5729  unsigned Size = Record[Idx++];
5730  assert(Idx + Size * 2 <= Record.size() &&
5731  "Invalid data, not enough diag/map pairs");
5732  while (Size--) {
5733  unsigned DiagID = Record[Idx++];
5734  DiagnosticMapping NewMapping =
5735  DiagnosticMapping::deserialize(Record[Idx++]);
5736  if (!NewMapping.isPragma() && !IncludeNonPragmaStates)
5737  continue;
5738 
5739  DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID);
5740 
5741  // If this mapping was specified as a warning but the severity was
5742  // upgraded due to diagnostic settings, simulate the current diagnostic
5743  // settings (and use a warning).
5744  if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) {
5746  NewMapping.setUpgradedFromWarning(false);
5747  }
5748 
5749  Mapping = NewMapping;
5750  }
5751  return NewState;
5752  };
5753 
5754  // Read the first state.
5755  DiagState *FirstState;
5756  if (F.Kind == MK_ImplicitModule) {
5757  // Implicitly-built modules are reused with different diagnostic
5758  // settings. Use the initial diagnostic state from Diag to simulate this
5759  // compilation's diagnostic settings.
5760  FirstState = Diag.DiagStatesByLoc.FirstDiagState;
5761  DiagStates.push_back(FirstState);
5762 
5763  // Skip the initial diagnostic state from the serialized module.
5764  assert(Record[1] == 0 &&
5765  "Invalid data, unexpected backref in initial state");
5766  Idx = 3 + Record[2] * 2;
5767  assert(Idx < Record.size() &&
5768  "Invalid data, not enough state change pairs in initial state");
5769  } else if (F.isModule()) {
5770  // For an explicit module, preserve the flags from the module build
5771  // command line (-w, -Weverything, -Werror, ...) along with any explicit
5772  // -Wblah flags.
5773  unsigned Flags = Record[Idx++];
5774  DiagState Initial;
5775  Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1;
5776  Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1;
5777  Initial.WarningsAsErrors = Flags & 1; Flags >>= 1;
5778  Initial.EnableAllWarnings = Flags & 1; Flags >>= 1;
5779  Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1;
5780  Initial.ExtBehavior = (diag::Severity)Flags;
5781  FirstState = ReadDiagState(Initial, SourceLocation(), true);
5782 
5783  assert(F.OriginalSourceFileID.isValid());
5784 
5785  // Set up the root buffer of the module to start with the initial
5786  // diagnostic state of the module itself, to cover files that contain no
5787  // explicit transitions (for which we did not serialize anything).
5788  Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID]
5789  .StateTransitions.push_back({FirstState, 0});
5790  } else {
5791  // For prefix ASTs, start with whatever the user configured on the
5792  // command line.
5793  Idx++; // Skip flags.
5794  FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState,
5795  SourceLocation(), false);
5796  }
5797 
5798  // Read the state transitions.
5799  unsigned NumLocations = Record[Idx++];
5800  while (NumLocations--) {
5801  assert(Idx < Record.size() &&
5802  "Invalid data, missing pragma diagnostic states");
5803  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
5804  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
5805  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
5806  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
5807  unsigned Transitions = Record[Idx++];
5808 
5809  // Note that we don't need to set up Parent/ParentOffset here, because
5810  // we won't be changing the diagnostic state within imported FileIDs
5811  // (other than perhaps appending to the main source file, which has no
5812  // parent).
5813  auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
5814  F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
5815  for (unsigned I = 0; I != Transitions; ++I) {
5816  unsigned Offset = Record[Idx++];
5817  auto *State =
5818  ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false);
5819  F.StateTransitions.push_back({State, Offset});
5820  }
5821  }
5822 
5823  // Read the final state.
5824  assert(Idx < Record.size() &&
5825  "Invalid data, missing final pragma diagnostic state");
5826  SourceLocation CurStateLoc =
5827  ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
5828  auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false);
5829 
5830  if (!F.isModule()) {
5831  Diag.DiagStatesByLoc.CurDiagState = CurState;
5832  Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc;
5833 
5834  // Preserve the property that the imaginary root file describes the
5835  // current state.
5836  FileID NullFile;
5837  auto &T = Diag.DiagStatesByLoc.Files[NullFile].StateTransitions;
5838  if (T.empty())
5839  T.push_back({CurState, 0});
5840  else
5841  T[0].State = CurState;
5842  }
5843 
5844  // Don't try to read these mappings again.
5845  Record.clear();
5846  }
5847 }
5848 
5849 /// Get the correct cursor and offset for loading a type.
5850 ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
5851  GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index);
5852  assert(I != GlobalTypeMap.end() && "Corrupted global type map");
5853  ModuleFile *M = I->second;
5854  return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]);
5855 }
5856 
5857 /// Read and return the type with the given index..
5858 ///
5859 /// The index is the type ID, shifted and minus the number of predefs. This
5860 /// routine actually reads the record corresponding to the type at the given
5861 /// location. It is a helper routine for GetType, which deals with reading type
5862 /// IDs.
5863 QualType ASTReader::readTypeRecord(unsigned Index) {
5864  assert(ContextObj && "reading type with no AST context");
5865  ASTContext &Context = *ContextObj;
5866  RecordLocation Loc = TypeCursorForIndex(Index);
5867  BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
5868 
5869  // Keep track of where we are in the stream, then jump back there
5870  // after reading this type.
5871  SavedStreamPosition SavedPosition(DeclsCursor);
5872 
5873  ReadingKindTracker ReadingKind(Read_Type, *this);
5874 
5875  // Note that we are loading a type record.
5876  Deserializing AType(this);
5877 
5878  unsigned Idx = 0;
5879  DeclsCursor.JumpToBit(Loc.Offset);
5880  RecordData Record;
5881  unsigned Code = DeclsCursor.ReadCode();
5882  switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) {
5883  case TYPE_EXT_QUAL: {
5884  if (Record.size() != 2) {
5885  Error("Incorrect encoding of extended qualifier type");
5886  return QualType();
5887  }
5888  QualType Base = readType(*Loc.F, Record, Idx);
5889  Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]);
5890  return Context.getQualifiedType(Base, Quals);
5891  }
5892 
5893  case TYPE_COMPLEX: {
5894  if (Record.size() != 1) {
5895  Error("Incorrect encoding of complex type");
5896  return QualType();
5897  }
5898  QualType ElemType = readType(*Loc.F, Record, Idx);
5899  return Context.getComplexType(ElemType);
5900  }
5901 
5902  case TYPE_POINTER: {
5903  if (Record.size() != 1) {
5904  Error("Incorrect encoding of pointer type");
5905  return QualType();
5906  }
5907  QualType PointeeType = readType(*Loc.F, Record, Idx);
5908  return Context.getPointerType(PointeeType);
5909  }
5910 
5911  case TYPE_DECAYED: {
5912  if (Record.size() != 1) {
5913  Error("Incorrect encoding of decayed type");
5914  return QualType();
5915  }
5916  QualType OriginalType = readType(*Loc.F, Record, Idx);
5917  QualType DT = Context.getAdjustedParameterType(OriginalType);
5918  if (!isa<DecayedType>(DT))
5919  Error("Decayed type does not decay");
5920  return DT;
5921  }
5922 
5923  case TYPE_ADJUSTED: {
5924  if (Record.size() != 2) {
5925  Error("Incorrect encoding of adjusted type");
5926  return QualType();
5927  }
5928  QualType OriginalTy = readType(*Loc.F, Record, Idx);
5929  QualType AdjustedTy = readType(*Loc.F, Record, Idx);
5930  return Context.getAdjustedType(OriginalTy, AdjustedTy);
5931  }
5932 
5933  case TYPE_BLOCK_POINTER: {
5934  if (Record.size() != 1) {
5935  Error("Incorrect encoding of block pointer type");
5936  return QualType();
5937  }
5938  QualType PointeeType = readType(*Loc.F, Record, Idx);
5939  return Context.getBlockPointerType(PointeeType);
5940  }
5941 
5942  case TYPE_LVALUE_REFERENCE: {
5943  if (Record.size() != 2) {
5944  Error("Incorrect encoding of lvalue reference type");
5945  return QualType();
5946  }
5947  QualType PointeeType = readType(*Loc.F, Record, Idx);
5948  return Context.getLValueReferenceType(PointeeType, Record[1]);
5949  }
5950 
5951  case TYPE_RVALUE_REFERENCE: {
5952  if (Record.size() != 1) {
5953  Error("Incorrect encoding of rvalue reference type");
5954  return QualType();
5955  }
5956  QualType PointeeType = readType(*Loc.F, Record, Idx);
5957  return Context.getRValueReferenceType(PointeeType);
5958  }
5959 
5960  case TYPE_MEMBER_POINTER: {
5961  if (Record.size() != 2) {
5962  Error("Incorrect encoding of member pointer type");
5963  return QualType();
5964  }
5965  QualType PointeeType = readType(*Loc.F, Record, Idx);
5966  QualType ClassType = readType(*Loc.F, Record, Idx);
5967  if (PointeeType.isNull() || ClassType.isNull())
5968  return QualType();
5969 
5970  return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr());
5971  }
5972 
5973  case TYPE_CONSTANT_ARRAY: {
5974  QualType ElementType = readType(*Loc.F, Record, Idx);
5976  unsigned IndexTypeQuals = Record[2];
5977  unsigned Idx = 3;
5978  llvm::APInt Size = ReadAPInt(Record, Idx);
5979  return Context.getConstantArrayType(ElementType, Size,
5980  ASM, IndexTypeQuals);
5981  }
5982 
5983  case TYPE_INCOMPLETE_ARRAY: {
5984  QualType ElementType = readType(*Loc.F, Record, Idx);
5986  unsigned IndexTypeQuals = Record[2];
5987  return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
5988  }
5989 
5990  case TYPE_VARIABLE_ARRAY: {
5991  QualType ElementType = readType(*Loc.F, Record, Idx);
5993  unsigned IndexTypeQuals = Record[2];
5994  SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]);
5995  SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]);
5996  return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F),
5997  ASM, IndexTypeQuals,
5998  SourceRange(LBLoc, RBLoc));
5999  }
6000 
6001  case TYPE_VECTOR: {
6002  if (Record.size() != 3) {
6003  Error("incorrect encoding of vector type in AST file");
6004  return QualType();
6005  }
6006 
6007  QualType ElementType = readType(*Loc.F, Record, Idx);
6008  unsigned NumElements = Record[1];
6009  unsigned VecKind = Record[2];
6010  return Context.getVectorType(ElementType, NumElements,
6011  (VectorType::VectorKind)VecKind);
6012  }
6013 
6014  case TYPE_EXT_VECTOR: {
6015  if (Record.size() != 3) {
6016  Error("incorrect encoding of extended vector type in AST file");
6017  return QualType();
6018  }
6019 
6020  QualType ElementType = readType(*Loc.F, Record, Idx);
6021  unsigned NumElements = Record[1];
6022  return Context.getExtVectorType(ElementType, NumElements);
6023  }
6024 
6025  case TYPE_FUNCTION_NO_PROTO: {
6026  if (Record.size() != 8) {
6027  Error("incorrect encoding of no-proto function type");
6028  return QualType();
6029  }
6030  QualType ResultType = readType(*Loc.F, Record, Idx);
6031  FunctionType::ExtInfo Info(Record[1], Record[2], Record[3],
6032  (CallingConv)Record[4], Record[5], Record[6],
6033  Record[7]);
6034  return Context.getFunctionNoProtoType(ResultType, Info);
6035  }
6036 
6037  case TYPE_FUNCTION_PROTO: {
6038  QualType ResultType = readType(*Loc.F, Record, Idx);
6039 
6041  EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1],
6042  /*hasregparm*/ Record[2],
6043  /*regparm*/ Record[3],
6044  static_cast<CallingConv>(Record[4]),
6045  /*produces*/ Record[5],
6046  /*nocallersavedregs*/ Record[6],
6047  /*nocfcheck*/ Record[7]);
6048 
6049  unsigned Idx = 8;
6050 
6051  EPI.Variadic = Record[Idx++];
6052  EPI.HasTrailingReturn = Record[Idx++];
6053  EPI.TypeQuals = Qualifiers::fromOpaqueValue(Record[Idx++]);
6054  EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]);
6055  SmallVector<QualType, 8> ExceptionStorage;
6056  readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx);
6057 
6058  unsigned NumParams = Record[Idx++];
6059  SmallVector<QualType, 16> ParamTypes;
6060  for (unsigned I = 0; I != NumParams; ++I)
6061  ParamTypes.push_back(readType(*Loc.F, Record, Idx));
6062 
6064  if (Idx != Record.size()) {
6065  for (unsigned I = 0; I != NumParams; ++I)
6066  ExtParameterInfos.push_back(
6068  ::getFromOpaqueValue(Record[Idx++]));
6069  EPI.ExtParameterInfos = ExtParameterInfos.data();
6070  }
6071 
6072  assert(Idx == Record.size());
6073 
6074  return Context.getFunctionType(ResultType, ParamTypes, EPI);
6075  }
6076 
6077  case TYPE_UNRESOLVED_USING: {
6078  unsigned Idx = 0;
6079  return Context.getTypeDeclType(
6080  ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx));
6081  }
6082 
6083  case TYPE_TYPEDEF: {
6084  if (Record.size() != 2) {
6085  Error("incorrect encoding of typedef type");
6086  return QualType();
6087  }
6088  unsigned Idx = 0;
6089  TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx);
6090  QualType Canonical = readType(*Loc.F, Record, Idx);
6091  if (!Canonical.isNull())
6092  Canonical = Context.getCanonicalType(Canonical);
6093  return Context.getTypedefType(Decl, Canonical);
6094  }
6095 
6096  case TYPE_TYPEOF_EXPR:
6097  return Context.getTypeOfExprType(ReadExpr(*Loc.F));
6098 
6099  case TYPE_TYPEOF: {
6100  if (Record.size() != 1) {
6101  Error("incorrect encoding of typeof(type) in AST file");
6102  return QualType();
6103  }
6104  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6105  return Context.getTypeOfType(UnderlyingType);
6106  }
6107 
6108  case TYPE_DECLTYPE: {
6109  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6110  return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType);
6111  }
6112 
6113  case TYPE_UNARY_TRANSFORM: {
6114  QualType BaseType = readType(*Loc.F, Record, Idx);
6115  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6117  return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind);
6118  }
6119 
6120  case TYPE_AUTO: {
6121  QualType Deduced = readType(*Loc.F, Record, Idx);
6122  AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++];
6123  bool IsDependent = Deduced.isNull() ? Record[Idx++] : false;
6124  return Context.getAutoType(Deduced, Keyword, IsDependent);
6125  }
6126 
6128  TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
6129  QualType Deduced = readType(*Loc.F, Record, Idx);
6130  bool IsDependent = Deduced.isNull() ? Record[Idx++] : false;
6131  return Context.getDeducedTemplateSpecializationType(Name, Deduced,
6132  IsDependent);
6133  }
6134 
6135  case TYPE_RECORD: {
6136  if (Record.size() != 2) {
6137  Error("incorrect encoding of record type");
6138  return QualType();
6139  }
6140  unsigned Idx = 0;
6141  bool IsDependent = Record[Idx++];
6142  RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx);
6143  RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl());
6144  QualType T = Context.getRecordType(RD);
6145  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6146  return T;
6147  }
6148 
6149  case TYPE_ENUM: {
6150  if (Record.size() != 2) {
6151  Error("incorrect encoding of enum type");
6152  return QualType();
6153  }
6154  unsigned Idx = 0;
6155  bool IsDependent = Record[Idx++];
6156  QualType T
6157  = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx));
6158  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6159  return T;
6160  }
6161 
6162  case TYPE_ATTRIBUTED: {
6163  if (Record.size() != 3) {
6164  Error("incorrect encoding of attributed type");
6165  return QualType();
6166  }
6167  QualType modifiedType = readType(*Loc.F, Record, Idx);
6168  QualType equivalentType = readType(*Loc.F, Record, Idx);
6169  AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]);
6170  return Context.getAttributedType(kind, modifiedType, equivalentType);
6171  }
6172 
6173  case TYPE_PAREN: {
6174  if (Record.size() != 1) {
6175  Error("incorrect encoding of paren type");
6176  return QualType();
6177  }
6178  QualType InnerType = readType(*Loc.F, Record, Idx);
6179  return Context.getParenType(InnerType);
6180  }
6181 
6182  case TYPE_PACK_EXPANSION: {
6183  if (Record.size() != 2) {
6184  Error("incorrect encoding of pack expansion type");
6185  return QualType();
6186  }
6187  QualType Pattern = readType(*Loc.F, Record, Idx);
6188  if (Pattern.isNull())
6189  return QualType();
6190  Optional<unsigned> NumExpansions;
6191  if (Record[1])
6192  NumExpansions = Record[1] - 1;
6193  return Context.getPackExpansionType(Pattern, NumExpansions);
6194  }
6195 
6196  case TYPE_ELABORATED: {
6197  unsigned Idx = 0;
6198  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6199  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6200  QualType NamedType = readType(*Loc.F, Record, Idx);
6201  TagDecl *OwnedTagDecl = ReadDeclAs<TagDecl>(*Loc.F, Record, Idx);
6202  return Context.getElaboratedType(Keyword, NNS, NamedType, OwnedTagDecl);
6203  }
6204 
6205  case TYPE_OBJC_INTERFACE: {
6206  unsigned Idx = 0;
6207  ObjCInterfaceDecl *ItfD
6208  = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx);
6209  return Context.getObjCInterfaceType(ItfD->getCanonicalDecl());
6210  }
6211 
6212  case TYPE_OBJC_TYPE_PARAM: {
6213  unsigned Idx = 0;
6215  = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx);
6216  unsigned NumProtos = Record[Idx++];
6218  for (unsigned I = 0; I != NumProtos; ++I)
6219  Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx));
6220  return Context.getObjCTypeParamType(Decl, Protos);
6221  }
6222 
6223  case TYPE_OBJC_OBJECT: {
6224  unsigned Idx = 0;
6225  QualType Base = readType(*Loc.F, Record, Idx);
6226  unsigned NumTypeArgs = Record[Idx++];
6227  SmallVector<QualType, 4> TypeArgs;
6228  for (unsigned I = 0; I != NumTypeArgs; ++I)
6229  TypeArgs.push_back(readType(*Loc.F, Record, Idx));
6230  unsigned NumProtos = Record[Idx++];
6232  for (unsigned I = 0; I != NumProtos; ++I)
6233  Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx));
6234  bool IsKindOf = Record[Idx++];
6235  return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf);
6236  }
6237 
6238  case TYPE_OBJC_OBJECT_POINTER: {
6239  unsigned Idx = 0;
6240  QualType Pointee = readType(*Loc.F, Record, Idx);
6241  return Context.getObjCObjectPointerType(Pointee);
6242  }
6243 
6245  unsigned Idx = 0;
6246  QualType Parm = readType(*Loc.F, Record, Idx);
6247  QualType Replacement = readType(*Loc.F, Record, Idx);
6248  return Context.getSubstTemplateTypeParmType(
6249  cast<TemplateTypeParmType>(Parm),
6250  Context.getCanonicalType(Replacement));
6251  }
6252 
6254  unsigned Idx = 0;
6255  QualType Parm = readType(*Loc.F, Record, Idx);
6256  TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx);
6257  return Context.getSubstTemplateTypeParmPackType(
6258  cast<TemplateTypeParmType>(Parm),
6259  ArgPack);
6260  }
6261 
6262  case TYPE_INJECTED_CLASS_NAME: {
6263  CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx);
6264  QualType TST = readType(*Loc.F, Record, Idx); // probably derivable
6265  // FIXME: ASTContext::getInjectedClassNameType is not currently suitable
6266  // for AST reading, too much interdependencies.
6267  const Type *T = nullptr;
6268  for (auto *DI = D; DI; DI = DI->getPreviousDecl()) {
6269  if (const Type *Existing = DI->getTypeForDecl()) {
6270  T = Existing;
6271  break;
6272  }
6273  }
6274  if (!T) {
6275  T = new (Context, TypeAlignment) InjectedClassNameType(D, TST);
6276  for (auto *DI = D; DI; DI = DI->getPreviousDecl())
6277  DI->setTypeForDecl(T);
6278  }
6279  return QualType(T, 0);
6280  }
6281 
6282  case TYPE_TEMPLATE_TYPE_PARM: {
6283  unsigned Idx = 0;
6284  unsigned Depth = Record[Idx++];
6285  unsigned Index = Record[Idx++];
6286  bool Pack = Record[Idx++];
6288  = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx);
6289  return Context.getTemplateTypeParmType(Depth, Index, Pack, D);
6290  }
6291 
6292  case TYPE_DEPENDENT_NAME: {
6293  unsigned Idx = 0;
6294  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6295  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6296  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
6297  QualType Canon = readType(*Loc.F, Record, Idx);
6298  if (!Canon.isNull())
6299  Canon = Context.getCanonicalType(Canon);
6300  return Context.getDependentNameType(Keyword, NNS, Name, Canon);
6301  }
6302 
6304  unsigned Idx = 0;
6305  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6306  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6307  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
6308  unsigned NumArgs = Record[Idx++];
6310  Args.reserve(NumArgs);
6311  while (NumArgs--)
6312  Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx));
6313  return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name,
6314  Args);
6315  }
6316 
6318  unsigned Idx = 0;
6319 
6320  // ArrayType
6321  QualType ElementType = readType(*Loc.F, Record, Idx);
6323  = (ArrayType::ArraySizeModifier)Record[Idx++];
6324  unsigned IndexTypeQuals = Record[Idx++];
6325 
6326  // DependentSizedArrayType
6327  Expr *NumElts = ReadExpr(*Loc.F);
6328  SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx);
6329 
6330  return Context.getDependentSizedArrayType(ElementType, NumElts, ASM,
6331  IndexTypeQuals, Brackets);
6332  }
6333 
6335  unsigned Idx = 0;
6336  bool IsDependent = Record[Idx++];
6337  TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
6339  ReadTemplateArgumentList(Args, *Loc.F, Record, Idx);
6340  QualType Underlying = readType(*Loc.F, Record, Idx);
6341  QualType T;
6342  if (Underlying.isNull())
6343  T = Context.getCanonicalTemplateSpecializationType(Name, Args);
6344  else
6345  T = Context.getTemplateSpecializationType(Name, Args, Underlying);
6346  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6347  return T;
6348  }
6349 
6350  case TYPE_ATOMIC: {
6351  if (Record.size() != 1) {
6352  Error("Incorrect encoding of atomic type");
6353  return QualType();
6354  }
6355  QualType ValueType = readType(*Loc.F, Record, Idx);
6356  return Context.getAtomicType(ValueType);
6357  }
6358 
6359  case TYPE_PIPE: {
6360  if (Record.size() != 2) {
6361  Error("Incorrect encoding of pipe type");
6362  return QualType();
6363  }
6364 
6365  // Reading the pipe element type.
6366  QualType ElementType = readType(*Loc.F, Record, Idx);
6367  unsigned ReadOnly = Record[1];
6368  return Context.getPipeType(ElementType, ReadOnly);
6369  }
6370 
6372  unsigned Idx = 0;
6373  QualType ElementType = readType(*Loc.F, Record, Idx);
6374  Expr *SizeExpr = ReadExpr(*Loc.F);
6375  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6376  unsigned VecKind = Record[Idx];
6377 
6378  return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc,
6379  (VectorType::VectorKind)VecKind);
6380  }
6381 
6383  unsigned Idx = 0;
6384 
6385  // DependentSizedExtVectorType
6386  QualType ElementType = readType(*Loc.F, Record, Idx);
6387  Expr *SizeExpr = ReadExpr(*Loc.F);
6388  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6389 
6390  return Context.getDependentSizedExtVectorType(ElementType, SizeExpr,
6391  AttrLoc);
6392  }
6393 
6395  unsigned Idx = 0;
6396 
6397  // DependentAddressSpaceType
6398  QualType PointeeType = readType(*Loc.F, Record, Idx);
6399  Expr *AddrSpaceExpr = ReadExpr(*Loc.F);
6400  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6401 
6402  return Context.getDependentAddressSpaceType(PointeeType, AddrSpaceExpr,
6403  AttrLoc);
6404  }
6405  }
6406  llvm_unreachable("Invalid TypeCode!");
6407 }
6408 
6409 void ASTReader::readExceptionSpec(ModuleFile &ModuleFile,
6410  SmallVectorImpl<QualType> &Exceptions,
6412  const RecordData &Record, unsigned &Idx) {
6414  static_cast<ExceptionSpecificationType>(Record[Idx++]);
6415  ESI.Type = EST;
6416  if (EST == EST_Dynamic) {
6417  for (unsigned I = 0, N = Record[Idx++]; I != N; ++I)
6418  Exceptions.push_back(readType(ModuleFile, Record, Idx));
6419  ESI.Exceptions = Exceptions;
6420  } else if (isComputedNoexcept(EST)) {
6421  ESI.NoexceptExpr = ReadExpr(ModuleFile);
6422  } else if (EST == EST_Uninstantiated) {
6423  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6424  ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6425  } else if (EST == EST_Unevaluated) {
6426  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6427  }
6428 }
6429 
6430 namespace clang {
6431 
6432 class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
6433  ModuleFile *F;
6434  ASTReader *Reader;
6435  const ASTReader::RecordData &Record;
6436  unsigned &Idx;
6437 
6438  SourceLocation ReadSourceLocation() {
6439  return Reader->ReadSourceLocation(*F, Record, Idx);
6440  }
6441 
6442  TypeSourceInfo *GetTypeSourceInfo() {
6443  return Reader->GetTypeSourceInfo(*F, Record, Idx);
6444  }
6445 
6446  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() {
6447  return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
6448  }
6449 
6450  Attr *ReadAttr() {
6451  return Reader->ReadAttr(*F, Record, Idx);
6452  }
6453 
6454 public:
6455  TypeLocReader(ModuleFile &F, ASTReader &Reader,
6456  const ASTReader::RecordData &Record, unsigned &Idx)
6457  : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {}
6458 
6459  // We want compile-time assurance that we've enumerated all of
6460  // these, so unfortunately we have to declare them first, then
6461  // define them out-of-line.
6462 #define ABSTRACT_TYPELOC(CLASS, PARENT)
6463 #define TYPELOC(CLASS, PARENT) \
6464  void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
6465 #include "clang/AST/TypeLocNodes.def"
6466 
6467  void VisitFunctionTypeLoc(FunctionTypeLoc);
6468  void VisitArrayTypeLoc(ArrayTypeLoc);
6469 };
6470 
6471 } // namespace clang
6472 
6473 void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
6474  // nothing to do
6475 }
6476 
6477 void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
6478  TL.setBuiltinLoc(ReadSourceLocation());
6479  if (TL.needsExtraLocalData()) {
6480  TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++]));
6481  TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++]));
6482  TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++]));
6483  TL.setModeAttr(Record[Idx++]);
6484  }
6485 }
6486 
6487 void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) {
6488  TL.setNameLoc(ReadSourceLocation());
6489 }
6490 
6491 void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
6492  TL.setStarLoc(ReadSourceLocation());
6493 }
6494 
6495 void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
6496  // nothing to do
6497 }
6498 
6499 void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
6500  // nothing to do
6501 }
6502 
6503 void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
6504  TL.setCaretLoc(ReadSourceLocation());
6505 }
6506 
6507 void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
6508  TL.setAmpLoc(ReadSourceLocation());
6509 }
6510 
6511 void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
6512  TL.setAmpAmpLoc(ReadSourceLocation());
6513 }
6514 
6515 void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
6516  TL.setStarLoc(ReadSourceLocation());
6517  TL.setClassTInfo(GetTypeSourceInfo());
6518 }
6519 
6521  TL.setLBracketLoc(ReadSourceLocation());
6522  TL.setRBracketLoc(ReadSourceLocation());
6523  if (Record[Idx++])
6524  TL.setSizeExpr(Reader->ReadExpr(*F));
6525  else
6526  TL.setSizeExpr(nullptr);
6527 }
6528 
6529 void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
6530  VisitArrayTypeLoc(TL);
6531 }
6532 
6533 void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
6534  VisitArrayTypeLoc(TL);
6535 }
6536 
6537 void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
6538  VisitArrayTypeLoc(TL);
6539 }
6540 
6541 void TypeLocReader::VisitDependentSizedArrayTypeLoc(
6543  VisitArrayTypeLoc(TL);
6544 }
6545 
6546 void TypeLocReader::VisitDependentAddressSpaceTypeLoc(
6548 
6549  TL.setAttrNameLoc(ReadSourceLocation());
6550  SourceRange range;
6551  range.setBegin(ReadSourceLocation());
6552  range.setEnd(ReadSourceLocation());
6553  TL.setAttrOperandParensRange(range);
6554  TL.setAttrExprOperand(Reader->ReadExpr(*F));
6555 }
6556 
6557 void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
6559  TL.setNameLoc(ReadSourceLocation());
6560 }
6561 
6562 void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
6563  TL.setNameLoc(ReadSourceLocation());
6564 }
6565 
6566 void TypeLocReader::VisitDependentVectorTypeLoc(
6568  TL.setNameLoc(ReadSourceLocation());
6569 }
6570 
6571 void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
6572  TL.setNameLoc(ReadSourceLocation());
6573 }
6574 
6576  TL.setLocalRangeBegin(ReadSourceLocation());
6577  TL.setLParenLoc(ReadSourceLocation());
6578  TL.setRParenLoc(ReadSourceLocation());
6579  TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx),
6580  Reader->ReadSourceLocation(*F, Record, Idx)));
6581  TL.setLocalRangeEnd(ReadSourceLocation());
6582  for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) {
6583  TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx));
6584  }
6585 }
6586 
6587 void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
6588  VisitFunctionTypeLoc(TL);
6589 }
6590 
6591 void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
6592  VisitFunctionTypeLoc(TL);
6593 }
6594 
6595 void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
6596  TL.setNameLoc(ReadSourceLocation());
6597 }
6598 
6599 void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
6600  TL.setNameLoc(ReadSourceLocation());
6601 }
6602 
6603 void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
6604  TL.setTypeofLoc(ReadSourceLocation());
6605  TL.setLParenLoc(ReadSourceLocation());
6606  TL.setRParenLoc(ReadSourceLocation());
6607 }
6608 
6609 void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
6610  TL.setTypeofLoc(ReadSourceLocation());
6611  TL.setLParenLoc(ReadSourceLocation());
6612  TL.setRParenLoc(ReadSourceLocation());
6613  TL.setUnderlyingTInfo(GetTypeSourceInfo());
6614 }
6615 
6616 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
6617  TL.setNameLoc(ReadSourceLocation());
6618 }
6619 
6620 void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
6621  TL.setKWLoc(ReadSourceLocation());
6622  TL.setLParenLoc(ReadSourceLocation());
6623  TL.setRParenLoc(ReadSourceLocation());
6624  TL.setUnderlyingTInfo(GetTypeSourceInfo());
6625 }
6626 
6627 void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) {
6628  TL.setNameLoc(ReadSourceLocation());
6629 }
6630 
6631 void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
6633  TL.setTemplateNameLoc(ReadSourceLocation());
6634 }
6635 
6636 void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) {
6637  TL.setNameLoc(ReadSourceLocation());
6638 }
6639 
6640 void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) {
6641  TL.setNameLoc(ReadSourceLocation());
6642 }
6643 
6644 void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
6645  TL.setAttr(ReadAttr());
6646 }
6647 
6648 void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
6649  TL.setNameLoc(ReadSourceLocation());
6650 }
6651 
6652 void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc(
6654  TL.setNameLoc(ReadSourceLocation());
6655 }
6656 
6657 void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc(
6659  TL.setNameLoc(ReadSourceLocation());
6660 }
6661 
6662 void TypeLocReader::VisitTemplateSpecializationTypeLoc(
6664  TL.setTemplateKeywordLoc(ReadSourceLocation());
6665  TL.setTemplateNameLoc(ReadSourceLocation());
6666  TL.setLAngleLoc(ReadSourceLocation());
6667  TL.setRAngleLoc(ReadSourceLocation());
6668  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
6669  TL.setArgLocInfo(
6670  i,
6671  Reader->GetTemplateArgumentLocInfo(
6672  *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx));
6673 }
6674 
6675 void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) {
6676  TL.setLParenLoc(ReadSourceLocation());
6677  TL.setRParenLoc(ReadSourceLocation());
6678 }
6679 
6680 void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
6681  TL.setElaboratedKeywordLoc(ReadSourceLocation());
6682  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
6683 }
6684 
6685 void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
6686  TL.setNameLoc(ReadSourceLocation());
6687 }
6688 
6689 void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
6690  TL.setElaboratedKeywordLoc(ReadSourceLocation());
6691  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
6692  TL.setNameLoc(ReadSourceLocation());
6693 }
6694 
6695 void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc(
6697  TL.setElaboratedKeywordLoc(ReadSourceLocation());
6698  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
6699  TL.setTemplateKeywordLoc(ReadSourceLocation());
6700  TL.setTemplateNameLoc(ReadSourceLocation());
6701  TL.setLAngleLoc(ReadSourceLocation());
6702  TL.setRAngleLoc(ReadSourceLocation());
6703  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
6704  TL.setArgLocInfo(
6705  I,
6706  Reader->GetTemplateArgumentLocInfo(
6707  *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx));
6708 }
6709 
6710 void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
6711  TL.setEllipsisLoc(ReadSourceLocation());
6712 }
6713 
6714 void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
6715  TL.setNameLoc(ReadSourceLocation());
6716 }
6717 
6718 void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
6719  if (TL.getNumProtocols()) {
6720  TL.setProtocolLAngleLoc(ReadSourceLocation());
6721  TL.setProtocolRAngleLoc(ReadSourceLocation());
6722  }
6723  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
6724  TL.setProtocolLoc(i, ReadSourceLocation());
6725 }
6726 
6727 void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
6728  TL.setHasBaseTypeAsWritten(Record[Idx++]);
6729  TL.setTypeArgsLAngleLoc(ReadSourceLocation());
6730  TL.setTypeArgsRAngleLoc(ReadSourceLocation());
6731  for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i)
6732  TL.setTypeArgTInfo(i, GetTypeSourceInfo());
6733  TL.setProtocolLAngleLoc(ReadSourceLocation());
6734  TL.setProtocolRAngleLoc(ReadSourceLocation());
6735  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
6736  TL.setProtocolLoc(i, ReadSourceLocation());
6737 }
6738 
6739 void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
6740  TL.setStarLoc(ReadSourceLocation());
6741 }
6742 
6743 void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
6744  TL.setKWLoc(ReadSourceLocation());
6745  TL.setLParenLoc(ReadSourceLocation());
6746  TL.setRParenLoc(ReadSourceLocation());
6747 }
6748 
6749 void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) {
6750  TL.setKWLoc(ReadSourceLocation());
6751 }
6752 
6753 void ASTReader::ReadTypeLoc(ModuleFile &F, const ASTReader::RecordData &Record,
6754  unsigned &Idx, TypeLoc TL) {
6755  TypeLocReader TLR(F, *this, Record, Idx);
6756  for (; !TL.isNull(); TL = TL.getNextTypeLoc())
6757  TLR.Visit(TL);
6758 }
6759 
6762  unsigned &Idx) {
6763  QualType InfoTy = readType(F, Record, Idx);
6764  if (InfoTy.isNull())
6765  return nullptr;
6766 
6767  TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy);
6768  ReadTypeLoc(F, Record, Idx, TInfo->getTypeLoc());
6769  return TInfo;
6770 }
6771 
6773  assert(ContextObj && "reading type with no AST context");
6774  ASTContext &Context = *ContextObj;
6775 
6776  unsigned FastQuals = ID & Qualifiers::FastMask;
6777  unsigned Index = ID >> Qualifiers::FastWidth;
6778 
6779  if (Index < NUM_PREDEF_TYPE_IDS) {
6780  QualType T;
6781  switch ((PredefinedTypeIDs)Index) {
6782  case PREDEF_TYPE_NULL_ID:
6783  return QualType();
6784  case PREDEF_TYPE_VOID_ID:
6785  T = Context.VoidTy;
6786  break;
6787  case PREDEF_TYPE_BOOL_ID:
6788  T = Context.BoolTy;
6789  break;
6790  case PREDEF_TYPE_CHAR_U_ID:
6791  case PREDEF_TYPE_CHAR_S_ID:
6792  // FIXME: Check that the signedness of CharTy is correct!
6793  T = Context.CharTy;
6794  break;
6795  case PREDEF_TYPE_UCHAR_ID:
6796  T = Context.UnsignedCharTy;
6797  break;
6798  case PREDEF_TYPE_USHORT_ID:
6799  T = Context.UnsignedShortTy;
6800  break;
6801  case PREDEF_TYPE_UINT_ID:
6802  T = Context.UnsignedIntTy;
6803  break;
6804  case PREDEF_TYPE_ULONG_ID:
6805  T = Context.UnsignedLongTy;
6806  break;
6808  T = Context.UnsignedLongLongTy;
6809  break;
6811  T = Context.UnsignedInt128Ty;
6812  break;
6813  case PREDEF_TYPE_SCHAR_ID:
6814  T = Context.SignedCharTy;
6815  break;
6816  case PREDEF_TYPE_WCHAR_ID:
6817  T = Context.WCharTy;
6818  break;
6819  case PREDEF_TYPE_SHORT_ID:
6820  T = Context.ShortTy;
6821  break;
6822  case PREDEF_TYPE_INT_ID:
6823  T = Context.IntTy;
6824  break;
6825  case PREDEF_TYPE_LONG_ID:
6826  T = Context.LongTy;
6827  break;
6829  T = Context.LongLongTy;
6830  break;
6831  case PREDEF_TYPE_INT128_ID:
6832  T = Context.Int128Ty;
6833  break;
6834  case PREDEF_TYPE_HALF_ID:
6835  T = Context.HalfTy;
6836  break;
6837  case PREDEF_TYPE_FLOAT_ID:
6838  T = Context.FloatTy;
6839  break;
6840  case PREDEF_TYPE_DOUBLE_ID:
6841  T = Context.DoubleTy;
6842  break;
6844  T = Context.LongDoubleTy;
6845  break;
6847  T = Context.ShortAccumTy;
6848  break;
6849  case PREDEF_TYPE_ACCUM_ID:
6850  T = Context.AccumTy;
6851  break;
6853  T = Context.LongAccumTy;
6854  break;
6856  T = Context.UnsignedShortAccumTy;
6857  break;
6858  case PREDEF_TYPE_UACCUM_ID:
6859  T = Context.UnsignedAccumTy;
6860  break;
6862  T = Context.UnsignedLongAccumTy;
6863  break;
6865  T = Context.ShortFractTy;
6866  break;
6867  case PREDEF_TYPE_FRACT_ID:
6868  T = Context.FractTy;
6869  break;
6871  T = Context.LongFractTy;
6872  break;
6874  T = Context.UnsignedShortFractTy;
6875  break;
6876  case PREDEF_TYPE_UFRACT_ID:
6877  T = Context.UnsignedFractTy;
6878  break;
6880  T = Context.UnsignedLongFractTy;
6881  break;
6883  T = Context.SatShortAccumTy;
6884  break;
6886  T = Context.SatAccumTy;
6887  break;
6889  T = Context.SatLongAccumTy;
6890  break;
6892  T = Context.SatUnsignedShortAccumTy;
6893  break;
6895  T = Context.SatUnsignedAccumTy;
6896  break;
6898  T = Context.SatUnsignedLongAccumTy;
6899  break;
6901  T = Context.SatShortFractTy;
6902  break;
6904  T = Context.SatFractTy;
6905  break;
6907  T = Context.SatLongFractTy;
6908  break;
6910  T = Context.SatUnsignedShortFractTy;
6911  break;
6913  T = Context.SatUnsignedFractTy;
6914  break;
6916  T = Context.SatUnsignedLongFractTy;
6917  break;
6919  T = Context.Float16Ty;
6920  break;
6922  T = Context.Float128Ty;
6923  break;
6925  T = Context.OverloadTy;
6926  break;
6928  T = Context.BoundMemberTy;
6929  break;
6931  T = Context.PseudoObjectTy;
6932  break;
6934  T = Context.DependentTy;
6935  break;
6937  T = Context.UnknownAnyTy;
6938  break;
6940  T = Context.NullPtrTy;
6941  break;
6942  case PREDEF_TYPE_CHAR8_ID:
6943  T = Context.Char8Ty;
6944  break;
6945  case PREDEF_TYPE_CHAR16_ID:
6946  T = Context.Char16Ty;
6947  break;
6948  case PREDEF_TYPE_CHAR32_ID:
6949  T = Context.Char32Ty;
6950  break;
6951  case PREDEF_TYPE_OBJC_ID:
6952  T = Context.ObjCBuiltinIdTy;
6953  break;
6955  T = Context.ObjCBuiltinClassTy;
6956  break;
6957  case PREDEF_TYPE_OBJC_SEL:
6958  T = Context.ObjCBuiltinSelTy;
6959  break;
6960 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6961  case PREDEF_TYPE_##Id##_ID: \
6962  T = Context.SingletonId; \
6963  break;
6964 #include "clang/Basic/OpenCLImageTypes.def"
6965 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
6966  case PREDEF_TYPE_##Id##_ID: \
6967  T = Context.Id##Ty; \
6968  break;
6969 #include "clang/Basic/OpenCLExtensionTypes.def"
6971  T = Context.OCLSamplerTy;
6972  break;
6973  case PREDEF_TYPE_EVENT_ID:
6974  T = Context.OCLEventTy;
6975  break;
6977  T = Context.OCLClkEventTy;
6978  break;
6979  case PREDEF_TYPE_QUEUE_ID:
6980  T = Context.OCLQueueTy;
6981  break;
6983  T = Context.OCLReserveIDTy;
6984  break;
6986  T = Context.getAutoDeductType();
6987  break;
6989  T = Context.getAutoRRefDeductType();
6990  break;
6992  T = Context.ARCUnbridgedCastTy;
6993  break;
6995  T = Context.BuiltinFnTy;
6996  break;
6998  T = Context.OMPArraySectionTy;
6999  break;
7000  }
7001 
7002  assert(!T.isNull() && "Unknown predefined type");
7003  return T.withFastQualifiers(FastQuals);
7004  }
7005 
7006  Index -= NUM_PREDEF_TYPE_IDS;
7007  assert(Index < TypesLoaded.size() && "Type index out-of-range");
7008  if (TypesLoaded[Index].isNull()) {
7009  TypesLoaded[Index] = readTypeRecord(Index);
7010  if (TypesLoaded[Index].isNull())
7011  return QualType();
7012 
7013  TypesLoaded[Index]->setFromAST();
7014  if (DeserializationListener)
7015  DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
7016  TypesLoaded[Index]);
7017  }
7018 
7019  return TypesLoaded[Index].withFastQualifiers(FastQuals);
7020 }
7021 
7022 QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) {
7023  return GetType(getGlobalTypeID(F, LocalID));
7024 }
7025 
7027 ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const {
7028  unsigned FastQuals = LocalID & Qualifiers::FastMask;
7029  unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
7030 
7031  if (LocalIndex < NUM_PREDEF_TYPE_IDS)
7032  return LocalID;
7033 
7034  if (!F.ModuleOffsetMap.empty())
7035  ReadModuleOffsetMap(F);
7036 
7038  = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS);
7039  assert(I != F.TypeRemap.end() && "Invalid index into type index remap");
7040 
7041  unsigned GlobalIndex = LocalIndex + I->second;
7042  return (GlobalIndex << Qualifiers::FastWidth) | FastQuals;
7043 }
7044 
7048  const RecordData &Record,
7049  unsigned &Index) {
7050  switch (Kind) {
7052  return ReadExpr(F);
7054  return GetTypeSourceInfo(F, Record, Index);
7056  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
7057  Index);
7058  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
7059  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
7060  SourceLocation());
7061  }
7063  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
7064  Index);
7065  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
7066  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index);
7067  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
7068  EllipsisLoc);
7069  }
7075  // FIXME: Is this right?
7076  return TemplateArgumentLocInfo();
7077  }
7078  llvm_unreachable("unexpected template argument loc");
7079 }
7080 
7083  const RecordData &Record, unsigned &Index) {
7084  TemplateArgument Arg = ReadTemplateArgument(F, Record, Index);
7085 
7086  if (Arg.getKind() == TemplateArgument::Expression) {
7087  if (Record[Index++]) // bool InfoHasSameExpr.
7089  }
7090  return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(),
7091  Record, Index));
7092 }
7093 
7096  const RecordData &Record,
7097  unsigned &Index) {
7098  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index);
7099  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index);
7100  unsigned NumArgsAsWritten = Record[Index++];
7101  TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
7102  for (unsigned i = 0; i != NumArgsAsWritten; ++i)
7103  TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index));
7104  return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo);
7105 }
7106 
7108  return GetDecl(ID);
7109 }
7110 
7112  if (NumCurrentElementsDeserializing) {
7113  // We arrange to not care about the complete redeclaration chain while we're
7114  // deserializing. Just remember that the AST has marked this one as complete
7115  // but that it's not actually complete yet, so we know we still need to
7116  // complete it later.
7117  PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D));
7118  return;
7119  }
7120 
7121  const DeclContext *DC = D->getDeclContext()->getRedeclContext();
7122 
7123  // If this is a named declaration, complete it by looking it up
7124  // within its context.
7125  //
7126  // FIXME: Merging a function definition should merge
7127  // all mergeable entities within it.
7128  if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) ||
7129  isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) {
7130  if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) {
7131  if (!getContext().getLangOpts().CPlusPlus &&
7132  isa<TranslationUnitDecl>(DC)) {
7133  // Outside of C++, we don't have a lookup table for the TU, so update
7134  // the identifier instead. (For C++ modules, we don't store decls
7135  // in the serialized identifier table, so we do the lookup in the TU.)
7136  auto *II = Name.getAsIdentifierInfo();
7137  assert(II && "non-identifier name in C?");
7138  if (II->isOutOfDate())
7139  updateOutOfDateIdentifier(*II);
7140  } else
7141  DC->lookup(Name);
7142  } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) {
7143  // Find all declarations of this kind from the relevant context.
7144  for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) {
7145  auto *DC = cast<DeclContext>(DCDecl);
7146  SmallVector<Decl*, 8> Decls;
7147  FindExternalLexicalDecls(
7148  DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls);
7149  }
7150  }
7151  }
7152 
7153  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
7154  CTSD->getSpecializedTemplate()->LoadLazySpecializations();
7155  if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
7156  VTSD->getSpecializedTemplate()->LoadLazySpecializations();
7157  if (auto *FD = dyn_cast<FunctionDecl>(D)) {
7158  if (auto *Template = FD->getPrimaryTemplate())
7159  Template->LoadLazySpecializations();
7160  }
7161 }
7162 
7165  RecordLocation Loc = getLocalBitOffset(Offset);
7166  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
7167  SavedStreamPosition SavedPosition(Cursor);
7168  Cursor.JumpToBit(Loc.Offset);
7169  ReadingKindTracker ReadingKind(Read_Decl, *this);
7170 
7171  RecordData Record;
7172  unsigned Code = Cursor.ReadCode();
7173  unsigned RecCode = Cursor.readRecord(Code, Record);
7174  if (RecCode != DECL_CXX_CTOR_INITIALIZERS) {
7175  Error("malformed AST file: missing C++ ctor initializers");
7176  return nullptr;
7177  }
7178 
7179  unsigned Idx = 0;
7180  return ReadCXXCtorInitializers(*Loc.F, Record, Idx);
7181 }
7182 
7184  assert(ContextObj && "reading base specifiers with no AST context");
7185  ASTContext &Context = *ContextObj;
7186 
7187  RecordLocation Loc = getLocalBitOffset(Offset);
7188  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
7189  SavedStreamPosition SavedPosition(Cursor);
7190  Cursor.JumpToBit(Loc.Offset);
7191  ReadingKindTracker ReadingKind(Read_Decl, *this);
7192  RecordData Record;
7193  unsigned Code = Cursor.ReadCode();
7194  unsigned RecCode = Cursor.readRecord(Code, Record);
7195  if (RecCode != DECL_CXX_BASE_SPECIFIERS) {
7196  Error("malformed AST file: missing C++ base specifiers");
7197  return nullptr;
7198  }
7199 
7200  unsigned Idx = 0;
7201  unsigned NumBases = Record[Idx++];
7202  void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases);
7203  CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases];
7204  for (unsigned I = 0; I != NumBases; ++I)
7205  Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx);
7206  return Bases;
7207 }
7208 
7210 ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const {
7211  if (LocalID < NUM_PREDEF_DECL_IDS)
7212  return LocalID;
7213 
7214  if (!F.ModuleOffsetMap.empty())
7215  ReadModuleOffsetMap(F);
7216 
7218  = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS);
7219  assert(I != F.DeclRemap.end() && "Invalid index into decl index remap");
7220 
7221  return LocalID + I->second;
7222 }
7223 
7225  ModuleFile &M) const {
7226  // Predefined decls aren't from any module.
7227  if (ID < NUM_PREDEF_DECL_IDS)
7228  return false;
7229 
7230  return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID &&
7231  ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls;
7232 }
7233 
7234 ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) {
7235  if (!D->isFromASTFile())
7236  return nullptr;
7237  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID());
7238  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
7239  return I->second;
7240 }
7241 
7243  if (ID < NUM_PREDEF_DECL_IDS)
7244  return SourceLocation();
7245 
7246  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7247 
7248  if (Index > DeclsLoaded.size()) {
7249  Error("declaration ID out-of-range for AST file");
7250  return SourceLocation();
7251  }
7252 
7253  if (Decl *D = DeclsLoaded[Index])
7254  return D->getLocation();
7255 
7256  SourceLocation Loc;
7257  DeclCursorForID(ID, Loc);
7258  return Loc;
7259 }
7260 
7262  switch (ID) {
7263  case PREDEF_DECL_NULL_ID:
7264  return nullptr;
7265 
7267  return Context.getTranslationUnitDecl();
7268 
7270  return Context.getObjCIdDecl();
7271 
7273  return Context.getObjCSelDecl();
7274 
7276  return Context.getObjCClassDecl();
7277 
7279  return Context.getObjCProtocolDecl();
7280 
7282  return Context.getInt128Decl();
7283 
7285  return Context.getUInt128Decl();
7286 
7288  return Context.getObjCInstanceTypeDecl();
7289 
7291  return Context.getBuiltinVaListDecl();
7292 
7294  return Context.getVaListTagDecl();
7295 
7297  return Context.getBuiltinMSVaListDecl();
7298 
7300  return Context.getExternCContextDecl();
7301 
7303  return Context.getMakeIntegerSeqDecl();
7304 
7306  return Context.getCFConstantStringDecl();
7307 
7309  return Context.getCFConstantStringTagDecl();
7310 
7312  return Context.getTypePackElementDecl();
7313  }
7314  llvm_unreachable("PredefinedDeclIDs unknown enum value");
7315 }
7316 
7318  assert(ContextObj && "reading decl with no AST context");
7319  if (ID < NUM_PREDEF_DECL_IDS) {
7320  Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID);
7321  if (D) {
7322  // Track that we have merged the declaration with ID \p ID into the
7323  // pre-existing predefined declaration \p D.
7324  auto &Merged = KeyDecls[D->getCanonicalDecl()];
7325  if (Merged.empty())
7326  Merged.push_back(ID);
7327  }
7328  return D;
7329  }
7330 
7331  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7332 
7333  if (Index >= DeclsLoaded.size()) {
7334  assert(0 && "declaration ID out-of-range for AST file");
7335  Error("declaration ID out-of-range for AST file");
7336  return nullptr;
7337  }
7338 
7339  return DeclsLoaded[Index];
7340 }
7341 
7343  if (ID < NUM_PREDEF_DECL_IDS)
7344  return GetExistingDecl(ID);
7345 
7346  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7347 
7348  if (Index >= DeclsLoaded.size()) {
7349  assert(0 && "declaration ID out-of-range for AST file");
7350  Error("declaration ID out-of-range for AST file");
7351  return nullptr;
7352  }
7353 
7354  if (!DeclsLoaded[Index]) {
7355  ReadDeclRecord(ID);
7356  if (DeserializationListener)
7357  DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
7358  }
7359 
7360  return DeclsLoaded[Index];
7361 }
7362 
7364  DeclID GlobalID) {
7365  if (GlobalID < NUM_PREDEF_DECL_IDS)
7366  return GlobalID;
7367 
7368  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID);
7369  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
7370  ModuleFile *Owner = I->second;
7371 
7372  llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos
7373  = M.GlobalToLocalDeclIDs.find(Owner);
7374  if (Pos == M.GlobalToLocalDeclIDs.end())
7375  return 0;
7376 
7377  return GlobalID - Owner->BaseDeclID + Pos->second;
7378 }
7379 
7381  const RecordData &Record,
7382  unsigned &Idx) {
7383  if (Idx >= Record.size()) {
7384  Error("Corrupted AST file");
7385  return 0;
7386  }
7387 
7388  return getGlobalDeclID(F, Record[Idx++]);
7389 }
7390 
7391 /// Resolve the offset of a statement into a statement.
7392 ///
7393 /// This operation will read a new statement from the external
7394 /// source each time it is called, and is meant to be used via a
7395 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
7397  // Switch case IDs are per Decl.
7398  ClearSwitchCaseIDs();
7399 
7400  // Offset here is a global offset across the entire chain.
7401  RecordLocation Loc = getLocalBitOffset(Offset);
7402  Loc.F->DeclsCursor.JumpToBit(Loc.Offset);
7403  assert(NumCurrentElementsDeserializing == 0 &&
7404  "should not be called while already deserializing");
7405  Deserializing D(this);
7406  return ReadStmtFromStream(*Loc.F);
7407 }
7408 
7410  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
7411  SmallVectorImpl<Decl *> &Decls) {
7412  bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {};
7413 
7414  auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) {
7415  assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries");
7416  for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) {
7417  auto K = (Decl::Kind)+LexicalDecls[I];
7418  if (!IsKindWeWant(K))
7419  continue;
7420 
7421  auto ID = (serialization::DeclID)+LexicalDecls[I + 1];
7422 
7423  // Don't add predefined declarations to the lexical context more
7424  // than once.
7425  if (ID < NUM_PREDEF_DECL_IDS) {
7426  if (PredefsVisited[ID])
7427  continue;
7428 
7429  PredefsVisited[ID] = true;
7430  }
7431 
7432  if (Decl *D = GetLocalDecl(*M, ID)) {
7433  assert(D->getKind() == K && "wrong kind for lexical decl");
7434  if (!DC->isDeclInLexicalTraversal(D))
7435  Decls.push_back(D);
7436  }
7437  }
7438  };
7439 
7440  if (isa<TranslationUnitDecl>(DC)) {
7441  for (auto Lexical : TULexicalDecls)
7442  Visit(Lexical.first, Lexical.second);
7443  } else {
7444  auto I = LexicalDecls.find(DC);
7445  if (I != LexicalDecls.end())
7446  Visit(I->second.first, I->second.second);
7447  }
7448 
7449  ++NumLexicalDeclContextsRead;
7450 }
7451 
7452 namespace {
7453 
7454 class DeclIDComp {
7455  ASTReader &Reader;
7456  ModuleFile &Mod;
7457 
7458 public:
7459  DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {}
7460 
7461  bool operator()(LocalDeclID L, LocalDeclID R) const {
7462  SourceLocation LHS = getLocation(L);
7463  SourceLocation RHS = getLocation(R);
7464  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7465  }
7466 
7467  bool operator()(SourceLocation LHS, LocalDeclID R) const {
7468  SourceLocation RHS = getLocation(R);
7469  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7470  }
7471 
7472  bool operator()(LocalDeclID L, SourceLocation RHS) const {
7473  SourceLocation LHS = getLocation(L);
7474  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7475  }
7476 
7477  SourceLocation getLocation(LocalDeclID ID) const {
7478  return Reader.getSourceManager().getFileLoc(
7479  Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID)));
7480  }
7481 };
7482 
7483 } // namespace
7484 
7486  unsigned Offset, unsigned Length,
7487  SmallVectorImpl<Decl *> &Decls) {
7488  SourceManager &SM = getSourceManager();
7489 
7490  llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File);
7491  if (I == FileDeclIDs.end())
7492  return;
7493 
7494  FileDeclsInfo &DInfo = I->second;
7495  if (DInfo.Decls.empty())
7496  return;
7497 
7499  BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset);
7500  SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length);
7501 
7502  DeclIDComp DIDComp(*this, *DInfo.Mod);
7504  BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
7505  BeginLoc, DIDComp);
7506  if (BeginIt != DInfo.Decls.begin())
7507  --BeginIt;
7508 
7509  // If we are pointing at a top-level decl inside an objc container, we need
7510  // to backtrack until we find it otherwise we will fail to report that the
7511  // region overlaps with an objc container.
7512  while (BeginIt != DInfo.Decls.begin() &&
7513  GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt))
7514  ->isTopLevelDeclInObjCContainer())
7515  --BeginIt;
7516 
7518  EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
7519  EndLoc, DIDComp);
7520  if (EndIt != DInfo.Decls.end())
7521  ++EndIt;
7522 
7524  DIt = BeginIt; DIt != EndIt; ++DIt)
7525  Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt)));
7526 }
7527 
7528 bool
7530  DeclarationName Name) {
7531  assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
7532  "DeclContext has no visible decls in storage");
7533  if (!Name)
7534  return false;
7535 
7536  auto It = Lookups.find(DC);
7537  if (It == Lookups.end())
7538  return false;
7539 
7540  Deserializing LookupResults(this);
7541 
7542  // Load the list of declarations.
7544  for (DeclID ID : It->second.Table.find(Name)) {
7545  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
7546  if (ND->getDeclName() == Name)
7547  Decls.push_back(ND);
7548  }
7549 
7550  ++NumVisibleDeclContextsRead;
7551  SetExternalVisibleDeclsForName(DC, Name, Decls);
7552  return !Decls.empty();
7553 }
7554 
7556  if (!DC->hasExternalVisibleStorage())
7557  return;
7558 
7559  auto It = Lookups.find(DC);
7560  assert(It != Lookups.end() &&
7561  "have external visible storage but no lookup tables");
7562 
7563  DeclsMap Decls;
7564 
7565  for (DeclID ID : It->second.Table.findAll()) {
7566  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
7567  Decls[ND->getDeclName()].push_back(ND);
7568  }
7569 
7570  ++NumVisibleDeclContextsRead;
7571 
7572  for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
7573  SetExternalVisibleDeclsForName(DC, I->first, I->second);
7574  }
7575  const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false);
7576 }
7577 
7580  auto I = Lookups.find(Primary);
7581  return I == Lookups.end() ? nullptr : &I->second;
7582 }
7583 
7584 /// Under non-PCH compilation the consumer receives the objc methods
7585 /// before receiving the implementation, and codegen depends on this.
7586 /// We simulate this by deserializing and passing to consumer the methods of the
7587 /// implementation before passing the deserialized implementation decl.
7589  ASTConsumer *Consumer) {
7590  assert(ImplD && Consumer);
7591 
7592  for (auto *I : ImplD->methods())
7593  Consumer->HandleInterestingDecl(DeclGroupRef(I));
7594 
7595  Consumer->HandleInterestingDecl(DeclGroupRef(ImplD));
7596 }
7597 
7598 void ASTReader::PassInterestingDeclToConsumer(Decl *D) {
7599  if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
7600  PassObjCImplDeclToConsumer(ImplD, Consumer);
7601  else
7602  Consumer->HandleInterestingDecl(DeclGroupRef(D));
7603 }
7604 
7606  this->Consumer = Consumer;
7607 
7608  if (Consumer)
7609  PassInterestingDeclsToConsumer();
7610 
7611  if (DeserializationListener)
7612  DeserializationListener->ReaderInitialized(this);
7613 }
7614 
7616  std::fprintf(stderr, "*** AST File Statistics:\n");
7617 
7618  unsigned NumTypesLoaded
7619  = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(),
7620  QualType());
7621  unsigned NumDeclsLoaded
7622  = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(),
7623  (Decl *)nullptr);
7624  unsigned NumIdentifiersLoaded
7625  = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(),
7626  IdentifiersLoaded.end(),
7627  (IdentifierInfo *)nullptr);
7628  unsigned NumMacrosLoaded
7629  = MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
7630  MacrosLoaded.end(),
7631  (MacroInfo *)nullptr);
7632  unsigned NumSelectorsLoaded
7633  = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
7634  SelectorsLoaded.end(),
7635  Selector());
7636 
7637  if (unsigned TotalNumSLocEntries = getTotalNumSLocs())
7638  std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n",
7639  NumSLocEntriesRead, TotalNumSLocEntries,
7640  ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100));
7641  if (!TypesLoaded.empty())
7642  std::fprintf(stderr, " %u/%u types read (%f%%)\n",
7643  NumTypesLoaded, (unsigned)TypesLoaded.size(),
7644  ((float)NumTypesLoaded/TypesLoaded.size() * 100));
7645  if (!DeclsLoaded.empty())
7646  std::fprintf(stderr, " %u/%u declarations read (%f%%)\n",
7647  NumDeclsLoaded, (unsigned)DeclsLoaded.size(),
7648  ((float)NumDeclsLoaded/DeclsLoaded.size() * 100));
7649  if (!IdentifiersLoaded.empty())
7650  std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n",
7651  NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(),
7652  ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100));
7653  if (!MacrosLoaded.empty())
7654  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
7655  NumMacrosLoaded, (unsigned)MacrosLoaded.size(),
7656  ((float)NumMacrosLoaded/MacrosLoaded.size() * 100));
7657  if (!SelectorsLoaded.empty())
7658  std::fprintf(stderr, " %u/%u selectors read (%f%%)\n",
7659  NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(),
7660  ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100));
7661  if (TotalNumStatements)
7662  std::fprintf(stderr, " %u/%u statements read (%f%%)\n",
7663  NumStatementsRead, TotalNumStatements,
7664  ((float)NumStatementsRead/TotalNumStatements * 100));
7665  if (TotalNumMacros)
7666  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
7667  NumMacrosRead, TotalNumMacros,
7668  ((float)NumMacrosRead/TotalNumMacros * 100));
7669  if (TotalLexicalDeclContexts)
7670  std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n",
7671  NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
7672  ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
7673  * 100));
7674  if (TotalVisibleDeclContexts)
7675  std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n",
7676  NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
7677  ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
7678  * 100));
7679  if (TotalNumMethodPoolEntries)
7680  std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n",
7681  NumMethodPoolEntriesRead, TotalNumMethodPoolEntries,
7682  ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries
7683  * 100));
7684  if (NumMethodPoolLookups)
7685  std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n",
7686  NumMethodPoolHits, NumMethodPoolLookups,
7687  ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0));
7688  if (NumMethodPoolTableLookups)
7689  std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n",
7690  NumMethodPoolTableHits, NumMethodPoolTableLookups,
7691  ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups
7692  * 100.0));
7693  if (NumIdentifierLookupHits)
7694  std::fprintf(stderr,
7695  " %u / %u identifier table lookups succeeded (%f%%)\n",
7696  NumIdentifierLookupHits, NumIdentifierLookups,
7697  (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
7698 
7699  if (GlobalIndex) {
7700  std::fprintf(stderr, "\n");
7701  GlobalIndex->printStats();
7702  }
7703 
7704  std::fprintf(stderr, "\n");
7705  dump();
7706  std::fprintf(stderr, "\n");
7707 }
7708 
7709 template<typename Key, typename ModuleFile, unsigned InitialCapacity>
7710 LLVM_DUMP_METHOD static void
7711 dumpModuleIDMap(StringRef Name,
7712  const ContinuousRangeMap<Key, ModuleFile *,
7713  InitialCapacity> &Map) {
7714  if (Map.begin() == Map.end())
7715  return;
7716 
7718 
7719  llvm::errs() << Name << ":\n";
7720  for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
7721  I != IEnd; ++I) {
7722  llvm::errs() << " " << I->first << " -> " << I->second->FileName
7723  << "\n";
7724  }
7725 }
7726 
7727 LLVM_DUMP_METHOD void ASTReader::dump() {
7728  llvm::errs() << "*** PCH/ModuleFile Remappings:\n";
7729  dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
7730  dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
7731  dumpModuleIDMap("Global type map", GlobalTypeMap);
7732  dumpModuleIDMap("Global declaration map", GlobalDeclMap);
7733  dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
7734  dumpModuleIDMap("Global macro map", GlobalMacroMap);
7735  dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
7736  dumpModuleIDMap("Global selector map", GlobalSelectorMap);
7737  dumpModuleIDMap("Global preprocessed entity map",
7738  GlobalPreprocessedEntityMap);
7739 
7740  llvm::errs() << "\n*** PCH/Modules Loaded:";
7741  for (ModuleFile &M : ModuleMgr)
7742  M.dump();
7743 }
7744 
7745 /// Return the amount of memory used by memory buffers, breaking down
7746 /// by heap-backed versus mmap'ed memory.
7748  for (ModuleFile &I : ModuleMgr) {
7749  if (llvm::MemoryBuffer *buf = I.Buffer) {
7750  size_t bytes = buf->getBufferSize();
7751  switch (buf->getBufferKind()) {
7752  case llvm::MemoryBuffer::MemoryBuffer_Malloc:
7753  sizes.malloc_bytes += bytes;
7754  break;
7755  case llvm::MemoryBuffer::MemoryBuffer_MMap:
7756  sizes.mmap_bytes += bytes;
7757  break;
7758  }
7759  }
7760  }
7761 }
7762 
7764  SemaObj = &S;
7765  S.addExternalSource(this);
7766 
7767  // Makes sure any declarations that were deserialized "too early"
7768  // still get added to the identifier's declaration chains.
7769  for (uint64_t ID : PreloadedDeclIDs) {
7770  NamedDecl *D = cast<NamedDecl>(GetDecl(ID));
7771  pushExternalDeclIntoScope(D, D->getDeclName());
7772  }
7773  PreloadedDeclIDs.clear();
7774 
7775  // FIXME: What happens if these are changed by a module import?
7776  if (!FPPragmaOptions.empty()) {
7777  assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
7778  SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]);
7779  }
7780 
7781  SemaObj->OpenCLFeatures.copy(OpenCLExtensions);
7782  SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap;
7783  SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap;
7784 
7785  UpdateSema();
7786 }
7787 
7789  assert(SemaObj && "no Sema to update");
7790 
7791  // Load the offsets of the declarations that Sema references.
7792  // They will be lazily deserialized when needed.
7793  if (!SemaDeclRefs.empty()) {
7794  assert(SemaDeclRefs.size() % 3 == 0);
7795  for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) {
7796  if (!SemaObj->StdNamespace)
7797  SemaObj->StdNamespace = SemaDeclRefs[I];
7798  if (!SemaObj->StdBadAlloc)
7799  SemaObj->StdBadAlloc = SemaDeclRefs[I+1];
7800  if (!SemaObj->StdAlignValT)
7801  SemaObj->StdAlignValT = SemaDeclRefs[I+2];
7802  }
7803  SemaDeclRefs.clear();
7804  }
7805 
7806  // Update the state of pragmas. Use the same API as if we had encountered the
7807  // pragma in the source.
7808  if(OptimizeOffPragmaLocation.isValid())
7809  SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation);
7810  if (PragmaMSStructState != -1)
7811  SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState);
7812  if (PointersToMembersPragmaLocation.isValid()) {
7813  SemaObj->ActOnPragmaMSPointersToMembers(
7815  PragmaMSPointersToMembersState,
7816  PointersToMembersPragmaLocation);
7817  }
7818  SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
7819 
7820  if (PragmaPackCurrentValue) {
7821  // The bottom of the stack might have a default value. It must be adjusted
7822  // to the current value to ensure that the packing state is preserved after
7823  // popping entries that were included/imported from a PCH/module.
7824  bool DropFirst = false;
7825  if (!PragmaPackStack.empty() &&
7826  PragmaPackStack.front().Location.isInvalid()) {
7827  assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue &&
7828  "Expected a default alignment value");
7829  SemaObj->PackStack.Stack.emplace_back(
7830  PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue,
7831  SemaObj->PackStack.CurrentPragmaLocation,
7832  PragmaPackStack.front().PushLocation);
7833  DropFirst = true;
7834  }
7835  for (const auto &Entry :
7836  llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0))
7837  SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value,
7838  Entry.Location, Entry.PushLocation);
7839  if (PragmaPackCurrentLocation.isInvalid()) {
7840  assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue &&
7841  "Expected a default alignment value");
7842  // Keep the current values.
7843  } else {
7844  SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue;
7845  SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation;
7846  }
7847  }
7848 }
7849 
7850 IdentifierInfo *ASTReader::get(StringRef Name) {
7851  // Note that we are loading an identifier.
7852  Deserializing AnIdentifier(this);
7853 
7854  IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0,
7855  NumIdentifierLookups,
7856  NumIdentifierLookupHits);
7857 
7858  // We don't need to do identifier table lookups in C++ modules (we preload
7859  // all interesting declarations, and don't need to use the scope for name
7860  // lookups). Perform the lookup in PCH files, though, since we don't build
7861  // a complete initial identifier table if we're carrying on from a PCH.
7862  if (PP.getLangOpts().CPlusPlus) {
7863  for (auto F : ModuleMgr.pch_modules())
7864  if (Visitor(*F))
7865  break;
7866  } else {
7867  // If there is a global index, look there first to determine which modules
7868  // provably do not have any results for this identifier.
7870  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
7871  if (!loadGlobalIndex()) {
7872  if (GlobalIndex->lookupIdentifier(Name, Hits)) {
7873  HitsPtr = &Hits;
7874  }
7875  }
7876 
7877  ModuleMgr.visit(Visitor, HitsPtr);
7878  }
7879 
7880  IdentifierInfo *II = Visitor.getIdentifierInfo();
7881  markIdentifierUpToDate(II);
7882  return II;
7883 }
7884 
7885 namespace clang {
7886 
7887  /// An identifier-lookup iterator that enumerates all of the
7888  /// identifiers stored within a set of AST files.
7890  /// The AST reader whose identifiers are being enumerated.
7891  const ASTReader &Reader;
7892 
7893  /// The current index into the chain of AST files stored in
7894  /// the AST reader.
7895  unsigned Index;
7896 
7897  /// The current position within the identifier lookup table
7898  /// of the current AST file.
7899  ASTIdentifierLookupTable::key_iterator Current;
7900 
7901  /// The end position within the identifier lookup table of
7902  /// the current AST file.
7903  ASTIdentifierLookupTable::key_iterator End;
7904 
7905  /// Whether to skip any modules in the ASTReader.
7906  bool SkipModules;
7907 
7908  public:
7909  explicit ASTIdentifierIterator(const ASTReader &Reader,
7910  bool SkipModules = false);
7911 
7912  StringRef Next() override;
7913  };
7914 
7915 } // namespace clang
7916 
7918  bool SkipModules)
7919  : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) {
7920 }
7921 
7923  while (Current == End) {
7924  // If we have exhausted all of our AST files, we're done.
7925  if (Index == 0)
7926  return StringRef();
7927 
7928  --Index;
7929  ModuleFile &F = Reader.ModuleMgr[Index];
7930  if (SkipModules && F.isModule())
7931  continue;
7932 
7933  ASTIdentifierLookupTable *IdTable =
7935  Current = IdTable->key_begin();
7936  End = IdTable->key_end();
7937  }
7938 
7939  // We have any identifiers remaining in the current AST file; return
7940  // the next one.
7941  StringRef Result = *Current;
7942  ++Current;
7943  return Result;
7944 }
7945 
7946 namespace {
7947 
7948 /// A utility for appending two IdentifierIterators.
7949 class ChainedIdentifierIterator : public IdentifierIterator {
7950  std::unique_ptr<IdentifierIterator> Current;
7951  std::unique_ptr<IdentifierIterator> Queued;
7952 
7953 public:
7954  ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First,
7955  std::unique_ptr<IdentifierIterator> Second)
7956  : Current(std::move(First)), Queued(std::move(Second)) {}
7957 
7958  StringRef Next() override {
7959  if (!Current)
7960  return StringRef();
7961 
7962  StringRef result = Current->Next();
7963  if (!result.empty())
7964  return result;
7965 
7966  // Try the queued iterator, which may itself be empty.
7967  Current.reset();
7968  std::swap(Current, Queued);
7969  return Next();
7970  }
7971 };
7972 
7973 } // namespace
7974 
7976  if (!loadGlobalIndex()) {
7977  std::unique_ptr<IdentifierIterator> ReaderIter(
7978  new ASTIdentifierIterator(*this, /*SkipModules=*/true));
7979  std::unique_ptr<IdentifierIterator> ModulesIter(
7980  GlobalIndex->createIdentifierIterator());
7981  return new ChainedIdentifierIterator(std::move(ReaderIter),
7982  std::move(ModulesIter));
7983  }
7984 
7985  return new ASTIdentifierIterator(*this);
7986 }
7987 
7988 namespace clang {
7989 namespace serialization {
7990 
7992  ASTReader &Reader;
7993  Selector Sel;
7994  unsigned PriorGeneration;
7995  unsigned InstanceBits = 0;
7996  unsigned FactoryBits = 0;
7997  bool InstanceHasMoreThanOneDecl = false;
7998  bool FactoryHasMoreThanOneDecl = false;
7999  SmallVector<ObjCMethodDecl *, 4> InstanceMethods;
8000  SmallVector<ObjCMethodDecl *, 4> FactoryMethods;
8001 
8002  public:
8004  unsigned PriorGeneration)
8005  : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) {}
8006 
8007  bool operator()(ModuleFile &M) {
8008  if (!M.SelectorLookupTable)
8009  return false;
8010 
8011  // If we've already searched this module file, skip it now.
8012  if (M.Generation <= PriorGeneration)
8013  return true;
8014 
8015  ++Reader.NumMethodPoolTableLookups;
8016  ASTSelectorLookupTable *PoolTable
8018  ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel);
8019  if (Pos == PoolTable->end())
8020  return false;
8021 
8022  ++Reader.NumMethodPoolTableHits;
8023  ++Reader.NumSelectorsRead;
8024  // FIXME: Not quite happy with the statistics here. We probably should
8025  // disable this tracking when called via LoadSelector.
8026  // Also, should entries without methods count as misses?
8027  ++Reader.NumMethodPoolEntriesRead;
8029  if (Reader.DeserializationListener)
8030  Reader.DeserializationListener->SelectorRead(Data.ID, Sel);
8031 
8032  InstanceMethods.append(Data.Instance.begin(), Data.Instance.end());
8033  FactoryMethods.append(Data.Factory.begin(), Data.Factory.end());
8034  InstanceBits = Data.InstanceBits;
8035  FactoryBits = Data.FactoryBits;
8036  InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl;
8037  FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl;
8038  return true;
8039  }
8040 
8041  /// Retrieve the instance methods found by this visitor.
8043  return InstanceMethods;
8044  }
8045 
8046  /// Retrieve the instance methods found by this visitor.
8048  return FactoryMethods;
8049  }
8050 
8051  unsigned getInstanceBits() const { return InstanceBits; }
8052  unsigned getFactoryBits() const { return FactoryBits; }
8053 
8055  return InstanceHasMoreThanOneDecl;
8056  }
8057 
8058  bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; }
8059  };
8060 
8061 } // namespace serialization
8062 } // namespace clang
8063 
8064 /// Add the given set of methods to the method list.
8066  ObjCMethodList &List) {
8067  for (unsigned I = 0, N = Methods.size(); I != N; ++I) {
8068  S.addMethodToGlobalList(&List, Methods[I]);
8069  }
8070 }
8071 
8073  // Get the selector generation and update it to the current generation.
8074  unsigned &Generation = SelectorGeneration[Sel];
8075  unsigned PriorGeneration = Generation;
8076  Generation = getGeneration();
8077  SelectorOutOfDate[Sel] = false;
8078 
8079  // Search for methods defined with this selector.
8080  ++NumMethodPoolLookups;
8081  ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration);
8082  ModuleMgr.visit(Visitor);
8083 
8084  if (Visitor.getInstanceMethods().empty() &&
8085  Visitor.getFactoryMethods().empty())
8086  return;
8087 
8088  ++NumMethodPoolHits;
8089 
8090  if (!getSema())
8091  return;
8092 
8093  Sema &S = *getSema();
8094  Sema::GlobalMethodPool::iterator Pos
8095  = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first;
8096 
8097  Pos->second.first.setBits(Visitor.getInstanceBits());
8098  Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
8099  Pos->second.second.setBits(Visitor.getFactoryBits());
8100  Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl());
8101 
8102  // Add methods to the global pool *after* setting hasMoreThanOneDecl, since
8103  // when building a module we keep every method individually and may need to
8104  // update hasMoreThanOneDecl as we add the methods.
8105  addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first);
8106  addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second);
8107 }
8108 
8110  if (SelectorOutOfDate[Sel])
8111  ReadMethodPool(Sel);
8112 }
8113 
8115  SmallVectorImpl<NamespaceDecl *> &Namespaces) {
8116  Namespaces.clear();
8117 
8118  for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) {
8119  if (NamespaceDecl *Namespace
8120  = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I])))
8121  Namespaces.push_back(Namespace);
8122  }
8123 }
8124 
8126  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
8127  for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) {
8128  NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++]));
8129  SourceLocation Loc =
8130  SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]);
8131  Undefined.insert(std::make_pair(D, Loc));
8132  }
8133 }
8134 
8136  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
8137  Exprs) {
8138  for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) {
8139  FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++]));
8140  uint64_t Count = DelayedDeleteExprs[Idx++];
8141  for (uint64_t C = 0; C < Count; ++C) {
8142  SourceLocation DeleteLoc =
8143  SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]);
8144  const bool IsArrayForm = DelayedDeleteExprs[Idx++];
8145  Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm));
8146  }
8147  }
8148 }
8149 
8151  SmallVectorImpl<VarDecl *> &TentativeDefs) {
8152  for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
8153  VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I]));
8154  if (Var)
8155  TentativeDefs.push_back(Var);
8156  }
8157  TentativeDefinitions.clear();
8158 }
8159 
8162  for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
8163  DeclaratorDecl *D
8164  = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I]));
8165  if (D)
8166  Decls.push_back(D);
8167  }
8168  UnusedFileScopedDecls.clear();
8169 }
8170 
8173  for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) {
8175  = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I]));
8176  if (D)
8177  Decls.push_back(D);
8178  }
8179  DelegatingCtorDecls.clear();
8180 }
8181 
8183  for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) {
8184  TypedefNameDecl *D
8185  = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]));
8186  if (D)
8187  Decls.push_back(D);
8188  }
8189  ExtVectorDecls.clear();
8190 }
8191 
8194  for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N;
8195  ++I) {
8196  TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>(
8197  GetDecl(UnusedLocalTypedefNameCandidates[I]));
8198  if (D)
8199  Decls.insert(D);
8200  }
8201  UnusedLocalTypedefNameCandidates.clear();
8202 }
8203 
8205  SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) {
8206  if (ReferencedSelectorsData.empty())
8207  return;
8208 
8209  // If there are @selector references added them to its pool. This is for
8210  // implementation of -Wselector.
8211  unsigned int DataSize = ReferencedSelectorsData.size()-1;
8212  unsigned I = 0;
8213  while (I < DataSize) {
8214  Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]);
8215  SourceLocation SelLoc
8216  = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]);
8217  Sels.push_back(std::make_pair(Sel, SelLoc));
8218  }
8219  ReferencedSelectorsData.clear();
8220 }
8221 
8223  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) {
8224  if (WeakUndeclaredIdentifiers.empty())
8225  return;
8226 
8227  for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) {
8228  IdentifierInfo *WeakId
8229  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
8230  IdentifierInfo *AliasId
8231  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
8232  SourceLocation Loc
8233  = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]);
8234  bool Used = WeakUndeclaredIdentifiers[I++];
8235  WeakInfo WI(AliasId, Loc);
8236  WI.setUsed(Used);
8237  WeakIDs.push_back(std::make_pair(WeakId, WI));
8238  }
8239  WeakUndeclaredIdentifiers.clear();
8240 }
8241 
8243  for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) {
8244  ExternalVTableUse VT;
8245  VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++]));
8246  VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]);
8247  VT.DefinitionRequired = VTableUses[Idx++];
8248  VTables.push_back(VT);
8249  }
8250 
8251  VTableUses.clear();
8252 }
8253 
8255  SmallVectorImpl<std::pair<ValueDecl *, SourceLocation>> &Pending) {
8256  for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) {
8257  ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));
8258  SourceLocation Loc
8259  = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);
8260 
8261  Pending.push_back(std::make_pair(D, Loc));
8262  }
8263  PendingInstantiations.clear();
8264 }
8265 
8267  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
8268  &LPTMap) {
8269  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
8270  /* In loop */) {
8271  FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++]));
8272 
8273  auto LT = llvm::make_unique<LateParsedTemplate>();
8274  LT->D = GetDecl(LateParsedTemplates[Idx++]);
8275 
8276  ModuleFile *F = getOwningModuleFile(LT->D);
8277  assert(F && "No module");
8278 
8279  unsigned TokN = LateParsedTemplates[Idx++];
8280  LT->Toks.reserve(TokN);
8281  for (unsigned T = 0; T < TokN; ++T)
8282  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
8283 
8284  LPTMap.insert(std::make_pair(FD, std::move(LT)));
8285  }
8286 
8287  LateParsedTemplates.clear();
8288 }
8289 
8291  // It would be complicated to avoid reading the methods anyway. So don't.
8292  ReadMethodPool(Sel);
8293 }
8294 
8296  assert(ID && "Non-zero identifier ID required");
8297  assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range");
8298  IdentifiersLoaded[ID - 1] = II;
8299  if (DeserializationListener)
8300  DeserializationListener->IdentifierRead(ID, II);
8301 }
8302 
8303 /// Set the globally-visible declarations associated with the given
8304 /// identifier.
8305 ///
8306 /// If the AST reader is currently in a state where the given declaration IDs
8307 /// cannot safely be resolved, they are queued until it is safe to resolve
8308 /// them.
8309 ///
8310 /// \param II an IdentifierInfo that refers to one or more globally-visible
8311 /// declarations.
8312 ///
8313 /// \param DeclIDs the set of declaration IDs with the name @p II that are
8314 /// visible at global scope.
8315 ///
8316 /// \param Decls if non-null, this vector will be populated with the set of
8317 /// deserialized declarations. These declarations will not be pushed into
8318 /// scope.
8319 void
8321  const SmallVectorImpl<uint32_t> &DeclIDs,
8322  SmallVectorImpl<Decl *> *Decls) {
8323  if (NumCurrentElementsDeserializing && !Decls) {
8324  PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end());
8325  return;
8326  }
8327 
8328  for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) {
8329  if (!SemaObj) {
8330  // Queue this declaration so that it will be added to the
8331  // translation unit scope and identifier's declaration chain
8332  // once a Sema object is known.
8333  PreloadedDeclIDs.push_back(DeclIDs[I]);
8334  continue;
8335  }
8336 
8337  NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I]));
8338 
8339  // If we're simply supposed to record the declarations, do so now.
8340  if (Decls) {
8341  Decls->push_back(D);
8342  continue;
8343  }
8344 
8345  // Introduce this declaration into the translation-unit scope
8346  // and add it to the declaration chain for this identifier, so
8347  // that (unqualified) name lookup will find it.
8348  pushExternalDeclIntoScope(D, II);
8349  }
8350 }
8351 
8353  if (ID == 0)
8354  return nullptr;
8355 
8356  if (IdentifiersLoaded.empty()) {
8357  Error("no identifier table in AST file");
8358  return nullptr;
8359  }
8360 
8361  ID -= 1;
8362  if (!IdentifiersLoaded[ID]) {
8363  GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
8364  assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
8365  ModuleFile *M = I->second;
8366  unsigned Index = ID - M->BaseIdentifierID;
8367  const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index];
8368 
8369  // All of the strings in the AST file are preceded by a 16-bit length.
8370  // Extract that 16-bit length to avoid having to execute strlen().
8371  // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as
8372  // unsigned integers. This is important to avoid integer overflow when
8373  // we cast them to 'unsigned'.
8374  const unsigned char *StrLenPtr = (const unsigned char*) Str - 2;
8375  unsigned StrLen = (((unsigned) StrLenPtr[0])
8376  | (((unsigned) StrLenPtr[1]) << 8)) - 1;
8377  auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen));
8378  IdentifiersLoaded[ID] = &II;
8379  markIdentifierFromAST(*this, II);
8380  if (DeserializationListener)
8381  DeserializationListener->IdentifierRead(ID + 1, &II);
8382  }
8383 
8384  return IdentifiersLoaded[ID];
8385 }
8386 
8387 IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
8388  return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
8389 }
8390 
8391 IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
8392  if (LocalID < NUM_PREDEF_IDENT_IDS)
8393  return LocalID;
8394 
8395  if (!M.ModuleOffsetMap.empty())
8396  ReadModuleOffsetMap(M);
8397 
8399  = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS);
8400  assert(I != M.IdentifierRemap.end()
8401  && "Invalid index into identifier index remap");
8402 
8403  return LocalID + I->second;
8404 }
8405 
8407  if (ID == 0)
8408  return nullptr;
8409 
8410  if (MacrosLoaded.empty()) {
8411  Error("no macro table in AST file");
8412  return nullptr;
8413  }
8414 
8415  ID -= NUM_PREDEF_MACRO_IDS;
8416  if (!MacrosLoaded[ID]) {
8418  = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS);
8419  assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
8420  ModuleFile *M = I->second;
8421  unsigned Index = ID - M->BaseMacroID;
8422  MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]);
8423 
8424  if (DeserializationListener)
8425  DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS,
8426  MacrosLoaded[ID]);
8427  }
8428 
8429  return MacrosLoaded[ID];
8430 }
8431 
8432 MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) {
8433  if (LocalID < NUM_PREDEF_MACRO_IDS)
8434  return LocalID;
8435 
8436  if (!M.ModuleOffsetMap.empty())
8437  ReadModuleOffsetMap(M);
8438 
8440  = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS);
8441  assert(I != M.MacroRemap.end() && "Invalid index into macro index remap");
8442 
8443  return LocalID + I->second;
8444 }
8445 
8447 ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) {
8448  if (LocalID < NUM_PREDEF_SUBMODULE_IDS)
8449  return LocalID;
8450 
8451  if (!M.ModuleOffsetMap.empty())
8452  ReadModuleOffsetMap(M);
8453 
8456  assert(I != M.SubmoduleRemap.end()
8457  && "Invalid index into submodule index remap");
8458 
8459  return LocalID + I->second;
8460 }
8461 
8463  if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) {
8464  assert(GlobalID == 0 && "Unhandled global submodule ID");
8465  return nullptr;
8466  }
8467 
8468  if (GlobalID > SubmodulesLoaded.size()) {
8469  Error("submodule ID out of range in AST file");
8470  return nullptr;
8471  }
8472 
8473  return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS];
8474 }
8475 
8477  return getSubmodule(ID);
8478 }
8479 
8481  ModuleFile *MF = getOwningModuleFile(D);
8482  return MF && MF->PCHHasObjectFile;
8483 }
8484 
8485 ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) {
8486  if (ID & 1) {
8487  // It's a module, look it up by submodule ID.
8488  auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1));
8489  return I == GlobalSubmoduleMap.end() ? nullptr : I->second;
8490  } else {
8491  // It's a prefix (preamble, PCH, ...). Look it up by index.
8492  unsigned IndexFromEnd = ID >> 1;
8493  assert(IndexFromEnd && "got reference to unknown module file");
8494  return getModuleManager().pch_modules().end()[-IndexFromEnd];
8495  }
8496 }
8497 
8498 unsigned ASTReader::getModuleFileID(ModuleFile *F) {
8499  if (!F)
8500  return 1;
8501 
8502  // For a file representing a module, use the submodule ID of the top-level
8503  // module as the file ID. For any other kind of file, the number of such
8504  // files loaded beforehand will be the same on reload.
8505  // FIXME: Is this true even if we have an explicit module file and a PCH?
8506  if (F->isModule())
8507  return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1;
8508 
8509  auto PCHModules = getModuleManager().pch_modules();
8510  auto I = std::find(PCHModules.begin(), PCHModules.end(), F);
8511  assert(I != PCHModules.end() && "emitting reference to unknown file");
8512  return (I - PCHModules.end()) << 1;
8513 }
8514 
8517  if (const Module *M = getSubmodule(ID))
8519 
8520  // If there is only a single PCH, return it instead.
8521  // Chained PCH are not supported.
8522  const auto &PCHChain = ModuleMgr.pch_modules();
8523  if (std::distance(std::begin(PCHChain), std::end(PCHChain))) {
8524  ModuleFile &MF = ModuleMgr.getPrimaryModule();
8525  StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName);
8526  StringRef FileName = llvm::sys::path::filename(MF.FileName);
8527  return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName,
8528  MF.Signature);
8529  }
8530  return None;
8531 }
8532 
8534  auto I = DefinitionSource.find(FD);
8535  if (I == DefinitionSource.end())
8536  return EK_ReplyHazy;
8537  return I->second ? EK_Never : EK_Always;
8538 }
8539 
8540 Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
8541  return DecodeSelector(getGlobalSelectorID(M, LocalID));
8542 }
8543 
8545  if (ID == 0)
8546  return Selector();
8547 
8548  if (ID > SelectorsLoaded.size()) {
8549  Error("selector ID out of range in AST file");
8550  return Selector();
8551  }
8552 
8553  if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) {
8554  // Load this selector from the selector table.
8555  GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
8556  assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
8557  ModuleFile &M = *I->second;
8558  ASTSelectorLookupTrait Trait(*this, M);
8559  unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS;
8560  SelectorsLoaded[ID - 1] =
8561  Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0);
8562  if (DeserializationListener)
8563  DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
8564  }
8565 
8566  return SelectorsLoaded[ID - 1];
8567 }
8568 
8570  return DecodeSelector(ID);
8571 }
8572 
8574  // ID 0 (the null selector) is considered an external selector.
8575  return getTotalNumSelectors() + 1;
8576 }
8577 
8579 ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const {
8580  if (LocalID < NUM_PREDEF_SELECTOR_IDS)
8581  return LocalID;
8582 
8583  if (!M.ModuleOffsetMap.empty())
8584  ReadModuleOffsetMap(M);
8585 
8588  assert(I != M.SelectorRemap.end()
8589  && "Invalid index into selector index remap");
8590 
8591  return LocalID + I->second;
8592 }
8593 
8596  const RecordData &Record, unsigned &Idx) {
8597  ASTContext &Context = getContext();
8599  switch (Kind) {
8601  return DeclarationName(GetIdentifierInfo(F, Record, Idx));
8602 
8606  return DeclarationName(ReadSelector(F, Record, Idx));
8607 
8609  return Context.DeclarationNames.getCXXConstructorName(
8610  Context.getCanonicalType(readType(F, Record, Idx)));
8611 
8613  return Context.DeclarationNames.getCXXDestructorName(
8614  Context.getCanonicalType(readType(F, Record, Idx)));
8615 
8618  ReadDeclAs<TemplateDecl>(F, Record, Idx));
8619 
8622  Context.getCanonicalType(readType(F, Record, Idx)));
8623 
8625  return Context.DeclarationNames.getCXXOperatorName(
8626  (OverloadedOperatorKind)Record[Idx++]);
8627 
8630  GetIdentifierInfo(F, Record, Idx));
8631 
8634  }
8635 
8636  llvm_unreachable("Invalid NameKind!");
8637 }
8638 
8640  DeclarationNameLoc &DNLoc,
8641  DeclarationName Name,
8642  const RecordData &Record, unsigned &Idx) {
8643  switch (Name.getNameKind()) {
8647  DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx);
8648  break;
8649 
8652  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
8654  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
8655  break;
8656 
8659  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
8660  break;
8661 
8668  break;
8669  }
8670 }
8671 
8673  DeclarationNameInfo &NameInfo,
8674  const RecordData &Record, unsigned &Idx) {
8675  NameInfo.setName(ReadDeclarationName(F, Record, Idx));
8676  NameInfo.setLoc(ReadSourceLocation(F, Record, Idx));
8677  DeclarationNameLoc DNLoc;
8678  ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx);
8679  NameInfo.setInfo(DNLoc);
8680 }
8681 
8683  const RecordData &Record, unsigned &Idx) {
8684  Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
8685  unsigned NumTPLists = Record[Idx++];
8686  Info.NumTemplParamLists = NumTPLists;
8687  if (NumTPLists) {
8688  Info.TemplParamLists =
8689  new (getContext()) TemplateParameterList *[NumTPLists];
8690  for (unsigned i = 0; i != NumTPLists; ++i)
8691  Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx);
8692  }
8693 }
8694 
8696 ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record,
8697  unsigned &Idx) {
8698  ASTContext &Context = getContext();
8700  switch (Kind) {
8702  return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx));
8703 
8705  unsigned size = Record[Idx++];
8706  UnresolvedSet<8> Decls;
8707  while (size--)
8708  Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx));
8709 
8710  return Context.getOverloadedTemplateName(Decls.begin(), Decls.end());
8711  }
8712 
8714  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
8715  bool hasTemplKeyword = Record[Idx++];
8716  TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx);
8717  return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template);
8718  }
8719 
8721  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
8722  if (Record[Idx++]) // isIdentifier
8723  return Context.getDependentTemplateName(NNS,
8724  GetIdentifierInfo(F, Record,
8725  Idx));
8726  return Context.getDependentTemplateName(NNS,
8727  (OverloadedOperatorKind)Record[Idx++]);
8728  }
8729 
8732  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
8733  if (!param) return TemplateName();
8734  TemplateName replacement = ReadTemplateName(F, Record, Idx);
8735  return Context.getSubstTemplateTemplateParm(param, replacement);
8736  }
8737 
8740  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
8741  if (!Param)
8742  return TemplateName();
8743 
8744  TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx);
8745  if (ArgPack.getKind() != TemplateArgument::Pack)
8746  return TemplateName();
8747 
8748  return Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
8749  }
8750  }
8751 
8752  llvm_unreachable("Unhandled template name kind!");
8753 }
8754 
8756  const RecordData &Record,
8757  unsigned &Idx,
8758  bool Canonicalize) {
8759  ASTContext &Context = getContext();
8760  if (Canonicalize) {
8761  // The caller wants a canonical template argument. Sometimes the AST only
8762  // wants template arguments in canonical form (particularly as the template
8763  // argument lists of template specializations) so ensure we preserve that
8764  // canonical form across serialization.
8765  TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false);
8766  return Context.getCanonicalTemplateArgument(Arg);
8767  }
8768 
8770  switch (Kind) {
8772  return TemplateArgument();
8774  return TemplateArgument(readType(F, Record, Idx));
8776  ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx);
8777  return TemplateArgument(D, readType(F, Record, Idx));
8778  }
8780  return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true);
8782  llvm::APSInt Value = ReadAPSInt(Record, Idx);
8783  QualType T = readType(F, Record, Idx);
8784  return TemplateArgument(Context, Value, T);
8785  }
8787  return TemplateArgument(ReadTemplateName(F, Record, Idx));
8789  TemplateName Name = ReadTemplateName(F, Record, Idx);
8790  Optional<unsigned> NumTemplateExpansions;
8791  if (unsigned NumExpansions = Record[Idx++])
8792  NumTemplateExpansions = NumExpansions - 1;
8793  return TemplateArgument(Name, NumTemplateExpansions);
8794  }
8796  return TemplateArgument(ReadExpr(F));
8797  case TemplateArgument::Pack: {
8798  unsigned NumArgs = Record[Idx++];
8799  TemplateArgument *Args = new (Context) TemplateArgument[NumArgs];
8800  for (unsigned I = 0; I != NumArgs; ++I)
8801  Args[I] = ReadTemplateArgument(F, Record, Idx);
8802  return TemplateArgument(llvm::makeArrayRef(Args, NumArgs));
8803  }
8804  }
8805 
8806  llvm_unreachable("Unhandled template argument kind!");
8807 }
8808 
8811  const RecordData &Record, unsigned &Idx) {
8812  SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx);
8813  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx);
8814  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx);
8815 
8816  unsigned NumParams = Record[Idx++];
8818  Params.reserve(NumParams);
8819  while (NumParams--)
8820  Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx));
8821 
8822  // TODO: Concepts
8824  getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr);
8825  return TemplateParams;
8826 }
8827 
8828 void
8831  ModuleFile &F, const RecordData &Record,
8832  unsigned &Idx, bool Canonicalize) {
8833  unsigned NumTemplateArgs = Record[Idx++];
8834  TemplArgs.reserve(NumTemplateArgs);
8835  while (NumTemplateArgs--)
8836  TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize));
8837 }
8838 
8839 /// Read a UnresolvedSet structure.
8841  const RecordData &Record, unsigned &Idx) {
8842  unsigned NumDecls = Record[Idx++];
8843  Set.reserve(getContext(), NumDecls);
8844  while (NumDecls--) {
8845  DeclID ID = ReadDeclID(F, Record, Idx);
8846  AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
8847  Set.addLazyDecl(getContext(), ID, AS);
8848  }
8849 }
8850 
8853  const RecordData &Record, unsigned &Idx) {
8854  bool isVirtual = static_cast<bool>(Record[Idx++]);
8855  bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
8856  AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
8857  bool inheritConstructors = static_cast<bool>(Record[Idx++]);
8858  TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx);
8859  SourceRange Range = ReadSourceRange(F, Record, Idx);
8860  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx);
8861  CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo,
8862  EllipsisLoc);
8863  Result.setInheritConstructors(inheritConstructors);
8864  return Result;
8865 }
8866 
8868 ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
8869  unsigned &Idx) {
8870  ASTContext &Context = getContext();
8871  unsigned NumInitializers = Record[Idx++];
8872  assert(NumInitializers && "wrote ctor initializers but have no inits");
8873  auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers];
8874  for (unsigned i = 0; i != NumInitializers; ++i) {
8875  TypeSourceInfo *TInfo = nullptr;
8876  bool IsBaseVirtual = false;
8877  FieldDecl *Member = nullptr;
8878  IndirectFieldDecl *IndirectMember = nullptr;
8879 
8880  CtorInitializerType Type = (CtorInitializerType)Record[Idx++];
8881  switch (Type) {
8882  case CTOR_INITIALIZER_BASE:
8883  TInfo = GetTypeSourceInfo(F, Record, Idx);
8884  IsBaseVirtual = Record[Idx++];
8885  break;
8886 
8888  TInfo = GetTypeSourceInfo(F, Record, Idx);
8889  break;
8890 
8892  Member = ReadDeclAs<FieldDecl>(F, Record, Idx);
8893  break;
8894 
8896  IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx);
8897  break;
8898  }
8899 
8900  SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx);
8901  Expr *Init = ReadExpr(F);
8902  SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx);
8903  SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx);
8904 
8905  CXXCtorInitializer *BOMInit;
8906  if (Type == CTOR_INITIALIZER_BASE)
8907  BOMInit = new (Context)
8908  CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init,
8909  RParenLoc, MemberOrEllipsisLoc);
8910  else if (Type == CTOR_INITIALIZER_DELEGATING)
8911  BOMInit = new (Context)
8912  CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc);
8913  else if (Member)
8914  BOMInit = new (Context)
8915  CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc,
8916  Init, RParenLoc);
8917  else
8918  BOMInit = new (Context)
8919  CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc,
8920  LParenLoc, Init, RParenLoc);
8921 
8922  if (/*IsWritten*/Record[Idx++]) {
8923  unsigned SourceOrder = Record[Idx++];
8924  BOMInit->setSourceOrder(SourceOrder);
8925  }
8926 
8927  CtorInitializers[i] = BOMInit;
8928  }
8929 
8930  return CtorInitializers;
8931 }
8932 
8935  const RecordData &Record, unsigned &Idx) {
8936  ASTContext &Context = getContext();
8937  unsigned N = Record[Idx++];
8938  NestedNameSpecifier *NNS = nullptr, *Prev = nullptr;
8939  for (unsigned I = 0; I != N; ++I) {
8941  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
8942  switch (Kind) {
8944  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
8945  NNS = NestedNameSpecifier::Create(Context, Prev, II);
8946  break;
8947  }
8948 
8950  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
8951  NNS = NestedNameSpecifier::Create(Context, Prev, NS);
8952  break;
8953  }
8954 
8956  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
8957  NNS = NestedNameSpecifier::Create(Context, Prev, Alias);
8958  break;
8959  }
8960 
8963  const Type *T = readType(F, Record, Idx).getTypePtrOrNull();
8964  if (!T)
8965  return nullptr;
8966 
8967  bool Template = Record[Idx++];
8968  NNS = NestedNameSpecifier::Create(Context, Prev, Template, T);
8969  break;
8970  }
8971 
8973  NNS = NestedNameSpecifier::GlobalSpecifier(Context);
8974  // No associated value, and there can't be a prefix.
8975  break;
8976 
8978  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
8979  NNS = NestedNameSpecifier::SuperSpecifier(Context, RD);
8980  break;
8981  }
8982  }
8983  Prev = NNS;
8984  }
8985  return NNS;
8986 }
8987 
8990  unsigned &Idx) {
8991  ASTContext &Context = getContext();
8992  unsigned N = Record[Idx++];
8994  for (unsigned I = 0; I != N; ++I) {
8996  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
8997  switch (Kind) {
8999  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
9000  SourceRange Range = ReadSourceRange(F, Record, Idx);
9001  Builder.Extend(Context, II, Range.getBegin(), Range.getEnd());
9002  break;
9003  }
9004 
9006  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
9007  SourceRange Range = ReadSourceRange(F, Record, Idx);
9008  Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd());
9009  break;
9010  }
9011 
9013  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
9014  SourceRange Range = ReadSourceRange(F, Record, Idx);
9015  Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd());
9016  break;
9017  }
9018 
9021  bool Template = Record[Idx++];
9022  TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx);
9023  if (!T)
9024  return NestedNameSpecifierLoc();
9025  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
9026 
9027  // FIXME: 'template' keyword location not saved anywhere, so we fake it.
9028  Builder.Extend(Context,
9029  Template? T->getTypeLoc().getBeginLoc() : SourceLocation(),
9030  T->getTypeLoc(), ColonColonLoc);
9031  break;
9032  }
9033 
9035  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
9036  Builder.MakeGlobal(Context, ColonColonLoc);
9037  break;
9038  }
9039 
9041  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
9042  SourceRange Range = ReadSourceRange(F, Record, Idx);
9043  Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd());
9044  break;
9045  }
9046  }
9047  }
9048 
9049  return Builder.getWithLocInContext(Context);
9050 }
9051 
9053 ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record,
9054  unsigned &Idx) {
9055  SourceLocation beg = ReadSourceLocation(F, Record, Idx);
9056  SourceLocation end = ReadSourceLocation(F, Record, Idx);
9057  return SourceRange(beg, end);
9058 }
9059 
9060 /// Read an integral value
9061 llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) {
9062  unsigned BitWidth = Record[Idx++];
9063  unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
9064  llvm::APInt Result(BitWidth, NumWords, &Record[Idx]);
9065  Idx += NumWords;
9066  return Result;
9067 }
9068 
9069 /// Read a signed integral value
9070 llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) {
9071  bool isUnsigned = Record[Idx++];
9072  return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned);
9073 }
9074 
9075 /// Read a floating-point value
9076 llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record,
9077  const llvm::fltSemantics &Sem,
9078  unsigned &Idx) {
9079  return llvm::APFloat(Sem, ReadAPInt(Record, Idx));
9080 }
9081 
9082 // Read a string
9083 std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) {
9084  unsigned Len = Record[Idx++];
9085  std::string Result(Record.data() + Idx, Record.data() + Idx + Len);
9086  Idx += Len;
9087  return Result;
9088 }
9089 
9090 std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record,
9091  unsigned &Idx) {
9092  std::string Filename = ReadString(Record, Idx);
9093  ResolveImportedPath(F, Filename);
9094  return Filename;
9095 }
9096 
9097 VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record,
9098  unsigned &Idx) {
9099  unsigned Major = Record[Idx++];
9100  unsigned Minor = Record[Idx++];
9101  unsigned Subminor = Record[Idx++];
9102  if (Minor == 0)
9103  return VersionTuple(Major);
9104  if (Subminor == 0)
9105  return VersionTuple(Major, Minor - 1);
9106  return VersionTuple(Major, Minor - 1, Subminor - 1);
9107 }
9108 
9110  const RecordData &Record,
9111  unsigned &Idx) {
9112  CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx);
9113  return CXXTemporary::Create(getContext(), Decl);
9114 }
9115 
9116 DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const {
9117  return Diag(CurrentImportLoc, DiagID);
9118 }
9119 
9120 DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const {
9121  return Diags.Report(Loc, DiagID);
9122 }
9123 
9124 /// Retrieve the identifier table associated with the
9125 /// preprocessor.
9127  return PP.getIdentifierTable();
9128 }
9129 
9130 /// Record that the given ID maps to the given switch-case
9131 /// statement.
9133  assert((*CurrSwitchCaseStmts)[ID] == nullptr &&
9134  "Already have a SwitchCase with this ID");
9135  (*CurrSwitchCaseStmts)[ID] = SC;
9136 }
9137 
9138 /// Retrieve the switch-case statement with the given ID.
9140  assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID");
9141  return (*CurrSwitchCaseStmts)[ID];
9142 }
9143 
9145  CurrSwitchCaseStmts->clear();
9146 }
9147 
9149  ASTContext &Context = getContext();
9150  std::vector<RawComment *> Comments;
9151  for (SmallVectorImpl<std::pair<BitstreamCursor,
9152  serialization::ModuleFile *>>::iterator
9153  I = CommentsCursors.begin(),
9154  E = CommentsCursors.end();
9155  I != E; ++I) {
9156  Comments.clear();
9157  BitstreamCursor &Cursor = I->first;
9158  serialization::ModuleFile &F = *I->second;
9159  SavedStreamPosition SavedPosition(Cursor);
9160 
9161  RecordData Record;
9162  while (true) {
9163  llvm::BitstreamEntry Entry =
9164  Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd);
9165 
9166  switch (Entry.Kind) {
9167  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
9169  Error("malformed block record in AST file");
9170  return;
9171  case llvm::BitstreamEntry::EndBlock:
9172  goto NextCursor;
9173  case llvm::BitstreamEntry::Record:
9174  // The interesting case.
9175  break;
9176  }
9177 
9178  // Read a record.
9179  Record.clear();
9180  switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
9181  case COMMENTS_RAW_COMMENT: {
9182  unsigned Idx = 0;
9183  SourceRange SR = ReadSourceRange(F, Record, Idx);
9185  (RawComment::CommentKind) Record[Idx++];
9186  bool IsTrailingComment = Record[Idx++];
9187  bool IsAlmostTrailingComment = Record[Idx++];
9188  Comments.push_back(new (Context) RawComment(
9189  SR, Kind, IsTrailingComment, IsAlmostTrailingComment));
9190  break;
9191  }
9192  }
9193  }
9194  NextCursor:
9195  // De-serialized SourceLocations get negative FileIDs for other modules,
9196  // potentially invalidating the original order. Sort it again.
9197  llvm::sort(Comments, BeforeThanCompare<RawComment>(SourceMgr));
9198  Context.Comments.addDeserializedComments(Comments);
9199  }
9200 }
9201 
9203  bool IncludeSystem, bool Complain,
9204  llvm::function_ref<void(const serialization::InputFile &IF,
9205  bool isSystem)> Visitor) {
9206  unsigned NumUserInputs = MF.NumUserInputFiles;
9207  unsigned NumInputs = MF.InputFilesLoaded.size();
9208  assert(NumUserInputs <= NumInputs);
9209  unsigned N = IncludeSystem ? NumInputs : NumUserInputs;
9210  for (unsigned I = 0; I < N; ++I) {
9211  bool IsSystem = I >= NumUserInputs;
9212  InputFile IF = getInputFile(MF, I+1, Complain);
9213  Visitor(IF, IsSystem);
9214  }
9215 }
9216 
9219  llvm::function_ref<void(const FileEntry *FE)> Visitor) {
9220  unsigned NumInputs = MF.InputFilesLoaded.size();
9221  for (unsigned I = 0; I < NumInputs; ++I) {
9222  InputFileInfo IFI = readInputFileInfo(MF, I + 1);
9223  if (IFI.TopLevelModuleMap)
9224  // FIXME: This unnecessarily re-reads the InputFileInfo.
9225  if (auto *FE = getInputFile(MF, I + 1).getFile())
9226  Visitor(FE);
9227  }
9228 }
9229 
9231  // If we know the owning module, use it.
9232  if (Module *M = D->getImportedOwningModule())
9233  return M->getFullModuleName();
9234 
9235  // Otherwise, use the name of the top-level module the decl is within.
9236  if (ModuleFile *M = getOwningModuleFile(D))
9237  return M->ModuleName;
9238 
9239  // Not from a module.
9240  return {};
9241 }
9242 
9243 void ASTReader::finishPendingActions() {
9244  while (!PendingIdentifierInfos.empty() || !PendingFunctionTypes.empty() ||
9245  !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() ||
9246  !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
9247  !PendingUpdateRecords.empty()) {
9248  // If any identifiers with corresponding top-level declarations have
9249  // been loaded, load those declarations now.
9250  using TopLevelDeclsMap =
9251  llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2>>;
9252  TopLevelDeclsMap TopLevelDecls;
9253 
9254  while (!PendingIdentifierInfos.empty()) {
9255  IdentifierInfo *II = PendingIdentifierInfos.back().first;
9256  SmallVector<uint32_t, 4> DeclIDs =
9257  std::move(PendingIdentifierInfos.back().second);
9258  PendingIdentifierInfos.pop_back();
9259 
9260  SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]);
9261  }
9262 
9263  // Load each function type that we deferred loading because it was a
9264  // deduced type that might refer to a local type declared within itself.
9265  for (unsigned I = 0; I != PendingFunctionTypes.size(); ++I) {
9266  auto *FD = PendingFunctionTypes[I].first;
9267  FD->setType(GetType(PendingFunctionTypes[I].second));
9268 
9269  // If we gave a function a deduced return type, remember that we need to
9270  // propagate that along the redeclaration chain.
9271  auto *DT = FD->getReturnType()->getContainedDeducedType();
9272  if (DT && DT->isDeduced())
9273  PendingDeducedTypeUpdates.insert(
9274  {FD->getCanonicalDecl(), FD->getReturnType()});
9275  }
9276  PendingFunctionTypes.clear();
9277 
9278  // For each decl chain that we wanted to complete while deserializing, mark
9279  // it as "still needs to be completed".
9280  for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
9281  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
9282  }
9283  PendingIncompleteDeclChains.clear();
9284 
9285  // Load pending declaration chains.
9286  for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
9287  loadPendingDeclChain(PendingDeclChains[I].first,
9288  PendingDeclChains[I].second);
9289  PendingDeclChains.clear();
9290 
9291  // Make the most recent of the top-level declarations visible.
9292  for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(),
9293  TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) {
9294  IdentifierInfo *II = TLD->first;
9295  for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) {
9296  pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II);
9297  }
9298  }
9299 
9300  // Load any pending macro definitions.
9301  for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
9302  IdentifierInfo *II = PendingMacroIDs.begin()[I].first;
9304  GlobalIDs.swap(PendingMacroIDs.begin()[I].second);
9305  // Initialize the macro history from chained-PCHs ahead of module imports.
9306  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
9307  ++IDIdx) {
9308  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
9309  if (!Info.M->isModule())
9310  resolvePendingMacro(II, Info);
9311  }
9312  // Handle module imports.
9313  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
9314  ++IDIdx) {
9315  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
9316  if (Info.M->isModule())
9317  resolvePendingMacro(II, Info);
9318  }
9319  }
9320  PendingMacroIDs.clear();
9321 
9322  // Wire up the DeclContexts for Decls that we delayed setting until
9323  // recursive loading is completed.
9324  while (!PendingDeclContextInfos.empty()) {
9325  PendingDeclContextInfo Info = PendingDeclContextInfos.front();
9326  PendingDeclContextInfos.pop_front();
9327  DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC));
9328  DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC));
9329  Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext());
9330  }
9331 
9332  // Perform any pending declaration updates.
9333  while (!PendingUpdateRecords.empty()) {
9334  auto Update = PendingUpdateRecords.pop_back_val();
9335  ReadingKindTracker ReadingKind(Read_Decl, *this);
9336  loadDeclUpdateRecords(Update);
9337  }
9338  }
9339 
9340  // At this point, all update records for loaded decls are in place, so any
9341  // fake class definitions should have become real.
9342  assert(PendingFakeDefinitionData.empty() &&
9343  "faked up a class definition but never saw the real one");
9344 
9345  // If we deserialized any C++ or Objective-C class definitions, any
9346  // Objective-C protocol definitions, or any redeclarable templates, make sure
9347  // that all redeclarations point to the definitions. Note that this can only
9348  // happen now, after the redeclaration chains have been fully wired.
9349  for (Decl *D : PendingDefinitions) {
9350  if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
9351  if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) {
9352  // Make sure that the TagType points at the definition.
9353  const_cast<TagType*>(TagT)->decl = TD;
9354  }
9355 
9356  if (auto RD = dyn_cast<CXXRecordDecl>(D)) {
9357  for (auto *R = getMostRecentExistingDecl(RD); R;
9358  R = R->getPreviousDecl()) {
9359  assert((R == D) ==
9360  cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() &&
9361  "declaration thinks it's the definition but it isn't");
9362  cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData;
9363  }
9364  }
9365 
9366  continue;
9367  }
9368 
9369  if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) {
9370  // Make sure that the ObjCInterfaceType points at the definition.
9371  const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl))
9372  ->Decl = ID;
9373 
9374  for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl())
9375  cast<ObjCInterfaceDecl>(R)->Data = ID->Data;
9376 
9377  continue;
9378  }
9379 
9380  if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) {
9381  for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl())
9382  cast<ObjCProtocolDecl>(R)->Data = PD->Data;
9383 
9384  continue;
9385  }
9386 
9387  auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl();
9388  for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl())
9389  cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common;
9390  }
9391  PendingDefinitions.clear();
9392 
9393  // Load the bodies of any functions or methods we've encountered. We do
9394  // this now (delayed) so that we can be sure that the declaration chains
9395  // have been fully wired up (hasBody relies on this).
9396  // FIXME: We shouldn't require complete redeclaration chains here.
9397  for (PendingBodiesMap::iterator PB = PendingBodies.begin(),
9398  PBEnd = PendingBodies.end();
9399  PB != PBEnd; ++PB) {
9400  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) {
9401  // For a function defined inline within a class template, force the
9402  // canonical definition to be the one inside the canonical definition of
9403  // the template. This ensures that we instantiate from a correct view
9404  // of the template.
9405  //
9406  // Sadly we can't do this more generally: we can't be sure that all
9407  // copies of an arbitrary class definition will have the same members
9408  // defined (eg, some member functions may not be instantiated, and some
9409  // special members may or may not have been implicitly defined).
9410  if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
9411  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
9412  continue;
9413 
9414  // FIXME: Check for =delete/=default?
9415  // FIXME: Complain about ODR violations here?
9416  const FunctionDecl *Defn = nullptr;
9417  if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) {
9418  FD->setLazyBody(PB->second);
9419  } else {
9420  auto *NonConstDefn = const_cast<FunctionDecl*>(Defn);
9421  mergeDefinitionVisibility(NonConstDefn, FD);
9422 
9423  if (!FD->isLateTemplateParsed() &&
9424  !NonConstDefn->isLateTemplateParsed() &&
9425  FD->getODRHash() != NonConstDefn->getODRHash()) {
9426  if (!isa<CXXMethodDecl>(FD)) {
9427  PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn);
9428  } else if (FD->getLexicalParent()->isFileContext() &&
9429  NonConstDefn->getLexicalParent()->isFileContext()) {
9430  // Only diagnose out-of-line method definitions. If they are
9431  // in class definitions, then an error will be generated when
9432  // processing the class bodies.
9433  PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn);
9434  }
9435  }
9436  }
9437  continue;
9438  }
9439 
9440  ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first);
9441  if (!getContext().getLangOpts().Modules || !MD->hasBody())
9442  MD->setLazyBody(PB->second);
9443  }
9444  PendingBodies.clear();
9445 
9446  // Do some cleanup.
9447  for (auto *ND : PendingMergedDefinitionsToDeduplicate)
9448  getContext().deduplicateMergedDefinitonsFor(ND);
9449  PendingMergedDefinitionsToDeduplicate.clear();
9450 }
9451 
9452 void ASTReader::diagnoseOdrViolations() {
9453  if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() &&
9454  PendingFunctionOdrMergeFailures.empty() &&
9455  PendingEnumOdrMergeFailures.empty())
9456  return;
9457 
9458  // Trigger the import of the full definition of each class that had any
9459  // odr-merging problems, so we can produce better diagnostics for them.
9460  // These updates may in turn find and diagnose some ODR failures, so take
9461  // ownership of the set first.
9462  auto OdrMergeFailures = std::move(PendingOdrMergeFailures);
9463  PendingOdrMergeFailures.clear();
9464  for (auto &Merge : OdrMergeFailures) {
9465  Merge.first->buildLookup();
9466  Merge.first->decls_begin();
9467  Merge.first->bases_begin();
9468  Merge.first->vbases_begin();
9469  for (auto &RecordPair : Merge.second) {
9470  auto *RD = RecordPair.first;
9471  RD->decls_begin();
9472  RD->bases_begin();
9473  RD->vbases_begin();
9474  }
9475  }
9476 
9477  // Trigger the import of functions.
9478  auto FunctionOdrMergeFailures = std::move(PendingFunctionOdrMergeFailures);
9479  PendingFunctionOdrMergeFailures.clear();
9480  for (auto &Merge : FunctionOdrMergeFailures) {
9481  Merge.first->buildLookup();
9482  Merge.first->decls_begin();
9483  Merge.first->getBody();
9484  for (auto &FD : Merge.second) {
9485  FD->buildLookup();
9486  FD->decls_begin();
9487  FD->getBody();
9488  }
9489  }
9490 
9491  // Trigger the import of enums.
9492  auto EnumOdrMergeFailures = std::move(PendingEnumOdrMergeFailures);
9493  PendingEnumOdrMergeFailures.clear();
9494  for (auto &Merge : EnumOdrMergeFailures) {
9495  Merge.first->decls_begin();
9496  for (auto &Enum : Merge.second) {
9497  Enum->decls_begin();
9498  }
9499  }
9500 
9501  // For each declaration from a merged context, check that the canonical
9502  // definition of that context also contains a declaration of the same
9503  // entity.
9504  //
9505  // Caution: this loop does things that might invalidate iterators into
9506  // PendingOdrMergeChecks. Don't turn this into a range-based for loop!
9507  while (!PendingOdrMergeChecks.empty()) {
9508  NamedDecl *D = PendingOdrMergeChecks.pop_back_val();
9509 
9510  // FIXME: Skip over implicit declarations for now. This matters for things
9511  // like implicitly-declared special member functions. This isn't entirely
9512  // correct; we can end up with multiple unmerged declarations of the same
9513  // implicit entity.
9514  if (D->isImplicit())
9515  continue;
9516 
9517  DeclContext *CanonDef = D->getDeclContext();
9518 
9519  bool Found = false;
9520  const Decl *DCanon = D->getCanonicalDecl();
9521 
9522  for (auto RI : D->redecls()) {
9523  if (RI->getLexicalDeclContext() == CanonDef) {
9524  Found = true;
9525  break;
9526  }
9527  }
9528  if (Found)
9529  continue;
9530 
9531  // Quick check failed, time to do the slow thing. Note, we can't just
9532  // look up the name of D in CanonDef here, because the member that is
9533  // in CanonDef might not be found by name lookup (it might have been
9534  // replaced by a more recent declaration in the lookup table), and we
9535  // can't necessarily find it in the redeclaration chain because it might
9536  // be merely mergeable, not redeclarable.
9538  for (auto *CanonMember : CanonDef->decls()) {
9539  if (CanonMember->getCanonicalDecl() == DCanon) {
9540  // This can happen if the declaration is merely mergeable and not
9541  // actually redeclarable (we looked for redeclarations earlier).
9542  //
9543  // FIXME: We should be able to detect this more efficiently, without
9544  // pulling in all of the members of CanonDef.
9545  Found = true;
9546  break;
9547  }
9548  if (auto *ND = dyn_cast<NamedDecl>(CanonMember))
9549  if (ND->getDeclName() == D->getDeclName())
9550  Candidates.push_back(ND);
9551  }
9552 
9553  if (!Found) {
9554  // The AST doesn't like TagDecls becoming invalid after they've been
9555  // completed. We only really need to mark FieldDecls as invalid here.
9556  if (!isa<TagDecl>(D))
9557  D->setInvalidDecl();
9558 
9559  // Ensure we don't accidentally recursively enter deserialization while
9560  // we're producing our diagnostic.
9561  Deserializing RecursionGuard(this);
9562 
9563  std::string CanonDefModule =
9564  getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef));
9565  Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl)
9566  << D << getOwningModuleNameForDiagnostic(D)
9567  << CanonDef << CanonDefModule.empty() << CanonDefModule;
9568 
9569  if (Candidates.empty())
9570  Diag(cast<Decl>(CanonDef)->getLocation(),
9571  diag::note_module_odr_violation_no_possible_decls) << D;
9572  else {
9573  for (unsigned I = 0, N = Candidates.size(); I != N; ++I)
9574  Diag(Candidates[I]->getLocation(),
9575  diag::note_module_odr_violation_possible_decl)
9576  << Candidates[I];
9577  }
9578 
9579  DiagnosedOdrMergeFailures.insert(CanonDef);
9580  }
9581  }
9582 
9583  if (OdrMergeFailures.empty() && FunctionOdrMergeFailures.empty() &&
9584  EnumOdrMergeFailures.empty())
9585  return;
9586 
9587  // Ensure we don't accidentally recursively enter deserialization while
9588  // we're producing our diagnostics.
9589  Deserializing RecursionGuard(this);
9590 
9591  // Common code for hashing helpers.
9592  ODRHash Hash;
9593  auto ComputeQualTypeODRHash = [&Hash](QualType Ty) {
9594  Hash.clear();
9595  Hash.AddQualType(Ty);
9596  return Hash.CalculateHash();
9597  };
9598 
9599  auto ComputeODRHash = [&Hash](const Stmt *S) {
9600  assert(S);
9601  Hash.clear();
9602  Hash.AddStmt(S);
9603  return Hash.CalculateHash();
9604  };
9605 
9606  auto ComputeSubDeclODRHash = [&Hash](const Decl *D) {
9607  assert(D);
9608  Hash.clear();
9609  Hash.AddSubDecl(D);
9610  return Hash.CalculateHash();
9611  };
9612 
9613  auto ComputeTemplateArgumentODRHash = [&Hash](const TemplateArgument &TA) {
9614  Hash.clear();
9615  Hash.AddTemplateArgument(TA);
9616  return Hash.CalculateHash();
9617  };
9618 
9619  auto ComputeTemplateParameterListODRHash =
9620  [&Hash](const TemplateParameterList *TPL) {
9621  assert(TPL);
9622  Hash.clear();
9623  Hash.AddTemplateParameterList(TPL);
9624  return Hash.CalculateHash();
9625  };
9626 
9627  // Issue any pending ODR-failure diagnostics.
9628  for (auto &Merge : OdrMergeFailures) {
9629  // If we've already pointed out a specific problem with this class, don't
9630  // bother issuing a general "something's different" diagnostic.
9631  if (!DiagnosedOdrMergeFailures.insert(Merge.first).second)
9632  continue;
9633 
9634  bool Diagnosed = false;
9635  CXXRecordDecl *FirstRecord = Merge.first;
9636  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord);
9637  for (auto &RecordPair : Merge.second) {
9638  CXXRecordDecl *SecondRecord = RecordPair.first;
9639  // Multiple different declarations got merged together; tell the user
9640  // where they came from.
9641  if (FirstRecord == SecondRecord)
9642  continue;
9643 
9644  std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord);
9645 
9646  auto *FirstDD = FirstRecord->DefinitionData;
9647  auto *SecondDD = RecordPair.second;
9648 
9649  assert(FirstDD && SecondDD && "Definitions without DefinitionData");
9650 
9651  // Diagnostics from DefinitionData are emitted here.
9652  if (FirstDD != SecondDD) {
9653  enum ODRDefinitionDataDifference {
9654  NumBases,
9655  NumVBases,
9656  BaseType,
9657  BaseVirtual,
9658  BaseAccess,
9659  };
9660  auto ODRDiagError = [FirstRecord, &FirstModule,
9661  this](SourceLocation Loc, SourceRange Range,
9662  ODRDefinitionDataDifference DiffType) {
9663  return Diag(Loc, diag::err_module_odr_violation_definition_data)
9664  << FirstRecord << FirstModule.empty() << FirstModule << Range
9665  << DiffType;
9666  };
9667  auto ODRDiagNote = [&SecondModule,
9668  this](SourceLocation Loc, SourceRange Range,
9669  ODRDefinitionDataDifference DiffType) {
9670  return Diag(Loc, diag::note_module_odr_violation_definition_data)
9671  << SecondModule << Range << DiffType;
9672  };
9673 
9674  unsigned FirstNumBases = FirstDD->NumBases;
9675  unsigned FirstNumVBases = FirstDD->NumVBases;
9676  unsigned SecondNumBases = SecondDD->NumBases;
9677  unsigned SecondNumVBases = SecondDD->NumVBases;
9678 
9679  auto GetSourceRange = [](struct CXXRecordDecl::DefinitionData *DD) {
9680  unsigned NumBases = DD->NumBases;
9681  if (NumBases == 0) return SourceRange();
9682  auto bases = DD->bases();
9683  return SourceRange(bases[0].getBeginLoc(),
9684  bases[NumBases - 1].getEndLoc());
9685  };
9686 
9687  if (FirstNumBases != SecondNumBases) {
9688  ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD),
9689  NumBases)
9690  << FirstNumBases;
9691  ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD),
9692  NumBases)
9693  << SecondNumBases;
9694  Diagnosed = true;
9695  break;
9696  }
9697 
9698  if (FirstNumVBases != SecondNumVBases) {
9699  ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD),
9700  NumVBases)
9701  << FirstNumVBases;
9702  ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD),
9703  NumVBases)
9704  << SecondNumVBases;
9705  Diagnosed = true;
9706  break;
9707  }
9708 
9709  auto FirstBases = FirstDD->bases();
9710  auto SecondBases = SecondDD->bases();
9711  unsigned i = 0;
9712  for (i = 0; i < FirstNumBases; ++i) {
9713  auto FirstBase = FirstBases[i];
9714  auto SecondBase = SecondBases[i];
9715  if (ComputeQualTypeODRHash(FirstBase.getType()) !=
9716  ComputeQualTypeODRHash(SecondBase.getType())) {
9717  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
9718  BaseType)
9719  << (i + 1) << FirstBase.getType();
9720  ODRDiagNote(SecondRecord->getLocation(),
9721  SecondBase.getSourceRange(), BaseType)
9722  << (i + 1) << SecondBase.getType();
9723  break;
9724  }
9725 
9726  if (FirstBase.isVirtual() != SecondBase.isVirtual()) {
9727  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
9728  BaseVirtual)
9729  << (i + 1) << FirstBase.isVirtual() << FirstBase.getType();
9730  ODRDiagNote(SecondRecord->getLocation(),
9731  SecondBase.getSourceRange(), BaseVirtual)
9732  << (i + 1) << SecondBase.isVirtual() << SecondBase.getType();
9733  break;
9734  }
9735 
9736  if (FirstBase.getAccessSpecifierAsWritten() !=
9737  SecondBase.getAccessSpecifierAsWritten()) {
9738  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
9739  BaseAccess)
9740  << (i + 1) << FirstBase.getType()
9741  << (int)FirstBase.getAccessSpecifierAsWritten();
9742  ODRDiagNote(SecondRecord->getLocation(),
9743  SecondBase.getSourceRange(), BaseAccess)
9744  << (i + 1) << SecondBase.getType()
9745  << (int)SecondBase.getAccessSpecifierAsWritten();
9746  break;
9747  }
9748  }
9749 
9750  if (i != FirstNumBases) {
9751  Diagnosed = true;
9752  break;
9753  }
9754  }
9755 
9756  using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>;
9757 
9758  const ClassTemplateDecl *FirstTemplate =
9759  FirstRecord->getDescribedClassTemplate();
9760  const ClassTemplateDecl *SecondTemplate =
9761  SecondRecord->getDescribedClassTemplate();
9762 
9763  assert(!FirstTemplate == !SecondTemplate &&
9764  "Both pointers should be null or non-null");
9765 
9766  enum ODRTemplateDifference {
9767  ParamEmptyName,
9768  ParamName,
9769  ParamSingleDefaultArgument,
9770  ParamDifferentDefaultArgument,
9771  };
9772 
9773  if (FirstTemplate && SecondTemplate) {
9774  DeclHashes FirstTemplateHashes;
9775  DeclHashes SecondTemplateHashes;
9776 
9777  auto PopulateTemplateParameterHashs =
9778  [&ComputeSubDeclODRHash](DeclHashes &Hashes,
9779  const ClassTemplateDecl *TD) {
9780  for (auto *D : TD->getTemplateParameters()->asArray()) {
9781  Hashes.emplace_back(D, ComputeSubDeclODRHash(D));
9782  }
9783  };
9784 
9785  PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate);
9786  PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate);
9787 
9788  assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() &&
9789  "Number of template parameters should be equal.");
9790 
9791  auto FirstIt = FirstTemplateHashes.begin();
9792  auto FirstEnd = FirstTemplateHashes.end();
9793  auto SecondIt = SecondTemplateHashes.begin();
9794  for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) {
9795  if (FirstIt->second == SecondIt->second)
9796  continue;
9797 
9798  auto ODRDiagError = [FirstRecord, &FirstModule,
9799  this](SourceLocation Loc, SourceRange Range,
9800  ODRTemplateDifference DiffType) {
9801  return Diag(Loc, diag::err_module_odr_violation_template_parameter)
9802  << FirstRecord << FirstModule.empty() << FirstModule << Range
9803  << DiffType;
9804  };
9805  auto ODRDiagNote = [&SecondModule,
9806  this](SourceLocation Loc, SourceRange Range,
9807  ODRTemplateDifference DiffType) {
9808  return Diag(Loc, diag::note_module_odr_violation_template_parameter)
9809  << SecondModule << Range << DiffType;
9810  };
9811 
9812  const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first);
9813  const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first);
9814 
9815  assert(FirstDecl->getKind() == SecondDecl->getKind() &&
9816  "Parameter Decl's should be the same kind.");
9817 
9818  DeclarationName FirstName = FirstDecl->getDeclName();
9819  DeclarationName SecondName = SecondDecl->getDeclName();
9820 
9821  if (FirstName != SecondName) {
9822  const bool FirstNameEmpty =
9823  FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo();
9824  const bool SecondNameEmpty =
9825  SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo();
9826  assert((!FirstNameEmpty || !SecondNameEmpty) &&
9827  "Both template parameters cannot be unnamed.");
9828  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
9829  FirstNameEmpty ? ParamEmptyName : ParamName)
9830  << FirstName;
9831  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
9832  SecondNameEmpty ? ParamEmptyName : ParamName)
9833  << SecondName;
9834  break;
9835  }
9836 
9837  switch (FirstDecl->getKind()) {
9838  default:
9839  llvm_unreachable("Invalid template parameter type.");
9840  case Decl::TemplateTypeParm: {
9841  const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl);
9842  const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl);
9843  const bool HasFirstDefaultArgument =
9844  FirstParam->hasDefaultArgument() &&
9845  !FirstParam->defaultArgumentWasInherited();
9846  const bool HasSecondDefaultArgument =
9847  SecondParam->hasDefaultArgument() &&
9848  !SecondParam->defaultArgumentWasInherited();
9849 
9850  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
9851  ODRDiagError(FirstDecl->getLocation(),
9852  FirstDecl->getSourceRange(),
9853  ParamSingleDefaultArgument)
9854  << HasFirstDefaultArgument;
9855  ODRDiagNote(SecondDecl->getLocation(),
9856  SecondDecl->getSourceRange(),
9857  ParamSingleDefaultArgument)
9858  << HasSecondDefaultArgument;
9859  break;
9860  }
9861 
9862  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
9863  "Expecting default arguments.");
9864 
9865  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
9866  ParamDifferentDefaultArgument);
9867  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
9868  ParamDifferentDefaultArgument);
9869 
9870  break;
9871  }
9872  case Decl::NonTypeTemplateParm: {
9873  const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl);
9874  const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl);
9875  const bool HasFirstDefaultArgument =
9876  FirstParam->hasDefaultArgument() &&
9877  !FirstParam->defaultArgumentWasInherited();
9878  const bool HasSecondDefaultArgument =
9879  SecondParam->hasDefaultArgument() &&
9880  !SecondParam->defaultArgumentWasInherited();
9881 
9882  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
9883  ODRDiagError(FirstDecl->getLocation(),
9884  FirstDecl->getSourceRange(),
9885  ParamSingleDefaultArgument)
9886  << HasFirstDefaultArgument;
9887  ODRDiagNote(SecondDecl->getLocation(),
9888  SecondDecl->getSourceRange(),
9889  ParamSingleDefaultArgument)
9890  << HasSecondDefaultArgument;
9891  break;
9892  }
9893 
9894  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
9895  "Expecting default arguments.");
9896 
9897  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
9898  ParamDifferentDefaultArgument);
9899  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
9900  ParamDifferentDefaultArgument);
9901 
9902  break;
9903  }
9904  case Decl::TemplateTemplateParm: {
9905  const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl);
9906  const auto *SecondParam =
9907  cast<TemplateTemplateParmDecl>(SecondDecl);
9908  const bool HasFirstDefaultArgument =
9909  FirstParam->hasDefaultArgument() &&
9910  !FirstParam->defaultArgumentWasInherited();
9911  const bool HasSecondDefaultArgument =
9912  SecondParam->hasDefaultArgument() &&
9913  !SecondParam->defaultArgumentWasInherited();
9914 
9915  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
9916  ODRDiagError(FirstDecl->getLocation(),
9917  FirstDecl->getSourceRange(),
9918  ParamSingleDefaultArgument)
9919  << HasFirstDefaultArgument;
9920  ODRDiagNote(SecondDecl->getLocation(),
9921  SecondDecl->getSourceRange(),
9922  ParamSingleDefaultArgument)
9923  << HasSecondDefaultArgument;
9924  break;
9925  }
9926 
9927  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
9928  "Expecting default arguments.");
9929 
9930  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
9931  ParamDifferentDefaultArgument);
9932  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
9933  ParamDifferentDefaultArgument);
9934 
9935  break;
9936  }
9937  }
9938 
9939  break;
9940  }
9941 
9942  if (FirstIt != FirstEnd) {
9943  Diagnosed = true;
9944  break;
9945  }
9946  }
9947 
9948  DeclHashes FirstHashes;
9949  DeclHashes SecondHashes;
9950 
9951  auto PopulateHashes = [&ComputeSubDeclODRHash, FirstRecord](
9952  DeclHashes &Hashes, CXXRecordDecl *Record) {
9953  for (auto *D : Record->decls()) {
9954  // Due to decl merging, the first CXXRecordDecl is the parent of
9955  // Decls in both records.
9956  if (!ODRHash::isWhitelistedDecl(D, FirstRecord))
9957  continue;
9958  Hashes.emplace_back(D, ComputeSubDeclODRHash(D));
9959  }
9960  };
9961  PopulateHashes(FirstHashes, FirstRecord);
9962  PopulateHashes(SecondHashes, SecondRecord);
9963 
9964  // Used with err_module_odr_violation_mismatch_decl and
9965  // note_module_odr_violation_mismatch_decl
9966  // This list should be the same Decl's as in ODRHash::isWhiteListedDecl
9967  enum {
9968  EndOfClass,
9969  PublicSpecifer,
9970  PrivateSpecifer,
9971  ProtectedSpecifer,
9972  StaticAssert,
9973  Field,
9974  CXXMethod,
9975  TypeAlias,
9976  TypeDef,
9977  Var,
9978  Friend,
9979  FunctionTemplate,
9980  Other
9981  } FirstDiffType = Other,
9982  SecondDiffType = Other;
9983 
9984  auto DifferenceSelector = [](Decl *D) {
9985  assert(D && "valid Decl required");
9986  switch (D->getKind()) {
9987  default:
9988  return Other;
9989  case Decl::AccessSpec:
9990  switch (D->getAccess()) {
9991  case AS_public:
9992  return PublicSpecifer;
9993  case AS_private:
9994  return PrivateSpecifer;
9995  case AS_protected:
9996  return ProtectedSpecifer;
9997  case AS_none:
9998  break;
9999  }
10000  llvm_unreachable("Invalid access specifier");
10001  case Decl::StaticAssert:
10002  return StaticAssert;
10003  case Decl::Field:
10004  return Field;
10005  case Decl::CXXMethod:
10006  case Decl::CXXConstructor:
10007  case Decl::CXXDestructor:
10008  return CXXMethod;
10009  case Decl::TypeAlias:
10010  return TypeAlias;
10011  case Decl::Typedef:
10012  return TypeDef;
10013  case Decl::Var:
10014  return Var;
10015  case Decl::Friend:
10016  return Friend;
10017  case Decl::FunctionTemplate:
10018  return FunctionTemplate;
10019  }
10020  };
10021 
10022  Decl *FirstDecl = nullptr;
10023  Decl *SecondDecl = nullptr;
10024  auto FirstIt = FirstHashes.begin();
10025  auto SecondIt = SecondHashes.begin();
10026 
10027  // If there is a diagnoseable difference, FirstDiffType and
10028  // SecondDiffType will not be Other and FirstDecl and SecondDecl will be
10029  // filled in if not EndOfClass.
10030  while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) {
10031  if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() &&
10032  FirstIt->second == SecondIt->second) {
10033  ++FirstIt;
10034  ++SecondIt;
10035  continue;
10036  }
10037 
10038  FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first;
10039  SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first;
10040 
10041  FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass;
10042  SecondDiffType =
10043  SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass;
10044 
10045  break;
10046  }
10047 
10048  if (FirstDiffType == Other || SecondDiffType == Other) {
10049  // Reaching this point means an unexpected Decl was encountered
10050  // or no difference was detected. This causes a generic error
10051  // message to be emitted.
10052  Diag(FirstRecord->getLocation(),
10053  diag::err_module_odr_violation_different_definitions)
10054  << FirstRecord << FirstModule.empty() << FirstModule;
10055 
10056  if (FirstDecl) {
10057  Diag(FirstDecl->getLocation(), diag::note_first_module_difference)
10058  << FirstRecord << FirstDecl->getSourceRange();
10059  }
10060 
10061  Diag(SecondRecord->getLocation(),
10062  diag::note_module_odr_violation_different_definitions)
10063  << SecondModule;
10064 
10065  if (SecondDecl) {
10066  Diag(SecondDecl->getLocation(), diag::note_second_module_difference)
10067  << SecondDecl->getSourceRange();
10068  }
10069 
10070  Diagnosed = true;
10071  break;
10072  }
10073 
10074  if (FirstDiffType != SecondDiffType) {
10075  SourceLocation FirstLoc;
10076  SourceRange FirstRange;
10077  if (FirstDiffType == EndOfClass) {
10078  FirstLoc = FirstRecord->getBraceRange().getEnd();
10079  } else {
10080  FirstLoc = FirstIt->first->getLocation();
10081  FirstRange = FirstIt->first->getSourceRange();
10082  }
10083  Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl)
10084  << FirstRecord << FirstModule.empty() << FirstModule << FirstRange
10085  << FirstDiffType;
10086 
10087  SourceLocation SecondLoc;
10088  SourceRange SecondRange;
10089  if (SecondDiffType == EndOfClass) {
10090  SecondLoc = SecondRecord->getBraceRange().getEnd();
10091  } else {
10092  SecondLoc = SecondDecl->getLocation();
10093  SecondRange = SecondDecl->getSourceRange();
10094  }
10095  Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl)
10096  << SecondModule << SecondRange << SecondDiffType;
10097  Diagnosed = true;
10098  break;
10099  }
10100 
10101  assert(FirstDiffType == SecondDiffType);
10102 
10103  // Used with err_module_odr_violation_mismatch_decl_diff and
10104  // note_module_odr_violation_mismatch_decl_diff
10105  enum ODRDeclDifference {
10106  StaticAssertCondition,
10107  StaticAssertMessage,
10108  StaticAssertOnlyMessage,
10109  FieldName,
10110  FieldTypeName,
10111  FieldSingleBitField,
10112  FieldDifferentWidthBitField,
10113  FieldSingleMutable,
10114  FieldSingleInitializer,
10115  FieldDifferentInitializers,
10116  MethodName,
10117  MethodDeleted,
10118  MethodDefaulted,
10119  MethodVirtual,
10120  MethodStatic,
10121  MethodVolatile,
10122  MethodConst,
10123  MethodInline,
10124  MethodNumberParameters,
10125  MethodParameterType,
10126  MethodParameterName,
10127  MethodParameterSingleDefaultArgument,
10128  MethodParameterDifferentDefaultArgument,
10129  MethodNoTemplateArguments,
10130  MethodDifferentNumberTemplateArguments,
10131  MethodDifferentTemplateArgument,
10132  MethodSingleBody,
10133  MethodDifferentBody,
10134  TypedefName,
10135  TypedefType,
10136  VarName,
10137  VarType,
10138  VarSingleInitializer,
10139  VarDifferentInitializer,
10140  VarConstexpr,
10141  FriendTypeFunction,
10142  FriendType,
10143  FriendFunction,
10144  FunctionTemplateDifferentNumberParameters,
10145  FunctionTemplateParameterDifferentKind,
10146  FunctionTemplateParameterName,
10147  FunctionTemplateParameterSingleDefaultArgument,
10148  FunctionTemplateParameterDifferentDefaultArgument,
10149  FunctionTemplateParameterDifferentType,
10150  FunctionTemplatePackParameter,
10151  };
10152 
10153  // These lambdas have the common portions of the ODR diagnostics. This
10154  // has the same return as Diag(), so addition parameters can be passed
10155  // in with operator<<
10156  auto ODRDiagError = [FirstRecord, &FirstModule, this](
10157  SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) {
10158  return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff)
10159  << FirstRecord << FirstModule.empty() << FirstModule << Range
10160  << DiffType;
10161  };
10162  auto ODRDiagNote = [&SecondModule, this](
10163  SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) {
10164  return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff)
10165  << SecondModule << Range << DiffType;
10166  };
10167 
10168  switch (FirstDiffType) {
10169  case Other:
10170  case EndOfClass:
10171  case PublicSpecifer:
10172  case PrivateSpecifer:
10173  case ProtectedSpecifer:
10174  llvm_unreachable("Invalid diff type");
10175 
10176  case StaticAssert: {
10177  StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl);
10178  StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl);
10179 
10180  Expr *FirstExpr = FirstSA->getAssertExpr();
10181  Expr *SecondExpr = SecondSA->getAssertExpr();
10182  unsigned FirstODRHash = ComputeODRHash(FirstExpr);
10183  unsigned SecondODRHash = ComputeODRHash(SecondExpr);
10184  if (FirstODRHash != SecondODRHash) {
10185  ODRDiagError(FirstExpr->getBeginLoc(), FirstExpr->getSourceRange(),
10186  StaticAssertCondition);
10187  ODRDiagNote(SecondExpr->getBeginLoc(), SecondExpr->getSourceRange(),
10188  StaticAssertCondition);
10189  Diagnosed = true;
10190  break;
10191  }
10192 
10193  StringLiteral *FirstStr = FirstSA->getMessage();
10194  StringLiteral *SecondStr = SecondSA->getMessage();
10195  assert((FirstStr || SecondStr) && "Both messages cannot be empty");
10196  if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) {
10197  SourceLocation FirstLoc, SecondLoc;
10198  SourceRange FirstRange, SecondRange;
10199  if (FirstStr) {
10200  FirstLoc = FirstStr->getBeginLoc();
10201  FirstRange = FirstStr->getSourceRange();
10202  } else {
10203  FirstLoc = FirstSA->getBeginLoc();
10204  FirstRange = FirstSA->getSourceRange();
10205  }
10206  if (SecondStr) {
10207  SecondLoc = SecondStr->getBeginLoc();
10208  SecondRange = SecondStr->getSourceRange();
10209  } else {
10210  SecondLoc = SecondSA->getBeginLoc();
10211  SecondRange = SecondSA->getSourceRange();
10212  }
10213  ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage)
10214  << (FirstStr == nullptr);
10215  ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage)
10216  << (SecondStr == nullptr);
10217  Diagnosed = true;
10218  break;
10219  }
10220 
10221  if (FirstStr && SecondStr &&
10222  FirstStr->getString() != SecondStr->getString()) {
10223  ODRDiagError(FirstStr->getBeginLoc(), FirstStr->getSourceRange(),
10224  StaticAssertMessage);
10225  ODRDiagNote(SecondStr->getBeginLoc(), SecondStr->getSourceRange(),
10226  StaticAssertMessage);
10227  Diagnosed = true;
10228  break;
10229  }
10230  break;
10231  }
10232  case Field: {
10233  FieldDecl *FirstField = cast<FieldDecl>(FirstDecl);
10234  FieldDecl *SecondField = cast<FieldDecl>(SecondDecl);
10235  IdentifierInfo *FirstII = FirstField->getIdentifier();
10236  IdentifierInfo *SecondII = SecondField->getIdentifier();
10237  if (FirstII->getName() != SecondII->getName()) {
10238  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10239  FieldName)
10240  << FirstII;
10241  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10242  FieldName)
10243  << SecondII;
10244 
10245  Diagnosed = true;
10246  break;
10247  }
10248 
10249  assert(getContext().hasSameType(FirstField->getType(),
10250  SecondField->getType()));
10251 
10252  QualType FirstType = FirstField->getType();
10253  QualType SecondType = SecondField->getType();
10254  if (ComputeQualTypeODRHash(FirstType) !=
10255  ComputeQualTypeODRHash(SecondType)) {
10256  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10257  FieldTypeName)
10258  << FirstII << FirstType;
10259  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10260  FieldTypeName)
10261  << SecondII << SecondType;
10262 
10263  Diagnosed = true;
10264  break;
10265  }
10266 
10267  const bool IsFirstBitField = FirstField->isBitField();
10268  const bool IsSecondBitField = SecondField->isBitField();
10269  if (IsFirstBitField != IsSecondBitField) {
10270  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10271  FieldSingleBitField)
10272  << FirstII << IsFirstBitField;
10273  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10274  FieldSingleBitField)
10275  << SecondII << IsSecondBitField;
10276  Diagnosed = true;
10277  break;
10278  }
10279 
10280  if (IsFirstBitField && IsSecondBitField) {
10281  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10282  FieldDifferentWidthBitField)
10283  << FirstII << FirstField->getBitWidth()->getSourceRange();
10284  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10285  FieldDifferentWidthBitField)
10286  << SecondII << SecondField->getBitWidth()->getSourceRange();
10287  Diagnosed = true;
10288  break;
10289  }
10290 
10291  const bool IsFirstMutable = FirstField->isMutable();
10292  const bool IsSecondMutable = SecondField->isMutable();
10293  if (IsFirstMutable != IsSecondMutable) {
10294  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10295  FieldSingleMutable)
10296  << FirstII << IsFirstMutable;
10297  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10298  FieldSingleMutable)
10299  << SecondII << IsSecondMutable;
10300  Diagnosed = true;
10301  break;
10302  }
10303 
10304  const Expr *FirstInitializer = FirstField->getInClassInitializer();
10305  const Expr *SecondInitializer = SecondField->getInClassInitializer();
10306  if ((!FirstInitializer && SecondInitializer) ||
10307  (FirstInitializer && !SecondInitializer)) {
10308  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10309  FieldSingleInitializer)
10310  << FirstII << (FirstInitializer != nullptr);
10311  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10312  FieldSingleInitializer)
10313  << SecondII << (SecondInitializer != nullptr);
10314  Diagnosed = true;
10315  break;
10316  }
10317 
10318  if (FirstInitializer && SecondInitializer) {
10319  unsigned FirstInitHash = ComputeODRHash(FirstInitializer);
10320  unsigned SecondInitHash = ComputeODRHash(SecondInitializer);
10321  if (FirstInitHash != SecondInitHash) {
10322  ODRDiagError(FirstField->getLocation(),
10323  FirstField->getSourceRange(),
10324  FieldDifferentInitializers)
10325  << FirstII << FirstInitializer->getSourceRange();
10326  ODRDiagNote(SecondField->getLocation(),
10327  SecondField->getSourceRange(),
10328  FieldDifferentInitializers)
10329  << SecondII << SecondInitializer->getSourceRange();
10330  Diagnosed = true;
10331  break;
10332  }
10333  }
10334 
10335  break;
10336  }
10337  case CXXMethod: {
10338  enum {
10339  DiagMethod,
10340  DiagConstructor,
10341  DiagDestructor,
10342  } FirstMethodType,
10343  SecondMethodType;
10344  auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) {
10345  if (isa<CXXConstructorDecl>(D)) return DiagConstructor;
10346  if (isa<CXXDestructorDecl>(D)) return DiagDestructor;
10347  return DiagMethod;
10348  };
10349  const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl);
10350  const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl);
10351  FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod);
10352  SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod);
10353  auto FirstName = FirstMethod->getDeclName();
10354  auto SecondName = SecondMethod->getDeclName();
10355  if (FirstMethodType != SecondMethodType || FirstName != SecondName) {
10356  ODRDiagError(FirstMethod->getLocation(),
10357  FirstMethod->getSourceRange(), MethodName)
10358  << FirstMethodType << FirstName;
10359  ODRDiagNote(SecondMethod->getLocation(),
10360  SecondMethod->getSourceRange(), MethodName)
10361  << SecondMethodType << SecondName;
10362 
10363  Diagnosed = true;
10364  break;
10365  }
10366 
10367  const bool FirstDeleted = FirstMethod->isDeletedAsWritten();
10368  const bool SecondDeleted = SecondMethod->isDeletedAsWritten();
10369  if (FirstDeleted != SecondDeleted) {
10370  ODRDiagError(FirstMethod->getLocation(),
10371  FirstMethod->getSourceRange(), MethodDeleted)
10372  << FirstMethodType << FirstName << FirstDeleted;
10373 
10374  ODRDiagNote(SecondMethod->getLocation(),
10375  SecondMethod->getSourceRange(), MethodDeleted)
10376  << SecondMethodType << SecondName << SecondDeleted;
10377  Diagnosed = true;
10378  break;
10379  }
10380 
10381  const bool FirstDefaulted = FirstMethod->isExplicitlyDefaulted();
10382  const bool SecondDefaulted = SecondMethod->isExplicitlyDefaulted();
10383  if (FirstDefaulted != SecondDefaulted) {
10384  ODRDiagError(FirstMethod->getLocation(),
10385  FirstMethod->getSourceRange(), MethodDefaulted)
10386  << FirstMethodType << FirstName << FirstDefaulted;
10387 
10388  ODRDiagNote(SecondMethod->getLocation(),
10389  SecondMethod->getSourceRange(), MethodDefaulted)
10390  << SecondMethodType << SecondName << SecondDefaulted;
10391  Diagnosed = true;
10392  break;
10393  }
10394 
10395  const bool FirstVirtual = FirstMethod->isVirtualAsWritten();
10396  const bool SecondVirtual = SecondMethod->isVirtualAsWritten();
10397  const bool FirstPure = FirstMethod->isPure();
10398  const bool SecondPure = SecondMethod->isPure();
10399  if ((FirstVirtual || SecondVirtual) &&
10400  (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) {
10401  ODRDiagError(FirstMethod->getLocation(),
10402  FirstMethod->getSourceRange(), MethodVirtual)
10403  << FirstMethodType << FirstName << FirstPure << FirstVirtual;
10404  ODRDiagNote(SecondMethod->getLocation(),
10405  SecondMethod->getSourceRange(), MethodVirtual)
10406  << SecondMethodType << SecondName << SecondPure << SecondVirtual;
10407  Diagnosed = true;
10408  break;
10409  }
10410 
10411  // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging,
10412  // FirstDecl is the canonical Decl of SecondDecl, so the storage
10413  // class needs to be checked instead.
10414  const auto FirstStorage = FirstMethod->getStorageClass();
10415  const auto SecondStorage = SecondMethod->getStorageClass();
10416  const bool FirstStatic = FirstStorage == SC_Static;
10417  const bool SecondStatic = SecondStorage == SC_Static;
10418  if (FirstStatic != SecondStatic) {
10419  ODRDiagError(FirstMethod->getLocation(),
10420  FirstMethod->getSourceRange(), MethodStatic)
10421  << FirstMethodType << FirstName << FirstStatic;
10422  ODRDiagNote(SecondMethod->getLocation(),
10423  SecondMethod->getSourceRange(), MethodStatic)
10424  << SecondMethodType << SecondName << SecondStatic;
10425  Diagnosed = true;
10426  break;
10427  }
10428 
10429  const bool FirstVolatile = FirstMethod->isVolatile();
10430  const bool SecondVolatile = SecondMethod->isVolatile();
10431  if (FirstVolatile != SecondVolatile) {
10432  ODRDiagError(FirstMethod->getLocation(),
10433  FirstMethod->getSourceRange(), MethodVolatile)
10434  << FirstMethodType << FirstName << FirstVolatile;
10435  ODRDiagNote(SecondMethod->getLocation(),
10436  SecondMethod->getSourceRange(), MethodVolatile)
10437  << SecondMethodType << SecondName << SecondVolatile;
10438  Diagnosed = true;
10439  break;
10440  }
10441 
10442  const bool FirstConst = FirstMethod->isConst();
10443  const bool SecondConst = SecondMethod->isConst();
10444  if (FirstConst != SecondConst) {
10445  ODRDiagError(FirstMethod->getLocation(),
10446  FirstMethod->getSourceRange(), MethodConst)
10447  << FirstMethodType << FirstName << FirstConst;
10448  ODRDiagNote(SecondMethod->getLocation(),
10449  SecondMethod->getSourceRange(), MethodConst)
10450  << SecondMethodType << SecondName << SecondConst;
10451  Diagnosed = true;
10452  break;
10453  }
10454 
10455  const bool FirstInline = FirstMethod->isInlineSpecified();
10456  const bool SecondInline = SecondMethod->isInlineSpecified();
10457  if (FirstInline != SecondInline) {
10458  ODRDiagError(FirstMethod->getLocation(),
10459  FirstMethod->getSourceRange(), MethodInline)
10460  << FirstMethodType << FirstName << FirstInline;
10461  ODRDiagNote(SecondMethod->getLocation(),
10462  SecondMethod->getSourceRange(), MethodInline)
10463  << SecondMethodType << SecondName << SecondInline;
10464  Diagnosed = true;
10465  break;
10466  }
10467 
10468  const unsigned FirstNumParameters = FirstMethod->param_size();
10469  const unsigned SecondNumParameters = SecondMethod->param_size();
10470  if (FirstNumParameters != SecondNumParameters) {
10471  ODRDiagError(FirstMethod->getLocation(),
10472  FirstMethod->getSourceRange(), MethodNumberParameters)
10473  << FirstMethodType << FirstName << FirstNumParameters;
10474  ODRDiagNote(SecondMethod->getLocation(),
10475  SecondMethod->getSourceRange(), MethodNumberParameters)
10476  << SecondMethodType << SecondName << SecondNumParameters;
10477  Diagnosed = true;
10478  break;
10479  }
10480 
10481  // Need this status boolean to know when break out of the switch.
10482  bool ParameterMismatch = false;
10483  for (unsigned I = 0; I < FirstNumParameters; ++I) {
10484  const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I);
10485  const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I);
10486 
10487  QualType FirstParamType = FirstParam->getType();
10488  QualType SecondParamType = SecondParam->getType();
10489  if (FirstParamType != SecondParamType &&
10490  ComputeQualTypeODRHash(FirstParamType) !=
10491  ComputeQualTypeODRHash(SecondParamType)) {
10492  if (const DecayedType *ParamDecayedType =
10493  FirstParamType->getAs<DecayedType>()) {
10494  ODRDiagError(FirstMethod->getLocation(),
10495  FirstMethod->getSourceRange(), MethodParameterType)
10496  << FirstMethodType << FirstName << (I + 1) << FirstParamType
10497  << true << ParamDecayedType->getOriginalType();
10498  } else {
10499  ODRDiagError(FirstMethod->getLocation(),
10500  FirstMethod->getSourceRange(), MethodParameterType)
10501  << FirstMethodType << FirstName << (I + 1) << FirstParamType
10502  << false;
10503  }
10504 
10505  if (const DecayedType *ParamDecayedType =
10506  SecondParamType->getAs<DecayedType>()) {
10507  ODRDiagNote(SecondMethod->getLocation(),
10508  SecondMethod->getSourceRange(), MethodParameterType)
10509  << SecondMethodType << SecondName << (I + 1)
10510  << SecondParamType << true
10511  << ParamDecayedType->getOriginalType();
10512  } else {
10513  ODRDiagNote(SecondMethod->getLocation(),
10514  SecondMethod->getSourceRange(), MethodParameterType)
10515  << SecondMethodType << SecondName << (I + 1)
10516  << SecondParamType << false;
10517  }
10518  ParameterMismatch = true;
10519  break;
10520  }
10521 
10522  DeclarationName FirstParamName = FirstParam->getDeclName();
10523  DeclarationName SecondParamName = SecondParam->getDeclName();
10524  if (FirstParamName != SecondParamName) {
10525  ODRDiagError(FirstMethod->getLocation(),
10526  FirstMethod->getSourceRange(), MethodParameterName)
10527  << FirstMethodType << FirstName << (I + 1) << FirstParamName;
10528  ODRDiagNote(SecondMethod->getLocation(),
10529  SecondMethod->getSourceRange(), MethodParameterName)
10530  << SecondMethodType << SecondName << (I + 1) << SecondParamName;
10531  ParameterMismatch = true;
10532  break;
10533  }
10534 
10535  const Expr *FirstInit = FirstParam->getInit();
10536  const Expr *SecondInit = SecondParam->getInit();
10537  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
10538  ODRDiagError(FirstMethod->getLocation(),
10539  FirstMethod->getSourceRange(),
10540  MethodParameterSingleDefaultArgument)
10541  << FirstMethodType << FirstName << (I + 1)
10542  << (FirstInit == nullptr)
10543  << (FirstInit ? FirstInit->getSourceRange() : SourceRange());
10544  ODRDiagNote(SecondMethod->getLocation(),
10545  SecondMethod->getSourceRange(),
10546  MethodParameterSingleDefaultArgument)
10547  << SecondMethodType << SecondName << (I + 1)
10548  << (SecondInit == nullptr)
10549  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
10550  ParameterMismatch = true;
10551  break;
10552  }
10553 
10554  if (FirstInit && SecondInit &&
10555  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
10556  ODRDiagError(FirstMethod->getLocation(),
10557  FirstMethod->getSourceRange(),
10558  MethodParameterDifferentDefaultArgument)
10559  << FirstMethodType << FirstName << (I + 1)
10560  << FirstInit->getSourceRange();
10561  ODRDiagNote(SecondMethod->getLocation(),
10562  SecondMethod->getSourceRange(),
10563  MethodParameterDifferentDefaultArgument)
10564  << SecondMethodType << SecondName << (I + 1)
10565  << SecondInit->getSourceRange();
10566  ParameterMismatch = true;
10567  break;
10568 
10569  }
10570  }
10571 
10572  if (ParameterMismatch) {
10573  Diagnosed = true;
10574  break;
10575  }
10576 
10577  const auto *FirstTemplateArgs =
10578  FirstMethod->getTemplateSpecializationArgs();
10579  const auto *SecondTemplateArgs =
10580  SecondMethod->getTemplateSpecializationArgs();
10581 
10582  if ((FirstTemplateArgs && !SecondTemplateArgs) ||
10583  (!FirstTemplateArgs && SecondTemplateArgs)) {
10584  ODRDiagError(FirstMethod->getLocation(),
10585  FirstMethod->getSourceRange(), MethodNoTemplateArguments)
10586  << FirstMethodType << FirstName << (FirstTemplateArgs != nullptr);
10587  ODRDiagNote(SecondMethod->getLocation(),
10588  SecondMethod->getSourceRange(), MethodNoTemplateArguments)
10589  << SecondMethodType << SecondName
10590  << (SecondTemplateArgs != nullptr);
10591 
10592  Diagnosed = true;
10593  break;
10594  }
10595 
10596  if (FirstTemplateArgs && SecondTemplateArgs) {
10597  // Remove pack expansions from argument list.
10598  auto ExpandTemplateArgumentList =
10599  [](const TemplateArgumentList *TAL) {
10601  for (const TemplateArgument &TA : TAL->asArray()) {
10602  if (TA.getKind() != TemplateArgument::Pack) {
10603  ExpandedList.push_back(&TA);
10604  continue;
10605  }
10606  for (const TemplateArgument &PackTA : TA.getPackAsArray()) {
10607  ExpandedList.push_back(&PackTA);
10608  }
10609  }
10610  return ExpandedList;
10611  };
10613  ExpandTemplateArgumentList(FirstTemplateArgs);
10615  ExpandTemplateArgumentList(SecondTemplateArgs);
10616 
10617  if (FirstExpandedList.size() != SecondExpandedList.size()) {
10618  ODRDiagError(FirstMethod->getLocation(),
10619  FirstMethod->getSourceRange(),
10620  MethodDifferentNumberTemplateArguments)
10621  << FirstMethodType << FirstName
10622  << (unsigned)FirstExpandedList.size();
10623  ODRDiagNote(SecondMethod->getLocation(),
10624  SecondMethod->getSourceRange(),
10625  MethodDifferentNumberTemplateArguments)
10626  << SecondMethodType << SecondName
10627  << (unsigned)SecondExpandedList.size();
10628 
10629  Diagnosed = true;
10630  break;
10631  }
10632 
10633  bool TemplateArgumentMismatch = false;
10634  for (unsigned i = 0, e = FirstExpandedList.size(); i != e; ++i) {
10635  const TemplateArgument &FirstTA = *FirstExpandedList[i],
10636  &SecondTA = *SecondExpandedList[i];
10637  if (ComputeTemplateArgumentODRHash(FirstTA) ==
10638  ComputeTemplateArgumentODRHash(SecondTA)) {
10639  continue;
10640  }
10641 
10642  ODRDiagError(FirstMethod->getLocation(),
10643  FirstMethod->getSourceRange(),
10644  MethodDifferentTemplateArgument)
10645  << FirstMethodType << FirstName << FirstTA << i + 1;
10646  ODRDiagNote(SecondMethod->getLocation(),
10647  SecondMethod->getSourceRange(),
10648  MethodDifferentTemplateArgument)
10649  << SecondMethodType << SecondName << SecondTA << i + 1;
10650 
10651  TemplateArgumentMismatch = true;
10652  break;
10653  }
10654 
10655  if (TemplateArgumentMismatch) {
10656  Diagnosed = true;
10657  break;
10658  }
10659  }
10660 
10661  // Compute the hash of the method as if it has no body.
10662  auto ComputeCXXMethodODRHash = [&Hash](const CXXMethodDecl *D) {
10663  Hash.clear();
10664  Hash.AddFunctionDecl(D, true /*SkipBody*/);
10665  return Hash.CalculateHash();
10666  };
10667 
10668  // Compare the hash generated to the hash stored. A difference means
10669  // that a body was present in the original source. Due to merging,
10670  // the stardard way of detecting a body will not work.
10671  const bool HasFirstBody =
10672  ComputeCXXMethodODRHash(FirstMethod) != FirstMethod->getODRHash();
10673  const bool HasSecondBody =
10674  ComputeCXXMethodODRHash(SecondMethod) != SecondMethod->getODRHash();
10675 
10676  if (HasFirstBody != HasSecondBody) {
10677  ODRDiagError(FirstMethod->getLocation(),
10678  FirstMethod->getSourceRange(), MethodSingleBody)
10679  << FirstMethodType << FirstName << HasFirstBody;
10680  ODRDiagNote(SecondMethod->getLocation(),
10681  SecondMethod->getSourceRange(), MethodSingleBody)
10682  << SecondMethodType << SecondName << HasSecondBody;
10683  Diagnosed = true;
10684  break;
10685  }
10686 
10687  if (HasFirstBody && HasSecondBody) {
10688  ODRDiagError(FirstMethod->getLocation(),
10689  FirstMethod->getSourceRange(), MethodDifferentBody)
10690  << FirstMethodType << FirstName;
10691  ODRDiagNote(SecondMethod->getLocation(),
10692  SecondMethod->getSourceRange(), MethodDifferentBody)
10693  << SecondMethodType << SecondName;
10694  Diagnosed = true;
10695  break;
10696  }
10697 
10698  break;
10699  }
10700  case TypeAlias:
10701  case TypeDef: {
10702  TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl);
10703  TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl);
10704  auto FirstName = FirstTD->getDeclName();
10705  auto SecondName = SecondTD->getDeclName();
10706  if (FirstName != SecondName) {
10707  ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(),
10708  TypedefName)
10709  << (FirstDiffType == TypeAlias) << FirstName;
10710  ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(),
10711  TypedefName)
10712  << (FirstDiffType == TypeAlias) << SecondName;
10713  Diagnosed = true;
10714  break;
10715  }
10716 
10717  QualType FirstType = FirstTD->getUnderlyingType();
10718  QualType SecondType = SecondTD->getUnderlyingType();
10719  if (ComputeQualTypeODRHash(FirstType) !=
10720  ComputeQualTypeODRHash(SecondType)) {
10721  ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(),
10722  TypedefType)
10723  << (FirstDiffType == TypeAlias) << FirstName << FirstType;
10724  ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(),
10725  TypedefType)
10726  << (FirstDiffType == TypeAlias) << SecondName << SecondType;
10727  Diagnosed = true;
10728  break;
10729  }
10730  break;
10731  }
10732  case Var: {
10733  VarDecl *FirstVD = cast<VarDecl>(FirstDecl);
10734  VarDecl *SecondVD = cast<VarDecl>(SecondDecl);
10735  auto FirstName = FirstVD->getDeclName();
10736  auto SecondName = SecondVD->getDeclName();
10737  if (FirstName != SecondName) {
10738  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
10739  VarName)
10740  << FirstName;
10741  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
10742  VarName)
10743  << SecondName;
10744  Diagnosed = true;
10745  break;
10746  }
10747 
10748  QualType FirstType = FirstVD->getType();
10749  QualType SecondType = SecondVD->getType();
10750  if (ComputeQualTypeODRHash(FirstType) !=
10751  ComputeQualTypeODRHash(SecondType)) {
10752  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
10753  VarType)
10754  << FirstName << FirstType;
10755  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
10756  VarType)
10757  << SecondName << SecondType;
10758  Diagnosed = true;
10759  break;
10760  }
10761 
10762  const Expr *FirstInit = FirstVD->getInit();
10763  const Expr *SecondInit = SecondVD->getInit();
10764  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
10765  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
10766  VarSingleInitializer)
10767  << FirstName << (FirstInit == nullptr)
10768  << (FirstInit ? FirstInit->getSourceRange(): SourceRange());
10769  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
10770  VarSingleInitializer)
10771  << SecondName << (SecondInit == nullptr)
10772  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
10773  Diagnosed = true;
10774  break;
10775  }
10776 
10777  if (FirstInit && SecondInit &&
10778  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
10779  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
10780  VarDifferentInitializer)
10781  << FirstName << FirstInit->getSourceRange();
10782  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
10783  VarDifferentInitializer)
10784  << SecondName << SecondInit->getSourceRange();
10785  Diagnosed = true;
10786  break;
10787  }
10788 
10789  const bool FirstIsConstexpr = FirstVD->isConstexpr();
10790  const bool SecondIsConstexpr = SecondVD->isConstexpr();
10791  if (FirstIsConstexpr != SecondIsConstexpr) {
10792  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
10793  VarConstexpr)
10794  << FirstName << FirstIsConstexpr;
10795  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
10796  VarConstexpr)
10797  << SecondName << SecondIsConstexpr;
10798  Diagnosed = true;
10799  break;
10800  }
10801  break;
10802  }
10803  case Friend: {
10804  FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl);
10805  FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl);
10806 
10807  NamedDecl *FirstND = FirstFriend->getFriendDecl();
10808  NamedDecl *SecondND = SecondFriend->getFriendDecl();
10809 
10810  TypeSourceInfo *FirstTSI = FirstFriend->getFriendType();
10811  TypeSourceInfo *SecondTSI = SecondFriend->getFriendType();
10812 
10813  if (FirstND && SecondND) {
10814  ODRDiagError(FirstFriend->getFriendLoc(),
10815  FirstFriend->getSourceRange(), FriendFunction)
10816  << FirstND;
10817  ODRDiagNote(SecondFriend->getFriendLoc(),
10818  SecondFriend->getSourceRange(), FriendFunction)
10819  << SecondND;
10820 
10821  Diagnosed = true;
10822  break;
10823  }
10824 
10825  if (FirstTSI && SecondTSI) {
10826  QualType FirstFriendType = FirstTSI->getType();
10827  QualType SecondFriendType = SecondTSI->getType();
10828  assert(ComputeQualTypeODRHash(FirstFriendType) !=
10829  ComputeQualTypeODRHash(SecondFriendType));
10830  ODRDiagError(FirstFriend->getFriendLoc(),
10831  FirstFriend->getSourceRange(), FriendType)
10832  << FirstFriendType;
10833  ODRDiagNote(SecondFriend->getFriendLoc(),
10834  SecondFriend->getSourceRange(), FriendType)
10835  << SecondFriendType;
10836  Diagnosed = true;
10837  break;
10838  }
10839 
10840  ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(),
10841  FriendTypeFunction)
10842  << (FirstTSI == nullptr);
10843  ODRDiagNote(SecondFriend->getFriendLoc(),
10844  SecondFriend->getSourceRange(), FriendTypeFunction)
10845  << (SecondTSI == nullptr);
10846 
10847  Diagnosed = true;
10848  break;
10849  }
10850  case FunctionTemplate: {
10851  FunctionTemplateDecl *FirstTemplate =
10852  cast<FunctionTemplateDecl>(FirstDecl);
10853  FunctionTemplateDecl *SecondTemplate =
10854  cast<FunctionTemplateDecl>(SecondDecl);
10855 
10856  TemplateParameterList *FirstTPL =
10857  FirstTemplate->getTemplateParameters();
10858  TemplateParameterList *SecondTPL =
10859  SecondTemplate->getTemplateParameters();
10860 
10861  if (FirstTPL->size() != SecondTPL->size()) {
10862  ODRDiagError(FirstTemplate->getLocation(),
10863  FirstTemplate->getSourceRange(),
10864  FunctionTemplateDifferentNumberParameters)
10865  << FirstTemplate << FirstTPL->size();
10866  ODRDiagNote(SecondTemplate->getLocation(),
10867  SecondTemplate->getSourceRange(),
10868  FunctionTemplateDifferentNumberParameters)
10869  << SecondTemplate << SecondTPL->size();
10870 
10871  Diagnosed = true;
10872  break;
10873  }
10874 
10875  bool ParameterMismatch = false;
10876  for (unsigned i = 0, e = FirstTPL->size(); i != e; ++i) {
10877  NamedDecl *FirstParam = FirstTPL->getParam(i);
10878  NamedDecl *SecondParam = SecondTPL->getParam(i);
10879 
10880  if (FirstParam->getKind() != SecondParam->getKind()) {
10881  enum {
10882  TemplateTypeParameter,
10883  NonTypeTemplateParameter,
10884  TemplateTemplateParameter,
10885  };
10886  auto GetParamType = [](NamedDecl *D) {
10887  switch (D->getKind()) {
10888  default:
10889  llvm_unreachable("Unexpected template parameter type");
10890  case Decl::TemplateTypeParm:
10891  return TemplateTypeParameter;
10892  case Decl::NonTypeTemplateParm:
10893  return NonTypeTemplateParameter;
10894  case Decl::TemplateTemplateParm:
10895  return TemplateTemplateParameter;
10896  }
10897  };
10898 
10899  ODRDiagError(FirstTemplate->getLocation(),
10900  FirstTemplate->getSourceRange(),
10901  FunctionTemplateParameterDifferentKind)
10902  << FirstTemplate << (i + 1) << GetParamType(FirstParam);
10903  ODRDiagNote(SecondTemplate->getLocation(),
10904  SecondTemplate->getSourceRange(),
10905  FunctionTemplateParameterDifferentKind)
10906  << SecondTemplate << (i + 1) << GetParamType(SecondParam);
10907 
10908  ParameterMismatch = true;
10909  break;
10910  }
10911 
10912  if (FirstParam->getName() != SecondParam->getName()) {
10913  ODRDiagError(FirstTemplate->getLocation(),
10914  FirstTemplate->getSourceRange(),
10915  FunctionTemplateParameterName)
10916  << FirstTemplate << (i + 1) << (bool)FirstParam->getIdentifier()
10917  << FirstParam;
10918  ODRDiagNote(SecondTemplate->getLocation(),
10919  SecondTemplate->getSourceRange(),
10920  FunctionTemplateParameterName)
10921  << SecondTemplate << (i + 1)
10922  << (bool)SecondParam->getIdentifier() << SecondParam;
10923  ParameterMismatch = true;
10924  break;
10925  }
10926 
10927  if (isa<TemplateTypeParmDecl>(FirstParam) &&
10928  isa<TemplateTypeParmDecl>(SecondParam)) {
10929  TemplateTypeParmDecl *FirstTTPD =
10930  cast<TemplateTypeParmDecl>(FirstParam);
10931  TemplateTypeParmDecl *SecondTTPD =
10932  cast<TemplateTypeParmDecl>(SecondParam);
10933  bool HasFirstDefaultArgument =
10934  FirstTTPD->hasDefaultArgument() &&
10935  !FirstTTPD->defaultArgumentWasInherited();
10936  bool HasSecondDefaultArgument =
10937  SecondTTPD->hasDefaultArgument() &&
10938  !SecondTTPD->defaultArgumentWasInherited();
10939  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
10940  ODRDiagError(FirstTemplate->getLocation(),
10941  FirstTemplate->getSourceRange(),
10942  FunctionTemplateParameterSingleDefaultArgument)
10943  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
10944  ODRDiagNote(SecondTemplate->getLocation(),
10945  SecondTemplate->getSourceRange(),
10946  FunctionTemplateParameterSingleDefaultArgument)
10947  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
10948  ParameterMismatch = true;
10949  break;
10950  }
10951 
10952  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
10953  QualType FirstType = FirstTTPD->getDefaultArgument();
10954  QualType SecondType = SecondTTPD->getDefaultArgument();
10955  if (ComputeQualTypeODRHash(FirstType) !=
10956  ComputeQualTypeODRHash(SecondType)) {
10957  ODRDiagError(FirstTemplate->getLocation(),
10958  FirstTemplate->getSourceRange(),
10959  FunctionTemplateParameterDifferentDefaultArgument)
10960  << FirstTemplate << (i + 1) << FirstType;
10961  ODRDiagNote(SecondTemplate->getLocation(),
10962  SecondTemplate->getSourceRange(),
10963  FunctionTemplateParameterDifferentDefaultArgument)
10964  << SecondTemplate << (i + 1) << SecondType;
10965  ParameterMismatch = true;
10966  break;
10967  }
10968  }
10969 
10970  if (FirstTTPD->isParameterPack() !=
10971  SecondTTPD->isParameterPack()) {
10972  ODRDiagError(FirstTemplate->getLocation(),
10973  FirstTemplate->getSourceRange(),
10974  FunctionTemplatePackParameter)
10975  << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack();
10976  ODRDiagNote(SecondTemplate->getLocation(),
10977  SecondTemplate->getSourceRange(),
10978  FunctionTemplatePackParameter)
10979  << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack();
10980  ParameterMismatch = true;
10981  break;
10982  }
10983  }
10984 
10985  if (isa<TemplateTemplateParmDecl>(FirstParam) &&
10986  isa<TemplateTemplateParmDecl>(SecondParam)) {
10987  TemplateTemplateParmDecl *FirstTTPD =
10988  cast<TemplateTemplateParmDecl>(FirstParam);
10989  TemplateTemplateParmDecl *SecondTTPD =
10990  cast<TemplateTemplateParmDecl>(SecondParam);
10991 
10992  TemplateParameterList *FirstTPL =
10993  FirstTTPD->getTemplateParameters();
10994  TemplateParameterList *SecondTPL =
10995  SecondTTPD->getTemplateParameters();
10996 
10997  if (ComputeTemplateParameterListODRHash(FirstTPL) !=
10998  ComputeTemplateParameterListODRHash(SecondTPL)) {
10999  ODRDiagError(FirstTemplate->getLocation(),
11000  FirstTemplate->getSourceRange(),
11001  FunctionTemplateParameterDifferentType)
11002  << FirstTemplate << (i + 1);
11003  ODRDiagNote(SecondTemplate->getLocation(),
11004  SecondTemplate->getSourceRange(),
11005  FunctionTemplateParameterDifferentType)
11006  << SecondTemplate << (i + 1);
11007  ParameterMismatch = true;
11008  break;
11009  }
11010 
11011  bool HasFirstDefaultArgument =
11012  FirstTTPD->hasDefaultArgument() &&
11013  !FirstTTPD->defaultArgumentWasInherited();
11014  bool HasSecondDefaultArgument =
11015  SecondTTPD->hasDefaultArgument() &&
11016  !SecondTTPD->defaultArgumentWasInherited();
11017  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
11018  ODRDiagError(FirstTemplate->getLocation(),
11019  FirstTemplate->getSourceRange(),
11020  FunctionTemplateParameterSingleDefaultArgument)
11021  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
11022  ODRDiagNote(SecondTemplate->getLocation(),
11023  SecondTemplate->getSourceRange(),
11024  FunctionTemplateParameterSingleDefaultArgument)
11025  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
11026  ParameterMismatch = true;
11027  break;
11028  }
11029 
11030  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
11031  TemplateArgument FirstTA =
11032  FirstTTPD->getDefaultArgument().getArgument();
11033  TemplateArgument SecondTA =
11034  SecondTTPD->getDefaultArgument().getArgument();
11035  if (ComputeTemplateArgumentODRHash(FirstTA) !=
11036  ComputeTemplateArgumentODRHash(SecondTA)) {
11037  ODRDiagError(FirstTemplate->getLocation(),
11038  FirstTemplate->getSourceRange(),
11039  FunctionTemplateParameterDifferentDefaultArgument)
11040  << FirstTemplate << (i + 1) << FirstTA;
11041  ODRDiagNote(SecondTemplate->getLocation(),
11042  SecondTemplate->getSourceRange(),
11043  FunctionTemplateParameterDifferentDefaultArgument)
11044  << SecondTemplate << (i + 1) << SecondTA;
11045  ParameterMismatch = true;
11046  break;
11047  }
11048  }
11049 
11050  if (FirstTTPD->isParameterPack() !=
11051  SecondTTPD->isParameterPack()) {
11052  ODRDiagError(FirstTemplate->getLocation(),
11053  FirstTemplate->getSourceRange(),
11054  FunctionTemplatePackParameter)
11055  << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack();
11056  ODRDiagNote(SecondTemplate->getLocation(),
11057  SecondTemplate->getSourceRange(),
11058  FunctionTemplatePackParameter)
11059  << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack();
11060  ParameterMismatch = true;
11061  break;
11062  }
11063  }
11064 
11065  if (isa<NonTypeTemplateParmDecl>(FirstParam) &&
11066  isa<NonTypeTemplateParmDecl>(SecondParam)) {
11067  NonTypeTemplateParmDecl *FirstNTTPD =
11068  cast<NonTypeTemplateParmDecl>(FirstParam);
11069  NonTypeTemplateParmDecl *SecondNTTPD =
11070  cast<NonTypeTemplateParmDecl>(SecondParam);
11071 
11072  QualType FirstType = FirstNTTPD->getType();
11073  QualType SecondType = SecondNTTPD->getType();
11074  if (ComputeQualTypeODRHash(FirstType) !=
11075  ComputeQualTypeODRHash(SecondType)) {
11076  ODRDiagError(FirstTemplate->getLocation(),
11077  FirstTemplate->getSourceRange(),
11078  FunctionTemplateParameterDifferentType)
11079  << FirstTemplate << (i + 1);
11080  ODRDiagNote(SecondTemplate->getLocation(),
11081  SecondTemplate->getSourceRange(),
11082  FunctionTemplateParameterDifferentType)
11083  << SecondTemplate << (i + 1);
11084  ParameterMismatch = true;
11085  break;
11086  }
11087 
11088  bool HasFirstDefaultArgument =
11089  FirstNTTPD->hasDefaultArgument() &&
11090  !FirstNTTPD->defaultArgumentWasInherited();
11091  bool HasSecondDefaultArgument =
11092  SecondNTTPD->hasDefaultArgument() &&
11093  !SecondNTTPD->defaultArgumentWasInherited();
11094  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
11095  ODRDiagError(FirstTemplate->getLocation(),
11096  FirstTemplate->getSourceRange(),
11097  FunctionTemplateParameterSingleDefaultArgument)
11098  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
11099  ODRDiagNote(SecondTemplate->getLocation(),
11100  SecondTemplate->getSourceRange(),
11101  FunctionTemplateParameterSingleDefaultArgument)
11102  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
11103  ParameterMismatch = true;
11104  break;
11105  }
11106 
11107  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
11108  Expr *FirstDefaultArgument = FirstNTTPD->getDefaultArgument();
11109  Expr *SecondDefaultArgument = SecondNTTPD->getDefaultArgument();
11110  if (ComputeODRHash(FirstDefaultArgument) !=
11111  ComputeODRHash(SecondDefaultArgument)) {
11112  ODRDiagError(FirstTemplate->getLocation(),
11113  FirstTemplate->getSourceRange(),
11114  FunctionTemplateParameterDifferentDefaultArgument)
11115  << FirstTemplate << (i + 1) << FirstDefaultArgument;
11116  ODRDiagNote(SecondTemplate->getLocation(),
11117  SecondTemplate->getSourceRange(),
11118  FunctionTemplateParameterDifferentDefaultArgument)
11119  << SecondTemplate << (i + 1) << SecondDefaultArgument;
11120  ParameterMismatch = true;
11121  break;
11122  }
11123  }
11124 
11125  if (FirstNTTPD->isParameterPack() !=
11126  SecondNTTPD->isParameterPack()) {
11127  ODRDiagError(FirstTemplate->getLocation(),
11128  FirstTemplate->getSourceRange(),
11129  FunctionTemplatePackParameter)
11130  << FirstTemplate << (i + 1) << FirstNTTPD->isParameterPack();
11131  ODRDiagNote(SecondTemplate->getLocation(),
11132  SecondTemplate->getSourceRange(),
11133  FunctionTemplatePackParameter)
11134  << SecondTemplate << (i + 1)
11135  << SecondNTTPD->isParameterPack();
11136  ParameterMismatch = true;
11137  break;
11138  }
11139  }
11140  }
11141 
11142  if (ParameterMismatch) {
11143  Diagnosed = true;
11144  break;
11145  }
11146 
11147  break;
11148  }
11149  }
11150 
11151  if (Diagnosed)
11152  continue;
11153 
11154  Diag(FirstDecl->getLocation(),
11155  diag::err_module_odr_violation_mismatch_decl_unknown)
11156  << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType
11157  << FirstDecl->getSourceRange();
11158  Diag(SecondDecl->getLocation(),
11159  diag::note_module_odr_violation_mismatch_decl_unknown)
11160  << SecondModule << FirstDiffType << SecondDecl->getSourceRange();
11161  Diagnosed = true;
11162  }
11163 
11164  if (!Diagnosed) {
11165  // All definitions are updates to the same declaration. This happens if a
11166  // module instantiates the declaration of a class template specialization
11167  // and two or more other modules instantiate its definition.
11168  //
11169  // FIXME: Indicate which modules had instantiations of this definition.
11170  // FIXME: How can this even happen?
11171  Diag(Merge.first->getLocation(),
11172  diag::err_module_odr_violation_different_instantiations)
11173  << Merge.first;
11174  }
11175  }
11176 
11177  // Issue ODR failures diagnostics for functions.
11178  for (auto &Merge : FunctionOdrMergeFailures) {
11179  enum ODRFunctionDifference {
11180  ReturnType,
11181  ParameterName,
11182  ParameterType,
11183  ParameterSingleDefaultArgument,
11184  ParameterDifferentDefaultArgument,
11185  FunctionBody,
11186  };
11187 
11188  FunctionDecl *FirstFunction = Merge.first;
11189  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstFunction);
11190 
11191  bool Diagnosed = false;
11192  for (auto &SecondFunction : Merge.second) {
11193 
11194  if (FirstFunction == SecondFunction)
11195  continue;
11196 
11197  std::string SecondModule =
11198  getOwningModuleNameForDiagnostic(SecondFunction);
11199 
11200  auto ODRDiagError = [FirstFunction, &FirstModule,
11201  this](SourceLocation Loc, SourceRange Range,
11202  ODRFunctionDifference DiffType) {
11203  return Diag(Loc, diag::err_module_odr_violation_function)
11204  << FirstFunction << FirstModule.empty() << FirstModule << Range
11205  << DiffType;
11206  };
11207  auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc,
11208  SourceRange Range,
11209  ODRFunctionDifference DiffType) {
11210  return Diag(Loc, diag::note_module_odr_violation_function)
11211  << SecondModule << Range << DiffType;
11212  };
11213 
11214  if (ComputeQualTypeODRHash(FirstFunction->getReturnType()) !=
11215  ComputeQualTypeODRHash(SecondFunction->getReturnType())) {
11216  ODRDiagError(FirstFunction->getReturnTypeSourceRange().getBegin(),
11217  FirstFunction->getReturnTypeSourceRange(), ReturnType)
11218  << FirstFunction->getReturnType();
11219  ODRDiagNote(SecondFunction->getReturnTypeSourceRange().getBegin(),
11220  SecondFunction->getReturnTypeSourceRange(), ReturnType)
11221  << SecondFunction->getReturnType();
11222  Diagnosed = true;
11223  break;
11224  }
11225 
11226  assert(FirstFunction->param_size() == SecondFunction->param_size() &&
11227  "Merged functions with different number of parameters");
11228 
11229  auto ParamSize = FirstFunction->param_size();
11230  bool ParameterMismatch = false;
11231  for (unsigned I = 0; I < ParamSize; ++I) {
11232  auto *FirstParam = FirstFunction->getParamDecl(I);
11233  auto *SecondParam = SecondFunction->getParamDecl(I);
11234 
11235  assert(getContext().hasSameType(FirstParam->getType(),
11236  SecondParam->getType()) &&
11237  "Merged function has different parameter types.");
11238 
11239  if (FirstParam->getDeclName() != SecondParam->getDeclName()) {
11240  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11241  ParameterName)
11242  << I + 1 << FirstParam->getDeclName();
11243  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11244  ParameterName)
11245  << I + 1 << SecondParam->getDeclName();
11246  ParameterMismatch = true;
11247  break;
11248  };
11249 
11250  QualType FirstParamType = FirstParam->getType();
11251  QualType SecondParamType = SecondParam->getType();
11252  if (FirstParamType != SecondParamType &&
11253  ComputeQualTypeODRHash(FirstParamType) !=
11254  ComputeQualTypeODRHash(SecondParamType)) {
11255  if (const DecayedType *ParamDecayedType =
11256  FirstParamType->getAs<DecayedType>()) {
11257  ODRDiagError(FirstParam->getLocation(),
11258  FirstParam->getSourceRange(), ParameterType)
11259  << (I + 1) << FirstParamType << true
11260  << ParamDecayedType->getOriginalType();
11261  } else {
11262  ODRDiagError(FirstParam->getLocation(),
11263  FirstParam->getSourceRange(), ParameterType)
11264  << (I + 1) << FirstParamType << false;
11265  }
11266 
11267  if (const DecayedType *ParamDecayedType =
11268  SecondParamType->getAs<DecayedType>()) {
11269  ODRDiagNote(SecondParam->getLocation(),
11270  SecondParam->getSourceRange(), ParameterType)
11271  << (I + 1) << SecondParamType << true
11272  << ParamDecayedType->getOriginalType();
11273  } else {
11274  ODRDiagNote(SecondParam->getLocation(),
11275  SecondParam->getSourceRange(), ParameterType)
11276  << (I + 1) << SecondParamType << false;
11277  }
11278  ParameterMismatch = true;
11279  break;
11280  }
11281 
11282  const Expr *FirstInit = FirstParam->getInit();
11283  const Expr *SecondInit = SecondParam->getInit();
11284  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
11285  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11286  ParameterSingleDefaultArgument)
11287  << (I + 1) << (FirstInit == nullptr)
11288  << (FirstInit ? FirstInit->getSourceRange() : SourceRange());
11289  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11290  ParameterSingleDefaultArgument)
11291  << (I + 1) << (SecondInit == nullptr)
11292  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
11293  ParameterMismatch = true;
11294  break;
11295  }
11296 
11297  if (FirstInit && SecondInit &&
11298  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
11299  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11300  ParameterDifferentDefaultArgument)
11301  << (I + 1) << FirstInit->getSourceRange();
11302  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11303  ParameterDifferentDefaultArgument)
11304  << (I + 1) << SecondInit->getSourceRange();
11305  ParameterMismatch = true;
11306  break;
11307  }
11308 
11309  assert(ComputeSubDeclODRHash(FirstParam) ==
11310  ComputeSubDeclODRHash(SecondParam) &&
11311  "Undiagnosed parameter difference.");
11312  }
11313 
11314  if (ParameterMismatch) {
11315  Diagnosed = true;
11316  break;
11317  }
11318 
11319  // If no error has been generated before now, assume the problem is in
11320  // the body and generate a message.
11321  ODRDiagError(FirstFunction->getLocation(),
11322  FirstFunction->getSourceRange(), FunctionBody);
11323  ODRDiagNote(SecondFunction->getLocation(),
11324  SecondFunction->getSourceRange(), FunctionBody);
11325  Diagnosed = true;
11326  break;
11327  }
11328  (void)Diagnosed;
11329  assert(Diagnosed && "Unable to emit ODR diagnostic.");
11330  }
11331 
11332  // Issue ODR failures diagnostics for enums.
11333  for (auto &Merge : EnumOdrMergeFailures) {
11334  enum ODREnumDifference {
11335  SingleScopedEnum,
11336  EnumTagKeywordMismatch,
11337  SingleSpecifiedType,
11338  DifferentSpecifiedTypes,
11339  DifferentNumberEnumConstants,
11340  EnumConstantName,
11341  EnumConstantSingleInitilizer,
11342  EnumConstantDifferentInitilizer,
11343  };
11344 
11345  // If we've already pointed out a specific problem with this enum, don't
11346  // bother issuing a general "something's different" diagnostic.
11347  if (!DiagnosedOdrMergeFailures.insert(Merge.first).second)
11348  continue;
11349 
11350  EnumDecl *FirstEnum = Merge.first;
11351  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstEnum);
11352 
11353  using DeclHashes =
11355  auto PopulateHashes = [&ComputeSubDeclODRHash, FirstEnum](
11356  DeclHashes &Hashes, EnumDecl *Enum) {
11357  for (auto *D : Enum->decls()) {
11358  // Due to decl merging, the first EnumDecl is the parent of
11359  // Decls in both records.
11360  if (!ODRHash::isWhitelistedDecl(D, FirstEnum))
11361  continue;
11362  assert(isa<EnumConstantDecl>(D) && "Unexpected Decl kind");
11363  Hashes.emplace_back(cast<EnumConstantDecl>(D),
11364  ComputeSubDeclODRHash(D));
11365  }
11366  };
11367  DeclHashes FirstHashes;
11368  PopulateHashes(FirstHashes, FirstEnum);
11369  bool Diagnosed = false;
11370  for (auto &SecondEnum : Merge.second) {
11371 
11372  if (FirstEnum == SecondEnum)
11373  continue;
11374 
11375  std::string SecondModule =
11376  getOwningModuleNameForDiagnostic(SecondEnum);
11377 
11378  auto ODRDiagError = [FirstEnum, &FirstModule,
11379  this](SourceLocation Loc, SourceRange Range,
11380  ODREnumDifference DiffType) {
11381  return Diag(Loc, diag::err_module_odr_violation_enum)
11382  << FirstEnum << FirstModule.empty() << FirstModule << Range
11383  << DiffType;
11384  };
11385  auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc,
11386  SourceRange Range,
11387  ODREnumDifference DiffType) {
11388  return Diag(Loc, diag::note_module_odr_violation_enum)
11389  << SecondModule << Range << DiffType;
11390  };
11391 
11392  if (FirstEnum->isScoped() != SecondEnum->isScoped()) {
11393  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11394  SingleScopedEnum)
11395  << FirstEnum->isScoped();
11396  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11397  SingleScopedEnum)
11398  << SecondEnum->isScoped();
11399  Diagnosed = true;
11400  continue;
11401  }
11402 
11403  if (FirstEnum->isScoped() && SecondEnum->isScoped()) {
11404  if (FirstEnum->isScopedUsingClassTag() !=
11405  SecondEnum->isScopedUsingClassTag()) {
11406  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11407  EnumTagKeywordMismatch)
11408  << FirstEnum->isScopedUsingClassTag();
11409  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11410  EnumTagKeywordMismatch)
11411  << SecondEnum->isScopedUsingClassTag();
11412  Diagnosed = true;
11413  continue;
11414  }
11415  }
11416 
11417  QualType FirstUnderlyingType =
11418  FirstEnum->getIntegerTypeSourceInfo()
11419  ? FirstEnum->getIntegerTypeSourceInfo()->getType()
11420  : QualType();
11421  QualType SecondUnderlyingType =
11422  SecondEnum->getIntegerTypeSourceInfo()
11423  ? SecondEnum->getIntegerTypeSourceInfo()->getType()
11424  : QualType();
11425  if (FirstUnderlyingType.isNull() != SecondUnderlyingType.isNull()) {
11426  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11427  SingleSpecifiedType)
11428  << !FirstUnderlyingType.isNull();
11429  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11430  SingleSpecifiedType)
11431  << !SecondUnderlyingType.isNull();
11432  Diagnosed = true;
11433  continue;
11434  }
11435 
11436  if (!FirstUnderlyingType.isNull() && !SecondUnderlyingType.isNull()) {
11437  if (ComputeQualTypeODRHash(FirstUnderlyingType) !=
11438  ComputeQualTypeODRHash(SecondUnderlyingType)) {
11439  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11440  DifferentSpecifiedTypes)
11441  << FirstUnderlyingType;
11442  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11443  DifferentSpecifiedTypes)
11444  << SecondUnderlyingType;
11445  Diagnosed = true;
11446  continue;
11447  }
11448  }
11449 
11450  DeclHashes SecondHashes;
11451  PopulateHashes(SecondHashes, SecondEnum);
11452 
11453  if (FirstHashes.size() != SecondHashes.size()) {
11454  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11455  DifferentNumberEnumConstants)
11456  << (int)FirstHashes.size();
11457  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11458  DifferentNumberEnumConstants)
11459  << (int)SecondHashes.size();
11460  Diagnosed = true;
11461  continue;
11462  }
11463 
11464  for (unsigned I = 0; I < FirstHashes.size(); ++I) {
11465  if (FirstHashes[I].second == SecondHashes[I].second)
11466  continue;
11467  const EnumConstantDecl *FirstEnumConstant = FirstHashes[I].first;
11468  const EnumConstantDecl *SecondEnumConstant = SecondHashes[I].first;
11469 
11470  if (FirstEnumConstant->getDeclName() !=
11471  SecondEnumConstant->getDeclName()) {
11472 
11473  ODRDiagError(FirstEnumConstant->getLocation(),
11474  FirstEnumConstant->getSourceRange(), EnumConstantName)
11475  << I + 1 << FirstEnumConstant;
11476  ODRDiagNote(SecondEnumConstant->getLocation(),
11477  SecondEnumConstant->getSourceRange(), EnumConstantName)
11478  << I + 1 << SecondEnumConstant;
11479  Diagnosed = true;
11480  break;
11481  }
11482 
11483  const Expr *FirstInit = FirstEnumConstant->getInitExpr();
11484  const Expr *SecondInit = SecondEnumConstant->getInitExpr();
11485  if (!FirstInit && !SecondInit)
11486  continue;
11487 
11488  if (!FirstInit || !SecondInit) {
11489  ODRDiagError(FirstEnumConstant->getLocation(),
11490  FirstEnumConstant->getSourceRange(),
11491  EnumConstantSingleInitilizer)
11492  << I + 1 << FirstEnumConstant << (FirstInit != nullptr);
11493  ODRDiagNote(SecondEnumConstant->getLocation(),
11494  SecondEnumConstant->getSourceRange(),
11495  EnumConstantSingleInitilizer)
11496  << I + 1 << SecondEnumConstant << (SecondInit != nullptr);
11497  Diagnosed = true;
11498  break;
11499  }
11500 
11501  if (ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
11502  ODRDiagError(FirstEnumConstant->getLocation(),
11503  FirstEnumConstant->getSourceRange(),
11504  EnumConstantDifferentInitilizer)
11505  << I + 1 << FirstEnumConstant;
11506  ODRDiagNote(SecondEnumConstant->getLocation(),
11507  SecondEnumConstant->getSourceRange(),
11508  EnumConstantDifferentInitilizer)
11509  << I + 1 << SecondEnumConstant;
11510  Diagnosed = true;
11511  break;
11512  }
11513  }
11514  }
11515 
11516  (void)Diagnosed;
11517  assert(Diagnosed && "Unable to emit ODR diagnostic.");
11518  }
11519 }
11520 
11522  if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get())
11523  ReadTimer->startTimer();
11524 }
11525 
11527  assert(NumCurrentElementsDeserializing &&
11528  "FinishedDeserializing not paired with StartedDeserializing");
11529  if (NumCurrentElementsDeserializing == 1) {
11530  // We decrease NumCurrentElementsDeserializing only after pending actions
11531  // are finished, to avoid recursively re-calling finishPendingActions().
11532  finishPendingActions();
11533  }
11534  --NumCurrentElementsDeserializing;
11535 
11536  if (NumCurrentElementsDeserializing == 0) {
11537  // Propagate exception specification and deduced type updates along
11538  // redeclaration chains.
11539  //
11540  // We do this now rather than in finishPendingActions because we want to
11541  // be able to walk the complete redeclaration chains of the updated decls.
11542  while (!PendingExceptionSpecUpdates.empty() ||
11543  !PendingDeducedTypeUpdates.empty()) {
11544  auto ESUpdates = std::move(PendingExceptionSpecUpdates);
11545  PendingExceptionSpecUpdates.clear();
11546  for (auto Update : ESUpdates) {
11547  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
11548  auto *FPT = Update.second->getType()->castAs<FunctionProtoType>();
11549  auto ESI = FPT->getExtProtoInfo().ExceptionSpec;
11550  if (auto *Listener = getContext().getASTMutationListener())
11551  Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second));
11552  for (auto *Redecl : Update.second->redecls())
11553  getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
11554  }
11555 
11556  auto DTUpdates = std::move(PendingDeducedTypeUpdates);
11557  PendingDeducedTypeUpdates.clear();
11558  for (auto Update : DTUpdates) {
11559  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
11560  // FIXME: If the return type is already deduced, check that it matches.
11561  getContext().adjustDeducedFunctionResultType(Update.first,
11562  Update.second);
11563  }
11564  }
11565 
11566  if (ReadTimer)
11567  ReadTimer->stopTimer();
11568 
11569  diagnoseOdrViolations();
11570 
11571  // We are not in recursive loading, so it's safe to pass the "interesting"
11572  // decls to the consumer.
11573  if (Consumer)
11574  PassInterestingDeclsToConsumer();
11575  }
11576 }
11577 
11578 void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) {
11579  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
11580  // Remove any fake results before adding any real ones.
11581  auto It = PendingFakeLookupResults.find(II);
11582  if (It != PendingFakeLookupResults.end()) {
11583  for (auto *ND : It->second)
11584  SemaObj->IdResolver.RemoveDecl(ND);
11585  // FIXME: this works around module+PCH performance issue.
11586  // Rather than erase the result from the map, which is O(n), just clear
11587  // the vector of NamedDecls.
11588  It->second.clear();
11589  }
11590  }
11591 
11592  if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) {
11593  SemaObj->TUScope->AddDecl(D);
11594  } else if (SemaObj->TUScope) {
11595  // Adding the decl to IdResolver may have failed because it was already in
11596  // (even though it was not added in scope). If it is already in, make sure
11597  // it gets in the scope as well.
11598  if (std::find(SemaObj->IdResolver.begin(Name),
11599  SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end())
11600  SemaObj->TUScope->AddDecl(D);
11601  }
11602 }
11603 
11605  const PCHContainerReader &PCHContainerRdr,
11606  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
11607  StringRef isysroot, bool DisableValidation,
11608  bool AllowASTWithCompilerErrors,
11609  bool AllowConfigurationMismatch, bool ValidateSystemInputs,
11610  bool UseGlobalIndex,
11611  std::unique_ptr<llvm::Timer> ReadTimer)
11612  : Listener(DisableValidation
11614  : cast<ASTReaderListener>(new PCHValidator(PP, *this))),
11615  SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
11616  PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP),
11617  ContextObj(Context),
11618  ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr,
11619  PP.getHeaderSearchInfo()),
11620  PCMCache(PP.getPCMCache()), DummyIdResolver(PP),
11621  ReadTimer(std::move(ReadTimer)), isysroot(isysroot),
11622  DisableValidation(DisableValidation),
11623  AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
11624  AllowConfigurationMismatch(AllowConfigurationMismatch),
11625  ValidateSystemInputs(ValidateSystemInputs),
11626  UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) {
11627  SourceMgr.setExternalSLocEntrySource(this);
11628 
11629  for (const auto &Ext : Extensions) {
11630  auto BlockName = Ext->getExtensionMetadata().BlockName;
11631  auto Known = ModuleFileExtensions.find(BlockName);
11632  if (Known != ModuleFileExtensions.end()) {
11633  Diags.Report(diag::warn_duplicate_module_file_extension)
11634  << BlockName;
11635  continue;
11636  }
11637 
11638  ModuleFileExtensions.insert({BlockName, Ext});
11639  }
11640 }
11641 
11643  if (OwnsDeserializationListener)
11644  delete DeserializationListener;
11645 }
11646 
11648  return SemaObj ? SemaObj->IdResolver : DummyIdResolver;
11649 }
11650 
11651 unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor,
11652  unsigned AbbrevID) {
11653  Idx = 0;
11654  Record.clear();
11655  return Cursor.readRecord(AbbrevID, Record);
11656 }
11657 //===----------------------------------------------------------------------===//
11658 //// OMPClauseReader implementation
11659 ////===----------------------------------------------------------------------===//
11660 
11662  OMPClause *C;
11663  switch (Record.readInt()) {
11664  case OMPC_if:
11665  C = new (Context) OMPIfClause();
11666  break;
11667  case OMPC_final:
11668  C = new (Context) OMPFinalClause();
11669  break;
11670  case OMPC_num_threads:
11671  C = new (Context) OMPNumThreadsClause();
11672  break;
11673  case OMPC_safelen:
11674  C = new (Context) OMPSafelenClause();
11675  break;
11676  case OMPC_simdlen:
11677  C = new (Context) OMPSimdlenClause();
11678  break;
11679  case OMPC_collapse:
11680  C = new (Context) OMPCollapseClause();
11681  break;
11682  case OMPC_default:
11683  C = new (Context) OMPDefaultClause();
11684  break;
11685  case OMPC_proc_bind:
11686  C = new (Context) OMPProcBindClause();
11687  break;
11688  case OMPC_schedule:
11689  C = new (Context) OMPScheduleClause();
11690  break;
11691  case OMPC_ordered:
11692  C = OMPOrderedClause::CreateEmpty(Context, Record.readInt());
11693  break;
11694  case OMPC_nowait:
11695  C = new (Context) OMPNowaitClause();
11696  break;
11697  case OMPC_untied:
11698  C = new (Context) OMPUntiedClause();
11699  break;
11700  case OMPC_mergeable:
11701  C = new (Context) OMPMergeableClause();
11702  break;
11703  case OMPC_read:
11704  C = new (Context) OMPReadClause();
11705  break;
11706  case OMPC_write:
11707  C = new (Context) OMPWriteClause();
11708  break;
11709  case OMPC_update:
11710  C = new (Context) OMPUpdateClause();
11711  break;
11712  case OMPC_capture:
11713  C = new (Context) OMPCaptureClause();
11714  break;
11715  case OMPC_seq_cst:
11716  C = new (Context) OMPSeqCstClause();
11717  break;
11718  case OMPC_threads:
11719  C = new (Context) OMPThreadsClause();
11720  break;
11721  case OMPC_simd:
11722  C = new (Context) OMPSIMDClause();
11723  break;
11724  case OMPC_nogroup:
11725  C = new (Context) OMPNogroupClause();
11726  break;
11727  case OMPC_unified_address:
11728  C = new (Context) OMPUnifiedAddressClause();
11729  break;
11730  case OMPC_unified_shared_memory:
11731  C = new (Context) OMPUnifiedSharedMemoryClause();
11732  break;
11733  case OMPC_reverse_offload:
11734  C = new (Context) OMPReverseOffloadClause();
11735  break;
11736  case OMPC_dynamic_allocators:
11737  C = new (Context) OMPDynamicAllocatorsClause();
11738  break;
11739  case OMPC_atomic_default_mem_order:
11740  C = new (Context) OMPAtomicDefaultMemOrderClause();
11741  break;
11742  case OMPC_private:
11743  C = OMPPrivateClause::CreateEmpty(Context, Record.readInt());
11744  break;
11745  case OMPC_firstprivate:
11746  C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt());
11747  break;
11748  case OMPC_lastprivate:
11749  C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt());
11750  break;
11751  case OMPC_shared:
11752  C = OMPSharedClause::CreateEmpty(Context, Record.readInt());
11753  break;
11754  case OMPC_reduction:
11755  C = OMPReductionClause::CreateEmpty(Context, Record.readInt());
11756  break;
11757  case OMPC_task_reduction:
11758  C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt());
11759  break;
11760  case OMPC_in_reduction:
11761  C = OMPInReductionClause::CreateEmpty(Context, Record.readInt());
11762  break;
11763  case OMPC_linear:
11764  C = OMPLinearClause::CreateEmpty(Context, Record.readInt());
11765  break;
11766  case OMPC_aligned:
11767  C = OMPAlignedClause::CreateEmpty(Context, Record.readInt());
11768  break;
11769  case OMPC_copyin:
11770  C = OMPCopyinClause::CreateEmpty(Context, Record.readInt());
11771  break;
11772  case OMPC_copyprivate:
11773  C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt());
11774  break;
11775  case OMPC_flush:
11776  C = OMPFlushClause::CreateEmpty(Context, Record.readInt());
11777  break;
11778  case OMPC_depend: {
11779  unsigned NumVars = Record.readInt();
11780  unsigned NumLoops = Record.readInt();
11781  C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops);
11782  break;
11783  }
11784  case OMPC_device:
11785  C = new (Context) OMPDeviceClause();
11786  break;
11787  case OMPC_map: {
11788  unsigned NumVars = Record.readInt();
11789  unsigned NumDeclarations = Record.readInt();
11790  unsigned NumLists = Record.readInt();
11791  unsigned NumComponents = Record.readInt();
11792  C = OMPMapClause::CreateEmpty(Context, NumVars, NumDeclarations, NumLists,
11793  NumComponents);
11794  break;
11795  }
11796  case OMPC_num_teams:
11797  C = new (Context) OMPNumTeamsClause();
11798  break;
11799  case OMPC_thread_limit:
11800  C = new (Context) OMPThreadLimitClause();
11801  break;
11802  case OMPC_priority:
11803  C = new (Context) OMPPriorityClause();
11804  break;
11805  case OMPC_grainsize:
11806  C = new (Context) OMPGrainsizeClause();
11807  break;
11808  case OMPC_num_tasks:
11809  C = new (Context) OMPNumTasksClause();
11810  break;
11811  case OMPC_hint:
11812  C = new (Context) OMPHintClause();
11813  break;
11814  case OMPC_dist_schedule:
11815  C = new (Context) OMPDistScheduleClause();
11816  break;
11817  case OMPC_defaultmap:
11818  C = new (Context) OMPDefaultmapClause();
11819  break;
11820  case OMPC_to: {
11821  unsigned NumVars = Record.readInt();
11822  unsigned NumDeclarations = Record.readInt();
11823  unsigned NumLists = Record.readInt();
11824  unsigned NumComponents = Record.readInt();
11825  C = OMPToClause::CreateEmpty(Context, NumVars, NumDeclarations, NumLists,
11826  NumComponents);
11827  break;
11828  }
11829  case OMPC_from: {
11830  unsigned NumVars = Record.readInt();
11831  unsigned NumDeclarations = Record.readInt();
11832  unsigned NumLists = Record.readInt();
11833  unsigned NumComponents = Record.readInt();
11834  C = OMPFromClause::CreateEmpty(Context, NumVars, NumDeclarations, NumLists,
11835  NumComponents);
11836  break;
11837  }
11838  case OMPC_use_device_ptr: {
11839  unsigned NumVars = Record.readInt();
11840  unsigned NumDeclarations = Record.readInt();
11841  unsigned NumLists = Record.readInt();
11842  unsigned NumComponents = Record.readInt();
11843  C = OMPUseDevicePtrClause::CreateEmpty(Context, NumVars, NumDeclarations,
11844  NumLists, NumComponents);
11845  break;
11846  }
11847  case OMPC_is_device_ptr: {
11848  unsigned NumVars = Record.readInt();
11849  unsigned NumDeclarations = Record.readInt();
11850  unsigned NumLists = Record.readInt();
11851  unsigned NumComponents = Record.readInt();
11852  C = OMPIsDevicePtrClause::CreateEmpty(Context, NumVars, NumDeclarations,
11853  NumLists, NumComponents);
11854  break;
11855  }
11856  }
11857  Visit(C);
11858  C->setLocStart(Record.readSourceLocation());
11859  C->setLocEnd(Record.readSourceLocation());
11860 
11861  return C;
11862 }
11863 
11865  C->setPreInitStmt(Record.readSubStmt(),
11866  static_cast<OpenMPDirectiveKind>(Record.readInt()));
11867 }
11868 
11870  VisitOMPClauseWithPreInit(C);
11871  C->setPostUpdateExpr(Record.readSubExpr());
11872 }
11873 
11874 void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) {
11875  VisitOMPClauseWithPreInit(C);
11876  C->setNameModifier(static_cast<OpenMPDirectiveKind>(Record.readInt()));
11877  C->setNameModifierLoc(Record.readSourceLocation());
11878  C->setColonLoc(Record.readSourceLocation());
11879  C->setCondition(Record.readSubExpr());
11880  C->setLParenLoc(Record.readSourceLocation());
11881 }
11882 
11883 void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) {
11884  C->setCondition(Record.readSubExpr());
11885  C->setLParenLoc(Record.readSourceLocation());
11886 }
11887 
11888 void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
11889  VisitOMPClauseWithPreInit(C);
11890  C->setNumThreads(Record.readSubExpr());
11891  C->setLParenLoc(Record.readSourceLocation());
11892 }
11893 
11894 void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) {
11895  C->setSafelen(Record.readSubExpr());
11896  C->setLParenLoc(Record.readSourceLocation());
11897 }
11898 
11899 void OMPClauseReader::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
11900  C->setSimdlen(Record.readSubExpr());
11901  C->setLParenLoc(Record.readSourceLocation());
11902 }
11903 
11904 void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
11905  C->setNumForLoops(Record.readSubExpr());
11906  C->setLParenLoc(Record.readSourceLocation());
11907 }
11908 
11909 void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
11910  C->setDefaultKind(
11911  static_cast<OpenMPDefaultClauseKind>(Record.readInt()));
11912  C->setLParenLoc(Record.readSourceLocation());
11913  C->setDefaultKindKwLoc(Record.readSourceLocation());
11914 }
11915 
11916 void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
11917  C->setProcBindKind(
11918  static_cast<OpenMPProcBindClauseKind>(Record.readInt()));
11919  C->setLParenLoc(Record.readSourceLocation());
11920  C->setProcBindKindKwLoc(Record.readSourceLocation());
11921 }
11922 
11923 void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
11924  VisitOMPClauseWithPreInit(C);
11925  C->setScheduleKind(
11926  static_cast<OpenMPScheduleClauseKind>(Record.readInt()));
11927  C->setFirstScheduleModifier(
11928  static_cast<OpenMPScheduleClauseModifier>(Record.readInt()));
11929  C->setSecondScheduleModifier(
11930  static_cast<OpenMPScheduleClauseModifier>(Record.readInt()));
11931  C->setChunkSize(Record.readSubExpr());
11932  C->setLParenLoc(Record.readSourceLocation());
11933  C->setFirstScheduleModifierLoc(Record.readSourceLocation());
11934  C->setSecondScheduleModifierLoc(Record.readSourceLocation());
11935  C->setScheduleKindLoc(Record.readSourceLocation());
11936  C->setCommaLoc(Record.readSourceLocation());
11937 }
11938 
11939 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *C) {
11940  C->setNumForLoops(Record.readSubExpr());
11941  for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I)
11942  C->setLoopNumIterations(I, Record.readSubExpr());
11943  for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I)
11944  C->setLoopCounter(I, Record.readSubExpr());
11945  C->setLParenLoc(Record.readSourceLocation());
11946 }
11947 
11948 void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
11949 
11950 void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}
11951 
11952 void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
11953 
11954 void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {}
11955 
11956 void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {}
11957 
11958 void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {}
11959 
11960 void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {}
11961 
11962 void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
11963 
11964 void OMPClauseReader::VisitOMPThreadsClause(OMPThreadsClause *) {}
11965 
11966 void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {}
11967 
11968 void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {}
11969 
11970 void OMPClauseReader::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {}
11971 
11972 void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause(
11974 
11975 void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {}
11976 
11977 void
11978 OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) {
11979 }
11980 
11981 void OMPClauseReader::VisitOMPAtomicDefaultMemOrderClause(
11983  C->setAtomicDefaultMemOrderKind(
11984  static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Record.readInt()));
11985  C->setLParenLoc(Record.readSourceLocation());
11986  C->setAtomicDefaultMemOrderKindKwLoc(Record.readSourceLocation());
11987 }
11988 
11989 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
11990  C->setLParenLoc(Record.readSourceLocation());
11991  unsigned NumVars = C->varlist_size();
11993  Vars.reserve(NumVars);
11994  for (unsigned i = 0; i != NumVars; ++i)
11995  Vars.push_back(Record.readSubExpr());
11996  C->setVarRefs(Vars);
11997  Vars.clear();
11998  for (unsigned i = 0; i != NumVars; ++i)
11999  Vars.push_back(Record.readSubExpr());
12000  C->setPrivateCopies(Vars);
12001 }
12002 
12003 void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
12004  VisitOMPClauseWithPreInit(C);
12005  C->setLParenLoc(Record.readSourceLocation());
12006  unsigned NumVars = C->varlist_size();
12008  Vars.reserve(NumVars);
12009  for (unsigned i = 0; i != NumVars; ++i)
12010  Vars.push_back(Record.readSubExpr());
12011  C->setVarRefs(Vars);
12012  Vars.clear();
12013  for (unsigned i = 0; i != NumVars; ++i)
12014  Vars.push_back(Record.readSubExpr());
12015  C->setPrivateCopies(Vars);
12016  Vars.clear();
12017  for (unsigned i = 0; i != NumVars; ++i)
12018  Vars.push_back(Record.readSubExpr());
12019  C->setInits(Vars);
12020 }
12021 
12022 void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
12023  VisitOMPClauseWithPostUpdate(C);
12024  C->setLParenLoc(Record.readSourceLocation());
12025  unsigned NumVars = C->varlist_size();
12027  Vars.reserve(NumVars);
12028  for (unsigned i = 0; i != NumVars; ++i)
12029  Vars.push_back(Record.readSubExpr());
12030  C->setVarRefs(Vars);
12031  Vars.clear();
12032  for (unsigned i = 0; i != NumVars; ++i)
12033  Vars.push_back(Record.readSubExpr());
12034  C->setPrivateCopies(Vars);
12035  Vars.clear();
12036  for (unsigned i = 0; i != NumVars; ++i)
12037  Vars.push_back(Record.readSubExpr());
12038  C->setSourceExprs(Vars);
12039  Vars.clear();
12040  for (unsigned i = 0; i != NumVars; ++i)
12041  Vars.push_back(Record.readSubExpr());
12042  C->setDestinationExprs(Vars);
12043  Vars.clear();
12044  for (unsigned i = 0; i != NumVars; ++i)
12045  Vars.push_back(Record.readSubExpr());
12046  C->setAssignmentOps(Vars);
12047 }
12048 
12049 void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
12050  C->setLParenLoc(Record.readSourceLocation());
12051  unsigned NumVars = C->varlist_size();
12053  Vars.reserve(NumVars);
12054  for (unsigned i = 0; i != NumVars; ++i)
12055  Vars.push_back(Record.readSubExpr());
12056  C->setVarRefs(Vars);
12057 }
12058 
12059 void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) {
12060  VisitOMPClauseWithPostUpdate(C);
12061  C->setLParenLoc(Record.readSourceLocation());
12062  C->setColonLoc(Record.readSourceLocation());
12063  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12064  DeclarationNameInfo DNI;
12065  Record.readDeclarationNameInfo(DNI);
12066  C->setQualifierLoc(NNSL);
12067  C->setNameInfo(DNI);
12068 
12069  unsigned NumVars = C->varlist_size();
12071  Vars.reserve(NumVars);
12072  for (unsigned i = 0; i != NumVars; ++i)
12073  Vars.push_back(Record.readSubExpr());
12074  C->setVarRefs(Vars);
12075  Vars.clear();
12076  for (unsigned i = 0; i != NumVars; ++i)
12077  Vars.push_back(Record.readSubExpr());
12078  C->setPrivates(Vars);
12079  Vars.clear();
12080  for (unsigned i = 0; i != NumVars; ++i)
12081  Vars.push_back(Record.readSubExpr());
12082  C->setLHSExprs(Vars);
12083  Vars.clear();
12084  for (unsigned i = 0; i != NumVars; ++i)
12085  Vars.push_back(Record.readSubExpr());
12086  C->setRHSExprs(Vars);
12087  Vars.clear();
12088  for (unsigned i = 0; i != NumVars; ++i)
12089  Vars.push_back(Record.readSubExpr());
12090  C->setReductionOps(Vars);
12091 }
12092 
12093 void OMPClauseReader::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
12094  VisitOMPClauseWithPostUpdate(C);
12095  C->setLParenLoc(Record.readSourceLocation());
12096  C->setColonLoc(Record.readSourceLocation());
12097  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12098  DeclarationNameInfo DNI;
12099  Record.readDeclarationNameInfo(DNI);
12100  C->setQualifierLoc(NNSL);
12101  C->setNameInfo(DNI);
12102 
12103  unsigned NumVars = C->varlist_size();
12105  Vars.reserve(NumVars);
12106  for (unsigned I = 0; I != NumVars; ++I)
12107  Vars.push_back(Record.readSubExpr());
12108  C->setVarRefs(Vars);
12109  Vars.clear();
12110  for (unsigned I = 0; I != NumVars; ++I)
12111  Vars.push_back(Record.readSubExpr());
12112  C->setPrivates(Vars);
12113  Vars.clear();
12114  for (unsigned I = 0; I != NumVars; ++I)
12115  Vars.push_back(Record.readSubExpr());
12116  C->setLHSExprs(Vars);
12117  Vars.clear();
12118  for (unsigned I = 0; I != NumVars; ++I)
12119  Vars.push_back(Record.readSubExpr());
12120  C->setRHSExprs(Vars);
12121  Vars.clear();
12122  for (unsigned I = 0; I != NumVars; ++I)
12123  Vars.push_back(Record.readSubExpr());
12124  C->setReductionOps(Vars);
12125 }
12126 
12127 void OMPClauseReader::VisitOMPInReductionClause(OMPInReductionClause *C) {
12128  VisitOMPClauseWithPostUpdate(C);
12129  C->setLParenLoc(Record.readSourceLocation());
12130  C->setColonLoc(Record.readSourceLocation());
12131  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12132  DeclarationNameInfo DNI;
12133  Record.readDeclarationNameInfo(DNI);
12134  C->setQualifierLoc(NNSL);
12135  C->setNameInfo(DNI);
12136 
12137  unsigned NumVars = C->varlist_size();
12139  Vars.reserve(NumVars);
12140  for (unsigned I = 0; I != NumVars; ++I)
12141  Vars.push_back(Record.readSubExpr());
12142  C->setVarRefs(Vars);
12143  Vars.clear();
12144  for (unsigned I = 0; I != NumVars; ++I)
12145  Vars.push_back(Record.readSubExpr());
12146  C->setPrivates(Vars);
12147  Vars.clear();
12148  for (unsigned I = 0; I != NumVars; ++I)
12149  Vars.push_back(Record.readSubExpr());
12150  C->setLHSExprs(Vars);
12151  Vars.clear();
12152  for (unsigned I = 0; I != NumVars; ++I)
12153  Vars.push_back(Record.readSubExpr());
12154  C->setRHSExprs(Vars);
12155  Vars.clear();
12156  for (unsigned I = 0; I != NumVars; ++I)
12157  Vars.push_back(Record.readSubExpr());
12158  C->setReductionOps(Vars);
12159  Vars.clear();
12160  for (unsigned I = 0; I != NumVars; ++I)
12161  Vars.push_back(Record.readSubExpr());
12162  C->setTaskgroupDescriptors(Vars);
12163 }
12164 
12165 void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) {
12166  VisitOMPClauseWithPostUpdate(C);
12167  C->setLParenLoc(Record.readSourceLocation());
12168  C->setColonLoc(Record.readSourceLocation());
12169  C->setModifier(static_cast<OpenMPLinearClauseKind>(Record.readInt()));
12170  C->setModifierLoc(Record.readSourceLocation());
12171  unsigned NumVars = C->varlist_size();
12173  Vars.reserve(NumVars);
12174  for (unsigned i = 0; i != NumVars; ++i)
12175  Vars.push_back(Record.readSubExpr());
12176  C->setVarRefs(Vars);
12177  Vars.clear();
12178  for (unsigned i = 0; i != NumVars; ++i)
12179  Vars.push_back(Record.readSubExpr());
12180  C->setPrivates(Vars);
12181  Vars.clear();
12182  for (unsigned i = 0; i != NumVars; ++i)
12183  Vars.push_back(Record.readSubExpr());
12184  C->setInits(Vars);
12185  Vars.clear();
12186  for (unsigned i = 0; i != NumVars; ++i)
12187  Vars.push_back(Record.readSubExpr());
12188  C->setUpdates(Vars);
12189  Vars.clear();
12190  for (unsigned i = 0; i != NumVars; ++i)
12191  Vars.push_back(Record.readSubExpr());
12192  C->setFinals(Vars);
12193  C->setStep(Record.readSubExpr());
12194  C->setCalcStep(Record.readSubExpr());
12195 }
12196 
12197 void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) {
12198  C->setLParenLoc(Record.readSourceLocation());
12199  C->setColonLoc(Record.readSourceLocation());
12200  unsigned NumVars = C->varlist_size();
12202  Vars.reserve(NumVars);
12203  for (unsigned i = 0; i != NumVars; ++i)
12204  Vars.push_back(Record.readSubExpr());
12205  C->setVarRefs(Vars);
12206  C->setAlignment(Record.readSubExpr());
12207 }
12208 
12209 void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) {
12210  C->setLParenLoc(Record.readSourceLocation());
12211  unsigned NumVars = C->varlist_size();
12213  Exprs.reserve(NumVars);
12214  for (unsigned i = 0; i != NumVars; ++i)
12215  Exprs.push_back(Record.readSubExpr());
12216  C->setVarRefs(Exprs);
12217  Exprs.clear();
12218  for (unsigned i = 0; i != NumVars; ++i)
12219  Exprs.push_back(Record.readSubExpr());
12220  C->setSourceExprs(Exprs);
12221  Exprs.clear();
12222  for (unsigned i = 0; i != NumVars; ++i)
12223  Exprs.push_back(Record.readSubExpr());
12224  C->setDestinationExprs(Exprs);
12225  Exprs.clear();
12226  for (unsigned i = 0; i != NumVars; ++i)
12227  Exprs.push_back(Record.readSubExpr());
12228  C->setAssignmentOps(Exprs);
12229 }
12230 
12231 void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
12232  C->setLParenLoc(Record.readSourceLocation());
12233  unsigned NumVars = C->varlist_size();
12235  Exprs.reserve(NumVars);
12236  for (unsigned i = 0; i != NumVars; ++i)
12237  Exprs.push_back(Record.readSubExpr());
12238  C->setVarRefs(Exprs);
12239  Exprs.clear();
12240  for (unsigned i = 0; i != NumVars; ++i)
12241  Exprs.push_back(Record.readSubExpr());
12242  C->setSourceExprs(Exprs);
12243  Exprs.clear();
12244  for (unsigned i = 0; i != NumVars; ++i)
12245  Exprs.push_back(Record.readSubExpr());
12246  C->setDestinationExprs(Exprs);
12247  Exprs.clear();
12248  for (unsigned i = 0; i != NumVars; ++i)
12249  Exprs.push_back(Record.readSubExpr());
12250  C->setAssignmentOps(Exprs);
12251 }
12252 
12253 void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) {
12254  C->setLParenLoc(Record.readSourceLocation());
12255  unsigned NumVars = C->varlist_size();
12257  Vars.reserve(NumVars);
12258  for (unsigned i = 0; i != NumVars; ++i)
12259  Vars.push_back(Record.readSubExpr());
12260  C->setVarRefs(Vars);
12261 }
12262 
12263 void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) {
12264  C->setLParenLoc(Record.readSourceLocation());
12265  C->setDependencyKind(
12266  static_cast<OpenMPDependClauseKind>(Record.readInt()));
12267  C->setDependencyLoc(Record.readSourceLocation());
12268  C->setColonLoc(Record.readSourceLocation());
12269  unsigned NumVars = C->varlist_size();
12271  Vars.reserve(NumVars);
12272  for (unsigned I = 0; I != NumVars; ++I)
12273  Vars.push_back(Record.readSubExpr());
12274  C->setVarRefs(Vars);
12275  for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
12276  C->setLoopData(I, Record.readSubExpr());
12277 }
12278 
12279 void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) {
12280  VisitOMPClauseWithPreInit(C);
12281  C->setDevice(Record.readSubExpr());
12282  C->setLParenLoc(Record.readSourceLocation());
12283 }
12284 
12285 void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) {
12286  C->setLParenLoc(Record.readSourceLocation());
12287  for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
12288  C->setMapTypeModifier(
12289  I, static_cast<OpenMPMapModifierKind>(Record.readInt()));
12290  C->setMapTypeModifierLoc(I, Record.readSourceLocation());
12291  }
12292  C->setMapType(
12293  static_cast<OpenMPMapClauseKind>(Record.readInt()));
12294  C->setMapLoc(Record.readSourceLocation());
12295  C->setColonLoc(Record.readSourceLocation());
12296  auto NumVars = C->varlist_size();
12297  auto UniqueDecls = C->getUniqueDeclarationsNum();
12298  auto TotalLists = C->getTotalComponentListNum();
12299  auto TotalComponents = C->getTotalComponentsNum();
12300 
12302  Vars.reserve(NumVars);
12303  for (unsigned i = 0; i != NumVars; ++i)
12304  Vars.push_back(Record.readSubExpr());
12305  C->setVarRefs(Vars);
12306 
12308  Decls.reserve(UniqueDecls);
12309  for (unsigned i = 0; i < UniqueDecls; ++i)
12310  Decls.push_back(Record.readDeclAs<ValueDecl>());
12311  C->setUniqueDecls(Decls);
12312 
12313  SmallVector<unsigned, 16> ListsPerDecl;
12314  ListsPerDecl.reserve(UniqueDecls);
12315  for (unsigned i = 0; i < UniqueDecls; ++i)
12316  ListsPerDecl.push_back(Record.readInt());
12317  C->setDeclNumLists(ListsPerDecl);
12318 
12319  SmallVector<unsigned, 32> ListSizes;
12320  ListSizes.reserve(TotalLists);
12321  for (unsigned i = 0; i < TotalLists; ++i)
12322  ListSizes.push_back(Record.readInt());
12323  C->setComponentListSizes(ListSizes);
12324 
12326  Components.reserve(TotalComponents);
12327  for (unsigned i = 0; i < TotalComponents; ++i) {
12328  Expr *AssociatedExpr = Record.readSubExpr();
12329  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12331  AssociatedExpr, AssociatedDecl));
12332  }
12333  C->setComponents(Components, ListSizes);
12334 }
12335 
12336 void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
12337  VisitOMPClauseWithPreInit(C);
12338  C->setNumTeams(Record.readSubExpr());
12339  C->setLParenLoc(Record.readSourceLocation());
12340 }
12341 
12342 void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
12343  VisitOMPClauseWithPreInit(C);
12344  C->setThreadLimit(Record.readSubExpr());
12345  C->setLParenLoc(Record.readSourceLocation());
12346 }
12347 
12348 void OMPClauseReader::VisitOMPPriorityClause(OMPPriorityClause *C) {
12349  C->setPriority(Record.readSubExpr());
12350  C->setLParenLoc(Record.readSourceLocation());
12351 }
12352 
12353 void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
12354  C->setGrainsize(Record.readSubExpr());
12355  C->setLParenLoc(Record.readSourceLocation());
12356 }
12357 
12358 void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
12359  C->setNumTasks(Record.readSubExpr());
12360  C->setLParenLoc(Record.readSourceLocation());
12361 }
12362 
12363 void OMPClauseReader::VisitOMPHintClause(OMPHintClause *C) {
12364  C->setHint(Record.readSubExpr());
12365  C->setLParenLoc(Record.readSourceLocation());
12366 }
12367 
12368 void OMPClauseReader::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
12369  VisitOMPClauseWithPreInit(C);
12370  C->setDistScheduleKind(
12371  static_cast<OpenMPDistScheduleClauseKind>(Record.readInt()));
12372  C->setChunkSize(Record.readSubExpr());
12373  C->setLParenLoc(Record.readSourceLocation());
12374  C->setDistScheduleKindLoc(Record.readSourceLocation());
12375  C->setCommaLoc(Record.readSourceLocation());
12376 }
12377 
12378 void OMPClauseReader::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
12379  C->setDefaultmapKind(
12380  static_cast<OpenMPDefaultmapClauseKind>(Record.readInt()));
12381  C->setDefaultmapModifier(
12382  static_cast<OpenMPDefaultmapClauseModifier>(Record.readInt()));
12383  C->setLParenLoc(Record.readSourceLocation());
12384  C->setDefaultmapModifierLoc(Record.readSourceLocation());
12385  C->setDefaultmapKindLoc(Record.readSourceLocation());
12386 }
12387 
12388 void OMPClauseReader::VisitOMPToClause(OMPToClause *C) {
12389  C->setLParenLoc(Record.readSourceLocation());
12390  auto NumVars = C->varlist_size();
12391  auto UniqueDecls = C->getUniqueDeclarationsNum();
12392  auto TotalLists = C->getTotalComponentListNum();
12393  auto TotalComponents = C->getTotalComponentsNum();
12394 
12396  Vars.reserve(NumVars);
12397  for (unsigned i = 0; i != NumVars; ++i)
12398  Vars.push_back(Record.readSubExpr());
12399  C->setVarRefs(Vars);
12400 
12402  Decls.reserve(UniqueDecls);
12403  for (unsigned i = 0; i < UniqueDecls; ++i)
12404  Decls.push_back(Record.readDeclAs<ValueDecl>());
12405  C->setUniqueDecls(Decls);
12406 
12407  SmallVector<unsigned, 16> ListsPerDecl;
12408  ListsPerDecl.reserve(UniqueDecls);
12409  for (unsigned i = 0; i < UniqueDecls; ++i)
12410  ListsPerDecl.push_back(Record.readInt());
12411  C->setDeclNumLists(ListsPerDecl);
12412 
12413  SmallVector<unsigned, 32> ListSizes;
12414  ListSizes.reserve(TotalLists);
12415  for (unsigned i = 0; i < TotalLists; ++i)
12416  ListSizes.push_back(Record.readInt());
12417  C->setComponentListSizes(ListSizes);
12418 
12420  Components.reserve(TotalComponents);
12421  for (unsigned i = 0; i < TotalComponents; ++i) {
12422  Expr *AssociatedExpr = Record.readSubExpr();
12423  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12425  AssociatedExpr, AssociatedDecl));
12426  }
12427  C->setComponents(Components, ListSizes);
12428 }
12429 
12430 void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) {
12431  C->setLParenLoc(Record.readSourceLocation());
12432  auto NumVars = C->varlist_size();
12433  auto UniqueDecls = C->getUniqueDeclarationsNum();
12434  auto TotalLists = C->getTotalComponentListNum();
12435  auto TotalComponents = C->getTotalComponentsNum();
12436 
12438  Vars.reserve(NumVars);
12439  for (unsigned i = 0; i != NumVars; ++i)
12440  Vars.push_back(Record.readSubExpr());
12441  C->setVarRefs(Vars);
12442 
12444  Decls.reserve(UniqueDecls);
12445  for (unsigned i = 0; i < UniqueDecls; ++i)
12446  Decls.push_back(Record.readDeclAs<ValueDecl>());
12447  C->setUniqueDecls(Decls);
12448 
12449  SmallVector<unsigned, 16> ListsPerDecl;
12450  ListsPerDecl.reserve(UniqueDecls);
12451  for (unsigned i = 0; i < UniqueDecls; ++i)
12452  ListsPerDecl.push_back(Record.readInt());
12453  C->setDeclNumLists(ListsPerDecl);
12454 
12455  SmallVector<unsigned, 32> ListSizes;
12456  ListSizes.reserve(TotalLists);
12457  for (unsigned i = 0; i < TotalLists; ++i)
12458  ListSizes.push_back(Record.readInt());
12459  C->setComponentListSizes(ListSizes);
12460 
12462  Components.reserve(TotalComponents);
12463  for (unsigned i = 0; i < TotalComponents; ++i) {
12464  Expr *AssociatedExpr = Record.readSubExpr();
12465  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12467  AssociatedExpr, AssociatedDecl));
12468  }
12469  C->setComponents(Components, ListSizes);
12470 }
12471 
12472 void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
12473  C->setLParenLoc(Record.readSourceLocation());
12474  auto NumVars = C->varlist_size();
12475  auto UniqueDecls = C->getUniqueDeclarationsNum();
12476  auto TotalLists = C->getTotalComponentListNum();
12477  auto TotalComponents = C->getTotalComponentsNum();
12478 
12480  Vars.reserve(NumVars);
12481  for (unsigned i = 0; i != NumVars; ++i)
12482  Vars.push_back(Record.readSubExpr());
12483  C->setVarRefs(Vars);
12484  Vars.clear();
12485  for (unsigned i = 0; i != NumVars; ++i)
12486  Vars.push_back(Record.readSubExpr());
12487  C->setPrivateCopies(Vars);
12488  Vars.clear();
12489  for (unsigned i = 0; i != NumVars; ++i)
12490  Vars.push_back(Record.readSubExpr());
12491  C->setInits(Vars);
12492 
12494  Decls.reserve(UniqueDecls);
12495  for (unsigned i = 0; i < UniqueDecls; ++i)
12496  Decls.push_back(Record.readDeclAs<ValueDecl>());
12497  C->setUniqueDecls(Decls);
12498 
12499  SmallVector<unsigned, 16> ListsPerDecl;
12500  ListsPerDecl.reserve(UniqueDecls);
12501  for (unsigned i = 0; i < UniqueDecls; ++i)
12502  ListsPerDecl.push_back(Record.readInt());
12503  C->setDeclNumLists(ListsPerDecl);
12504 
12505  SmallVector<unsigned, 32> ListSizes;
12506  ListSizes.reserve(TotalLists);
12507  for (unsigned i = 0; i < TotalLists; ++i)
12508  ListSizes.push_back(Record.readInt());
12509  C->setComponentListSizes(ListSizes);
12510 
12512  Components.reserve(TotalComponents);
12513  for (unsigned i = 0; i < TotalComponents; ++i) {
12514  Expr *AssociatedExpr = Record.readSubExpr();
12515  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12517  AssociatedExpr, AssociatedDecl));
12518  }
12519  C->setComponents(Components, ListSizes);
12520 }
12521 
12522 void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
12523  C->setLParenLoc(Record.readSourceLocation());
12524  auto NumVars = C->varlist_size();
12525  auto UniqueDecls = C->getUniqueDeclarationsNum();
12526  auto TotalLists = C->getTotalComponentListNum();
12527  auto TotalComponents = C->getTotalComponentsNum();
12528 
12530  Vars.reserve(NumVars);
12531  for (unsigned i = 0; i != NumVars; ++i)
12532  Vars.push_back(Record.readSubExpr());
12533  C->setVarRefs(Vars);
12534  Vars.clear();
12535 
12537  Decls.reserve(UniqueDecls);
12538  for (unsigned i = 0; i < UniqueDecls; ++i)
12539  Decls.push_back(Record.readDeclAs<ValueDecl>());
12540  C->setUniqueDecls(Decls);
12541 
12542  SmallVector<unsigned, 16> ListsPerDecl;
12543  ListsPerDecl.reserve(UniqueDecls);
12544  for (unsigned i = 0; i < UniqueDecls; ++i)
12545  ListsPerDecl.push_back(Record.readInt());
12546  C->setDeclNumLists(ListsPerDecl);
12547 
12548  SmallVector<unsigned, 32> ListSizes;
12549  ListSizes.reserve(TotalLists);
12550  for (unsigned i = 0; i < TotalLists; ++i)
12551  ListSizes.push_back(Record.readInt());
12552  C->setComponentListSizes(ListSizes);
12553 
12555  Components.reserve(TotalComponents);
12556  for (unsigned i = 0; i < TotalComponents; ++i) {
12557  Expr *AssociatedExpr = Record.readSubExpr();
12558  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12560  AssociatedExpr, AssociatedDecl));
12561  }
12562  C->setComponents(Components, ListSizes);
12563 }
llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx)
Read an integral value.
Definition: ASTReader.cpp:9061
Decl * GetExistingDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration.
Definition: ASTReader.cpp:7317
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Module.h:213
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
TypedefDecl * getObjCInstanceTypeDecl()
Retrieve the typedef declaration corresponding to the Objective-C "instancetype" type.
CanQualType SatShortAccumTy
Definition: ASTContext.h:1034
void setSourceOrder(int Pos)
Set the source order of this initializer.
Definition: DeclCXX.h:2439
CanQualType SatUnsignedLongFractTy
Definition: ASTContext.h:1038
Defines the clang::ASTContext interface.
The ObjC &#39;SEL&#39; type.
Definition: ASTBitCodes.h:889
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, StringRef ExistingModuleCachePath)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
Definition: ASTReader.cpp:4933
const FileEntry * OrigEntry
Reference to the file entry representing this ContentCache.
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
Definition: ASTReader.cpp:8109
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Finds all the visible declarations with a given name.
Definition: ASTReader.cpp:7529
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons...
Definition: ASTReader.h:381
Record code for the preprocessor options table.
Definition: ASTBitCodes.h:358
std::vector< unsigned > PreloadIdentifierOffsets
Offsets of identifiers that we&#39;re going to preload within IdentifierTableData.
Definition: Module.h:293
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:309
The &#39;unsigned _Accum&#39; type.
Definition: ASTBitCodes.h:955
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
CanQualType LongLongTy
Definition: ASTContext.h:1025
static const Decl * getCanonicalDecl(const Decl *D)
The client can handle an AST file that cannot load because it was built with a different version of C...
Definition: ASTReader.h:1520
void setInfo(const DeclarationNameLoc &Info)
Represents a function declaration or definition.
Definition: Decl.h:1738
ASTReader(Preprocessor &PP, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef< std::shared_ptr< ModuleFileExtension >> Extensions, StringRef isysroot="", bool DisableValidation=false, bool AllowASTWithCompilerErrors=false, bool AllowConfigurationMismatch=false, bool ValidateSystemInputs=false, bool UseGlobalIndex=true, std::unique_ptr< llvm::Timer > ReadTimer={})
Load the AST file and validate its contents against the given Preprocessor.
ASTFileSignature Signature
The module signature.
Definition: Module.h:106
std::string Name
The name of this module.
Definition: Module.h:68
This represents &#39;thread_limit&#39; clause in the &#39;#pragma omp ...&#39; directive.
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.
unsigned DirInfo
Keep track of whether this is a system header, and if so, whether it is C++ clean or not...
Definition: HeaderSearch.h:62
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:178
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:1684
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:7975
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
void * IdentifierLookupTable
A pointer to an on-disk hash table of opaque type IdentifierHashTable.
Definition: Module.h:289
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
Definition: ASTContext.h:1749
The &#39;unsigned short _Fract&#39; type.
Definition: ASTBitCodes.h:970
CanQualType AccumTy
Definition: ASTContext.h:1029
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
Definition: ASTReader.cpp:192
static OMPCopyinClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
CanQualType OCLQueueTy
Definition: ASTContext.h:1054
Record code for potentially unused local typedef names.
Definition: ASTBitCodes.h:619
Record code for map of Objective-C class definition IDs to the ObjC categories in a module that are a...
Definition: ASTBitCodes.h:577
Smart pointer class that efficiently represents Objective-C method names.
static void updateModuleTimestamp(ModuleFile &MF)
Definition: ASTReader.cpp:3823
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
This represents clause &#39;copyin&#39; in the &#39;#pragma omp ...&#39; directives.
TypedefDecl * getCFConstantStringDecl() const
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
static hash_value_type ComputeHash(Selector Sel)
Definition: ASTReader.cpp:814
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system...
Definition: Module.h:188
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:369
A (possibly-)qualified type.
Definition: Type.h:638
static LLVM_DUMP_METHOD void dumpModuleIDMap(StringRef Name, const ContinuousRangeMap< Key, ModuleFile *, InitialCapacity > &Map)
Definition: ASTReader.cpp:7711
static OMPUseDevicePtrClause * CreateEmpty(const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
Creates an empty clause with the place for NumVars variables.
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
Definition: ASTReader.h:197
static void addMethodsToPool(Sema &S, ArrayRef< ObjCMethodDecl *> Methods, ObjCMethodList &List)
Add the given set of methods to the method list.
Definition: ASTReader.cpp:8065
void * getAsOpaquePtr() const
CtorInitializerType
The different kinds of data that can occur in a CtorInitializer.
Definition: ASTBitCodes.h:1999
The &#39;_Float16&#39; type.
Definition: ASTBitCodes.h:937
unsigned BasePreprocessedSkippedRangeID
Base ID for preprocessed skipped ranges local to this module.
Definition: Module.h:340
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
Definition: MacroInfo.h:249
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1278
NameKind
The kind of the name stored in this DeclarationName.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
The macro directives history for a particular identifier.
Definition: ASTBitCodes.h:698
static bool startsWithASTFileMagic(BitstreamCursor &Stream)
Whether Stream starts with the AST/PCH file magic number &#39;CPCH&#39;.
Definition: ASTReader.cpp:4103
void SetIdentifierInfo(unsigned ID, IdentifierInfo *II)
Definition: ASTReader.cpp:8295
unsigned ImplicitModuleMaps
Implicit module maps.
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:225
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:121
The &#39;unsigned int&#39; type.
Definition: ASTBitCodes.h:823
The (signed) &#39;long long&#39; type.
Definition: ASTBitCodes.h:850
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:34
CanQualType UnsignedLongFractTy
Definition: ASTContext.h:1033
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
Definition: ASTReader.h:208
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
SourceManager & getSourceManager() const
Definition: ASTReader.h:1497
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:403
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes...
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:366
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4512
Defines the clang::FileManager interface and associated types.
time_t getModificationTime() const
Definition: FileManager.h:92
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:7183
Record code for the source manager line table information, which stores information about #line direc...
Definition: ASTBitCodes.h:573
CanQualType FractTy
Definition: ASTContext.h:1032
SourceRange getBraceRange() const
Definition: Decl.h:3145
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:133
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
The &#39;bool&#39; or &#39;_Bool&#39; type.
Definition: ASTBitCodes.h:811
std::string ModuleUserBuildPath
The directory used for a user build.
This represents &#39;atomic_default_mem_order&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:870
CanQualType Char32Ty
Definition: ASTContext.h:1024
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:2272
unsigned isPragmaOnce
True if this is a #pragma once file.
Definition: HeaderSearch.h:56
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1374
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:1029
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
Definition: TypeLoc.h:168
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1370
void setUniqueDecls(ArrayRef< ValueDecl *> UDs)
Set the unique declarations that are in the trailing objects of the class.
Stmt - This represents one statement.
Definition: Stmt.h:66
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1209
This represents clause &#39;in_reduction&#39; in the &#39;#pragma omp task&#39; directives.
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:5647
Expr * getBitWidth() const
Definition: Decl.h:2668
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1568
const FileEntry * getFile() const
Definition: Module.h:95
bool getEnableAllWarnings() const
Definition: Diagnostic.h:602
void AddQualType(QualType T)
Definition: ODRHash.cpp:1040
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1388
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:184
SourceLocation DirectImportLoc
The source location where the module was explicitly or implicitly imported in the local translation u...
Definition: Module.h:202
unsigned IsExternC
Whether this is an &#39;extern "C"&#39; module (which implicitly puts all headers in it within an &#39;extern "C"...
Definition: Module.h:231
Class that handles pre-initialization statement for some clauses, like &#39;shedule&#39;, &#39;firstprivate&#39; etc...
Definition: OpenMPClause.h:99
ControlRecordTypes
Record types that occur within the control block.
Definition: ASTBitCodes.h:301
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2786
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition: Module.h:502
llvm::MemoryBuffer * Buffer
The memory buffer that stores the data associated with this AST file, owned by the PCMCache in the Mo...
Definition: Module.h:179
unsigned Generation
The generation of which this module file is a part.
Definition: Module.h:175
void ReadComments() override
Loads comments ranges.
Definition: ASTReader.cpp:9148
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:357
C Language Family Type Representation.
Defines the SourceManager interface.
The &#39;unknown any&#39; placeholder type.
Definition: ASTBitCodes.h:892
void setWrittenWidthSpec(TypeSpecifierWidth written)
Definition: TypeLoc.h:623
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
Source range of a skipped preprocessor region.
Definition: ASTBitCodes.h:202
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
Definition: ASTContext.h:1773
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
Definition: ASTReader.cpp:170
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
RawCommentList Comments
All comments in this translation unit.
Definition: ASTContext.h:724
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
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:8462
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const
Read a source location from raw form.
Definition: ASTReader.h:2188
static OMPFirstprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1933
QualType getEnumType(const EnumDecl *Decl) const
Defines the clang::Module class, which describes a module in the source code.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:157
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
This represents &#39;grainsize&#39; clause in the &#39;#pragma omp ...&#39; directive.
SmallVector< uint64_t, 4 > PreloadSLocEntries
SLocEntries that we&#39;re going to preload.
Definition: Module.h:258
Module * getCurrentModule()
Retrieves the module that we&#39;re currently building, if any.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
TagDecl * getDecl() const
Definition: Type.cpp:3166
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:410
CanQualType ObjCBuiltinSelTy
Definition: ASTContext.h:1048
RetTy Visit(TypeLoc TyLoc)
static constexpr unsigned NumberOfModifiers
Number of allowed map-type-modifiers.
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:7485
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
void VisitFunctionTypeLoc(FunctionTypeLoc)
Definition: ASTReader.cpp:6575
ModuleKind Kind
The type of this module.
Definition: Module.h:120
virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value)
Receives COUNTER value.
Definition: ASTReader.h:204
This represents &#39;if&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:240
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
Defines the C++ template declaration subclasses.
Describes a source location entry (SLocEntry) for a macro expansion.
Definition: ASTBitCodes.h:676
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
std::vector< std::string > Includes
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags, FileManager &FileMgr, std::string &SuggestedPredefines, const LangOptions &LangOpts, bool Validate=true)
Check the preprocessor options deserialized from the control block against the preprocessor options i...
Definition: ASTReader.cpp:623
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl *> &Decls) override
Read the set of delegating constructors known to the external Sema source.
Definition: ASTReader.cpp:8171
static OMPMapClause * CreateEmpty(const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
Creates an empty clause with the place for NumVars original expressions, NumUniqueDeclarations declar...
An LValueReferenceType record.
Definition: ASTBitCodes.h:1051
The placeholder type for builtin functions.
Definition: ASTBitCodes.h:913
Defines the clang::MacroInfo and clang::MacroDirective classes.
const FileEntry * getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:466
Defines types useful for describing an Objective-C runtime.
Specifies the submodules that are imported by this submodule.
Definition: ASTBitCodes.h:742
QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc, VectorType::VectorKind VecKind) const
Return the unique reference to the type for a dependently sized vector of the specified element type...
std::string ModuleName
The name of the module.
Definition: Module.h:126
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl *> &TentativeDefs) override
Read the set of tentative definitions known to the external Sema source.
Definition: ASTReader.cpp:8150
CanQualType ARCUnbridgedCastTy
Definition: ASTContext.h:1047
A record that stores the set of declarations that are lexically stored within a given DeclContext...
Definition: ASTBitCodes.h:1383
This represents &#39;priority&#39; clause in the &#39;#pragma omp ...&#39; directive.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The module file is out-of-date.
Specifies an umbrella directory.
Definition: ASTBitCodes.h:738
The base class of the type hierarchy.
Definition: Type.h:1407
CanQualType SatUnsignedAccumTy
Definition: ASTContext.h:1035
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
IdentifierInfo * getLocalIdentifier(ModuleFile &M, unsigned LocalID)
Definition: ASTReader.cpp:8387
CanQualType LongTy
Definition: ASTContext.h:1025
DiagnosticsEngine & getDiagnostics() const
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:717
unsigned LocalNumObjCCategoriesInMap
The number of redeclaration info entries in ObjCCategoriesMap.
Definition: Module.h:439
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:1668
#define CHECK_TARGET_OPT(Field, Name)
A SubstTemplateTypeParmType record.
Definition: ASTBitCodes.h:1108
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:7342
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2091
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:64
Represent a C++ namespace.
Definition: Decl.h:515
Wrapper for source info for typedefs.
Definition: TypeLoc.h:664
static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II)
Definition: ASTReader.cpp:927
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
A container of type source information.
Definition: Decl.h:87
This represents &#39;update&#39; clause in the &#39;#pragma omp atomic&#39; directive.
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.
Definition: Module.h:185
void setComponents(ArrayRef< MappableComponent > Components, ArrayRef< unsigned > CLSs)
Set the components that are in the trailing objects of the class.
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:2338
Record code for enabled OpenCL extensions.
Definition: ASTBitCodes.h:556
Record code for the module build directory.
Definition: ASTBitCodes.h:334
Floating point control options.
Definition: LangOptions.h:307
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
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:3732
An ElaboratedType record.
Definition: ASTBitCodes.h:1105
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
Definition: Module.h:384
An UnresolvedUsingType record.
Definition: ASTBitCodes.h:1111
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:584
bool getSuppressSystemWarnings() const
Definition: Diagnostic.h:626
Wrapper for source info for pointers decayed from arrays and functions.
Definition: TypeLoc.h:1163
The &#39;short _Fract&#39; type.
Definition: ASTBitCodes.h:961
ASTFileSignature Signature
The signature of the module file, which may be used instead of the size and modification time to iden...
Definition: Module.h:168
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2324
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2484
An IncompleteArrayType record.
Definition: ASTBitCodes.h:1063
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:529
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
The internal &#39;__type_pack_element&#39; template.
Definition: ASTBitCodes.h:1270
diag::Severity getExtensionHandlingBehavior() const
Definition: Diagnostic.h:688
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:207
void addPendingMacro(IdentifierInfo *II, ModuleFile *M, uint64_t MacroDirectivesOffset)
Add a macro to deserialize its macro directive history.
Definition: ASTReader.cpp:1812
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2000
Specifies a header that is part of the module but must be textually included.
Definition: ASTBitCodes.h:769
const uint32_t * SLocEntryOffsets
Offsets for all of the source location entries in the AST file.
Definition: Module.h:255
size_t param_size() const
Definition: Decl.h:2278
bool RelocatablePCH
Whether this precompiled header is a relocatable PCH file.
Definition: Module.h:155
CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a C++ base specifier.
Definition: ASTReader.cpp:8852
ARC&#39;s unbridged-cast placeholder type.
Definition: ASTBitCodes.h:907
CanQualType HalfTy
Definition: ASTContext.h:1040
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
The client can handle an AST file that cannot load because it is out-of-date relative to its input fi...
Definition: ASTReader.h:1516
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
The &#39;__int128_t&#39; type.
Definition: ASTBitCodes.h:871
static OMPReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
The AST file has errors.
Definition: ASTReader.h:404
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:853
The C++ &#39;char32_t&#39; type.
Definition: ASTBitCodes.h:880
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
An identifier, stored as an IdentifierInfo*.
The internal &#39;__builtin_va_list&#39; typedef.
Definition: ASTBitCodes.h:1249
The stack of open #ifs/#ifdefs recorded in a preamble.
Definition: ASTBitCodes.h:648
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.
Definition: Module.cpp:277
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:49
This represents &#39;read&#39; clause in the &#39;#pragma omp atomic&#39; directive.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
static Qualifiers fromOpaqueValue(unsigned opaque)
Definition: Type.h:247
Represents a variable declaration or definition.
Definition: Decl.h:813
This represents clause &#39;private&#39; in the &#39;#pragma omp ...&#39; directives.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
Record code for #pragma pack options.
Definition: ASTBitCodes.h:645
A block with unhashed content.
Definition: ASTBitCodes.h:297
QualType getReturnType() const
Definition: Decl.h:2302
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Read the contents of a CXXCtorInitializer array.
Definition: ASTReader.cpp:7164
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:382
Wrapper for source info for member pointers.
Definition: TypeLoc.h:1232
void VisitArrayTypeLoc(ArrayTypeLoc)
Definition: ASTReader.cpp:6520
Options for controlling the target.
Definition: TargetOptions.h:27
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:271
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing)...
Definition: DiagnosticIDs.h:80
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
Record code for declarations associated with OpenCL extensions.
Definition: ASTBitCodes.h:640
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:7111
CanQualType Float128Ty
Definition: ASTContext.h:1028
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
Extra information about a function prototype.
Definition: Type.h:3767
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
CanQualType ShortAccumTy
Definition: ASTContext.h:1029
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1997
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Definition: ASTReader.cpp:7763
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
Definition: Module.h:367
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:1277
The value of the next COUNTER to dispense.
Definition: ASTBitCodes.h:481
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
unsigned getLineTableFilenameID(StringRef Str)
Specifies the umbrella header used to create this module, if any.
Definition: ASTBitCodes.h:729
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:604
A namespace, stored as a NamespaceDecl*.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation >> &Sels) override
Definition: ASTReader.cpp:8204
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 ...
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:78
Record code for header search information.
Definition: ASTBitCodes.h:550
data_type ReadData(Selector, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:850
BlockCommandNamesTy BlockCommandNames
Command names to treat as block commands in comments.
void setAttrOperandParensRange(SourceRange range)
Definition: TypeLoc.h:1690
void setProtocolRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:782
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
void setBegin(SourceLocation b)
std::string ModuleCachePath
The directory used for the module cache.
This represents implicit clause &#39;flush&#39; for the &#39;#pragma omp flush&#39; directive.
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName replacement) const
Describes a source location entry (SLocEntry) for a buffer.
Definition: ASTBitCodes.h:662
Used to hold and unique data used to represent #line information.
Record code for the target options table.
Definition: ASTBitCodes.h:349
CanQualType ShortFractTy
Definition: ASTContext.h:1032
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:120
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:152
unsigned getTotalComponentsNum() const
Return the total number of components in all lists derived from the clause.
This represents &#39;reverse_offload&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
Definition: OpenMPClause.h:807
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
Definition: ASTReader.cpp:800
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
Record code for the array of eagerly deserialized decls.
Definition: ASTBitCodes.h:452
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:100
Represents a parameter to a function.
Definition: Decl.h:1550
Defines the clang::Expr interface and subclasses for C++ expressions.
unsigned isImport
True if this is a #import&#39;d or #pragma once file.
Definition: HeaderSearch.h:53
int SLocEntryBaseID
The base ID in the source manager&#39;s view of this module.
Definition: Module.h:248
static OMPTaskReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:462
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
ContinuousRangeMap< uint32_t, int, 2 > DeclRemap
Remapping table for declaration IDs in this module.
Definition: Module.h:419
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1952
This represents &#39;nogroup&#39; clause in the &#39;#pragma omp ...&#39; directive.
The collection of all-type qualifiers we support.
Definition: Type.h:141
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
Definition: TypeLoc.h:958
void clear()
Definition: ODRHash.cpp:193
SourceLocation ImportLoc
The source location where this module was first imported.
Definition: Module.h:205
This represents &#39;safelen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:447
An UnresolvedSet-like class that might not have been loaded from the external AST source yet...
bool needsExtraLocalData() const
Definition: TypeLoc.h:576
ModuleKind Kind
The kind of this module.
Definition: Module.h:87
The client can handle an AST file that cannot load because it is missing.
Definition: ASTReader.h:1512
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
Definition: Decl.cpp:3202
CanQualType OCLSamplerTy
Definition: ASTContext.h:1053
static OMPOrderedClause * CreateEmpty(const ASTContext &C, unsigned NumLoops)
Build an empty clause.
bool DeclIsFromPCHWithObjectFile(const Decl *D) override
Determine whether D comes from a PCH which was built with a corresponding object file.
Definition: ASTReader.cpp:8480
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Defines the clang::SanitizerKind enum.
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage, or used but not defined internal functions.
Definition: ASTReader.cpp:8125
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:57
void setIsGNUVarargs()
Definition: MacroInfo.h:205
StringRef ModuleOffsetMap
The module offset map data for this file.
Definition: Module.h:216
Represents a struct/union/class.
Definition: Decl.h:3593
const unsigned VERSION_MAJOR
AST file major version number supported by this version of Clang.
Definition: ASTBitCodes.h:45
unsigned varlist_size() const
Definition: OpenMPClause.h:204
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
RecordDecl * getCFConstantStringTagDecl() const
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:298
Selector getUnarySelector(IdentifierInfo *ID)
QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, QualType Replacement) const
Retrieve a substitution-result type.
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists...
Definition: Decl.h:3496
TypedefDecl * getObjCIdDecl() const
Retrieve the typedef corresponding to the predefined id type in Objective-C.
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3768
One of these records is kept for each identifier that is lexed.
A macro directive exported by a module.
Definition: ASTBitCodes.h:702
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context...
Definition: DeclBase.h:2318
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:124
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1358
void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS)
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
Definition: ASTReader.cpp:179
void disableFileContentsOverride(const FileEntry *File)
Disable overridding the contents of a file, previously enabled with overrideFileContents.
Specifies a top-level header that falls into this (sub)module.
Definition: ASTBitCodes.h:735
std::string ActualOriginalSourceFileName
The actual original source file name that was used to build this AST file.
Definition: Module.h:142
The block containing comments.
Definition: ASTBitCodes.h:270
This table allows us to fully hide how we implement multi-keyword caching.
AddModuleResult
The result of attempting to add a new module.
bool isConst() const
Definition: DeclCXX.h:2083
The Objective-C &#39;SEL&#39; type.
Definition: ASTBitCodes.h:1231
StringLiteral * getMessage()
Definition: DeclCXX.h:3772
A library or framework to link against when an entity from this module is used.
Definition: Module.h:319
void finalizeForWriting()
Finalizes the AST reader&#39;s state before writing an AST file to disk.
Definition: ASTReader.cpp:4589
Iteration over the preprocessed entities.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
static Module * getTopImportImplicitModule(ModuleManager &ModuleMgr, Preprocessor &PP)
Return the top import module if it is implicit, nullptr otherwise.
Definition: ASTReader.cpp:532
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:736
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
A C++ nested-name-specifier augmented with source location information.
Record the location of a macro definition.
LineState State
This represents &#39;simd&#39; clause in the &#39;#pragma omp ...&#39; directive.
The &#39;char&#39; type, when it is signed.
Definition: ASTBitCodes.h:832
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:1333
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
void setBuiltinLoc(SourceLocation Loc)
Definition: TypeLoc.h:553
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1584
CanQualType UnsignedFractTy
Definition: ASTContext.h:1033
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
The &#39;unsigned long&#39; type.
Definition: ASTBitCodes.h:826
Specifies a header that has been explicitly excluded from this submodule.
Definition: ASTBitCodes.h:753
void setRBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1477
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:198
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
SourceLocation getBegin() const
Definition: ASTBitCodes.h:192
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:288
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
Definition: Decl.h:2579
bool isVolatile() const
Definition: DeclCXX.h:2084
This represents clause &#39;lastprivate&#39; in the &#39;#pragma omp ...&#39; directives.
bool isCPlusPlusOperatorKeyword() const
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
The &#39;_Sat unsigned _Accum&#39; type.
Definition: ASTBitCodes.h:991
Definition: Format.h:2072
void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations)
Set number of iterations for the specified loop.
ContinuousRangeMap< uint32_t, int, 2 > PreprocessedEntityRemap
Remapping table for preprocessed entity IDs in this module.
Definition: Module.h:334
Record code for the module map file that was used to build this AST file.
Definition: ASTBitCodes.h:331
One instance of this struct is kept for every file loaded or used.
Definition: SourceManager.h:95
std::vector< Entry > UserEntries
User specified include entries.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
Definition: DeclBase.h:773
An ExtVectorType record.
Definition: ASTBitCodes.h:1072
Delete expressions that will be analyzed later.
Definition: ASTBitCodes.h:624
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.
CanQualType LongAccumTy
Definition: ASTContext.h:1029
method_range methods() const
Definition: DeclObjC.h:1037
Helper class that saves the current stream position and then restores it when destroyed.
Definition: ASTReader.h:2664
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:483
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
CanQualType OCLEventTy
Definition: ASTContext.h:1053
This represents clause &#39;map&#39; in the &#39;#pragma omp ...&#39; directives.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:139
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2002
TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template name.
Definition: ASTReader.cpp:8696
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:406
The &#39;unsigned long _Fract&#39; type.
Definition: ASTBitCodes.h:976
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
Definition: ASTReader.h:145
This represents clause &#39;to&#39; in the &#39;#pragma omp ...&#39; directives.
void setColonLoc(SourceLocation Loc)
Sets the location of &#39;:&#39;.
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:73
static std::pair< GlobalModuleIndex *, ErrorCode > readIndex(llvm::StringRef Path)
Read a global index file for the given directory.
The &#39;long _Fract&#39; type.
Definition: ASTBitCodes.h:967
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten)
Sets the umbrella directory of the given module to the given directory.
Definition: ModuleMap.cpp:1098
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:184
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:686
std::string OriginalDir
The directory that the PCH was originally created in.
Definition: Module.h:150
void setKind(tok::TokenKind K)
Definition: Token.h:91
An AttributedType record.
Definition: ASTBitCodes.h:1141
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:141
llvm::OnDiskChainedHashTable< HeaderFileInfoTrait > HeaderFileInfoLookupTable
The on-disk hash table used for known header files.
An object-like macro definition.
Definition: ASTBitCodes.h:686
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C)
void setUnderlyingTInfo(TypeSourceInfo *TInfo)
Definition: TypeLoc.h:1885
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1525
CanQualType OCLReserveIDTy
Definition: ASTContext.h:1054
The signature of a module, which is a hash of the AST content.
Definition: Module.h:55
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:815
Describes one token.
Definition: ASTBitCodes.h:695
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:828
An AdjustedType record.
Definition: ASTBitCodes.h:1159
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Describes a module or submodule.
Definition: Module.h:65
The &#39;short _Accum&#39; type.
Definition: ASTBitCodes.h:943
ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, unsigned ClientLoadCapabilities, SmallVectorImpl< ImportedSubmodule > *Imported=nullptr)
Load the AST file designated by the given file name.
Definition: ASTReader.cpp:3865
void completeVisibleDeclsMap(const DeclContext *DC) override
Load all external visible decls in the given DeclContext.
Definition: ASTReader.cpp:7555
unsigned LocalNumHeaderFileInfos
The number of local HeaderFileInfo structures.
Definition: Module.h:348
virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const =0
Returns the serialized AST inside the PCH container Buffer.
Record code for the set of ext_vector type names.
Definition: ASTBitCodes.h:496
The &#39;long _Accum&#39; type.
Definition: ASTBitCodes.h:949
CanQualType LongFractTy
Definition: ASTContext.h:1032
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
Definition: ASTReader.cpp:9097
llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Return a descriptor for the corresponding module.
Definition: ASTReader.cpp:8516
unsigned External
Whether this header file info was supplied by an external source, and has not changed since...
Definition: HeaderSearch.h:66
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:581
This represents clause &#39;copyprivate&#39; in the &#39;#pragma omp ...&#39; directives.
void setLoopCounter(unsigned NumLoop, Expr *Counter)
Set loop counter for the specified loop.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:461
bool isInvalid() const
const PPEntityOffset * PreprocessedEntityOffsets
Definition: Module.h:336
Specifies the submodules that are re-exported from this submodule.
Definition: ASTBitCodes.h:746
void setProtocolLoc(unsigned i, SourceLocation Loc)
Definition: TypeLoc.h:795
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition: Decl.h:676
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.
Definition: Module.h:312
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2657
Selector getNullarySelector(IdentifierInfo *ID)
The Objective-C &#39;id&#39; type.
Definition: ASTBitCodes.h:1228
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2228
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
Definition: Module.h:248
void setAttr(const Attr *A)
Definition: TypeLoc.h:874
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:521
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:199
virtual void HandleInterestingDecl(DeclGroupRef D)
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: ASTConsumer.cpp:23
PreprocessedEntity * ReadPreprocessedEntity(unsigned Index) override
Read a preallocated preprocessed entity from the external source.
Definition: ASTReader.cpp:5441
void setCaretLoc(SourceLocation Loc)
Definition: TypeLoc.h:1222
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2115
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:675
bool PCHHasObjectFile
Whether the PCH has a corresponding object file.
Definition: Module.h:161
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:6761
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:821
static void hash_combine(std::size_t &seed, const T &v)
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
static OMPIsDevicePtrClause * CreateEmpty(const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
Creates an empty clause with the place for NumVars variables.
unsigned getNumProtocols() const
Definition: TypeLoc.h:786
const unsigned NumSpecialTypeIDs
The number of special type IDs.
Definition: ASTBitCodes.h:1212
A convenient class for passing around template argument information.
Definition: TemplateBase.h:555
void setcudaConfigureCallDecl(FunctionDecl *FD)
Definition: ASTContext.h:1275
CanQualType SatShortFractTy
Definition: ASTContext.h:1037
Describes a blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:668
const FormatToken & Tok
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:346
The &#39;unsigned short _Accum&#39; type.
Definition: ASTBitCodes.h:952
TypedefDecl * getObjCSelDecl() const
Retrieve the typedef corresponding to the predefined &#39;SEL&#39; type in Objective-C.
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:509
void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8682
CanQualType SatUnsignedShortAccumTy
Definition: ASTContext.h:1035
static OMPInReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::string Message
The message provided to the user when there is a conflict.
Definition: Module.h:365
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:7210
Wrapper for source info for functions.
Definition: TypeLoc.h:1327
Specifies a conflict with another module.
Definition: ASTBitCodes.h:762
The signed 128-bit integer type.
Definition: ASTBitCodes.h:1240
unsigned getHash() const
Compute a fingerprint of this key for use in on-disk hash table.
Definition: ASTReader.cpp:1052
CXXCtorInitializer ** ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a CXXCtorInitializer array.
Definition: ASTReader.cpp:8868
llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx)
Read a signed integral value.
Definition: ASTReader.cpp:9070
A UnaryTransformType record.
Definition: ASTBitCodes.h:1150
bool isFileOverridden(const FileEntry *File) const
Returns true if the file contents have been overridden.
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:7409
An ObjCObjectType record.
Definition: ASTBitCodes.h:1117
A ConstantArrayType record.
Definition: ASTBitCodes.h:1060
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9090
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
Definition: ASTReader.cpp:745
llvm::iterator_range< ModuleDeclIterator > getModuleFileLevelDecls(ModuleFile &Mod)
Definition: ASTReader.cpp:5420
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:838
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:9230
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID)
Retrieve the global submodule ID given a module and its local ID number.
Definition: ASTReader.cpp:8447
Record code for #pragma optimize options.
Definition: ASTBitCodes.h:616
uint32_t BitOffset
Offset in the AST file.
Definition: ASTBitCodes.h:186
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9109
unsigned short NumIncludes
The number of times the file has been included already.
Definition: HeaderSearch.h:91
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Definition: Sema.h:1160
StringRef Data
The serialized bitstream data for this file.
Definition: Module.h:188
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:773
Record code for pending implicit instantiations.
Definition: ASTBitCodes.h:526
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:831
ExtKind hasExternalDefinitions(const Decl *D) override
Definition: ASTReader.cpp:8533
CanQualType PseudoObjectTy
Definition: ASTContext.h:1047
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:647
The internal &#39;__make_integer_seq&#39; template.
Definition: ASTBitCodes.h:1261
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1796
void setLazyBody(uint64_t Offset)
Definition: DeclObjC.h:509
static OMPToClause * CreateEmpty(const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
Creates an empty clause with the place for NumVars variables.
TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument.
Definition: ASTReader.cpp:8755
const TemplateArgument & getArg(unsigned Idx) const
Definition: TemplateBase.h:701
bool isNull() const
Definition: TypeLoc.h:119
Record code for floating point #pragma options.
Definition: ASTBitCodes.h:553
CommentRecordTypes
Record types used within a comments block.
Definition: ASTBitCodes.h:785
Class that handles post-update expression for some clauses, like &#39;lastprivate&#39;, &#39;reduction&#39; etc...
Definition: OpenMPClause.h:135
Defines the Diagnostic-related interfaces.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1382
static internal_key_type ReadKey(const unsigned char *d, unsigned n)
Definition: ASTReader.cpp:898
CanQualType LongDoubleTy
Definition: ASTContext.h:1028
This represents &#39;default&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:606
void setMustBuildLookupTable()
Mark that there are external lexical declarations that we need to include in our lookup table (and th...
Definition: DeclBase.h:2297
void addExternalSource(ExternalSemaSource *E)
Registers an external source.
Definition: Sema.cpp:408
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition: Module.h:216
std::string OriginalSourceFileName
The original source file name that was used to build the primary AST file, which may have been modifi...
Definition: Module.h:138
Wrapper for source info for ObjC interfaces.
Definition: TypeLoc.h:1049
Record code for the set of known namespaces, which are used for typo correction.
Definition: ASTBitCodes.h:563
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6072
static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps)
Definition: ASTReader.cpp:2242
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
Definition: ASTReader.cpp:7579
bool hasRevertedBuiltin() const
True if setNotBuiltin() was called.
Record code for an array of all of the (sub)modules that were imported by the AST file...
Definition: ASTBitCodes.h:584
This represents &#39;final&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:330
This represents &#39;mergeable&#39; clause in the &#39;#pragma omp ...&#39; directive.
The &#39;unsigned short&#39; type.
Definition: ASTBitCodes.h:820
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
Definition: Module.h:416
Present this diagnostic as an error.
const Expr * getInitExpr() const
Definition: Decl.h:2805
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
This represents clause &#39;reduction&#39; in the &#39;#pragma omp ...&#39; directives.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
SourceLocation FirstLoc
The first source location in this module.
Definition: Module.h:208
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:821
A BlockPointerType record.
Definition: ASTBitCodes.h:1048
void setProtocolLoc(unsigned i, SourceLocation Loc)
Definition: TypeLoc.h:988
A MemberPointerType record.
Definition: ASTBitCodes.h:1057
ContinuousRangeMap< uint32_t, int, 2 > SLocRemap
Remapping table for source locations in this module.
Definition: Module.h:261
The &#39;_Sat short _Fract&#39; type.
Definition: ASTBitCodes.h:997
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
The &#39;unsigned long _Accum&#39; type.
Definition: ASTBitCodes.h:958
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo >> &WI) override
Definition: ASTReader.cpp:8222
This represents clause &#39;is_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1350
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag)
Definition: ASTReader.cpp:5706
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
void revertBuiltin()
Revert the identifier to a non-builtin identifier.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.h:3779
The AST file itself appears corrupted.
Definition: ASTReader.h:387
unsigned getUniqueDeclarationsNum() const
Return the number of unique base declarations in this clause.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
void dump()
Dump information about the AST reader to standard error.
Definition: ASTReader.cpp:7727
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3753
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 >> &Exprs) override
Definition: ASTReader.cpp:8135
static ASTFileSignature readASTFileSignature(StringRef PCH)
Reads and return the signature record from PCH&#39;s control block, or else returns 0.
Definition: ASTReader.cpp:4595
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:51
A DependentSizedExtVectorType record.
Definition: ASTBitCodes.h:1171
The type of &#39;nullptr&#39;.
Definition: ASTBitCodes.h:874
uint64_t PreprocessorDetailStartOffset
The offset of the start of the preprocessor detail cursor.
Definition: Module.h:327
The &#39;_Sat unsigned long _Fract&#39; type.
Definition: ASTBitCodes.h:1012
CanQualType UnsignedCharTy
Definition: ASTContext.h:1026
Record code for the table of offsets into the block of source-location information.
Definition: ASTBitCodes.h:485
void setAttrNameLoc(SourceLocation loc)
Definition: TypeLoc.h:1669
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:870
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:1873
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.h:213
A SubstTemplateTypeParmPackType record.
Definition: ASTBitCodes.h:1144
This represents clause &#39;from&#39; in the &#39;#pragma omp ...&#39; directives.
static std::string ReadString(const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9083
TypeCode
Record codes for each kind of type.
Definition: ASTBitCodes.h:1037
Records the location of a macro expansion.
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:174
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:233
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1595
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void getExportedModules(SmallVectorImpl< Module *> &Exported) const
Appends this module&#39;s list of exported modules to Exported.
Definition: Module.cpp:325
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
Definition: Module.h:226
The block containing information about the source manager.
Definition: ASTBitCodes.h:253
NodeId Parent
Definition: ASTDiff.cpp:192
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
The placeholder type for OpenMP array section.
Definition: ASTBitCodes.h:931
A VariableArrayType record.
Definition: ASTBitCodes.h:1066
This represents &#39;dynamic_allocators&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:838
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
void setLazyBody(uint64_t Offset)
Definition: Decl.h:1994
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
const unsigned int NUM_PREDEF_PP_ENTITY_IDS
The number of predefined preprocessed entity IDs.
Definition: ASTBitCodes.h:242
StringRef getString() const
Definition: Expr.h:1649
void setUsedForHeaderGuard(bool Val)
Definition: MacroInfo.h:274
ASTRecordTypes
Record types that occur within the AST block itself.
Definition: ASTBitCodes.h:390
HashTableTy::const_iterator iterator
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1043
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:4380
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement into a statement.
Definition: ASTReader.cpp:7396
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition: Decl.h:669
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
Defines the major attributes of a submodule, including its name and parent.
Definition: ASTBitCodes.h:725
llvm::BitstreamCursor Stream
The main bitstream cursor for the main block.
Definition: Module.h:191
This represents &#39;threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:227
The &#39;__uint128_t&#39; type.
Definition: ASTBitCodes.h:868
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...
Definition: Module.h:428
QualType getDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttrLoc) const
virtual bool needsImportVisitation() const
Returns true if this ASTReaderListener wants to receive the imports of the AST file via visitImport...
Definition: ASTReader.h:232
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:689
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:124
This represents clause &#39;aligned&#39; in the &#39;#pragma omp ...&#39; directives.
ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, unsigned PriorGeneration)
Definition: ASTReader.cpp:8003
ModuleKind
Specifies the kind of module that has been loaded.
Definition: Module.h:43
StringRef Filename
Definition: Format.cpp:1629
A table of skipped ranges within the preprocessing record.
Definition: ASTBitCodes.h:651
static OMPAlignedClause * CreateEmpty(const ASTContext &C, unsigned NumVars)
Creates an empty clause with the place for NumVars variables.
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:203
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:569
TypedefDecl * getBuiltinMSVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_ms_va_list type...
void setLocEnd(SourceLocation Loc)
Sets the ending location of the clause.
Definition: OpenMPClause.h:76
bool isValid() const
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2818
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
void ReadModuleMapFile(StringRef ModuleMapPath) override
Definition: ASTReader.cpp:155
This represents clause &#39;task_reduction&#39; in the &#39;#pragma omp taskgroup&#39; directives.
void setSizeExpr(Expr *Size)
Definition: TypeLoc.h:1489
unsigned LocalNumSLocEntries
The number of source location entries in this AST file.
Definition: Module.h:245
QualType getAutoRRefDeductType() const
C++11 deduction pattern for &#39;auto &&&#39; type.
void setCFConstantStringType(QualType T)
Captures information about a #pragma weak directive.
Definition: Weak.h:25
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2123
void visitInputFiles(serialization::ModuleFile &MF, bool IncludeSystem, bool Complain, llvm::function_ref< void(const serialization::InputFile &IF, bool isSystem)> Visitor)
Visit all the input files of the given module file.
Definition: ASTReader.cpp:9202
ArrayRef< ObjCMethodDecl * > getInstanceMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:8042
Record code for the table of offsets of each macro ID.
Definition: ASTBitCodes.h:601
const DirectoryEntry * Entry
Definition: Module.h:162
CanQualType UnsignedAccumTy
Definition: ASTContext.h:1031
const uint32_t * TypeOffsets
Offset of each type within the bitstream, indexed by the type ID, or the representation of a Type*...
Definition: Module.h:452
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo)
Definition: ASTReader.cpp:1959
unsigned getNumLoops() const
Get number of loops associated with the clause.
unsigned Offset
Definition: Format.cpp:1631
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2099
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
CanQualType UnsignedShortFractTy
Definition: ASTContext.h:1033
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1497
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
Definition: ASTReader.cpp:9116
ASTReaderListener implementation to validate the information of the PCH file against an initialized P...
Definition: ASTReader.h:289
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:190
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:236
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
Specifies some declarations with initializers that must be emitted to initialize the module...
Definition: ASTBitCodes.h:777
An TemplateSpecializationType record.
Definition: ASTBitCodes.h:1123
An ObjCObjectPointerType record.
Definition: ASTBitCodes.h:1099
File is from a prebuilt module path.
Definition: Module.h:60
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:7027
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2342
Type source information for an attributed type.
Definition: TypeLoc.h:849
An ObjCInterfaceType record.
Definition: ASTBitCodes.h:1096
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.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2071
HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override
Read the header file information for the given file entry.
Definition: ASTReader.cpp:5697
This represents &#39;proc_bind&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:675
This represents &#39;capture&#39; clause in the &#39;#pragma omp atomic&#39; directive.
Describes a zlib-compressed blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:672
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
This represents one expression.
Definition: Expr.h:106
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Definition: ASTReader.cpp:8498
Defines the clang::LangOptions interface.
SourceLocation getEnd() const
Definition: ASTBitCodes.h:196
SourceLocation End
Record code for the array of VTable uses.
Definition: ASTBitCodes.h:506
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
The &#39;char&#39; type, when it is unsigned.
Definition: ASTBitCodes.h:814
void setHasCommaPasting()
Definition: MacroInfo.h:219
static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, bool IsModule)
Whether the given identifier is "interesting".
Definition: ASTReader.cpp:904
static InputFile getNotFound()
Definition: Module.h:89
void setModeAttr(bool written)
Definition: TypeLoc.h:646
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
Definition: ASTReader.cpp:9139
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:8432
The directory that the PCH was originally created in.
Definition: ASTBitCodes.h:316
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3523
int Id
Definition: ASTDiff.cpp:191
This represents &#39;simdlen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:501
The &#39;_Sat long _Fract&#39; type.
Definition: ASTBitCodes.h:1003
QualType getCanonicalTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args) const
Declaration of a template type parameter.
bool wasUpgradedFromWarning() const
Whether this mapping attempted to map the diagnostic to a warning, but was overruled because the diag...
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.
Definition: Module.h:266
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
Definition: ASTReader.cpp:8242
The placeholder type for overloaded function sets.
Definition: ASTBitCodes.h:862
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:247
Defines the clang::CommentOptions interface.
Implements an efficient mapping from strings to IdentifierInfo nodes.
Defines implementation details of the clang::SourceManager class.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5050
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
Definition: ASTReader.h:239
Inits[]
Definition: OpenMPClause.h:151
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:255
QualType getTypeOfExprType(Expr *e) const
GCC extension.
Record code for the table of offsets to entries in the preprocessing record.
Definition: ASTBitCodes.h:503
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2706
ContinuousRangeMap< uint32_t, int, 2 > IdentifierRemap
Remapping table for identifier IDs in this module.
Definition: Module.h:279
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
QualType getParenType(QualType NamedType) const
CanQualType OMPArraySectionTy
Definition: ASTContext.h:1055
llvm::BitstreamCursor SLocEntryCursor
Cursor used to read source location entries.
Definition: Module.h:242
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
Defines version macros and version-related utility functions for Clang.
The OpenCL &#39;half&#39; / ARM NEON __fp16 type.
Definition: ASTBitCodes.h:904
const FileEntry * ContentsEntry
References the file which the contents were actually loaded from.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:547
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:722
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3475
static OMPDependClause * CreateEmpty(const ASTContext &C, unsigned N, unsigned NumLoops)
Creates an empty clause with N variables.
Defines an enumeration for C++ overloaded operators.
Defines the clang::Preprocessor interface.
ArgKind
The kind of template argument we&#39;re storing.
Definition: TemplateBase.h:54
The block containing the detailed preprocessing record.
Definition: ASTBitCodes.h:264
ASTReaderListenter implementation to set SuggestedPredefines of ASTReader which is required to use a ...
Definition: ASTReader.h:318
Record code for #pragma diagnostic mappings.
Definition: ASTBitCodes.h:370
#define bool
Definition: stdbool.h:31
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
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:1507
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:220
DeclContext * getDeclContext()
Definition: DeclBase.h:427
static LineEntry get(unsigned Offs, unsigned Line, int Filename, SrcMgr::CharacteristicKind FileKind, unsigned IncludeOffset)
void setWrittenSignSpec(TypeSpecifierSign written)
Definition: TypeLoc.h:607
llvm::BitstreamCursor InputFilesCursor
The cursor to the start of the input-files block.
Definition: Module.h:221
unsigned LocalNumMacros
The number of macros in this AST file.
Definition: Module.h:302
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a source range.
Definition: ASTReader.cpp:9053
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1500
CanQualType ShortTy
Definition: ASTContext.h:1025
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
Record code for the original file that was used to generate the AST file, including both its file ID ...
Definition: ASTBitCodes.h:313
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2331
TypedefDecl * getInt128Decl() const
Retrieve the declaration for the 128-bit signed integer type.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2236
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:179
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
Definition: Module.h:336
void clear(SanitizerMask K=SanitizerKind::All)
Disable the sanitizers specified in K.
Definition: Sanitizers.h:67
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:359
QualType getLocalType(ModuleFile &F, unsigned LocalID)
Resolve a local type ID within a given AST file into a type.
Definition: ASTReader.cpp:7022
Information about a module that has been loaded by the ASTReader.
Definition: Module.h:108
void setDeclNumLists(ArrayRef< unsigned > DNLs)
Set the number of lists per declaration that are in the trailing objects of the class.
Defines the clang::TypeLoc interface and its subclasses.
A namespace alias, stored as a NamespaceAliasDecl*.
int Depth
Definition: ASTDiff.cpp:191
This represents &#39;ordered&#39; clause in the &#39;#pragma omp ...&#39; directive.
The &#39;long double&#39; type.
Definition: ASTBitCodes.h:859
static OMPFlushClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
Record code for the diagnostic options table.
Definition: ASTBitCodes.h:367
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn&#39;t...
uint32_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:61
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
Definition: ASTReader.cpp:209
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1027
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.
Definition: Module.h:443
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1062
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1788
FileID OriginalSourceFileID
The file ID for the original source file that was used to build this AST file.
Definition: Module.h:146
A FunctionProtoType record.
Definition: ASTBitCodes.h:1078
void setInheritConstructors(bool Inherit=true)
Set that this base class&#39;s constructors should be inherited.
Definition: DeclCXX.h:258
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isInvalid() const
bool HasTimestamps
Whether timestamps are included in this module file.
Definition: Module.h:158
Describes a source location entry (SLocEntry) for a file.
Definition: ASTBitCodes.h:658
Wrapper for source info for enum types.
Definition: TypeLoc.h:724
A block containing a module file extension.
Definition: ASTBitCodes.h:291
bool isIdentifier() const
Predicate functions for querying what type of name this is.
static OMPLinearClause * CreateEmpty(const ASTContext &C, unsigned NumVars)
Creates an empty clause with the place for NumVars variables.
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:207
std::string FileName
The file name of the module file.
Definition: Module.h:123
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...
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten)
Sets the umbrella header of the given module to the given header.
Definition: ModuleMap.cpp:1086
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2180
Record code for an update to a decl context&#39;s lookup table.
Definition: ASTBitCodes.h:533
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition: TypeLoc.h:746
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition: TypeLoc.h:1007
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:439
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:627
InclusionKind
The kind of inclusion directives known to the preprocessor.
QualType getRecordType(const RecordDecl *Decl) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
SourceLocation getEnd() const
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
bool isInstanceMethod() const
Definition: DeclObjC.h:422
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1380
struct CXXOpName CXXOperatorName
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:919
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation >> &Pending) override
Definition: ASTReader.cpp:8254
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
TypedefDecl * getBuiltinVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_va_list type...
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.
CanQualType SatLongAccumTy
Definition: ASTContext.h:1034
void insertOrReplace(const value_type &Val)
void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method)
Add the given method to the list of globally-known methods.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Definition: Module.h:379
static OMPPrivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
This represents &#39;collapse&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:555
This represents clause &#39;firstprivate&#39; in the &#39;#pragma omp ...&#39; directives.
void StartedDeserializing() override
Notify ASTReader that we started deserialization of a decl or type so until FinishedDeserializing is ...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3817
Selector getSelector() const
Definition: DeclObjC.h:321
Information about a header directive as found in the module map file.
Definition: Module.h:151
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:1396
The result type of a method or function.
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1876
unsigned SLocEntryBaseOffset
The base offset in the source manager&#39;s view of this module.
Definition: Module.h:251
Record code for the table of offsets of each identifier ID.
Definition: ASTBitCodes.h:423
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2011
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap&#39;ed memor...
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:703
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
Record code for undefined but used functions and variables that need a definition in this TU...
Definition: ASTBitCodes.h:610
void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8672
A DependentNameType record.
Definition: ASTBitCodes.h:1126
const SourceManager & SM
Definition: Format.cpp:1490
unsigned MajorVersion
The major version of the extension data.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:236
CanQualType SignedCharTy
Definition: ASTContext.h:1025
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Record code for the identifier table.
Definition: ASTBitCodes.h:442
The &#39;_Sat unsigned long _Accum&#39; type.
Definition: ASTBitCodes.h:994
The AST file was missing.
Definition: ASTReader.h:390
uint64_t BuildSessionTimestamp
The time in seconds when the build session started.
unsigned MinorVersion
The minor version of the extension data.
This represents &#39;seq_cst&#39; clause in the &#39;#pragma omp atomic&#39; directive.
NestedNameSpecifier * ReadNestedNameSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8934
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...
This represents &#39;untied&#39; clause in the &#39;#pragma omp ...&#39; directive.
The placeholder type for bound member functions.
Definition: ASTBitCodes.h:895
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
Attr * ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Reads one attribute from the current stream position.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Definition: MacroInfo.h:153
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType)
void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef)
Note that MergedDef is a redefinition of the canonical definition Def, so Def should be visible whene...
Definition: ASTReader.cpp:3781
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:37
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID)
Reads a record with id AbbrevID from Cursor, resetting the internal state.
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1240
std::vector< std::unique_ptr< ModuleFileExtensionReader > > ExtensionReaders
The list of extension readers that are attached to this module file.
Definition: Module.h:212
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:138
void setTypeofLoc(SourceLocation Loc)
Definition: TypeLoc.h:1780
SanitizerMask getPPTransparentSanitizers()
Return the sanitizers which do not affect preprocessing.
Definition: Sanitizers.h:85
The Objective-C &#39;Class&#39; type.
Definition: ASTBitCodes.h:1234
This represents &#39;unified_address&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
Definition: OpenMPClause.h:745
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:790
void setPostUpdateExpr(Expr *S)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:147
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:172
void makeNamesVisible(const HiddenNames &Names, Module *Owner)
Make the names within this set of hidden names visible.
Definition: ASTReader.cpp:3718
The &#39;_Sat short _Accum&#39; type.
Definition: ASTBitCodes.h:979
StringRef Next() override
Retrieve the next string in the identifier table and advances the iterator for the following string...
Definition: ASTReader.cpp:7922
The &#39;unsigned long long&#39; type.
Definition: ASTBitCodes.h:829
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:212
Wrapper for source info for arrays.
Definition: TypeLoc.h:1460
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
Record code for the set of source location entries that need to be preloaded by the AST reader...
Definition: ASTBitCodes.h:493
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:662
CanQualType OverloadTy
Definition: ASTContext.h:1045
This represents &#39;num_teams&#39; clause in the &#39;#pragma omp ...&#39; directive.
The control block was read successfully.
Definition: ASTReader.h:384
The list of delegating constructor declarations.
Definition: ASTBitCodes.h:559
Information about a FileID, basically just the logical file that it represents and include stack info...
Compare comments&#39; source locations.
The C++ &#39;char8_t&#39; type.
Definition: ASTBitCodes.h:940
Record code for types associated with OpenCL extensions.
Definition: ASTBitCodes.h:637
static bool readBit(unsigned &Bits)
Definition: ASTReader.cpp:914
void setIsFunctionLike()
Function/Object-likeness.
Definition: MacroInfo.h:199
unsigned isModuleHeader
Whether this header is part of a module.
Definition: HeaderSearch.h:69
const unsigned char * SelectorLookupTableData
A pointer to the character data that comprises the selector table.
Definition: Module.h:392
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Definition: MacroInfo.h:291
bool ReadFullVersionInformation(StringRef FullVersion) override
Receives the full Clang version information.
Definition: ASTReader.cpp:145
#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.
Definition: Module.h:456
CanQualType BuiltinFnTy
Definition: ASTContext.h:1046
ContinuousRangeMap< uint32_t, int, 2 > SelectorRemap
Remapping table for selector IDs in this module.
Definition: Module.h:387
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply...
Kind
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:43
void setASTFile(const FileEntry *File)
Set the serialized AST file for the top-level module of this module.
Definition: Module.h:471
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3743
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
void LoadSelector(Selector Sel)
Load a selector from disk, registering its ID if it exists.
Definition: ASTReader.cpp:8290
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2107
serialization::IdentID BaseIdentifierID
Base identifier ID for identifiers local to this module.
Definition: Module.h:276
MacroInfo * ReadMacroRecord(ModuleFile &F, uint64_t Offset)
Reads the macro record located at the given offset.
Definition: ASTReader.cpp:1574
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:8114
File is a PCH file treated as the preamble.
Definition: Module.h:54
std::string getTimestampFilename() const
Definition: Module.h:131
unsigned getTotalComponentListNum() const
Return the number of lists derived from the clause expressions.
static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method)
Move the given method to the back of the global list of methods.
Definition: ASTReader.cpp:3690
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3774
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into &#39;__super&#39; nested-name-specifier.
The &#39;_Sat unsigned _Fract&#39; type.
Definition: ASTBitCodes.h:1009
bool isParameterPack() const
Returns whether this is a parameter pack.
Encodes a location in the source.
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
TypedefDecl * getUInt128Decl() const
Retrieve the declaration for the 128-bit unsigned integer type.
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2009
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:774
This represents &#39;hint&#39; clause in the &#39;#pragma omp ...&#39; directive.
StringRef getName() const
Definition: FileManager.h:85
CanQualType UnsignedLongAccumTy
Definition: ASTContext.h:1031
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1392
File is a PCH file treated as such.
Definition: Module.h:51
CanQualType Int128Ty
Definition: ASTContext.h:1025
IdentifierInfo * get(StringRef Name) override
Retrieve the IdentifierInfo for the named identifier.
Definition: ASTReader.cpp:7850
void setLength(unsigned Len)
Definition: Token.h:133
Specifies a library or framework to link against.
Definition: ASTBitCodes.h:756
Record code for file ID of the file or buffer that was used to generate the AST file.
Definition: ASTBitCodes.h:320
Represents a C++ temporary.
Definition: ExprCXX.h:1185
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5738
void InitializeContext()
Initializes the ASTContext.
Definition: ASTReader.cpp:4450
Specifies a header that falls into this (sub)module.
Definition: ASTBitCodes.h:732
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed, for use in "private" modules.
Definition: Module.h:113
ContinuousRangeMap< uint32_t, int, 2 > SubmoduleRemap
Remapping table for submodule IDs in this module.
Definition: Module.h:370
void setUsed(bool Used=true)
Definition: Weak.h:36
typename Representation::const_iterator const_iterator
Record code for special CUDA declarations.
Definition: ASTBitCodes.h:547
Options for controlling the compiler diagnostics engine.
A list of "interesting" identifiers.
Definition: ASTBitCodes.h:606
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition: Module.h:275
An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files...
Definition: ASTReader.cpp:7889
void setProtocolLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:772
The block of configuration options, used to check that a module is being used in a configuration comp...
Definition: ASTBitCodes.h:288
CanQualType SatFractTy
Definition: ASTContext.h:1037
DeclarationName getName() const
getName - Returns the embedded declaration name.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3064
This represents &#39;schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:948
PredefinedTypeIDs
Predefined type IDs.
Definition: ASTBitCodes.h:803
All of the names in this module are hidden.
Definition: Module.h:269
File is an implicitly-loaded module.
Definition: Module.h:45
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:420
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
This represents clause &#39;shared&#39; in the &#39;#pragma omp ...&#39; directives.
void setProtocolRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:975
The &#39;unsigned char&#39; type.
Definition: ASTBitCodes.h:817
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2721
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
Definition: Module.h:477
ObjCInterfaceDecl * getObjCProtocolDecl() const
Retrieve the Objective-C class declaration corresponding to the predefined Protocol class...
Metadata describing this particular extension.
Definition: ASTBitCodes.h:376
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
Definition: ASTReader.cpp:201
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
Definition: MacroInfo.h:204
MacroInfo * getMacro(serialization::MacroID ID)
Retrieve the macro with the given ID.
Definition: ASTReader.cpp:8406
uint64_t SizeInBits
The size of this file, in bits.
Definition: Module.h:182
TemplateParameterList * ReadTemplateParameterList(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template parameter list.
Definition: ASTReader.cpp:8810
An ObjCTypeParamType record.
Definition: ASTBitCodes.h:1165
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
The (signed) &#39;long&#39; type.
Definition: ASTBitCodes.h:847
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2041
ModuleReverseIterator rbegin()
Reverse iterator to traverse all loaded modules.
Record code for the offsets of each decl.
Definition: ASTBitCodes.h:415
SourceLocation getFriendLoc() const
Retrieves the location of the &#39;friend&#39; keyword.
Definition: DeclFriend.h:144
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:8072
void * SelectorLookupTable
A pointer to an on-disk hash table of opaque type ASTSelectorLookupTable.
Definition: Module.h:399
Metadata for submodules as a whole.
Definition: ASTBitCodes.h:721
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
const uint32_t * IdentifierOffsets
Offsets into the identifier table data.
Definition: Module.h:273
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Class that performs lookup for a selector&#39;s entries in the global method pool stored in an AST file...
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:613
CanQualType FloatTy
Definition: ASTContext.h:1028
const FileEntry * Entry
Definition: Module.h:153
A dependentSizedVectorType record.
Definition: ASTBitCodes.h:1177
The (signed) &#39;short&#39; type.
Definition: ASTBitCodes.h:841
Defines the clang::TargetOptions class.
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier &#39;::&#39;.
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2285
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
Definition: MacroInfo.h:127
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3860
bool isPoisoned() const
Return true if this token has been poisoned.
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:135
CanQualType SatUnsignedLongAccumTy
Definition: ASTContext.h:1035
void setPrivateCopies(ArrayRef< Expr *> PrivateCopies)
Set list of helper expressions, required for generation of private copies of original lastprivate var...
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings startin...
Definition: TargetOptions.h:56
The &#39;_Sat _Accum&#39; type.
Definition: ASTBitCodes.h:982
unsigned LocalNumDecls
The number of declarations in this AST file.
Definition: Module.h:409
void setUpgradedFromWarning(bool Value)
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:51
SourceRange ReadSkippedRange(unsigned Index) override
Read a preallocated skipped range from the external source.
Definition: ASTReader.cpp:5427
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2312
The internal &#39;instancetype&#39; typedef.
Definition: ASTBitCodes.h:1246
CanQualType VoidTy
Definition: ASTContext.h:1016
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3520
OptionsRecordTypes
Record types that occur within the options block inside the control block.
Definition: ASTBitCodes.h:339
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:89
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1741
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
CanQualType Float16Ty
Definition: ASTContext.h:1041
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:2036
QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, ArrayRef< ObjCProtocolDecl *> protocols, QualType Canonical=QualType()) const
bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
Definition: ASTReader.cpp:7224
CanQualType SatLongFractTy
Definition: ASTContext.h:1037
The AST block, which acts as a container around the full AST block.
Definition: ASTBitCodes.h:249
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1358
ArrayRef< ObjCMethodDecl * > getFactoryMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:8047
void setVarRefs(ArrayRef< Expr *> VL)
Sets the list of variables for this clause.
Definition: OpenMPClause.h:191
IdentID ReadIdentifierID(const unsigned char *d)
Definition: ASTReader.cpp:920
A DeducedTemplateSpecializationType record.
Definition: ASTBitCodes.h:1168
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2059
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:695
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:86
void setWrittenTypeSpec(TypeSpecifierType written)
Definition: TypeLoc.h:634
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:52
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:3741
void setAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1300
UnhashedControlBlockRecordTypes
Record codes for the unhashed control block.
Definition: ASTBitCodes.h:362
llvm::SetVector< ModuleFile * > ImportedBy
List of modules which depend on this module.
Definition: Module.h:467
void setLBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1469
void dump()
Dump debugging output for this module.
Definition: Module.cpp:48
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:267
An InjectedClassNameType record.
Definition: ASTBitCodes.h:1114
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:8320
const serialization::DeclID * FileSortedDecls
Array of file-level DeclIDs sorted by file.
Definition: Module.h:431
Record code for the extra statistics we gather while generating an AST file.
Definition: ASTBitCodes.h:465
static Decl * getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID)
Definition: ASTReader.cpp:7261
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1958
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:2039
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3746
static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool Complain)
Definition: ASTReader.cpp:456
virtual void visitImport(StringRef ModuleName, StringRef Filename)
If needsImportVisitation returns true, this is called for each AST file imported by this AST file...
Definition: ASTReader.h:236
The width of the "fast" qualifier mask.
Definition: Type.h:184
std::vector< InputFile > InputFilesLoaded
The input files that have been loaded from this AST file.
Definition: Module.h:227
CanQualType SatUnsignedFractTy
Definition: ASTContext.h:1038
std::string PCHThroughHeader
If non-empty, the filename used in an #include directive in the primary source file (or command-line ...
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:169
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:8595
The &#39;signed char&#39; type.
Definition: ASTBitCodes.h:835
unsigned LocalNumSubmodules
The number of submodules in this module.
Definition: Module.h:364
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:247
The AST file was writtten with a different language/target configuration.
Definition: ASTReader.h:401
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C)
CanQualType SatUnsignedShortFractTy
Definition: ASTContext.h:1038
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:8579
const char * HeaderFileInfoTableData
Actual data for the on-disk hash table of header file information.
Definition: Module.h:355
void markIdentifierUpToDate(IdentifierInfo *II)
Note that this identifier is up-to-date.
Definition: ASTReader.cpp:1948
const llvm::support::unaligned_uint64_t * InputFileOffsets
Offsets for all of the input file entries in the AST file.
Definition: Module.h:224
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:595
Record code for the signature that identifiers this AST file.
Definition: ASTBitCodes.h:364
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
Definition: ModuleMap.cpp:1166
File is a PCH file treated as the actual main file.
Definition: Module.h:57
llvm::APFloat ReadAPFloat(const RecordData &Record, const llvm::fltSemantics &Sem, unsigned &Idx)
Read a floating-point value.
Definition: ASTReader.cpp:9076
Record code for referenced selector pool.
Definition: ASTBitCodes.h:511
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
Definition: Module.h:66
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:456
std::vector< std::string > MacroIncludes
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2622
CanQualType SatAccumTy
Definition: ASTContext.h:1034
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4978
ModuleFile * getLocalModuleFile(ModuleFile &M, unsigned ID)
Retrieve the module file with a given local ID within the specified ModuleFile.
Definition: ASTReader.cpp:8485
Record code for the set of non-builtin, special types.
Definition: ASTBitCodes.h:461
Defines various enumerations that describe declaration and type specifiers.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1366
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:669
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1560
SourceLocation getBegin() const
Definition: ASTBitCodes.h:212
StringRef getName() const
Return the actual identifier string.
void setTypeArgsLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:937
uint64_t InputFilesValidationTimestamp
If non-zero, specifies the time when we last validated input files.
Definition: Module.h:237
CanQualType UnsignedShortTy
Definition: ASTContext.h:1026
llvm::MemoryBuffer * getRawBuffer() const
Get the underlying buffer, returning NULL if the buffer is not yet available.
const uint32_t * MacroOffsets
Offsets of macros in the preprocessor block.
Definition: Module.h:309
The ObjC &#39;id&#39; type.
Definition: ASTBitCodes.h:883
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Canon=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
unsigned LocalNumSelectors
The number of selectors new to this file.
Definition: Module.h:377
unsigned getObjCOrBuiltinID() const
const PPSkippedRange * PreprocessedSkippedRangeOffsets
Definition: Module.h:342
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
CanQualType CharTy
Definition: ASTContext.h:1018
unsigned ControllingMacroID
The ID number of the controlling macro.
Definition: HeaderSearch.h:98
Represents a template argument.
Definition: TemplateBase.h:51
Record code for the list of other AST files imported by this AST file.
Definition: ASTBitCodes.h:308
Selector getLocalSelector(ModuleFile &M, unsigned LocalID)
Retrieve a selector from the given module with its local ID number.
Definition: ASTReader.cpp:8540
Describes a macro definition within the preprocessing record.
Definition: ASTBitCodes.h:711
const ASTTemplateArgumentListInfo * ReadASTTemplateArgumentListInfo(ModuleFile &F, const RecordData &Record, unsigned &Index)
Definition: ASTReader.cpp:7095
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
A conflict between two modules.
Definition: Module.h:360
void setClassTInfo(TypeSourceInfo *TI)
Definition: TypeLoc.h:1252
bool ReadSLocEntry(int ID) override
Read the source location entry with index ID.
Definition: ASTReader.cpp:1363
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
Definition: ASTReader.cpp:791
The internal &#39;__NSConstantString&#39; typedef.
Definition: ASTBitCodes.h:1264
Record code for the module name.
Definition: ASTBitCodes.h:327
QualType getTypeOfType(QualType t) const
getTypeOfType - Unlike many "get<Type>" functions, we don&#39;t unique TypeOfType nodes.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:154
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:941
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1048
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
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:2227
Dataflow Directional Tag Classes.
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const
Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...
Definition: Diagnostic.h:834
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const
This represents &#39;device&#39; clause in the &#39;#pragma omp ...&#39; directive.
bool isValid() const
Return true if this is a valid SourceLocation object.
void setDeserializationListener(ASTDeserializationListener *Listener, bool TakeOwnership=false)
Set the AST deserialization listener.
Definition: ASTReader.cpp:808
Describes an inclusion directive within the preprocessing record.
Definition: ASTBitCodes.h:715
The internal &#39;__builtin_ms_va_list&#39; typedef.
Definition: ASTBitCodes.h:1255
llvm::BitstreamCursor DeclsCursor
DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.
Definition: Module.h:406
unsigned IsMissingRequirement
Whether this module is missing a feature from Requirements.
Definition: Module.h:204
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:499
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:1262
Record code for a file sorted array of DeclIDs in a module.
Definition: ASTBitCodes.h:580
void setAmpAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1314
CanQualType NullPtrTy
Definition: ASTContext.h:1044
Record code for the array of Objective-C categories (including extensions).
Definition: ASTBitCodes.h:594
void updateOutOfDateIdentifier(IdentifierInfo &II) override
Update an out-of-date identifier.
Definition: ASTReader.cpp:1923
void reserve(ASTContext &C, unsigned N)
Specifies a configuration macro for this module.
Definition: ASTBitCodes.h:759
void ReadDefinedMacros() override
Read the set of macros defined by this external macro source.
Definition: ASTReader.cpp:1819
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
PreprocessorDetailRecordTypes
Record types used within a preprocessor detail block.
Definition: ASTBitCodes.h:706
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
static unsigned moduleKindForDiagnostic(ModuleKind Kind)
Definition: ASTReader.cpp:4111
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) override
Receives the file system options.
Definition: ASTReader.cpp:186
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
uint64_t MacroStartOffset
The offset of the start of the set of defined macros.
Definition: Module.h:318
CanQualType UnsignedShortAccumTy
Definition: ASTContext.h:1031
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, SourceLocation Loc) const
Translate a source location from another module file&#39;s source location space into ours...
Definition: ASTReader.h:2195
Record code for the array of unused file scoped decls.
Definition: ASTBitCodes.h:499
A FunctionNoProtoType record.
Definition: ASTBitCodes.h:1075
off_t getSize() const
Definition: FileManager.h:88
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:243
The &#39;_Sat unsigned short _Accum&#39; type.
Definition: ASTBitCodes.h:988
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:3838
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:355
File is an explicitly-loaded module.
Definition: Module.h:48
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2825
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:430
QualType getUnderlyingType() const
Definition: Decl.h:2971
Interesting information about a specific parameter that can&#39;t simply be reflected in parameter&#39;s type...
Definition: Type.h:3381
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1027
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:231
const Expr * getInit() const
Definition: Decl.h:1220
AccessSpecifier getAccess() const
Definition: DeclBase.h:462
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.
The &#39;_Sat long _Accum&#39; type.
Definition: ASTBitCodes.h:985
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl *> &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
Definition: ASTReader.cpp:8182
The name of a declaration.
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:559
Record code for the Objective-C method pool,.
Definition: ASTBitCodes.h:477
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:288
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension...
virtual void ReadModuleMapFile(StringRef ModuleMapPath)
Definition: ASTReader.h:140
Kind getKind() const
Definition: DeclBase.h:421
Specifies a header that is private to this submodule.
Definition: ASTBitCodes.h:765
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like &#39;int()&#39;.
bool needsInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.cpp:215
U cast(CodeGen::Address addr)
Definition: Address.h:109
Describes a macro expansion within the preprocessing record.
Definition: ASTBitCodes.h:708
This represents &#39;unified_shared_memory&#39; clause in the &#39;#pragma omp requires&#39; directive.
Definition: OpenMPClause.h:776
llvm::OnDiskChainedHashTable< ASTSelectorLookupTrait > ASTSelectorLookupTable
The on-disk hash table used for the global method pool.
This represents clause &#39;linear&#39; in the &#39;#pragma omp ...&#39; directives.
Represents an enum.
Definition: Decl.h:3326
void * getFETokenInfo() const
Get and set FETokenInfo.
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:3818
IdentifierTable & getIdentifierTable()
Retrieve the identifier table associated with the preprocessor.
Definition: ASTReader.cpp:9126
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
IdentifierResolver IdResolver
Definition: Sema.h:823
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.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
ContinuousRangeMap< uint32_t, int, 2 > MacroRemap
Remapping table for macro IDs in this module.
Definition: Module.h:315
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
An RValueReferenceType record.
Definition: ASTBitCodes.h:1054
void ReadDeclarationNameLoc(ModuleFile &F, DeclarationNameLoc &DNLoc, DeclarationName Name, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8639
void setLocStart(SourceLocation Loc)
Sets the starting location of the clause.
Definition: OpenMPClause.h:73
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
void ClearSwitchCaseIDs()
Definition: ASTReader.cpp:9144
static OMPSharedClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
std::string BlockName
The name used to identify this particular extension block within the resulting module file...
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:767
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:69
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate >> &LPTMap) override
Read the set of late parsed template functions for this source.
Definition: ASTReader.cpp:8266
An AtomicType record.
Definition: ASTBitCodes.h:1153
static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, ASTConsumer *Consumer)
Under non-PCH compilation the consumer receives the objc methods before receiving the implementation...
Definition: ASTReader.cpp:7588
The placeholder type for dependent types.
Definition: ASTBitCodes.h:865
All of the names in this module are visible.
Definition: Module.h:271
unsigned getNumParams() const
Definition: TypeLoc.h:1402
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2022
void setComponentListSizes(ArrayRef< unsigned > CLSs)
Set the cumulative component lists sizes that are in the trailing objects of the class.
Number of unmatched #pragma clang cuda_force_host_device begin directives we&#39;ve seen.
Definition: ASTBitCodes.h:634
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map...
Definition: Module.h:263
uint64_t SanitizerMask
Definition: Sanitizers.h:26
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
Decl * GetExternalDecl(uint32_t ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:7107
Class that represents a component of a mappable expression.
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope...
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:889
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...
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3757
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, const RecordData &Record, unsigned &Idx)
Read a UnresolvedSet structure.
Definition: ASTReader.cpp:8840
struct CXXLitOpName CXXLiteralOperatorName
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:127
void addLinkAsDependency(Module *Mod)
Make module to use export_as as the link dependency name if enough information is available or add it...
Definition: ModuleMap.cpp:70
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
BuiltinTemplateDecl * getTypePackElementDecl() const
CanQualType UnknownAnyTy
Definition: ASTContext.h:1045
The &#39;unsigned _Fract&#39; type.
Definition: ASTBitCodes.h:973
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:369
NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8989
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:5634
Record code for the table of offsets into the Objective-C method pool.
Definition: ASTBitCodes.h:474
Defines the clang::FileSystemOptions interface.
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2256
ContinuousRangeMap< unsigned, int, 2 > SLocRemap
Definition: ASTUnit.cpp:2326
A DependentSizedArrayType record.
Definition: ASTBitCodes.h:1132
CanQualType UnsignedLongTy
Definition: ASTContext.h:1026
Record code for the remapping information used to relate loaded modules to the various offsets and ID...
Definition: ASTBitCodes.h:569
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
Definition: TemplateBase.h:695
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:135
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:2069
static OMPCopyprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata) override
Indicates that a particular module file extension has been read.
Definition: ASTReader.cpp:247
Record code for declarations that Sema keeps references of.
Definition: ASTBitCodes.h:520
void ReadTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument array.
Definition: ASTReader.cpp:8830
CanQualType DependentTy
Definition: ASTContext.h:1045
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1922
void * HeaderFileInfoTable
The on-disk hash table that contains information about each of the header files.
Definition: Module.h:359
CanQualType WCharTy
Definition: ASTContext.h:1019
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:151
void visitTopLevelModuleMaps(serialization::ModuleFile &MF, llvm::function_ref< void(const FileEntry *)> Visitor)
Visit all the top-level module maps loaded when building the given module file.
Definition: ASTReader.cpp:9217
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:504
Offsets into the input-files block where input files reside.
Definition: ASTBitCodes.h:324
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:161
CanQualType ObjCBuiltinClassTy
Definition: ASTContext.h:1048
unsigned getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.h:699
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:819
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1730
PreprocessorRecordTypes
Record types used within a preprocessor block.
Definition: ASTBitCodes.h:680
static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags)
Definition: ASTReader.cpp:486
CanQualType BoundMemberTy
Definition: ASTContext.h:1045
SourceLocation getEnd() const
Definition: ASTBitCodes.h:215
The block containing the submodule structure.
Definition: ASTBitCodes.h:267
QualType getAutoDeductType() const
C++11 deduction pattern for &#39;auto&#39; type.
Module * lookupModule(StringRef ModuleName, bool AllowSearch=true, bool AllowExtraModuleMapSearch=false)
Lookup a module Search for a module with the given name.
void setTypeArgsRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:945
void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx, TypeLoc TL)
Raad the type locations for the given TInfo.
Definition: ASTReader.cpp:6753
Wrapper for source info for record types.
Definition: TypeLoc.h:716
std::string BaseDirectory
The base directory of the module.
Definition: Module.h:129
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1915
unsigned CalculateHash()
Definition: ODRHash.cpp:199
The template argument is a type.
Definition: TemplateBase.h:60
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
PragmaMSStructKind
Definition: PragmaKinds.h:24
Wraps an ObjCPointerType with source location information.
Definition: TypeLoc.h:1270
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:239
Holds information about the various types of exception specification.
Definition: Type.h:3741
ContinuousRangeMap< uint32_t, int, 2 > TypeRemap
Remapping table for type IDs in this module.
Definition: Module.h:459
Selector DecodeSelector(serialization::SelectorID Idx)
Definition: ASTReader.cpp:8544
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
Definition: ASTReader.h:1664
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
Definition: Module.h:331
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
Represents a base class of a C++ class.
Definition: DeclCXX.h:192
This represents &#39;write&#39; clause in the &#39;#pragma omp atomic&#39; directive.
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:46
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
Definition: ASTReader.cpp:8573
unsigned BufferOverridden
Indicates whether the buffer itself was provided to override the actual file contents.
void PrintStats() override
Print some statistics about AST usage.
Definition: ASTReader.cpp:7615
void setSeverity(diag::Severity Value)
unsigned size() const
Number of modules loaded.
void setLoopData(unsigned NumLoop, Expr *Cnt)
Set the loop data for the depend clauses with &#39;sink|source&#39; kind of dependency.
Defines the clang::TokenKind enum and support functions.
void insert(const value_type &Val)
Metadata for a module file extension.
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3746
Keeps track of options that affect how file operations are performed.
CanQualType Char8Ty
Definition: ASTContext.h:1022
llvm::OnDiskIterableChainedHashTable< ASTIdentifierLookupTrait > ASTIdentifierLookupTable
The on-disk hash table used to contain information about all of the identifiers in the program...
StringRef Framework
If this header came from a framework include, this is the name of the framework.
Definition: HeaderSearch.h:112
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2253
static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID)
ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the specified cursor.
Definition: ASTReader.cpp:1544
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
Definition: ASTReader.cpp:6772
A template argument list.
Definition: DeclTemplate.h:210
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1619
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
ExternCContextDecl * getExternCContextDecl() const
IdentifierInfo * DecodeIdentifierInfo(serialization::IdentifierID ID)
Definition: ASTReader.cpp:8352
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:3749
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:663
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
Definition: ASTReader.h:183
The fast qualifier mask.
Definition: Type.h:187
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:2220
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
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...
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1009
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:495
The C++ &#39;char16_t&#39; type.
Definition: ASTBitCodes.h:877
Defines the clang::SourceLocation class and associated facilities.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
This represents &#39;nowait&#39; clause in the &#39;#pragma omp ...&#39; directive.
TemplateArgumentLoc ReadTemplateArgumentLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a TemplateArgumentLoc.
Definition: ASTReader.cpp:7082
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2654
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:240
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:7046
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
Selector GetExternalSelector(serialization::SelectorID ID) override
Resolve a selector ID into a selector.
Definition: ASTReader.cpp:8569
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
bool isValid() const
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:7380
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.h:217
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl *> &Decls) override
Read the set of unused file-scope declarations known to the external Sema source. ...
Definition: ASTReader.cpp:8160
An TemplateTypeParmType record.
Definition: ASTBitCodes.h:1120
This represents &#39;num_tasks&#39; clause in the &#39;#pragma omp ...&#39; directive.
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
bool needsSystemInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.cpp:220
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:919
SmallVector< uint64_t, 8 > PragmaDiagMappings
Diagnostic IDs and their mappings that the user changed.
Definition: Module.h:464
Record code for the filesystem options table.
Definition: ASTBitCodes.h:352
static hash_value_type ComputeHash(const internal_key_type &a)
Definition: ASTReader.cpp:884
Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx)
Reads a token out of a record.
Definition: ASTReader.cpp:1561
const char * IdentifierTableData
Actual data for the on-disk hash table of identifiers.
Definition: Module.h:285
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1409
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:410
CanQualType Char16Ty
Definition: ASTContext.h:1023
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:152
static DiagnosticMapping deserialize(unsigned Bits)
Deserialize a mapping.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source...
unsigned getNumProtocols() const
Definition: TypeLoc.h:979
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1101
ASTImporterLookupTable & LT
const DeclOffset * DeclOffsets
Offset of each declaration within the bitstream, indexed by the declaration ID (-1).
Definition: Module.h:413
Location information for a TemplateArgument.
Definition: TemplateBase.h:393
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
Definition: ASTReader.h:155
Declaration of a class template.
Record code for the offsets of each type.
Definition: ASTBitCodes.h:403
A DependentAddressSpaceType record.
Definition: ASTBitCodes.h:1174
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:2903
The block containing the definitions of all of the types and decls used within the AST file...
Definition: ASTBitCodes.h:261
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
The internal &#39;__va_list_tag&#39; struct, if any.
Definition: ASTBitCodes.h:1252
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
virtual void ReadModuleName(StringRef ModuleName)
Definition: ASTReader.h:139
TypedefDecl * getObjCClassDecl() const
Retrieve the typedef declaration corresponding to the predefined Objective-C &#39;Class&#39; type...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:276
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
Definition: ASTReader.cpp:555
ASTIdentifierIterator(const ASTReader &Reader, bool SkipModules=false)
Definition: ASTReader.cpp:7917
void resolveLinkAsDependencies(Module *Mod)
Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...
Definition: ModuleMap.cpp:59
The module file had already been loaded.
Specifies the name of the module that will eventually re-export the entities in this module...
Definition: ASTBitCodes.h:781
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1566
Defines the clang::TargetInfo interface.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:475
void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion=OMPD_unknown)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:114
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition: ASTReader.h:394
TypeLocReader(ModuleFile &F, ASTReader &Reader, const ASTReader::RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:6455
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:267
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition: MacroInfo.h:326
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1879
The (signed) &#39;int&#39; type.
Definition: ASTBitCodes.h:844
a linked list of methods with the same selector name but different signatures.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3637
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1576
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
std::pair< ObjCMethodList, ObjCMethodList > GlobalMethods
Definition: Sema.h:1151
data_type ReadData(const internal_key_type &k, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:936
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:90
Specifies a required feature.
Definition: ASTBitCodes.h:749
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
This represents &#39;dist_schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID)
Returns the source location for the decl ID.
Definition: ASTReader.cpp:7242
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:344
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:25
SourceRange getSourceRange() const override LLVM_READONLY
Retrieves the source range for the friend declaration.
Definition: DeclFriend.h:149
unsigned getNumTypeArgs() const
Definition: TypeLoc.h:949
__DEVICE__ int max(int __a, int __b)
static OMPFromClause * CreateEmpty(const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
Creates an empty clause with the place for NumVars variables.
CanQualType IntTy
Definition: ASTContext.h:1025
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:397
Record for offsets of DECL_UPDATES records for declarations that were modified after being deserializ...
Definition: ASTBitCodes.h:537
unsigned ModuleMapFileHomeIsCwd
Set the &#39;home directory&#39; of a module map file to the current working directory (or the home directory...
static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool IsSystem, bool Complain)
Definition: ASTReader.cpp:493
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions)
Read the control block for the named AST file.
Definition: ASTReader.cpp:4718
llvm::BitstreamCursor PreprocessorDetailCursor
The cursor to the start of the (optional) detailed preprocessing record block.
Definition: Module.h:324
The C++ &#39;wchar_t&#39; type.
Definition: ASTBitCodes.h:838
The ObjC &#39;Class&#39; type.
Definition: ASTBitCodes.h:886
void setProtocolLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:967
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1158
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 &#39;type...
unsigned IndexHeaderMapHeader
Whether this is a header inside a framework that is currently being built.
Definition: HeaderSearch.h:85
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:7234
unsigned IsValid
Whether this file has been looked up as a header.
Definition: HeaderSearch.h:88
static bool isWhitelistedDecl(const Decl *D, const DeclContext *Parent)
Definition: ODRHash.cpp:433
Record code for weak undeclared identifiers.
Definition: ASTBitCodes.h:523
The block containing information about the preprocessor.
Definition: ASTBitCodes.h:257
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, const TemplateArgumentListInfo &Args) const
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
Definition: ASTReader.cpp:757
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:7605
QualType getDefaultArgument() const
Retrieve the default argument, if any.
void setLocation(SourceLocation L)
Definition: Token.h:132
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
bool getWarningsAsErrors() const
Definition: Diagnostic.h:610
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...
QualType getType() const
Definition: Decl.h:648
Wrapper for source info for builtin types.
Definition: TypeLoc.h:544
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1105
A set of overloaded template declarations.
Definition: TemplateName.h:195
Wrapper for template type parameters.
Definition: TypeLoc.h:732
Record code for the headers search options table.
Definition: ASTBitCodes.h:355
Module * Other
The module that this module conflicts with.
Definition: Module.h:362
A trivial tuple used to represent a source range.
void setParameterList(ArrayRef< IdentifierInfo *> List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
Definition: MacroInfo.h:165
This represents a decl that may have a name.
Definition: Decl.h:249
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
Definition: ASTContext.h:1761
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
Definition: ASTContext.h:1739
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
AST file metadata, including the AST file version number and information about the compiler used to b...
Definition: ASTBitCodes.h:304
The block of input files, which were used as inputs to create this AST file.
Definition: ASTBitCodes.h:281
Present this diagnostic as a warning.
llvm::BitstreamCursor MacroCursor
The cursor to the start of the preprocessor block, which stores all of the macro definitions.
Definition: Module.h:299
const uint32_t * SelectorOffsets
Offsets into the selector lookup table&#39;s data array where each selector resides.
Definition: Module.h:381
CanQualType BoolTy
Definition: ASTContext.h:1017
void UpdateSema()
Update the state of Sema after loading some additional modules.
Definition: ASTReader.cpp:7788
unsigned LocalNumTypes
The number of types in this AST file.
Definition: Module.h:448
Represents a C++ namespace alias.
Definition: DeclCXX.h:3020
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1600
Kind
The basic Objective-C runtimes that we know about.
Definition: ObjCRuntime.h:31
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...
The internal &#39;__NSConstantString&#39; tag type.
Definition: ASTBitCodes.h:1267
static TypeIdx fromTypeID(TypeID ID)
Definition: ASTBitCodes.h:105
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:7363
InputFileRecordTypes
Record types that occur within the input-files block inside the control block.
Definition: ASTBitCodes.h:384
void FinishedDeserializing() override
Notify ASTReader that we finished the deserialization of a decl or type.
CanQualType DoubleTy
Definition: ASTContext.h:1028
A function-like macro definition.
Definition: ASTBitCodes.h:691
~ASTReader() override
The Objective-C &#39;Protocol&#39; type.
Definition: ASTBitCodes.h:1237
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
static OMPLastprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
The global specifier &#39;::&#39;. There is no stored value.
The control block, which contains all of the information that needs to be validated prior to committi...
Definition: ASTBitCodes.h:275
Wrapper for source info for pointers.
Definition: TypeLoc.h:1202
SourceLocation getBegin() const
const FileEntry * File
The file entry for the module file.
Definition: Module.h:164
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:30
void setObjCOrBuiltinID(unsigned ID)
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:299
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1215
void ReadModuleName(StringRef ModuleName) override
Definition: ASTReader.cpp:150
The &#39;_Sat unsigned short _Fract&#39; type.
Definition: ASTBitCodes.h:1006
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:83
This class handles loading and caching of source files into memory.
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3773
PredefinedDeclIDs
Predefined declaration IDs.
Definition: ASTBitCodes.h:1220
QualType getAdjustedType(QualType Orig, QualType New) const
Return the uniqued reference to a type adjusted from the original type to a new type.
Declaration of a template function.
Definition: DeclTemplate.h:969
Record code for an update to the TU&#39;s lexically contained declarations.
Definition: ASTBitCodes.h:515
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3466
The &#39;_Sat _Fract&#39; type.
Definition: ASTBitCodes.h:1000
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1943
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:221
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateDecl *Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override
This is called for each AST file loaded.
Definition: ASTReader.cpp:225
Attr - This represents one attribute.
Definition: Attr.h:44
bool isDeletedAsWritten() const
Definition: Decl.h:2140
SourceLocation getLocation() const
Definition: DeclBase.h:418
This represents clause &#39;use_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
const serialization::ObjCCategoriesInfo * ObjCCategoriesMap
Array of category list location information within this module file, sorted by the definition ID...
Definition: Module.h:436
bool loadGlobalIndex()
Attempts to load the global index.
Definition: ASTReader.cpp:3796
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:8476
Objective-C "Class" redefinition type.
Definition: ASTBitCodes.h:1202
A PackExpansionType record.
Definition: ASTBitCodes.h:1138
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
Definition: ASTReader.cpp:8192
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:98
A single template declaration.
Definition: TemplateName.h:192
CanQualType OCLClkEventTy
Definition: ASTContext.h:1053
The pseudo-object placeholder type.
Definition: ASTBitCodes.h:910
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:175
virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain)
Receives the diagnostic options.
Definition: ASTReader.h:165
void setUnderlyingTInfo(TypeSourceInfo *TI) const
Definition: TypeLoc.h:1845
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:244
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
Record code for #pragma ms_struct options.
Definition: ASTBitCodes.h:630
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
Definition: ASTReader.cpp:9132
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125
A DependentTemplateSpecializationType record.
Definition: ASTBitCodes.h:1129
CanQualType UnsignedIntTy
Definition: ASTContext.h:1026
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...
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
bool ParseAllComments
Treat ordinary comments as documentation comments.
OMPClause * readClause()
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, unsigned LocalID)
Definition: ASTReader.cpp:8391
Record code for the array of tentative definitions.
Definition: ASTBitCodes.h:468
The &#39;__float128&#39; type.
Definition: ASTBitCodes.h:934
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.