clang  9.0.0
ASTReader.cpp
Go to the documentation of this file.
1 //===- ASTReader.cpp - AST File Reader ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ASTReader class, which reads AST files.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "ASTCommon.h"
15 #include "ASTReaderInternals.h"
16 #include "clang/AST/ASTConsumer.h"
17 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/DeclBase.h"
22 #include "clang/AST/DeclCXX.h"
23 #include "clang/AST/DeclFriend.h"
24 #include "clang/AST/DeclGroup.h"
25 #include "clang/AST/DeclObjC.h"
26 #include "clang/AST/DeclTemplate.h"
28 #include "clang/AST/Expr.h"
29 #include "clang/AST/ExprCXX.h"
32 #include "clang/AST/ODRHash.h"
34 #include "clang/AST/TemplateBase.h"
35 #include "clang/AST/TemplateName.h"
36 #include "clang/AST/Type.h"
37 #include "clang/AST/TypeLoc.h"
41 #include "clang/Basic/Diagnostic.h"
47 #include "clang/Basic/LLVM.h"
49 #include "clang/Basic/Module.h"
53 #include "clang/Basic/Sanitizers.h"
57 #include "clang/Basic/Specifiers.h"
58 #include "clang/Basic/TargetInfo.h"
60 #include "clang/Basic/TokenKinds.h"
61 #include "clang/Basic/Version.h"
62 #include "clang/Lex/HeaderSearch.h"
64 #include "clang/Lex/MacroInfo.h"
65 #include "clang/Lex/ModuleMap.h"
67 #include "clang/Lex/Preprocessor.h"
69 #include "clang/Lex/Token.h"
71 #include "clang/Sema/Scope.h"
72 #include "clang/Sema/Sema.h"
73 #include "clang/Sema/Weak.h"
84 #include "llvm/ADT/APFloat.h"
85 #include "llvm/ADT/APInt.h"
86 #include "llvm/ADT/APSInt.h"
87 #include "llvm/ADT/ArrayRef.h"
88 #include "llvm/ADT/DenseMap.h"
89 #include "llvm/ADT/FoldingSet.h"
90 #include "llvm/ADT/Hashing.h"
91 #include "llvm/ADT/IntrusiveRefCntPtr.h"
92 #include "llvm/ADT/None.h"
93 #include "llvm/ADT/Optional.h"
94 #include "llvm/ADT/STLExtras.h"
95 #include "llvm/ADT/ScopeExit.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/Bitstream/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  if (llvm::Error Err = Cursor.JumpToBit(Offset)) {
1152  Error(std::move(Err));
1153  return true;
1154  }
1155 
1156  RecordData Record;
1157  StringRef Blob;
1158  Expected<unsigned> MaybeCode = Cursor.ReadCode();
1159  if (!MaybeCode) {
1160  Error(MaybeCode.takeError());
1161  return true;
1162  }
1163  unsigned Code = MaybeCode.get();
1164 
1165  Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record, &Blob);
1166  if (!MaybeRecCode) {
1167  Error(MaybeRecCode.takeError());
1168  return true;
1169  }
1170  unsigned RecCode = MaybeRecCode.get();
1171  if (RecCode != DECL_CONTEXT_LEXICAL) {
1172  Error("Expected lexical block");
1173  return true;
1174  }
1175 
1176  assert(!isa<TranslationUnitDecl>(DC) &&
1177  "expected a TU_UPDATE_LEXICAL record for TU");
1178  // If we are handling a C++ class template instantiation, we can see multiple
1179  // lexical updates for the same record. It's important that we select only one
1180  // of them, so that field numbering works properly. Just pick the first one we
1181  // see.
1182  auto &Lex = LexicalDecls[DC];
1183  if (!Lex.first) {
1184  Lex = std::make_pair(
1185  &M, llvm::makeArrayRef(
1186  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
1187  Blob.data()),
1188  Blob.size() / 4));
1189  }
1190  DC->setHasExternalLexicalStorage(true);
1191  return false;
1192 }
1193 
1194 bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
1195  BitstreamCursor &Cursor,
1196  uint64_t Offset,
1197  DeclID ID) {
1198  assert(Offset != 0);
1199 
1200  SavedStreamPosition SavedPosition(Cursor);
1201  if (llvm::Error Err = Cursor.JumpToBit(Offset)) {
1202  Error(std::move(Err));
1203  return true;
1204  }
1205 
1206  RecordData Record;
1207  StringRef Blob;
1208  Expected<unsigned> MaybeCode = Cursor.ReadCode();
1209  if (!MaybeCode) {
1210  Error(MaybeCode.takeError());
1211  return true;
1212  }
1213  unsigned Code = MaybeCode.get();
1214 
1215  Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record, &Blob);
1216  if (!MaybeRecCode) {
1217  Error(MaybeRecCode.takeError());
1218  return true;
1219  }
1220  unsigned RecCode = MaybeRecCode.get();
1221  if (RecCode != DECL_CONTEXT_VISIBLE) {
1222  Error("Expected visible lookup table block");
1223  return true;
1224  }
1225 
1226  // We can't safely determine the primary context yet, so delay attaching the
1227  // lookup table until we're done with recursive deserialization.
1228  auto *Data = (const unsigned char*)Blob.data();
1229  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data});
1230  return false;
1231 }
1232 
1233 void ASTReader::Error(StringRef Msg) const {
1234  Error(diag::err_fe_pch_malformed, Msg);
1235  if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() &&
1236  !PP.getHeaderSearchInfo().getModuleCachePath().empty()) {
1237  Diag(diag::note_module_cache_path)
1238  << PP.getHeaderSearchInfo().getModuleCachePath();
1239  }
1240 }
1241 
1242 void ASTReader::Error(unsigned DiagID,
1243  StringRef Arg1, StringRef Arg2) const {
1244  if (Diags.isDiagnosticInFlight())
1245  Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2);
1246  else
1247  Diag(DiagID) << Arg1 << Arg2;
1248 }
1249 
1250 void ASTReader::Error(llvm::Error &&Err) const {
1251  Error(toString(std::move(Err)));
1252 }
1253 
1254 //===----------------------------------------------------------------------===//
1255 // Source Manager Deserialization
1256 //===----------------------------------------------------------------------===//
1257 
1258 /// Read the line table in the source manager block.
1259 /// \returns true if there was an error.
1260 bool ASTReader::ParseLineTable(ModuleFile &F,
1261  const RecordData &Record) {
1262  unsigned Idx = 0;
1263  LineTableInfo &LineTable = SourceMgr.getLineTable();
1264 
1265  // Parse the file names
1266  std::map<int, int> FileIDs;
1267  FileIDs[-1] = -1; // For unspecified filenames.
1268  for (unsigned I = 0; Record[Idx]; ++I) {
1269  // Extract the file name
1270  auto Filename = ReadPath(F, Record, Idx);
1271  FileIDs[I] = LineTable.getLineTableFilenameID(Filename);
1272  }
1273  ++Idx;
1274 
1275  // Parse the line entries
1276  std::vector<LineEntry> Entries;
1277  while (Idx < Record.size()) {
1278  int FID = Record[Idx++];
1279  assert(FID >= 0 && "Serialized line entries for non-local file.");
1280  // Remap FileID from 1-based old view.
1281  FID += F.SLocEntryBaseID - 1;
1282 
1283  // Extract the line entries
1284  unsigned NumEntries = Record[Idx++];
1285  assert(NumEntries && "no line entries for file ID");
1286  Entries.clear();
1287  Entries.reserve(NumEntries);
1288  for (unsigned I = 0; I != NumEntries; ++I) {
1289  unsigned FileOffset = Record[Idx++];
1290  unsigned LineNo = Record[Idx++];
1291  int FilenameID = FileIDs[Record[Idx++]];
1293  = (SrcMgr::CharacteristicKind)Record[Idx++];
1294  unsigned IncludeOffset = Record[Idx++];
1295  Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID,
1296  FileKind, IncludeOffset));
1297  }
1298  LineTable.AddEntry(FileID::get(FID), Entries);
1299  }
1300 
1301  return false;
1302 }
1303 
1304 /// Read a source manager block
1305 bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
1306  using namespace SrcMgr;
1307 
1308  BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
1309 
1310  // Set the source-location entry cursor to the current position in
1311  // the stream. This cursor will be used to read the contents of the
1312  // source manager block initially, and then lazily read
1313  // source-location entries as needed.
1314  SLocEntryCursor = F.Stream;
1315 
1316  // The stream itself is going to skip over the source manager block.
1317  if (llvm::Error Err = F.Stream.SkipBlock()) {
1318  Error(std::move(Err));
1319  return true;
1320  }
1321 
1322  // Enter the source manager block.
1323  if (llvm::Error Err =
1324  SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) {
1325  Error(std::move(Err));
1326  return true;
1327  }
1328 
1329  RecordData Record;
1330  while (true) {
1332  SLocEntryCursor.advanceSkippingSubblocks();
1333  if (!MaybeE) {
1334  Error(MaybeE.takeError());
1335  return true;
1336  }
1337  llvm::BitstreamEntry E = MaybeE.get();
1338 
1339  switch (E.Kind) {
1340  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1342  Error("malformed block record in AST file");
1343  return true;
1344  case llvm::BitstreamEntry::EndBlock:
1345  return false;
1346  case llvm::BitstreamEntry::Record:
1347  // The interesting case.
1348  break;
1349  }
1350 
1351  // Read a record.
1352  Record.clear();
1353  StringRef Blob;
1354  Expected<unsigned> MaybeRecord =
1355  SLocEntryCursor.readRecord(E.ID, Record, &Blob);
1356  if (!MaybeRecord) {
1357  Error(MaybeRecord.takeError());
1358  return true;
1359  }
1360  switch (MaybeRecord.get()) {
1361  default: // Default behavior: ignore.
1362  break;
1363 
1364  case SM_SLOC_FILE_ENTRY:
1365  case SM_SLOC_BUFFER_ENTRY:
1367  // Once we hit one of the source location entries, we're done.
1368  return false;
1369  }
1370  }
1371 }
1372 
1373 /// If a header file is not found at the path that we expect it to be
1374 /// and the PCH file was moved from its original location, try to resolve the
1375 /// file by assuming that header+PCH were moved together and the header is in
1376 /// the same place relative to the PCH.
1377 static std::string
1379  const std::string &OriginalDir,
1380  const std::string &CurrDir) {
1381  assert(OriginalDir != CurrDir &&
1382  "No point trying to resolve the file if the PCH dir didn't change");
1383 
1384  using namespace llvm::sys;
1385 
1386  SmallString<128> filePath(Filename);
1387  fs::make_absolute(filePath);
1388  assert(path::is_absolute(OriginalDir));
1389  SmallString<128> currPCHPath(CurrDir);
1390 
1391  path::const_iterator fileDirI = path::begin(path::parent_path(filePath)),
1392  fileDirE = path::end(path::parent_path(filePath));
1393  path::const_iterator origDirI = path::begin(OriginalDir),
1394  origDirE = path::end(OriginalDir);
1395  // Skip the common path components from filePath and OriginalDir.
1396  while (fileDirI != fileDirE && origDirI != origDirE &&
1397  *fileDirI == *origDirI) {
1398  ++fileDirI;
1399  ++origDirI;
1400  }
1401  for (; origDirI != origDirE; ++origDirI)
1402  path::append(currPCHPath, "..");
1403  path::append(currPCHPath, fileDirI, fileDirE);
1404  path::append(currPCHPath, path::filename(Filename));
1405  return currPCHPath.str();
1406 }
1407 
1409  if (ID == 0)
1410  return false;
1411 
1412  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1413  Error("source location entry ID out-of-range for AST file");
1414  return true;
1415  }
1416 
1417  // Local helper to read the (possibly-compressed) buffer data following the
1418  // entry record.
1419  auto ReadBuffer = [this](
1420  BitstreamCursor &SLocEntryCursor,
1421  StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> {
1422  RecordData Record;
1423  StringRef Blob;
1424  Expected<unsigned> MaybeCode = SLocEntryCursor.ReadCode();
1425  if (!MaybeCode) {
1426  Error(MaybeCode.takeError());
1427  return nullptr;
1428  }
1429  unsigned Code = MaybeCode.get();
1430 
1431  Expected<unsigned> MaybeRecCode =
1432  SLocEntryCursor.readRecord(Code, Record, &Blob);
1433  if (!MaybeRecCode) {
1434  Error(MaybeRecCode.takeError());
1435  return nullptr;
1436  }
1437  unsigned RecCode = MaybeRecCode.get();
1438 
1439  if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
1440  if (!llvm::zlib::isAvailable()) {
1441  Error("zlib is not available");
1442  return nullptr;
1443  }
1444  SmallString<0> Uncompressed;
1445  if (llvm::Error E =
1446  llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) {
1447  Error("could not decompress embedded file contents: " +
1448  llvm::toString(std::move(E)));
1449  return nullptr;
1450  }
1451  return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name);
1452  } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
1453  return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
1454  } else {
1455  Error("AST record has invalid code");
1456  return nullptr;
1457  }
1458  };
1459 
1460  ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
1461  if (llvm::Error Err = F->SLocEntryCursor.JumpToBit(
1462  F->SLocEntryOffsets[ID - F->SLocEntryBaseID])) {
1463  Error(std::move(Err));
1464  return true;
1465  }
1466 
1467  BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
1468  unsigned BaseOffset = F->SLocEntryBaseOffset;
1469 
1470  ++NumSLocEntriesRead;
1471  Expected<llvm::BitstreamEntry> MaybeEntry = SLocEntryCursor.advance();
1472  if (!MaybeEntry) {
1473  Error(MaybeEntry.takeError());
1474  return true;
1475  }
1476  llvm::BitstreamEntry Entry = MaybeEntry.get();
1477 
1478  if (Entry.Kind != llvm::BitstreamEntry::Record) {
1479  Error("incorrectly-formatted source location entry in AST file");
1480  return true;
1481  }
1482 
1483  RecordData Record;
1484  StringRef Blob;
1485  Expected<unsigned> MaybeSLOC =
1486  SLocEntryCursor.readRecord(Entry.ID, Record, &Blob);
1487  if (!MaybeSLOC) {
1488  Error(MaybeSLOC.takeError());
1489  return true;
1490  }
1491  switch (MaybeSLOC.get()) {
1492  default:
1493  Error("incorrectly-formatted source location entry in AST file");
1494  return true;
1495 
1496  case SM_SLOC_FILE_ENTRY: {
1497  // We will detect whether a file changed and return 'Failure' for it, but
1498  // we will also try to fail gracefully by setting up the SLocEntry.
1499  unsigned InputID = Record[4];
1500  InputFile IF = getInputFile(*F, InputID);
1501  const FileEntry *File = IF.getFile();
1502  bool OverriddenBuffer = IF.isOverridden();
1503 
1504  // Note that we only check if a File was returned. If it was out-of-date
1505  // we have complained but we will continue creating a FileID to recover
1506  // gracefully.
1507  if (!File)
1508  return true;
1509 
1510  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1511  if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) {
1512  // This is the module's main file.
1513  IncludeLoc = getImportLocation(F);
1514  }
1516  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1517  FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter,
1518  ID, BaseOffset + Record[0]);
1519  SrcMgr::FileInfo &FileInfo =
1520  const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
1521  FileInfo.NumCreatedFIDs = Record[5];
1522  if (Record[3])
1523  FileInfo.setHasLineDirectives();
1524 
1525  const DeclID *FirstDecl = F->FileSortedDecls + Record[6];
1526  unsigned NumFileDecls = Record[7];
1527  if (NumFileDecls && ContextObj) {
1528  assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?");
1529  FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl,
1530  NumFileDecls));
1531  }
1532 
1533  const SrcMgr::ContentCache *ContentCache
1534  = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
1535  if (OverriddenBuffer && !ContentCache->BufferOverridden &&
1536  ContentCache->ContentsEntry == ContentCache->OrigEntry &&
1537  !ContentCache->getRawBuffer()) {
1538  auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
1539  if (!Buffer)
1540  return true;
1541  SourceMgr.overrideFileContents(File, std::move(Buffer));
1542  }
1543 
1544  break;
1545  }
1546 
1547  case SM_SLOC_BUFFER_ENTRY: {
1548  const char *Name = Blob.data();
1549  unsigned Offset = Record[0];
1551  FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
1552  SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
1553  if (IncludeLoc.isInvalid() && F->isModule()) {
1554  IncludeLoc = getImportLocation(F);
1555  }
1556 
1557  auto Buffer = ReadBuffer(SLocEntryCursor, Name);
1558  if (!Buffer)
1559  return true;
1560  SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
1561  BaseOffset + Offset, IncludeLoc);
1562  break;
1563  }
1564 
1565  case SM_SLOC_EXPANSION_ENTRY: {
1566  SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]);
1567  SourceMgr.createExpansionLoc(SpellingLoc,
1568  ReadSourceLocation(*F, Record[2]),
1569  ReadSourceLocation(*F, Record[3]),
1570  Record[5],
1571  Record[4],
1572  ID,
1573  BaseOffset + Record[0]);
1574  break;
1575  }
1576  }
1577 
1578  return false;
1579 }
1580 
1581 std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) {
1582  if (ID == 0)
1583  return std::make_pair(SourceLocation(), "");
1584 
1585  if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) {
1586  Error("source location entry ID out-of-range for AST file");
1587  return std::make_pair(SourceLocation(), "");
1588  }
1589 
1590  // Find which module file this entry lands in.
1591  ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second;
1592  if (!M->isModule())
1593  return std::make_pair(SourceLocation(), "");
1594 
1595  // FIXME: Can we map this down to a particular submodule? That would be
1596  // ideal.
1597  return std::make_pair(M->ImportLoc, StringRef(M->ModuleName));
1598 }
1599 
1600 /// Find the location where the module F is imported.
1601 SourceLocation ASTReader::getImportLocation(ModuleFile *F) {
1602  if (F->ImportLoc.isValid())
1603  return F->ImportLoc;
1604 
1605  // Otherwise we have a PCH. It's considered to be "imported" at the first
1606  // location of its includer.
1607  if (F->ImportedBy.empty() || !F->ImportedBy[0]) {
1608  // Main file is the importer.
1609  assert(SourceMgr.getMainFileID().isValid() && "missing main file");
1610  return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
1611  }
1612  return F->ImportedBy[0]->FirstLoc;
1613 }
1614 
1615 /// Enter a subblock of the specified BlockID with the specified cursor. Read
1616 /// the abbreviations that are at the top of the block and then leave the cursor
1617 /// pointing into the block.
1618 bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) {
1619  if (llvm::Error Err = Cursor.EnterSubBlock(BlockID)) {
1620  // FIXME this drops errors on the floor.
1621  consumeError(std::move(Err));
1622  return true;
1623  }
1624 
1625  while (true) {
1626  uint64_t Offset = Cursor.GetCurrentBitNo();
1627  Expected<unsigned> MaybeCode = Cursor.ReadCode();
1628  if (!MaybeCode) {
1629  // FIXME this drops errors on the floor.
1630  consumeError(MaybeCode.takeError());
1631  return true;
1632  }
1633  unsigned Code = MaybeCode.get();
1634 
1635  // We expect all abbrevs to be at the start of the block.
1636  if (Code != llvm::bitc::DEFINE_ABBREV) {
1637  if (llvm::Error Err = Cursor.JumpToBit(Offset)) {
1638  // FIXME this drops errors on the floor.
1639  consumeError(std::move(Err));
1640  return true;
1641  }
1642  return false;
1643  }
1644  if (llvm::Error Err = Cursor.ReadAbbrevRecord()) {
1645  // FIXME this drops errors on the floor.
1646  consumeError(std::move(Err));
1647  return true;
1648  }
1649  }
1650 }
1651 
1653  unsigned &Idx) {
1654  Token Tok;
1655  Tok.startToken();
1656  Tok.setLocation(ReadSourceLocation(F, Record, Idx));
1657  Tok.setLength(Record[Idx++]);
1658  if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++]))
1659  Tok.setIdentifierInfo(II);
1660  Tok.setKind((tok::TokenKind)Record[Idx++]);
1661  Tok.setFlag((Token::TokenFlags)Record[Idx++]);
1662  return Tok;
1663 }
1664 
1666  BitstreamCursor &Stream = F.MacroCursor;
1667 
1668  // Keep track of where we are in the stream, then jump back there
1669  // after reading this macro.
1670  SavedStreamPosition SavedPosition(Stream);
1671 
1672  if (llvm::Error Err = Stream.JumpToBit(Offset)) {
1673  // FIXME this drops errors on the floor.
1674  consumeError(std::move(Err));
1675  return nullptr;
1676  }
1677  RecordData Record;
1679  MacroInfo *Macro = nullptr;
1680 
1681  while (true) {
1682  // Advance to the next record, but if we get to the end of the block, don't
1683  // pop it (removing all the abbreviations from the cursor) since we want to
1684  // be able to reseek within the block and read entries.
1685  unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd;
1686  Expected<llvm::BitstreamEntry> MaybeEntry =
1687  Stream.advanceSkippingSubblocks(Flags);
1688  if (!MaybeEntry) {
1689  Error(MaybeEntry.takeError());
1690  return Macro;
1691  }
1692  llvm::BitstreamEntry Entry = MaybeEntry.get();
1693 
1694  switch (Entry.Kind) {
1695  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1697  Error("malformed block record in AST file");
1698  return Macro;
1699  case llvm::BitstreamEntry::EndBlock:
1700  return Macro;
1701  case llvm::BitstreamEntry::Record:
1702  // The interesting case.
1703  break;
1704  }
1705 
1706  // Read a record.
1707  Record.clear();
1708  PreprocessorRecordTypes RecType;
1709  if (Expected<unsigned> MaybeRecType = Stream.readRecord(Entry.ID, Record))
1710  RecType = (PreprocessorRecordTypes)MaybeRecType.get();
1711  else {
1712  Error(MaybeRecType.takeError());
1713  return Macro;
1714  }
1715  switch (RecType) {
1716  case PP_MODULE_MACRO:
1718  return Macro;
1719 
1720  case PP_MACRO_OBJECT_LIKE:
1721  case PP_MACRO_FUNCTION_LIKE: {
1722  // If we already have a macro, that means that we've hit the end
1723  // of the definition of the macro we were looking for. We're
1724  // done.
1725  if (Macro)
1726  return Macro;
1727 
1728  unsigned NextIndex = 1; // Skip identifier ID.
1729  SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
1730  MacroInfo *MI = PP.AllocateMacroInfo(Loc);
1731  MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
1732  MI->setIsUsed(Record[NextIndex++]);
1733  MI->setUsedForHeaderGuard(Record[NextIndex++]);
1734 
1735  if (RecType == PP_MACRO_FUNCTION_LIKE) {
1736  // Decode function-like macro info.
1737  bool isC99VarArgs = Record[NextIndex++];
1738  bool isGNUVarArgs = Record[NextIndex++];
1739  bool hasCommaPasting = Record[NextIndex++];
1740  MacroParams.clear();
1741  unsigned NumArgs = Record[NextIndex++];
1742  for (unsigned i = 0; i != NumArgs; ++i)
1743  MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++]));
1744 
1745  // Install function-like macro info.
1746  MI->setIsFunctionLike();
1747  if (isC99VarArgs) MI->setIsC99Varargs();
1748  if (isGNUVarArgs) MI->setIsGNUVarargs();
1749  if (hasCommaPasting) MI->setHasCommaPasting();
1750  MI->setParameterList(MacroParams, PP.getPreprocessorAllocator());
1751  }
1752 
1753  // Remember that we saw this macro last so that we add the tokens that
1754  // form its body to it.
1755  Macro = MI;
1756 
1757  if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() &&
1758  Record[NextIndex]) {
1759  // We have a macro definition. Register the association
1761  GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]);
1762  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
1763  PreprocessingRecord::PPEntityID PPID =
1764  PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true);
1765  MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>(
1766  PPRec.getPreprocessedEntity(PPID));
1767  if (PPDef)
1768  PPRec.RegisterMacroDefinition(Macro, PPDef);
1769  }
1770 
1771  ++NumMacrosRead;
1772  break;
1773  }
1774 
1775  case PP_TOKEN: {
1776  // If we see a TOKEN before a PP_MACRO_*, then the file is
1777  // erroneous, just pretend we didn't see this.
1778  if (!Macro) break;
1779 
1780  unsigned Idx = 0;
1781  Token Tok = ReadToken(F, Record, Idx);
1782  Macro->AddTokenToBody(Tok);
1783  break;
1784  }
1785  }
1786  }
1787 }
1788 
1791  unsigned LocalID) const {
1792  if (!M.ModuleOffsetMap.empty())
1793  ReadModuleOffsetMap(M);
1794 
1797  assert(I != M.PreprocessedEntityRemap.end()
1798  && "Invalid index into preprocessed entity index remap");
1799 
1800  return LocalID + I->second;
1801 }
1802 
1804  return llvm::hash_combine(ikey.Size, ikey.ModTime);
1805 }
1806 
1808 HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) {
1809  internal_key_type ikey = {FE->getSize(),
1810  M.HasTimestamps ? FE->getModificationTime() : 0,
1811  FE->getName(), /*Imported*/ false};
1812  return ikey;
1813 }
1814 
1815 bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
1816  if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime))
1817  return false;
1818 
1819  if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename)
1820  return true;
1821 
1822  // Determine whether the actual files are equivalent.
1823  FileManager &FileMgr = Reader.getFileManager();
1824  auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* {
1825  if (!Key.Imported)
1826  return FileMgr.getFile(Key.Filename);
1827 
1828  std::string Resolved = Key.Filename;
1829  Reader.ResolveImportedPath(M, Resolved);
1830  return FileMgr.getFile(Resolved);
1831  };
1832 
1833  const FileEntry *FEA = GetFile(a);
1834  const FileEntry *FEB = GetFile(b);
1835  return FEA && FEA == FEB;
1836 }
1837 
1838 std::pair<unsigned, unsigned>
1839 HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) {
1840  using namespace llvm::support;
1841 
1842  unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d);
1843  unsigned DataLen = (unsigned) *d++;
1844  return std::make_pair(KeyLen, DataLen);
1845 }
1846 
1848 HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) {
1849  using namespace llvm::support;
1850 
1851  internal_key_type ikey;
1852  ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d));
1853  ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d));
1854  ikey.Filename = (const char *)d;
1855  ikey.Imported = true;
1856  return ikey;
1857 }
1858 
1860 HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
1861  unsigned DataLen) {
1862  using namespace llvm::support;
1863 
1864  const unsigned char *End = d + DataLen;
1865  HeaderFileInfo HFI;
1866  unsigned Flags = *d++;
1867  // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
1868  HFI.isImport |= (Flags >> 5) & 0x01;
1869  HFI.isPragmaOnce |= (Flags >> 4) & 0x01;
1870  HFI.DirInfo = (Flags >> 1) & 0x07;
1871  HFI.IndexHeaderMapHeader = Flags & 0x01;
1872  // FIXME: Find a better way to handle this. Maybe just store a
1873  // "has been included" flag?
1874  HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d),
1875  HFI.NumIncludes);
1876  HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
1877  M, endian::readNext<uint32_t, little, unaligned>(d));
1878  if (unsigned FrameworkOffset =
1879  endian::readNext<uint32_t, little, unaligned>(d)) {
1880  // The framework offset is 1 greater than the actual offset,
1881  // since 0 is used as an indicator for "no framework name".
1882  StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1);
1883  HFI.Framework = HS->getUniqueFrameworkName(FrameworkName);
1884  }
1885 
1886  assert((End - d) % 4 == 0 &&
1887  "Wrong data length in HeaderFileInfo deserialization");
1888  while (d != End) {
1889  uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d);
1890  auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3);
1891  LocalSMID >>= 2;
1892 
1893  // This header is part of a module. Associate it with the module to enable
1894  // implicit module import.
1895  SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
1896  Module *Mod = Reader.getSubmodule(GlobalSMID);
1897  FileManager &FileMgr = Reader.getFileManager();
1898  ModuleMap &ModMap =
1899  Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
1900 
1901  std::string Filename = key.Filename;
1902  if (key.Imported)
1903  Reader.ResolveImportedPath(M, Filename);
1904  // FIXME: This is not always the right filename-as-written, but we're not
1905  // going to use this information to rebuild the module, so it doesn't make
1906  // a lot of difference.
1907  Module::Header H = { key.Filename, FileMgr.getFile(Filename) };
1908  ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
1909  HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
1910  }
1911 
1912  // This HeaderFileInfo was externally loaded.
1913  HFI.External = true;
1914  HFI.IsValid = true;
1915  return HFI;
1916 }
1917 
1919  ModuleFile *M,
1920  uint64_t MacroDirectivesOffset) {
1921  assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
1922  PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset));
1923 }
1924 
1926  // Note that we are loading defined macros.
1927  Deserializing Macros(this);
1928 
1929  for (ModuleFile &I : llvm::reverse(ModuleMgr)) {
1930  BitstreamCursor &MacroCursor = I.MacroCursor;
1931 
1932  // If there was no preprocessor block, skip this file.
1933  if (MacroCursor.getBitcodeBytes().empty())
1934  continue;
1935 
1936  BitstreamCursor Cursor = MacroCursor;
1937  if (llvm::Error Err = Cursor.JumpToBit(I.MacroStartOffset)) {
1938  Error(std::move(Err));
1939  return;
1940  }
1941 
1942  RecordData Record;
1943  while (true) {
1944  Expected<llvm::BitstreamEntry> MaybeE = Cursor.advanceSkippingSubblocks();
1945  if (!MaybeE) {
1946  Error(MaybeE.takeError());
1947  return;
1948  }
1949  llvm::BitstreamEntry E = MaybeE.get();
1950 
1951  switch (E.Kind) {
1952  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
1954  Error("malformed block record in AST file");
1955  return;
1956  case llvm::BitstreamEntry::EndBlock:
1957  goto NextCursor;
1958 
1959  case llvm::BitstreamEntry::Record: {
1960  Record.clear();
1961  Expected<unsigned> MaybeRecord = Cursor.readRecord(E.ID, Record);
1962  if (!MaybeRecord) {
1963  Error(MaybeRecord.takeError());
1964  return;
1965  }
1966  switch (MaybeRecord.get()) {
1967  default: // Default behavior: ignore.
1968  break;
1969 
1970  case PP_MACRO_OBJECT_LIKE:
1971  case PP_MACRO_FUNCTION_LIKE: {
1972  IdentifierInfo *II = getLocalIdentifier(I, Record[0]);
1973  if (II->isOutOfDate())
1974  updateOutOfDateIdentifier(*II);
1975  break;
1976  }
1977 
1978  case PP_TOKEN:
1979  // Ignore tokens.
1980  break;
1981  }
1982  break;
1983  }
1984  }
1985  }
1986  NextCursor: ;
1987  }
1988 }
1989 
1990 namespace {
1991 
1992  /// Visitor class used to look up identifirs in an AST file.
1993  class IdentifierLookupVisitor {
1994  StringRef Name;
1995  unsigned NameHash;
1996  unsigned PriorGeneration;
1997  unsigned &NumIdentifierLookups;
1998  unsigned &NumIdentifierLookupHits;
1999  IdentifierInfo *Found = nullptr;
2000 
2001  public:
2002  IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration,
2003  unsigned &NumIdentifierLookups,
2004  unsigned &NumIdentifierLookupHits)
2005  : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)),
2006  PriorGeneration(PriorGeneration),
2007  NumIdentifierLookups(NumIdentifierLookups),
2008  NumIdentifierLookupHits(NumIdentifierLookupHits) {}
2009 
2010  bool operator()(ModuleFile &M) {
2011  // If we've already searched this module file, skip it now.
2012  if (M.Generation <= PriorGeneration)
2013  return true;
2014 
2015  ASTIdentifierLookupTable *IdTable
2017  if (!IdTable)
2018  return false;
2019 
2020  ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M,
2021  Found);
2022  ++NumIdentifierLookups;
2023  ASTIdentifierLookupTable::iterator Pos =
2024  IdTable->find_hashed(Name, NameHash, &Trait);
2025  if (Pos == IdTable->end())
2026  return false;
2027 
2028  // Dereferencing the iterator has the effect of building the
2029  // IdentifierInfo node and populating it with the various
2030  // declarations it needs.
2031  ++NumIdentifierLookupHits;
2032  Found = *Pos;
2033  return true;
2034  }
2035 
2036  // Retrieve the identifier info found within the module
2037  // files.
2038  IdentifierInfo *getIdentifierInfo() const { return Found; }
2039  };
2040 
2041 } // namespace
2042 
2044  // Note that we are loading an identifier.
2045  Deserializing AnIdentifier(this);
2046 
2047  unsigned PriorGeneration = 0;
2048  if (getContext().getLangOpts().Modules)
2049  PriorGeneration = IdentifierGeneration[&II];
2050 
2051  // If there is a global index, look there first to determine which modules
2052  // provably do not have any results for this identifier.
2054  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
2055  if (!loadGlobalIndex()) {
2056  if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) {
2057  HitsPtr = &Hits;
2058  }
2059  }
2060 
2061  IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration,
2062  NumIdentifierLookups,
2063  NumIdentifierLookupHits);
2064  ModuleMgr.visit(Visitor, HitsPtr);
2065  markIdentifierUpToDate(&II);
2066 }
2067 
2069  if (!II)
2070  return;
2071 
2072  II->setOutOfDate(false);
2073 
2074  // Update the generation for this identifier.
2075  if (getContext().getLangOpts().Modules)
2076  IdentifierGeneration[II] = getGeneration();
2077 }
2078 
2080  const PendingMacroInfo &PMInfo) {
2081  ModuleFile &M = *PMInfo.M;
2082 
2083  BitstreamCursor &Cursor = M.MacroCursor;
2084  SavedStreamPosition SavedPosition(Cursor);
2085  if (llvm::Error Err = Cursor.JumpToBit(PMInfo.MacroDirectivesOffset)) {
2086  Error(std::move(Err));
2087  return;
2088  }
2089 
2090  struct ModuleMacroRecord {
2091  SubmoduleID SubModID;
2092  MacroInfo *MI;
2093  SmallVector<SubmoduleID, 8> Overrides;
2094  };
2096 
2097  // We expect to see a sequence of PP_MODULE_MACRO records listing exported
2098  // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete
2099  // macro histroy.
2100  RecordData Record;
2101  while (true) {
2102  Expected<llvm::BitstreamEntry> MaybeEntry =
2103  Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
2104  if (!MaybeEntry) {
2105  Error(MaybeEntry.takeError());
2106  return;
2107  }
2108  llvm::BitstreamEntry Entry = MaybeEntry.get();
2109 
2110  if (Entry.Kind != llvm::BitstreamEntry::Record) {
2111  Error("malformed block record in AST file");
2112  return;
2113  }
2114 
2115  Record.clear();
2116  Expected<unsigned> MaybePP = Cursor.readRecord(Entry.ID, Record);
2117  if (!MaybePP) {
2118  Error(MaybePP.takeError());
2119  return;
2120  }
2121  switch ((PreprocessorRecordTypes)MaybePP.get()) {
2123  break;
2124 
2125  case PP_MODULE_MACRO: {
2126  ModuleMacros.push_back(ModuleMacroRecord());
2127  auto &Info = ModuleMacros.back();
2128  Info.SubModID = getGlobalSubmoduleID(M, Record[0]);
2129  Info.MI = getMacro(getGlobalMacroID(M, Record[1]));
2130  for (int I = 2, N = Record.size(); I != N; ++I)
2131  Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I]));
2132  continue;
2133  }
2134 
2135  default:
2136  Error("malformed block record in AST file");
2137  return;
2138  }
2139 
2140  // We found the macro directive history; that's the last record
2141  // for this macro.
2142  break;
2143  }
2144 
2145  // Module macros are listed in reverse dependency order.
2146  {
2147  std::reverse(ModuleMacros.begin(), ModuleMacros.end());
2149  for (auto &MMR : ModuleMacros) {
2150  Overrides.clear();
2151  for (unsigned ModID : MMR.Overrides) {
2152  Module *Mod = getSubmodule(ModID);
2153  auto *Macro = PP.getModuleMacro(Mod, II);
2154  assert(Macro && "missing definition for overridden macro");
2155  Overrides.push_back(Macro);
2156  }
2157 
2158  bool Inserted = false;
2159  Module *Owner = getSubmodule(MMR.SubModID);
2160  PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted);
2161  }
2162  }
2163 
2164  // Don't read the directive history for a module; we don't have anywhere
2165  // to put it.
2166  if (M.isModule())
2167  return;
2168 
2169  // Deserialize the macro directives history in reverse source-order.
2170  MacroDirective *Latest = nullptr, *Earliest = nullptr;
2171  unsigned Idx = 0, N = Record.size();
2172  while (Idx < N) {
2173  MacroDirective *MD = nullptr;
2174  SourceLocation Loc = ReadSourceLocation(M, Record, Idx);
2175  MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++];
2176  switch (K) {
2178  MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++]));
2179  MD = PP.AllocateDefMacroDirective(MI, Loc);
2180  break;
2181  }
2183  MD = PP.AllocateUndefMacroDirective(Loc);
2184  break;
2186  bool isPublic = Record[Idx++];
2187  MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic);
2188  break;
2189  }
2190 
2191  if (!Latest)
2192  Latest = MD;
2193  if (Earliest)
2194  Earliest->setPrevious(MD);
2195  Earliest = MD;
2196  }
2197 
2198  if (Latest)
2199  PP.setLoadedMacroDirective(II, Earliest, Latest);
2200 }
2201 
2202 ASTReader::InputFileInfo
2203 ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
2204  // Go find this input file.
2205  BitstreamCursor &Cursor = F.InputFilesCursor;
2206  SavedStreamPosition SavedPosition(Cursor);
2207  if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) {
2208  // FIXME this drops errors on the floor.
2209  consumeError(std::move(Err));
2210  }
2211 
2212  Expected<unsigned> MaybeCode = Cursor.ReadCode();
2213  if (!MaybeCode) {
2214  // FIXME this drops errors on the floor.
2215  consumeError(MaybeCode.takeError());
2216  }
2217  unsigned Code = MaybeCode.get();
2218  RecordData Record;
2219  StringRef Blob;
2220 
2221  if (Expected<unsigned> Maybe = Cursor.readRecord(Code, Record, &Blob))
2222  assert(static_cast<InputFileRecordTypes>(Maybe.get()) == INPUT_FILE &&
2223  "invalid record type for input file");
2224  else {
2225  // FIXME this drops errors on the floor.
2226  consumeError(Maybe.takeError());
2227  }
2228 
2229  assert(Record[0] == ID && "Bogus stored ID or offset");
2230  InputFileInfo R;
2231  R.StoredSize = static_cast<off_t>(Record[1]);
2232  R.StoredTime = static_cast<time_t>(Record[2]);
2233  R.Overridden = static_cast<bool>(Record[3]);
2234  R.Transient = static_cast<bool>(Record[4]);
2235  R.TopLevelModuleMap = static_cast<bool>(Record[5]);
2236  R.Filename = Blob;
2237  ResolveImportedPath(F, R.Filename);
2238  return R;
2239 }
2240 
2241 static unsigned moduleKindForDiagnostic(ModuleKind Kind);
2242 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
2243  // If this ID is bogus, just return an empty input file.
2244  if (ID == 0 || ID > F.InputFilesLoaded.size())
2245  return InputFile();
2246 
2247  // If we've already loaded this input file, return it.
2248  if (F.InputFilesLoaded[ID-1].getFile())
2249  return F.InputFilesLoaded[ID-1];
2250 
2251  if (F.InputFilesLoaded[ID-1].isNotFound())
2252  return InputFile();
2253 
2254  // Go find this input file.
2255  BitstreamCursor &Cursor = F.InputFilesCursor;
2256  SavedStreamPosition SavedPosition(Cursor);
2257  if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) {
2258  // FIXME this drops errors on the floor.
2259  consumeError(std::move(Err));
2260  }
2261 
2262  InputFileInfo FI = readInputFileInfo(F, ID);
2263  off_t StoredSize = FI.StoredSize;
2264  time_t StoredTime = FI.StoredTime;
2265  bool Overridden = FI.Overridden;
2266  bool Transient = FI.Transient;
2267  StringRef Filename = FI.Filename;
2268 
2269  const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false);
2270  // If we didn't find the file, resolve it relative to the
2271  // original directory from which this AST file was created.
2272  if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
2273  F.OriginalDir != F.BaseDirectory) {
2274  std::string Resolved = resolveFileRelativeToOriginalDir(
2275  Filename, F.OriginalDir, F.BaseDirectory);
2276  if (!Resolved.empty())
2277  File = FileMgr.getFile(Resolved);
2278  }
2279 
2280  // For an overridden file, create a virtual file with the stored
2281  // size/timestamp.
2282  if ((Overridden || Transient) && File == nullptr)
2283  File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime);
2284 
2285  if (File == nullptr) {
2286  if (Complain) {
2287  std::string ErrorStr = "could not find file '";
2288  ErrorStr += Filename;
2289  ErrorStr += "' referenced by AST file '";
2290  ErrorStr += F.FileName;
2291  ErrorStr += "'";
2292  Error(ErrorStr);
2293  }
2294  // Record that we didn't find the file.
2296  return InputFile();
2297  }
2298 
2299  // Check if there was a request to override the contents of the file
2300  // that was part of the precompiled header. Overriding such a file
2301  // can lead to problems when lexing using the source locations from the
2302  // PCH.
2303  SourceManager &SM = getSourceManager();
2304  // FIXME: Reject if the overrides are different.
2305  if ((!Overridden && !Transient) && SM.isFileOverridden(File)) {
2306  if (Complain)
2307  Error(diag::err_fe_pch_file_overridden, Filename);
2308  // After emitting the diagnostic, recover by disabling the override so
2309  // that the original file will be used.
2310  //
2311  // FIXME: This recovery is just as broken as the original state; there may
2312  // be another precompiled module that's using the overridden contents, or
2313  // we might be half way through parsing it. Instead, we should treat the
2314  // overridden contents as belonging to a separate FileEntry.
2315  SM.disableFileContentsOverride(File);
2316  // The FileEntry is a virtual file entry with the size of the contents
2317  // that would override the original contents. Set it to the original's
2318  // size/time.
2319  FileMgr.modifyFileEntry(const_cast<FileEntry*>(File),
2320  StoredSize, StoredTime);
2321  }
2322 
2323  bool IsOutOfDate = false;
2324 
2325  // For an overridden file, there is nothing to validate.
2326  if (!Overridden && //
2327  (StoredSize != File->getSize() ||
2328  (StoredTime && StoredTime != File->getModificationTime() &&
2329  !DisableValidation)
2330  )) {
2331  if (Complain) {
2332  // Build a list of the PCH imports that got us here (in reverse).
2333  SmallVector<ModuleFile *, 4> ImportStack(1, &F);
2334  while (!ImportStack.back()->ImportedBy.empty())
2335  ImportStack.push_back(ImportStack.back()->ImportedBy[0]);
2336 
2337  // The top-level PCH is stale.
2338  StringRef TopLevelPCHName(ImportStack.back()->FileName);
2339  unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
2340  if (DiagnosticKind == 0)
2341  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
2342  else if (DiagnosticKind == 1)
2343  Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
2344  else
2345  Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
2346 
2347  // Print the import stack.
2348  if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
2349  Diag(diag::note_pch_required_by)
2350  << Filename << ImportStack[0]->FileName;
2351  for (unsigned I = 1; I < ImportStack.size(); ++I)
2352  Diag(diag::note_pch_required_by)
2353  << ImportStack[I-1]->FileName << ImportStack[I]->FileName;
2354  }
2355 
2356  if (!Diags.isDiagnosticInFlight())
2357  Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
2358  }
2359 
2360  IsOutOfDate = true;
2361  }
2362  // FIXME: If the file is overridden and we've already opened it,
2363  // issue an error (or split it into a separate FileEntry).
2364 
2365  InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate);
2366 
2367  // Note that we've loaded this input file.
2368  F.InputFilesLoaded[ID-1] = IF;
2369  return IF;
2370 }
2371 
2372 /// If we are loading a relocatable PCH or module file, and the filename
2373 /// is not an absolute path, add the system or module root to the beginning of
2374 /// the file name.
2376  // Resolve relative to the base directory, if we have one.
2377  if (!M.BaseDirectory.empty())
2378  return ResolveImportedPath(Filename, M.BaseDirectory);
2379 }
2380 
2381 void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) {
2382  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
2383  return;
2384 
2385  SmallString<128> Buffer;
2386  llvm::sys::path::append(Buffer, Prefix, Filename);
2387  Filename.assign(Buffer.begin(), Buffer.end());
2388 }
2389 
2390 static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) {
2391  switch (ARR) {
2392  case ASTReader::Failure: return true;
2393  case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing);
2394  case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate);
2397  return !(Caps & ASTReader::ARR_ConfigurationMismatch);
2398  case ASTReader::HadErrors: return true;
2399  case ASTReader::Success: return false;
2400  }
2401 
2402  llvm_unreachable("unknown ASTReadResult");
2403 }
2404 
2405 ASTReader::ASTReadResult ASTReader::ReadOptionsBlock(
2406  BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
2407  bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
2408  std::string &SuggestedPredefines) {
2409  if (llvm::Error Err = Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) {
2410  // FIXME this drops errors on the floor.
2411  consumeError(std::move(Err));
2412  return Failure;
2413  }
2414 
2415  // Read all of the records in the options block.
2416  RecordData Record;
2417  ASTReadResult Result = Success;
2418  while (true) {
2419  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
2420  if (!MaybeEntry) {
2421  // FIXME this drops errors on the floor.
2422  consumeError(MaybeEntry.takeError());
2423  return Failure;
2424  }
2425  llvm::BitstreamEntry Entry = MaybeEntry.get();
2426 
2427  switch (Entry.Kind) {
2429  case llvm::BitstreamEntry::SubBlock:
2430  return Failure;
2431 
2432  case llvm::BitstreamEntry::EndBlock:
2433  return Result;
2434 
2435  case llvm::BitstreamEntry::Record:
2436  // The interesting case.
2437  break;
2438  }
2439 
2440  // Read and process a record.
2441  Record.clear();
2442  Expected<unsigned> MaybeRecordType = Stream.readRecord(Entry.ID, Record);
2443  if (!MaybeRecordType) {
2444  // FIXME this drops errors on the floor.
2445  consumeError(MaybeRecordType.takeError());
2446  return Failure;
2447  }
2448  switch ((OptionsRecordTypes)MaybeRecordType.get()) {
2449  case LANGUAGE_OPTIONS: {
2450  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2451  if (ParseLanguageOptions(Record, Complain, Listener,
2452  AllowCompatibleConfigurationMismatch))
2453  Result = ConfigurationMismatch;
2454  break;
2455  }
2456 
2457  case TARGET_OPTIONS: {
2458  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2459  if (ParseTargetOptions(Record, Complain, Listener,
2460  AllowCompatibleConfigurationMismatch))
2461  Result = ConfigurationMismatch;
2462  break;
2463  }
2464 
2465  case FILE_SYSTEM_OPTIONS: {
2466  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2467  if (!AllowCompatibleConfigurationMismatch &&
2468  ParseFileSystemOptions(Record, Complain, Listener))
2469  Result = ConfigurationMismatch;
2470  break;
2471  }
2472 
2473  case HEADER_SEARCH_OPTIONS: {
2474  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2475  if (!AllowCompatibleConfigurationMismatch &&
2476  ParseHeaderSearchOptions(Record, Complain, Listener))
2477  Result = ConfigurationMismatch;
2478  break;
2479  }
2480 
2481  case PREPROCESSOR_OPTIONS:
2482  bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2483  if (!AllowCompatibleConfigurationMismatch &&
2484  ParsePreprocessorOptions(Record, Complain, Listener,
2485  SuggestedPredefines))
2486  Result = ConfigurationMismatch;
2487  break;
2488  }
2489  }
2490 }
2491 
2493 ASTReader::ReadControlBlock(ModuleFile &F,
2495  const ModuleFile *ImportedBy,
2496  unsigned ClientLoadCapabilities) {
2497  BitstreamCursor &Stream = F.Stream;
2498  ASTReadResult Result = Success;
2499 
2500  if (llvm::Error Err = Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
2501  Error(std::move(Err));
2502  return Failure;
2503  }
2504 
2505  // Lambda to read the unhashed control block the first time it's called.
2506  //
2507  // For PCM files, the unhashed control block cannot be read until after the
2508  // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still
2509  // need to look ahead before reading the IMPORTS record. For consistency,
2510  // this block is always read somehow (see BitstreamEntry::EndBlock).
2511  bool HasReadUnhashedControlBlock = false;
2512  auto readUnhashedControlBlockOnce = [&]() {
2513  if (!HasReadUnhashedControlBlock) {
2514  HasReadUnhashedControlBlock = true;
2515  if (ASTReadResult Result =
2516  readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities))
2517  return Result;
2518  }
2519  return Success;
2520  };
2521 
2522  // Read all of the records and blocks in the control block.
2523  RecordData Record;
2524  unsigned NumInputs = 0;
2525  unsigned NumUserInputs = 0;
2526  StringRef BaseDirectoryAsWritten;
2527  while (true) {
2528  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
2529  if (!MaybeEntry) {
2530  Error(MaybeEntry.takeError());
2531  return Failure;
2532  }
2533  llvm::BitstreamEntry Entry = MaybeEntry.get();
2534 
2535  switch (Entry.Kind) {
2537  Error("malformed block record in AST file");
2538  return Failure;
2539  case llvm::BitstreamEntry::EndBlock: {
2540  // Validate the module before returning. This call catches an AST with
2541  // no module name and no imports.
2542  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2543  return Result;
2544 
2545  // Validate input files.
2546  const HeaderSearchOptions &HSOpts =
2547  PP.getHeaderSearchInfo().getHeaderSearchOpts();
2548 
2549  // All user input files reside at the index range [0, NumUserInputs), and
2550  // system input files reside at [NumUserInputs, NumInputs). For explicitly
2551  // loaded module files, ignore missing inputs.
2552  if (!DisableValidation && F.Kind != MK_ExplicitModule &&
2553  F.Kind != MK_PrebuiltModule) {
2554  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
2555 
2556  // If we are reading a module, we will create a verification timestamp,
2557  // so we verify all input files. Otherwise, verify only user input
2558  // files.
2559 
2560  unsigned N = NumUserInputs;
2561  if (ValidateSystemInputs ||
2564  F.Kind == MK_ImplicitModule))
2565  N = NumInputs;
2566 
2567  for (unsigned I = 0; I < N; ++I) {
2568  InputFile IF = getInputFile(F, I+1, Complain);
2569  if (!IF.getFile() || IF.isOutOfDate())
2570  return OutOfDate;
2571  }
2572  }
2573 
2574  if (Listener)
2575  Listener->visitModuleFile(F.FileName, F.Kind);
2576 
2577  if (Listener && Listener->needsInputFileVisitation()) {
2578  unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs
2579  : NumUserInputs;
2580  for (unsigned I = 0; I < N; ++I) {
2581  bool IsSystem = I >= NumUserInputs;
2582  InputFileInfo FI = readInputFileInfo(F, I+1);
2583  Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden,
2584  F.Kind == MK_ExplicitModule ||
2585  F.Kind == MK_PrebuiltModule);
2586  }
2587  }
2588 
2589  return Result;
2590  }
2591 
2592  case llvm::BitstreamEntry::SubBlock:
2593  switch (Entry.ID) {
2594  case INPUT_FILES_BLOCK_ID:
2595  F.InputFilesCursor = Stream;
2596  if (llvm::Error Err = Stream.SkipBlock()) {
2597  Error(std::move(Err));
2598  return Failure;
2599  }
2600  if (ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) {
2601  Error("malformed block record in AST file");
2602  return Failure;
2603  }
2604  continue;
2605 
2606  case OPTIONS_BLOCK_ID:
2607  // If we're reading the first module for this group, check its options
2608  // are compatible with ours. For modules it imports, no further checking
2609  // is required, because we checked them when we built it.
2610  if (Listener && !ImportedBy) {
2611  // Should we allow the configuration of the module file to differ from
2612  // the configuration of the current translation unit in a compatible
2613  // way?
2614  //
2615  // FIXME: Allow this for files explicitly specified with -include-pch.
2616  bool AllowCompatibleConfigurationMismatch =
2618 
2619  Result = ReadOptionsBlock(Stream, ClientLoadCapabilities,
2620  AllowCompatibleConfigurationMismatch,
2621  *Listener, SuggestedPredefines);
2622  if (Result == Failure) {
2623  Error("malformed block record in AST file");
2624  return Result;
2625  }
2626 
2627  if (DisableValidation ||
2628  (AllowConfigurationMismatch && Result == ConfigurationMismatch))
2629  Result = Success;
2630 
2631  // If we can't load the module, exit early since we likely
2632  // will rebuild the module anyway. The stream may be in the
2633  // middle of a block.
2634  if (Result != Success)
2635  return Result;
2636  } else if (llvm::Error Err = Stream.SkipBlock()) {
2637  Error(std::move(Err));
2638  return Failure;
2639  }
2640  continue;
2641 
2642  default:
2643  if (llvm::Error Err = Stream.SkipBlock()) {
2644  Error(std::move(Err));
2645  return Failure;
2646  }
2647  continue;
2648  }
2649 
2650  case llvm::BitstreamEntry::Record:
2651  // The interesting case.
2652  break;
2653  }
2654 
2655  // Read and process a record.
2656  Record.clear();
2657  StringRef Blob;
2658  Expected<unsigned> MaybeRecordType =
2659  Stream.readRecord(Entry.ID, Record, &Blob);
2660  if (!MaybeRecordType) {
2661  Error(MaybeRecordType.takeError());
2662  return Failure;
2663  }
2664  switch ((ControlRecordTypes)MaybeRecordType.get()) {
2665  case METADATA: {
2666  if (Record[0] != VERSION_MAJOR && !DisableValidation) {
2667  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2668  Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old
2669  : diag::err_pch_version_too_new);
2670  return VersionMismatch;
2671  }
2672 
2673  bool hasErrors = Record[7];
2674  if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) {
2675  Diag(diag::err_pch_with_compiler_errors);
2676  return HadErrors;
2677  }
2678  if (hasErrors) {
2679  Diags.ErrorOccurred = true;
2680  Diags.UncompilableErrorOccurred = true;
2681  Diags.UnrecoverableErrorOccurred = true;
2682  }
2683 
2684  F.RelocatablePCH = Record[4];
2685  // Relative paths in a relocatable PCH are relative to our sysroot.
2686  if (F.RelocatablePCH)
2687  F.BaseDirectory = isysroot.empty() ? "/" : isysroot;
2688 
2689  F.HasTimestamps = Record[5];
2690 
2691  F.PCHHasObjectFile = Record[6];
2692 
2693  const std::string &CurBranch = getClangFullRepositoryVersion();
2694  StringRef ASTBranch = Blob;
2695  if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
2696  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
2697  Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch;
2698  return VersionMismatch;
2699  }
2700  break;
2701  }
2702 
2703  case IMPORTS: {
2704  // Validate the AST before processing any imports (otherwise, untangling
2705  // them can be error-prone and expensive). A module will have a name and
2706  // will already have been validated, but this catches the PCH case.
2707  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2708  return Result;
2709 
2710  // Load each of the imported PCH files.
2711  unsigned Idx = 0, N = Record.size();
2712  while (Idx < N) {
2713  // Read information about the AST file.
2714  ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
2715  // The import location will be the local one for now; we will adjust
2716  // all import locations of module imports after the global source
2717  // location info are setup, in ReadAST.
2718  SourceLocation ImportLoc =
2719  ReadUntranslatedSourceLocation(Record[Idx++]);
2720  off_t StoredSize = (off_t)Record[Idx++];
2721  time_t StoredModTime = (time_t)Record[Idx++];
2722  ASTFileSignature StoredSignature = {
2723  {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
2724  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
2725  (uint32_t)Record[Idx++]}}};
2726 
2727  std::string ImportedName = ReadString(Record, Idx);
2728  std::string ImportedFile;
2729 
2730  // For prebuilt and explicit modules first consult the file map for
2731  // an override. Note that here we don't search prebuilt module
2732  // directories, only the explicit name to file mappings. Also, we will
2733  // still verify the size/signature making sure it is essentially the
2734  // same file but perhaps in a different location.
2735  if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule)
2736  ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName(
2737  ImportedName, /*FileMapOnly*/ true);
2738 
2739  if (ImportedFile.empty())
2740  // Use BaseDirectoryAsWritten to ensure we use the same path in the
2741  // ModuleCache as when writing.
2742  ImportedFile = ReadPath(BaseDirectoryAsWritten, Record, Idx);
2743  else
2744  SkipPath(Record, Idx);
2745 
2746  // If our client can't cope with us being out of date, we can't cope with
2747  // our dependency being missing.
2748  unsigned Capabilities = ClientLoadCapabilities;
2749  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2750  Capabilities &= ~ARR_Missing;
2751 
2752  // Load the AST file.
2753  auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F,
2754  Loaded, StoredSize, StoredModTime,
2755  StoredSignature, Capabilities);
2756 
2757  // If we diagnosed a problem, produce a backtrace.
2758  if (isDiagnosedResult(Result, Capabilities))
2759  Diag(diag::note_module_file_imported_by)
2760  << F.FileName << !F.ModuleName.empty() << F.ModuleName;
2761 
2762  switch (Result) {
2763  case Failure: return Failure;
2764  // If we have to ignore the dependency, we'll have to ignore this too.
2765  case Missing:
2766  case OutOfDate: return OutOfDate;
2767  case VersionMismatch: return VersionMismatch;
2768  case ConfigurationMismatch: return ConfigurationMismatch;
2769  case HadErrors: return HadErrors;
2770  case Success: break;
2771  }
2772  }
2773  break;
2774  }
2775 
2776  case ORIGINAL_FILE:
2777  F.OriginalSourceFileID = FileID::get(Record[0]);
2780  ResolveImportedPath(F, F.OriginalSourceFileName);
2781  break;
2782 
2783  case ORIGINAL_FILE_ID:
2784  F.OriginalSourceFileID = FileID::get(Record[0]);
2785  break;
2786 
2787  case ORIGINAL_PCH_DIR:
2788  F.OriginalDir = Blob;
2789  break;
2790 
2791  case MODULE_NAME:
2792  F.ModuleName = Blob;
2793  Diag(diag::remark_module_import)
2794  << F.ModuleName << F.FileName << (ImportedBy ? true : false)
2795  << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
2796  if (Listener)
2797  Listener->ReadModuleName(F.ModuleName);
2798 
2799  // Validate the AST as soon as we have a name so we can exit early on
2800  // failure.
2801  if (ASTReadResult Result = readUnhashedControlBlockOnce())
2802  return Result;
2803 
2804  break;
2805 
2806  case MODULE_DIRECTORY: {
2807  // Save the BaseDirectory as written in the PCM for computing the module
2808  // filename for the ModuleCache.
2809  BaseDirectoryAsWritten = Blob;
2810  assert(!F.ModuleName.empty() &&
2811  "MODULE_DIRECTORY found before MODULE_NAME");
2812  // If we've already loaded a module map file covering this module, we may
2813  // have a better path for it (relative to the current build).
2814  Module *M = PP.getHeaderSearchInfo().lookupModule(
2815  F.ModuleName, /*AllowSearch*/ true,
2816  /*AllowExtraModuleMapSearch*/ true);
2817  if (M && M->Directory) {
2818  // If we're implicitly loading a module, the base directory can't
2819  // change between the build and use.
2820  // Don't emit module relocation error if we have -fno-validate-pch
2821  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
2823  const DirectoryEntry *BuildDir =
2824  PP.getFileManager().getDirectory(Blob);
2825  if (!BuildDir || BuildDir != M->Directory) {
2826  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
2827  Diag(diag::err_imported_module_relocated)
2828  << F.ModuleName << Blob << M->Directory->getName();
2829  return OutOfDate;
2830  }
2831  }
2832  F.BaseDirectory = M->Directory->getName();
2833  } else {
2834  F.BaseDirectory = Blob;
2835  }
2836  break;
2837  }
2838 
2839  case MODULE_MAP_FILE:
2840  if (ASTReadResult Result =
2841  ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities))
2842  return Result;
2843  break;
2844 
2845  case INPUT_FILE_OFFSETS:
2846  NumInputs = Record[0];
2847  NumUserInputs = Record[1];
2848  F.InputFileOffsets =
2849  (const llvm::support::unaligned_uint64_t *)Blob.data();
2850  F.InputFilesLoaded.resize(NumInputs);
2851  F.NumUserInputFiles = NumUserInputs;
2852  break;
2853  }
2854  }
2855 }
2856 
2858 ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
2859  BitstreamCursor &Stream = F.Stream;
2860 
2861  if (llvm::Error Err = Stream.EnterSubBlock(AST_BLOCK_ID)) {
2862  Error(std::move(Err));
2863  return Failure;
2864  }
2865 
2866  // Read all of the records and blocks for the AST file.
2867  RecordData Record;
2868  while (true) {
2869  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
2870  if (!MaybeEntry) {
2871  Error(MaybeEntry.takeError());
2872  return Failure;
2873  }
2874  llvm::BitstreamEntry Entry = MaybeEntry.get();
2875 
2876  switch (Entry.Kind) {
2878  Error("error at end of module block in AST file");
2879  return Failure;
2880  case llvm::BitstreamEntry::EndBlock:
2881  // Outside of C++, we do not store a lookup map for the translation unit.
2882  // Instead, mark it as needing a lookup map to be built if this module
2883  // contains any declarations lexically within it (which it always does!).
2884  // This usually has no cost, since we very rarely need the lookup map for
2885  // the translation unit outside C++.
2886  if (ASTContext *Ctx = ContextObj) {
2887  DeclContext *DC = Ctx->getTranslationUnitDecl();
2888  if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus)
2890  }
2891 
2892  return Success;
2893  case llvm::BitstreamEntry::SubBlock:
2894  switch (Entry.ID) {
2895  case DECLTYPES_BLOCK_ID:
2896  // We lazily load the decls block, but we want to set up the
2897  // DeclsCursor cursor to point into it. Clone our current bitcode
2898  // cursor to it, enter the block and read the abbrevs in that block.
2899  // With the main cursor, we just skip over it.
2900  F.DeclsCursor = Stream;
2901  if (llvm::Error Err = Stream.SkipBlock()) {
2902  Error(std::move(Err));
2903  return Failure;
2904  }
2905  if (ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) {
2906  Error("malformed block record in AST file");
2907  return Failure;
2908  }
2909  break;
2910 
2911  case PREPROCESSOR_BLOCK_ID:
2912  F.MacroCursor = Stream;
2913  if (!PP.getExternalSource())
2914  PP.setExternalSource(this);
2915 
2916  if (llvm::Error Err = Stream.SkipBlock()) {
2917  Error(std::move(Err));
2918  return Failure;
2919  }
2920  if (ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) {
2921  Error("malformed block record in AST file");
2922  return Failure;
2923  }
2924  F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo();
2925  break;
2926 
2928  F.PreprocessorDetailCursor = Stream;
2929 
2930  if (llvm::Error Err = Stream.SkipBlock()) {
2931  Error(std::move(Err));
2932  return Failure;
2933  }
2934  if (ReadBlockAbbrevs(F.PreprocessorDetailCursor,
2936  Error("malformed preprocessor detail record in AST file");
2937  return Failure;
2938  }
2940  = F.PreprocessorDetailCursor.GetCurrentBitNo();
2941 
2942  if (!PP.getPreprocessingRecord())
2943  PP.createPreprocessingRecord();
2944  if (!PP.getPreprocessingRecord()->getExternalSource())
2945  PP.getPreprocessingRecord()->SetExternalSource(*this);
2946  break;
2947 
2949  if (ReadSourceManagerBlock(F))
2950  return Failure;
2951  break;
2952 
2953  case SUBMODULE_BLOCK_ID:
2954  if (ASTReadResult Result =
2955  ReadSubmoduleBlock(F, ClientLoadCapabilities))
2956  return Result;
2957  break;
2958 
2959  case COMMENTS_BLOCK_ID: {
2960  BitstreamCursor C = Stream;
2961 
2962  if (llvm::Error Err = Stream.SkipBlock()) {
2963  Error(std::move(Err));
2964  return Failure;
2965  }
2966  if (ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) {
2967  Error("malformed comments block in AST file");
2968  return Failure;
2969  }
2970  CommentsCursors.push_back(std::make_pair(C, &F));
2971  break;
2972  }
2973 
2974  default:
2975  if (llvm::Error Err = Stream.SkipBlock()) {
2976  Error(std::move(Err));
2977  return Failure;
2978  }
2979  break;
2980  }
2981  continue;
2982 
2983  case llvm::BitstreamEntry::Record:
2984  // The interesting case.
2985  break;
2986  }
2987 
2988  // Read and process a record.
2989  Record.clear();
2990  StringRef Blob;
2991  Expected<unsigned> MaybeRecordType =
2992  Stream.readRecord(Entry.ID, Record, &Blob);
2993  if (!MaybeRecordType) {
2994  Error(MaybeRecordType.takeError());
2995  return Failure;
2996  }
2997  ASTRecordTypes RecordType = (ASTRecordTypes)MaybeRecordType.get();
2998 
2999  // If we're not loading an AST context, we don't care about most records.
3000  if (!ContextObj) {
3001  switch (RecordType) {
3002  case IDENTIFIER_TABLE:
3003  case IDENTIFIER_OFFSET:
3005  case STATISTICS:
3006  case PP_CONDITIONAL_STACK:
3007  case PP_COUNTER_VALUE:
3009  case MODULE_OFFSET_MAP:
3012  case PPD_ENTITIES_OFFSETS:
3013  case HEADER_SEARCH_TABLE:
3014  case IMPORTED_MODULES:
3015  case MACRO_OFFSET:
3016  break;
3017  default:
3018  continue;
3019  }
3020  }
3021 
3022  switch (RecordType) {
3023  default: // Default behavior: ignore.
3024  break;
3025 
3026  case TYPE_OFFSET: {
3027  if (F.LocalNumTypes != 0) {
3028  Error("duplicate TYPE_OFFSET record in AST file");
3029  return Failure;
3030  }
3031  F.TypeOffsets = (const uint32_t *)Blob.data();
3032  F.LocalNumTypes = Record[0];
3033  unsigned LocalBaseTypeIndex = Record[1];
3034  F.BaseTypeIndex = getTotalNumTypes();
3035 
3036  if (F.LocalNumTypes > 0) {
3037  // Introduce the global -> local mapping for types within this module.
3038  GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F));
3039 
3040  // Introduce the local -> global mapping for types within this module.
3042  std::make_pair(LocalBaseTypeIndex,
3043  F.BaseTypeIndex - LocalBaseTypeIndex));
3044 
3045  TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
3046  }
3047  break;
3048  }
3049 
3050  case DECL_OFFSET: {
3051  if (F.LocalNumDecls != 0) {
3052  Error("duplicate DECL_OFFSET record in AST file");
3053  return Failure;
3054  }
3055  F.DeclOffsets = (const DeclOffset *)Blob.data();
3056  F.LocalNumDecls = Record[0];
3057  unsigned LocalBaseDeclID = Record[1];
3058  F.BaseDeclID = getTotalNumDecls();
3059 
3060  if (F.LocalNumDecls > 0) {
3061  // Introduce the global -> local mapping for declarations within this
3062  // module.
3063  GlobalDeclMap.insert(
3064  std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F));
3065 
3066  // Introduce the local -> global mapping for declarations within this
3067  // module.
3069  std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID));
3070 
3071  // Introduce the global -> local mapping for declarations within this
3072  // module.
3073  F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID;
3074 
3075  DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
3076  }
3077  break;
3078  }
3079 
3080  case TU_UPDATE_LEXICAL: {
3081  DeclContext *TU = ContextObj->getTranslationUnitDecl();
3082  LexicalContents Contents(
3083  reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
3084  Blob.data()),
3085  static_cast<unsigned int>(Blob.size() / 4));
3086  TULexicalDecls.push_back(std::make_pair(&F, Contents));
3087  TU->setHasExternalLexicalStorage(true);
3088  break;
3089  }
3090 
3091  case UPDATE_VISIBLE: {
3092  unsigned Idx = 0;
3093  serialization::DeclID ID = ReadDeclID(F, Record, Idx);
3094  auto *Data = (const unsigned char*)Blob.data();
3095  PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data});
3096  // If we've already loaded the decl, perform the updates when we finish
3097  // loading this block.
3098  if (Decl *D = GetExistingDecl(ID))
3099  PendingUpdateRecords.push_back(
3100  PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
3101  break;
3102  }
3103 
3104  case IDENTIFIER_TABLE:
3105  F.IdentifierTableData = Blob.data();
3106  if (Record[0]) {
3108  (const unsigned char *)F.IdentifierTableData + Record[0],
3109  (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t),
3110  (const unsigned char *)F.IdentifierTableData,
3111  ASTIdentifierLookupTrait(*this, F));
3112 
3113  PP.getIdentifierTable().setExternalIdentifierLookup(this);
3114  }
3115  break;
3116 
3117  case IDENTIFIER_OFFSET: {
3118  if (F.LocalNumIdentifiers != 0) {
3119  Error("duplicate IDENTIFIER_OFFSET record in AST file");
3120  return Failure;
3121  }
3122  F.IdentifierOffsets = (const uint32_t *)Blob.data();
3123  F.LocalNumIdentifiers = Record[0];
3124  unsigned LocalBaseIdentifierID = Record[1];
3125  F.BaseIdentifierID = getTotalNumIdentifiers();
3126 
3127  if (F.LocalNumIdentifiers > 0) {
3128  // Introduce the global -> local mapping for identifiers within this
3129  // module.
3130  GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1,
3131  &F));
3132 
3133  // Introduce the local -> global mapping for identifiers within this
3134  // module.
3136  std::make_pair(LocalBaseIdentifierID,
3137  F.BaseIdentifierID - LocalBaseIdentifierID));
3138 
3139  IdentifiersLoaded.resize(IdentifiersLoaded.size()
3140  + F.LocalNumIdentifiers);
3141  }
3142  break;
3143  }
3144 
3146  F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end());
3147  break;
3148 
3150  // FIXME: Skip reading this record if our ASTConsumer doesn't care
3151  // about "interesting" decls (for instance, if we're building a module).
3152  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3153  EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
3154  break;
3155 
3156  case MODULAR_CODEGEN_DECLS:
3157  // FIXME: Skip reading this record if our ASTConsumer doesn't care about
3158  // them (ie: if we're not codegenerating this module).
3159  if (F.Kind == MK_MainFile)
3160  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3161  EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
3162  break;
3163 
3164  case SPECIAL_TYPES:
3165  if (SpecialTypes.empty()) {
3166  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3167  SpecialTypes.push_back(getGlobalTypeID(F, Record[I]));
3168  break;
3169  }
3170 
3171  if (SpecialTypes.size() != Record.size()) {
3172  Error("invalid special-types record");
3173  return Failure;
3174  }
3175 
3176  for (unsigned I = 0, N = Record.size(); I != N; ++I) {
3177  serialization::TypeID ID = getGlobalTypeID(F, Record[I]);
3178  if (!SpecialTypes[I])
3179  SpecialTypes[I] = ID;
3180  // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate
3181  // merge step?
3182  }
3183  break;
3184 
3185  case STATISTICS:
3186  TotalNumStatements += Record[0];
3187  TotalNumMacros += Record[1];
3188  TotalLexicalDeclContexts += Record[2];
3189  TotalVisibleDeclContexts += Record[3];
3190  break;
3191 
3193  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3194  UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I]));
3195  break;
3196 
3197  case DELEGATING_CTORS:
3198  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3199  DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I]));
3200  break;
3201 
3203  if (Record.size() % 4 != 0) {
3204  Error("invalid weak identifiers record");
3205  return Failure;
3206  }
3207 
3208  // FIXME: Ignore weak undeclared identifiers from non-original PCH
3209  // files. This isn't the way to do it :)
3210  WeakUndeclaredIdentifiers.clear();
3211 
3212  // Translate the weak, undeclared identifiers into global IDs.
3213  for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) {
3214  WeakUndeclaredIdentifiers.push_back(
3215  getGlobalIdentifierID(F, Record[I++]));
3216  WeakUndeclaredIdentifiers.push_back(
3217  getGlobalIdentifierID(F, Record[I++]));
3218  WeakUndeclaredIdentifiers.push_back(
3219  ReadSourceLocation(F, Record, I).getRawEncoding());
3220  WeakUndeclaredIdentifiers.push_back(Record[I++]);
3221  }
3222  break;
3223 
3224  case SELECTOR_OFFSETS: {
3225  F.SelectorOffsets = (const uint32_t *)Blob.data();
3226  F.LocalNumSelectors = Record[0];
3227  unsigned LocalBaseSelectorID = Record[1];
3228  F.BaseSelectorID = getTotalNumSelectors();
3229 
3230  if (F.LocalNumSelectors > 0) {
3231  // Introduce the global -> local mapping for selectors within this
3232  // module.
3233  GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F));
3234 
3235  // Introduce the local -> global mapping for selectors within this
3236  // module.
3238  std::make_pair(LocalBaseSelectorID,
3239  F.BaseSelectorID - LocalBaseSelectorID));
3240 
3241  SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
3242  }
3243  break;
3244  }
3245 
3246  case METHOD_POOL:
3247  F.SelectorLookupTableData = (const unsigned char *)Blob.data();
3248  if (Record[0])
3251  F.SelectorLookupTableData + Record[0],
3253  ASTSelectorLookupTrait(*this, F));
3254  TotalNumMethodPoolEntries += Record[1];
3255  break;
3256 
3258  if (!Record.empty()) {
3259  for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) {
3260  ReferencedSelectorsData.push_back(getGlobalSelectorID(F,
3261  Record[Idx++]));
3262  ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx).
3263  getRawEncoding());
3264  }
3265  }
3266  break;
3267 
3268  case PP_CONDITIONAL_STACK:
3269  if (!Record.empty()) {
3270  unsigned Idx = 0, End = Record.size() - 1;
3271  bool ReachedEOFWhileSkipping = Record[Idx++];
3273  if (ReachedEOFWhileSkipping) {
3274  SourceLocation HashToken = ReadSourceLocation(F, Record, Idx);
3275  SourceLocation IfTokenLoc = ReadSourceLocation(F, Record, Idx);
3276  bool FoundNonSkipPortion = Record[Idx++];
3277  bool FoundElse = Record[Idx++];
3278  SourceLocation ElseLoc = ReadSourceLocation(F, Record, Idx);
3279  SkipInfo.emplace(HashToken, IfTokenLoc, FoundNonSkipPortion,
3280  FoundElse, ElseLoc);
3281  }
3282  SmallVector<PPConditionalInfo, 4> ConditionalStack;
3283  while (Idx < End) {
3284  auto Loc = ReadSourceLocation(F, Record, Idx);
3285  bool WasSkipping = Record[Idx++];
3286  bool FoundNonSkip = Record[Idx++];
3287  bool FoundElse = Record[Idx++];
3288  ConditionalStack.push_back(
3289  {Loc, WasSkipping, FoundNonSkip, FoundElse});
3290  }
3291  PP.setReplayablePreambleConditionalStack(ConditionalStack, SkipInfo);
3292  }
3293  break;
3294 
3295  case PP_COUNTER_VALUE:
3296  if (!Record.empty() && Listener)
3297  Listener->ReadCounter(F, Record[0]);
3298  break;
3299 
3300  case FILE_SORTED_DECLS:
3301  F.FileSortedDecls = (const DeclID *)Blob.data();
3302  F.NumFileSortedDecls = Record[0];
3303  break;
3304 
3305  case SOURCE_LOCATION_OFFSETS: {
3306  F.SLocEntryOffsets = (const uint32_t *)Blob.data();
3307  F.LocalNumSLocEntries = Record[0];
3308  unsigned SLocSpaceSize = Record[1];
3309  std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
3310  SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries,
3311  SLocSpaceSize);
3312  if (!F.SLocEntryBaseID) {
3313  Error("ran out of source locations");
3314  break;
3315  }
3316  // Make our entry in the range map. BaseID is negative and growing, so
3317  // we invert it. Because we invert it, though, we need the other end of
3318  // the range.
3319  unsigned RangeStart =
3320  unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1;
3321  GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F));
3323 
3324  // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing.
3325  assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0);
3326  GlobalSLocOffsetMap.insert(
3327  std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset
3328  - SLocSpaceSize,&F));
3329 
3330  // Initialize the remapping table.
3331  // Invalid stays invalid.
3332  F.SLocRemap.insertOrReplace(std::make_pair(0U, 0));
3333  // This module. Base was 2 when being compiled.
3334  F.SLocRemap.insertOrReplace(std::make_pair(2U,
3335  static_cast<int>(F.SLocEntryBaseOffset - 2)));
3336 
3337  TotalNumSLocEntries += F.LocalNumSLocEntries;
3338  break;
3339  }
3340 
3341  case MODULE_OFFSET_MAP:
3342  F.ModuleOffsetMap = Blob;
3343  break;
3344 
3346  if (ParseLineTable(F, Record))
3347  return Failure;
3348  break;
3349 
3350  case SOURCE_LOCATION_PRELOADS: {
3351  // Need to transform from the local view (1-based IDs) to the global view,
3352  // which is based off F.SLocEntryBaseID.
3353  if (!F.PreloadSLocEntries.empty()) {
3354  Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file");
3355  return Failure;
3356  }
3357 
3358  F.PreloadSLocEntries.swap(Record);
3359  break;
3360  }
3361 
3362  case EXT_VECTOR_DECLS:
3363  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3364  ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I]));
3365  break;
3366 
3367  case VTABLE_USES:
3368  if (Record.size() % 3 != 0) {
3369  Error("Invalid VTABLE_USES record");
3370  return Failure;
3371  }
3372 
3373  // Later tables overwrite earlier ones.
3374  // FIXME: Modules will have some trouble with this. This is clearly not
3375  // the right way to do this.
3376  VTableUses.clear();
3377 
3378  for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) {
3379  VTableUses.push_back(getGlobalDeclID(F, Record[Idx++]));
3380  VTableUses.push_back(
3381  ReadSourceLocation(F, Record, Idx).getRawEncoding());
3382  VTableUses.push_back(Record[Idx++]);
3383  }
3384  break;
3385 
3387  if (PendingInstantiations.size() % 2 != 0) {
3388  Error("Invalid existing PendingInstantiations");
3389  return Failure;
3390  }
3391 
3392  if (Record.size() % 2 != 0) {
3393  Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block");
3394  return Failure;
3395  }
3396 
3397  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3398  PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++]));
3399  PendingInstantiations.push_back(
3400  ReadSourceLocation(F, Record, I).getRawEncoding());
3401  }
3402  break;
3403 
3404  case SEMA_DECL_REFS:
3405  if (Record.size() != 3) {
3406  Error("Invalid SEMA_DECL_REFS block");
3407  return Failure;
3408  }
3409  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3410  SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
3411  break;
3412 
3413  case PPD_ENTITIES_OFFSETS: {
3414  F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data();
3415  assert(Blob.size() % sizeof(PPEntityOffset) == 0);
3416  F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset);
3417 
3418  unsigned LocalBasePreprocessedEntityID = Record[0];
3419 
3420  unsigned StartingID;
3421  if (!PP.getPreprocessingRecord())
3422  PP.createPreprocessingRecord();
3423  if (!PP.getPreprocessingRecord()->getExternalSource())
3424  PP.getPreprocessingRecord()->SetExternalSource(*this);
3425  StartingID
3426  = PP.getPreprocessingRecord()
3427  ->allocateLoadedEntities(F.NumPreprocessedEntities);
3428  F.BasePreprocessedEntityID = StartingID;
3429 
3430  if (F.NumPreprocessedEntities > 0) {
3431  // Introduce the global -> local mapping for preprocessed entities in
3432  // this module.
3433  GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F));
3434 
3435  // Introduce the local -> global mapping for preprocessed entities in
3436  // this module.
3438  std::make_pair(LocalBasePreprocessedEntityID,
3439  F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID));
3440  }
3441 
3442  break;
3443  }
3444 
3445  case PPD_SKIPPED_RANGES: {
3446  F.PreprocessedSkippedRangeOffsets = (const PPSkippedRange*)Blob.data();
3447  assert(Blob.size() % sizeof(PPSkippedRange) == 0);
3448  F.NumPreprocessedSkippedRanges = Blob.size() / sizeof(PPSkippedRange);
3449 
3450  if (!PP.getPreprocessingRecord())
3451  PP.createPreprocessingRecord();
3452  if (!PP.getPreprocessingRecord()->getExternalSource())
3453  PP.getPreprocessingRecord()->SetExternalSource(*this);
3454  F.BasePreprocessedSkippedRangeID = PP.getPreprocessingRecord()
3455  ->allocateSkippedRanges(F.NumPreprocessedSkippedRanges);
3456 
3457  if (F.NumPreprocessedSkippedRanges > 0)
3458  GlobalSkippedRangeMap.insert(
3459  std::make_pair(F.BasePreprocessedSkippedRangeID, &F));
3460  break;
3461  }
3462 
3463  case DECL_UPDATE_OFFSETS:
3464  if (Record.size() % 2 != 0) {
3465  Error("invalid DECL_UPDATE_OFFSETS block in AST file");
3466  return Failure;
3467  }
3468  for (unsigned I = 0, N = Record.size(); I != N; I += 2) {
3469  GlobalDeclID ID = getGlobalDeclID(F, Record[I]);
3470  DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1]));
3471 
3472  // If we've already loaded the decl, perform the updates when we finish
3473  // loading this block.
3474  if (Decl *D = GetExistingDecl(ID))
3475  PendingUpdateRecords.push_back(
3476  PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
3477  }
3478  break;
3479 
3480  case OBJC_CATEGORIES_MAP:
3481  if (F.LocalNumObjCCategoriesInMap != 0) {
3482  Error("duplicate OBJC_CATEGORIES_MAP record in AST file");
3483  return Failure;
3484  }
3485 
3486  F.LocalNumObjCCategoriesInMap = Record[0];
3487  F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data();
3488  break;
3489 
3490  case OBJC_CATEGORIES:
3491  F.ObjCCategories.swap(Record);
3492  break;
3493 
3495  // Later tables overwrite earlier ones.
3496  // FIXME: Modules will have trouble with this.
3497  CUDASpecialDeclRefs.clear();
3498  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3499  CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I]));
3500  break;
3501 
3502  case HEADER_SEARCH_TABLE:
3503  F.HeaderFileInfoTableData = Blob.data();
3504  F.LocalNumHeaderFileInfos = Record[1];
3505  if (Record[0]) {
3508  (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
3509  (const unsigned char *)F.HeaderFileInfoTableData,
3510  HeaderFileInfoTrait(*this, F,
3511  &PP.getHeaderSearchInfo(),
3512  Blob.data() + Record[2]));
3513 
3514  PP.getHeaderSearchInfo().SetExternalSource(this);
3515  if (!PP.getHeaderSearchInfo().getExternalLookup())
3516  PP.getHeaderSearchInfo().SetExternalLookup(this);
3517  }
3518  break;
3519 
3520  case FP_PRAGMA_OPTIONS:
3521  // Later tables overwrite earlier ones.
3522  FPPragmaOptions.swap(Record);
3523  break;
3524 
3525  case OPENCL_EXTENSIONS:
3526  for (unsigned I = 0, E = Record.size(); I != E; ) {
3527  auto Name = ReadString(Record, I);
3528  auto &Opt = OpenCLExtensions.OptMap[Name];
3529  Opt.Supported = Record[I++] != 0;
3530  Opt.Enabled = Record[I++] != 0;
3531  Opt.Avail = Record[I++];
3532  Opt.Core = Record[I++];
3533  }
3534  break;
3535 
3537  for (unsigned I = 0, E = Record.size(); I != E;) {
3538  auto TypeID = static_cast<::TypeID>(Record[I++]);
3539  auto *Type = GetType(TypeID).getTypePtr();
3540  auto NumExt = static_cast<unsigned>(Record[I++]);
3541  for (unsigned II = 0; II != NumExt; ++II) {
3542  auto Ext = ReadString(Record, I);
3543  OpenCLTypeExtMap[Type].insert(Ext);
3544  }
3545  }
3546  break;
3547 
3549  for (unsigned I = 0, E = Record.size(); I != E;) {
3550  auto DeclID = static_cast<::DeclID>(Record[I++]);
3551  auto *Decl = GetDecl(DeclID);
3552  auto NumExt = static_cast<unsigned>(Record[I++]);
3553  for (unsigned II = 0; II != NumExt; ++II) {
3554  auto Ext = ReadString(Record, I);
3555  OpenCLDeclExtMap[Decl].insert(Ext);
3556  }
3557  }
3558  break;
3559 
3560  case TENTATIVE_DEFINITIONS:
3561  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3562  TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I]));
3563  break;
3564 
3565  case KNOWN_NAMESPACES:
3566  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3567  KnownNamespaces.push_back(getGlobalDeclID(F, Record[I]));
3568  break;
3569 
3570  case UNDEFINED_BUT_USED:
3571  if (UndefinedButUsed.size() % 2 != 0) {
3572  Error("Invalid existing UndefinedButUsed");
3573  return Failure;
3574  }
3575 
3576  if (Record.size() % 2 != 0) {
3577  Error("invalid undefined-but-used record");
3578  return Failure;
3579  }
3580  for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3581  UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++]));
3582  UndefinedButUsed.push_back(
3583  ReadSourceLocation(F, Record, I).getRawEncoding());
3584  }
3585  break;
3586 
3588  for (unsigned I = 0, N = Record.size(); I != N;) {
3589  DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++]));
3590  const uint64_t Count = Record[I++];
3591  DelayedDeleteExprs.push_back(Count);
3592  for (uint64_t C = 0; C < Count; ++C) {
3593  DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding());
3594  bool IsArrayForm = Record[I++] == 1;
3595  DelayedDeleteExprs.push_back(IsArrayForm);
3596  }
3597  }
3598  break;
3599 
3600  case IMPORTED_MODULES:
3601  if (!F.isModule()) {
3602  // If we aren't loading a module (which has its own exports), make
3603  // all of the imported modules visible.
3604  // FIXME: Deal with macros-only imports.
3605  for (unsigned I = 0, N = Record.size(); I != N; /**/) {
3606  unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]);
3607  SourceLocation Loc = ReadSourceLocation(F, Record, I);
3608  if (GlobalID) {
3609  ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc));
3610  if (DeserializationListener)
3611  DeserializationListener->ModuleImportRead(GlobalID, Loc);
3612  }
3613  }
3614  }
3615  break;
3616 
3617  case MACRO_OFFSET: {
3618  if (F.LocalNumMacros != 0) {
3619  Error("duplicate MACRO_OFFSET record in AST file");
3620  return Failure;
3621  }
3622  F.MacroOffsets = (const uint32_t *)Blob.data();
3623  F.LocalNumMacros = Record[0];
3624  unsigned LocalBaseMacroID = Record[1];
3625  F.BaseMacroID = getTotalNumMacros();
3626 
3627  if (F.LocalNumMacros > 0) {
3628  // Introduce the global -> local mapping for macros within this module.
3629  GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F));
3630 
3631  // Introduce the local -> global mapping for macros within this module.
3633  std::make_pair(LocalBaseMacroID,
3634  F.BaseMacroID - LocalBaseMacroID));
3635 
3636  MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros);
3637  }
3638  break;
3639  }
3640 
3641  case LATE_PARSED_TEMPLATE:
3642  LateParsedTemplates.append(Record.begin(), Record.end());
3643  break;
3644 
3646  if (Record.size() != 1) {
3647  Error("invalid pragma optimize record");
3648  return Failure;
3649  }
3650  OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]);
3651  break;
3652 
3654  if (Record.size() != 1) {
3655  Error("invalid pragma ms_struct record");
3656  return Failure;
3657  }
3658  PragmaMSStructState = Record[0];
3659  break;
3660 
3662  if (Record.size() != 2) {
3663  Error("invalid pragma ms_struct record");
3664  return Failure;
3665  }
3666  PragmaMSPointersToMembersState = Record[0];
3667  PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]);
3668  break;
3669 
3671  for (unsigned I = 0, N = Record.size(); I != N; ++I)
3672  UnusedLocalTypedefNameCandidates.push_back(
3673  getGlobalDeclID(F, Record[I]));
3674  break;
3675 
3677  if (Record.size() != 1) {
3678  Error("invalid cuda pragma options record");
3679  return Failure;
3680  }
3681  ForceCUDAHostDeviceDepth = Record[0];
3682  break;
3683 
3684  case PACK_PRAGMA_OPTIONS: {
3685  if (Record.size() < 3) {
3686  Error("invalid pragma pack record");
3687  return Failure;
3688  }
3689  PragmaPackCurrentValue = Record[0];
3690  PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]);
3691  unsigned NumStackEntries = Record[2];
3692  unsigned Idx = 3;
3693  // Reset the stack when importing a new module.
3694  PragmaPackStack.clear();
3695  for (unsigned I = 0; I < NumStackEntries; ++I) {
3696  PragmaPackStackEntry Entry;
3697  Entry.Value = Record[Idx++];
3698  Entry.Location = ReadSourceLocation(F, Record[Idx++]);
3699  Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
3700  PragmaPackStrings.push_back(ReadString(Record, Idx));
3701  Entry.SlotLabel = PragmaPackStrings.back();
3702  PragmaPackStack.push_back(Entry);
3703  }
3704  break;
3705  }
3706  }
3707  }
3708 }
3709 
3710 void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
3711  assert(!F.ModuleOffsetMap.empty() && "no module offset map to read");
3712 
3713  // Additional remapping information.
3714  const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data();
3715  const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size();
3716  F.ModuleOffsetMap = StringRef();
3717 
3718  // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders.
3719  if (F.SLocRemap.find(0) == F.SLocRemap.end()) {
3720  F.SLocRemap.insert(std::make_pair(0U, 0));
3721  F.SLocRemap.insert(std::make_pair(2U, 1));
3722  }
3723 
3724  // Continuous range maps we may be updating in our module.
3725  using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder;
3726  RemapBuilder SLocRemap(F.SLocRemap);
3727  RemapBuilder IdentifierRemap(F.IdentifierRemap);
3728  RemapBuilder MacroRemap(F.MacroRemap);
3729  RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
3730  RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
3731  RemapBuilder SelectorRemap(F.SelectorRemap);
3732  RemapBuilder DeclRemap(F.DeclRemap);
3733  RemapBuilder TypeRemap(F.TypeRemap);
3734 
3735  while (Data < DataEnd) {
3736  // FIXME: Looking up dependency modules by filename is horrible. Let's
3737  // start fixing this with prebuilt and explicit modules and see how it
3738  // goes...
3739  using namespace llvm::support;
3740  ModuleKind Kind = static_cast<ModuleKind>(
3741  endian::readNext<uint8_t, little, unaligned>(Data));
3742  uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data);
3743  StringRef Name = StringRef((const char*)Data, Len);
3744  Data += Len;
3745  ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule
3746  ? ModuleMgr.lookupByModuleName(Name)
3747  : ModuleMgr.lookupByFileName(Name));
3748  if (!OM) {
3749  std::string Msg =
3750  "SourceLocation remap refers to unknown module, cannot find ";
3751  Msg.append(Name);
3752  Error(Msg);
3753  return;
3754  }
3755 
3756  uint32_t SLocOffset =
3757  endian::readNext<uint32_t, little, unaligned>(Data);
3758  uint32_t IdentifierIDOffset =
3759  endian::readNext<uint32_t, little, unaligned>(Data);
3760  uint32_t MacroIDOffset =
3761  endian::readNext<uint32_t, little, unaligned>(Data);
3762  uint32_t PreprocessedEntityIDOffset =
3763  endian::readNext<uint32_t, little, unaligned>(Data);
3764  uint32_t SubmoduleIDOffset =
3765  endian::readNext<uint32_t, little, unaligned>(Data);
3766  uint32_t SelectorIDOffset =
3767  endian::readNext<uint32_t, little, unaligned>(Data);
3768  uint32_t DeclIDOffset =
3769  endian::readNext<uint32_t, little, unaligned>(Data);
3770  uint32_t TypeIndexOffset =
3771  endian::readNext<uint32_t, little, unaligned>(Data);
3772 
3773  uint32_t None = std::numeric_limits<uint32_t>::max();
3774 
3775  auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset,
3776  RemapBuilder &Remap) {
3777  if (Offset != None)
3778  Remap.insert(std::make_pair(Offset,
3779  static_cast<int>(BaseOffset - Offset)));
3780  };
3781  mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap);
3782  mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap);
3783  mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
3784  mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
3785  PreprocessedEntityRemap);
3786  mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap);
3787  mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap);
3788  mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap);
3789  mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap);
3790 
3791  // Global -> local mappings.
3792  F.GlobalToLocalDeclIDs[OM] = DeclIDOffset;
3793  }
3794 }
3795 
3797 ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
3798  const ModuleFile *ImportedBy,
3799  unsigned ClientLoadCapabilities) {
3800  unsigned Idx = 0;
3801  F.ModuleMapPath = ReadPath(F, Record, Idx);
3802 
3803  // Try to resolve ModuleName in the current header search context and
3804  // verify that it is found in the same module map file as we saved. If the
3805  // top-level AST file is a main file, skip this check because there is no
3806  // usable header search context.
3807  assert(!F.ModuleName.empty() &&
3808  "MODULE_NAME should come before MODULE_MAP_FILE");
3809  if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) {
3810  // An implicitly-loaded module file should have its module listed in some
3811  // module map file that we've already loaded.
3812  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
3813  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
3814  const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
3815  // Don't emit module relocation error if we have -fno-validate-pch
3816  if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
3817  assert(ImportedBy && "top-level import should be verified");
3818  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
3819  if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
3820  // This module was defined by an imported (explicit) module.
3821  Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName
3822  << ASTFE->getName();
3823  } else {
3824  // This module was built with a different module map.
3825  Diag(diag::err_imported_module_not_found)
3826  << F.ModuleName << F.FileName << ImportedBy->FileName
3827  << F.ModuleMapPath;
3828  // In case it was imported by a PCH, there's a chance the user is
3829  // just missing to include the search path to the directory containing
3830  // the modulemap.
3831  if (ImportedBy->Kind == MK_PCH)
3832  Diag(diag::note_imported_by_pch_module_not_found)
3833  << llvm::sys::path::parent_path(F.ModuleMapPath);
3834  }
3835  }
3836  return OutOfDate;
3837  }
3838 
3839  assert(M->Name == F.ModuleName && "found module with different name");
3840 
3841  // Check the primary module map file.
3842  const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath);
3843  if (StoredModMap == nullptr || StoredModMap != ModMap) {
3844  assert(ModMap && "found module is missing module map file");
3845  assert(ImportedBy && "top-level import should be verified");
3846  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3847  Diag(diag::err_imported_module_modmap_changed)
3848  << F.ModuleName << ImportedBy->FileName
3849  << ModMap->getName() << F.ModuleMapPath;
3850  return OutOfDate;
3851  }
3852 
3853  llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps;
3854  for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) {
3855  // FIXME: we should use input files rather than storing names.
3856  std::string Filename = ReadPath(F, Record, Idx);
3857  const FileEntry *F =
3858  FileMgr.getFile(Filename, false, false);
3859  if (F == nullptr) {
3860  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3861  Error("could not find file '" + Filename +"' referenced by AST file");
3862  return OutOfDate;
3863  }
3864  AdditionalStoredMaps.insert(F);
3865  }
3866 
3867  // Check any additional module map files (e.g. module.private.modulemap)
3868  // that are not in the pcm.
3869  if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) {
3870  for (const FileEntry *ModMap : *AdditionalModuleMaps) {
3871  // Remove files that match
3872  // Note: SmallPtrSet::erase is really remove
3873  if (!AdditionalStoredMaps.erase(ModMap)) {
3874  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3875  Diag(diag::err_module_different_modmap)
3876  << F.ModuleName << /*new*/0 << ModMap->getName();
3877  return OutOfDate;
3878  }
3879  }
3880  }
3881 
3882  // Check any additional module map files that are in the pcm, but not
3883  // found in header search. Cases that match are already removed.
3884  for (const FileEntry *ModMap : AdditionalStoredMaps) {
3885  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3886  Diag(diag::err_module_different_modmap)
3887  << F.ModuleName << /*not new*/1 << ModMap->getName();
3888  return OutOfDate;
3889  }
3890  }
3891 
3892  if (Listener)
3893  Listener->ReadModuleMapFile(F.ModuleMapPath);
3894  return Success;
3895 }
3896 
3897 /// Move the given method to the back of the global list of methods.
3899  // Find the entry for this selector in the method pool.
3900  Sema::GlobalMethodPool::iterator Known
3901  = S.MethodPool.find(Method->getSelector());
3902  if (Known == S.MethodPool.end())
3903  return;
3904 
3905  // Retrieve the appropriate method list.
3906  ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first
3907  : Known->second.second;
3908  bool Found = false;
3909  for (ObjCMethodList *List = &Start; List; List = List->getNext()) {
3910  if (!Found) {
3911  if (List->getMethod() == Method) {
3912  Found = true;
3913  } else {
3914  // Keep searching.
3915  continue;
3916  }
3917  }
3918 
3919  if (List->getNext())
3920  List->setMethod(List->getNext()->getMethod());
3921  else
3922  List->setMethod(Method);
3923  }
3924 }
3925 
3926 void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) {
3927  assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?");
3928  for (Decl *D : Names) {
3929  bool wasHidden = D->isHidden();
3930  D->setVisibleDespiteOwningModule();
3931 
3932  if (wasHidden && SemaObj) {
3933  if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) {
3934  moveMethodToBackOfGlobalList(*SemaObj, Method);
3935  }
3936  }
3937  }
3938 }
3939 
3941  Module::NameVisibilityKind NameVisibility,
3942  SourceLocation ImportLoc) {
3943  llvm::SmallPtrSet<Module *, 4> Visited;
3945  Stack.push_back(Mod);
3946  while (!Stack.empty()) {
3947  Mod = Stack.pop_back_val();
3948 
3949  if (NameVisibility <= Mod->NameVisibility) {
3950  // This module already has this level of visibility (or greater), so
3951  // there is nothing more to do.
3952  continue;
3953  }
3954 
3955  if (!Mod->isAvailable()) {
3956  // Modules that aren't available cannot be made visible.
3957  continue;
3958  }
3959 
3960  // Update the module's name visibility.
3961  Mod->NameVisibility = NameVisibility;
3962 
3963  // If we've already deserialized any names from this module,
3964  // mark them as visible.
3965  HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod);
3966  if (Hidden != HiddenNamesMap.end()) {
3967  auto HiddenNames = std::move(*Hidden);
3968  HiddenNamesMap.erase(Hidden);
3969  makeNamesVisible(HiddenNames.second, HiddenNames.first);
3970  assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() &&
3971  "making names visible added hidden names");
3972  }
3973 
3974  // Push any exported modules onto the stack to be marked as visible.
3975  SmallVector<Module *, 16> Exports;
3976  Mod->getExportedModules(Exports);
3978  I = Exports.begin(), E = Exports.end(); I != E; ++I) {
3979  Module *Exported = *I;
3980  if (Visited.insert(Exported).second)
3981  Stack.push_back(Exported);
3982  }
3983  }
3984 }
3985 
3986 /// We've merged the definition \p MergedDef into the existing definition
3987 /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made
3988 /// visible.
3990  NamedDecl *MergedDef) {
3991  if (Def->isHidden()) {
3992  // If MergedDef is visible or becomes visible, make the definition visible.
3993  if (!MergedDef->isHidden())
3995  else {
3996  getContext().mergeDefinitionIntoModule(
3997  Def, MergedDef->getImportedOwningModule(),
3998  /*NotifyListeners*/ false);
3999  PendingMergedDefinitionsToDeduplicate.insert(Def);
4000  }
4001  }
4002 }
4003 
4005  if (GlobalIndex)
4006  return false;
4007 
4008  if (TriedLoadingGlobalIndex || !UseGlobalIndex ||
4009  !PP.getLangOpts().Modules)
4010  return true;
4011 
4012  // Try to load the global index.
4013  TriedLoadingGlobalIndex = true;
4014  StringRef ModuleCachePath
4015  = getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
4016  std::pair<GlobalModuleIndex *, llvm::Error> Result =
4017  GlobalModuleIndex::readIndex(ModuleCachePath);
4018  if (llvm::Error Err = std::move(Result.second)) {
4019  assert(!Result.first);
4020  consumeError(std::move(Err)); // FIXME this drops errors on the floor.
4021  return true;
4022  }
4023 
4024  GlobalIndex.reset(Result.first);
4025  ModuleMgr.setGlobalIndex(GlobalIndex.get());
4026  return false;
4027 }
4028 
4030  return PP.getLangOpts().Modules && UseGlobalIndex &&
4031  !hasGlobalIndex() && TriedLoadingGlobalIndex;
4032 }
4033 
4035  // Overwrite the timestamp file contents so that file's mtime changes.
4036  std::string TimestampFilename = MF.getTimestampFilename();
4037  std::error_code EC;
4038  llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
4039  if (EC)
4040  return;
4041  OS << "Timestamp file\n";
4042  OS.close();
4043  OS.clear_error(); // Avoid triggering a fatal error.
4044 }
4045 
4046 /// Given a cursor at the start of an AST file, scan ahead and drop the
4047 /// cursor into the start of the given block ID, returning false on success and
4048 /// true on failure.
4049 static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) {
4050  while (true) {
4051  Expected<llvm::BitstreamEntry> MaybeEntry = Cursor.advance();
4052  if (!MaybeEntry) {
4053  // FIXME this drops errors on the floor.
4054  consumeError(MaybeEntry.takeError());
4055  return true;
4056  }
4057  llvm::BitstreamEntry Entry = MaybeEntry.get();
4058 
4059  switch (Entry.Kind) {
4061  case llvm::BitstreamEntry::EndBlock:
4062  return true;
4063 
4064  case llvm::BitstreamEntry::Record:
4065  // Ignore top-level records.
4066  if (Expected<unsigned> Skipped = Cursor.skipRecord(Entry.ID))
4067  break;
4068  else {
4069  // FIXME this drops errors on the floor.
4070  consumeError(Skipped.takeError());
4071  return true;
4072  }
4073 
4074  case llvm::BitstreamEntry::SubBlock:
4075  if (Entry.ID == BlockID) {
4076  if (llvm::Error Err = Cursor.EnterSubBlock(BlockID)) {
4077  // FIXME this drops the error on the floor.
4078  consumeError(std::move(Err));
4079  return true;
4080  }
4081  // Found it!
4082  return false;
4083  }
4084 
4085  if (llvm::Error Err = Cursor.SkipBlock()) {
4086  // FIXME this drops the error on the floor.
4087  consumeError(std::move(Err));
4088  return true;
4089  }
4090  }
4091  }
4092 }
4093 
4095  ModuleKind Type,
4096  SourceLocation ImportLoc,
4097  unsigned ClientLoadCapabilities,
4100  SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
4101 
4102  // Defer any pending actions until we get to the end of reading the AST file.
4103  Deserializing AnASTFile(this);
4104 
4105  // Bump the generation number.
4106  unsigned PreviousGeneration = 0;
4107  if (ContextObj)
4108  PreviousGeneration = incrementGeneration(*ContextObj);
4109 
4110  unsigned NumModules = ModuleMgr.size();
4112  switch (ASTReadResult ReadResult =
4113  ReadASTCore(FileName, Type, ImportLoc,
4114  /*ImportedBy=*/nullptr, Loaded, 0, 0,
4115  ASTFileSignature(), ClientLoadCapabilities)) {
4116  case Failure:
4117  case Missing:
4118  case OutOfDate:
4119  case VersionMismatch:
4120  case ConfigurationMismatch:
4121  case HadErrors: {
4122  llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet;
4123  for (const ImportedModule &IM : Loaded)
4124  LoadedSet.insert(IM.Mod);
4125 
4126  ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet,
4127  PP.getLangOpts().Modules
4128  ? &PP.getHeaderSearchInfo().getModuleMap()
4129  : nullptr);
4130 
4131  // If we find that any modules are unusable, the global index is going
4132  // to be out-of-date. Just remove it.
4133  GlobalIndex.reset();
4134  ModuleMgr.setGlobalIndex(nullptr);
4135  return ReadResult;
4136  }
4137  case Success:
4138  break;
4139  }
4140 
4141  // Here comes stuff that we only do once the entire chain is loaded.
4142 
4143  // Load the AST blocks of all of the modules that we loaded.
4144  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
4145  MEnd = Loaded.end();
4146  M != MEnd; ++M) {
4147  ModuleFile &F = *M->Mod;
4148 
4149  // Read the AST block.
4150  if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities))
4151  return Result;
4152 
4153  // Read the extension blocks.
4155  if (ASTReadResult Result = ReadExtensionBlock(F))
4156  return Result;
4157  }
4158 
4159  // Once read, set the ModuleFile bit base offset and update the size in
4160  // bits of all files we've seen.
4161  F.GlobalBitOffset = TotalModulesSizeInBits;
4162  TotalModulesSizeInBits += F.SizeInBits;
4163  GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F));
4164 
4165  // Preload SLocEntries.
4166  for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) {
4167  int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID;
4168  // Load it through the SourceManager and don't call ReadSLocEntry()
4169  // directly because the entry may have already been loaded in which case
4170  // calling ReadSLocEntry() directly would trigger an assertion in
4171  // SourceManager.
4172  SourceMgr.getLoadedSLocEntryByID(Index);
4173  }
4174 
4175  // Map the original source file ID into the ID space of the current
4176  // compilation.
4177  if (F.OriginalSourceFileID.isValid()) {
4178  F.OriginalSourceFileID = FileID::get(
4179  F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1);
4180  }
4181 
4182  // Preload all the pending interesting identifiers by marking them out of
4183  // date.
4184  for (auto Offset : F.PreloadIdentifierOffsets) {
4185  const unsigned char *Data = reinterpret_cast<const unsigned char *>(
4187 
4188  ASTIdentifierLookupTrait Trait(*this, F);
4189  auto KeyDataLen = Trait.ReadKeyDataLength(Data);
4190  auto Key = Trait.ReadKey(Data, KeyDataLen.first);
4191  auto &II = PP.getIdentifierTable().getOwn(Key);
4192  II.setOutOfDate(true);
4193 
4194  // Mark this identifier as being from an AST file so that we can track
4195  // whether we need to serialize it.
4196  markIdentifierFromAST(*this, II);
4197 
4198  // Associate the ID with the identifier so that the writer can reuse it.
4199  auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
4200  SetIdentifierInfo(ID, &II);
4201  }
4202  }
4203 
4204  // Setup the import locations and notify the module manager that we've
4205  // committed to these module files.
4206  for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(),
4207  MEnd = Loaded.end();
4208  M != MEnd; ++M) {
4209  ModuleFile &F = *M->Mod;
4210 
4211  ModuleMgr.moduleFileAccepted(&F);
4212 
4213  // Set the import location.
4214  F.DirectImportLoc = ImportLoc;
4215  // FIXME: We assume that locations from PCH / preamble do not need
4216  // any translation.
4217  if (!M->ImportedBy)
4218  F.ImportLoc = M->ImportLoc;
4219  else
4220  F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc);
4221  }
4222 
4223  if (!PP.getLangOpts().CPlusPlus ||
4224  (Type != MK_ImplicitModule && Type != MK_ExplicitModule &&
4225  Type != MK_PrebuiltModule)) {
4226  // Mark all of the identifiers in the identifier table as being out of date,
4227  // so that various accessors know to check the loaded modules when the
4228  // identifier is used.
4229  //
4230  // For C++ modules, we don't need information on many identifiers (just
4231  // those that provide macros or are poisoned), so we mark all of
4232  // the interesting ones via PreloadIdentifierOffsets.
4233  for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(),
4234  IdEnd = PP.getIdentifierTable().end();
4235  Id != IdEnd; ++Id)
4236  Id->second->setOutOfDate(true);
4237  }
4238  // Mark selectors as out of date.
4239  for (auto Sel : SelectorGeneration)
4240  SelectorOutOfDate[Sel.first] = true;
4241 
4242  // Resolve any unresolved module exports.
4243  for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) {
4244  UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I];
4245  SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID);
4246  Module *ResolvedMod = getSubmodule(GlobalID);
4247 
4248  switch (Unresolved.Kind) {
4249  case UnresolvedModuleRef::Conflict:
4250  if (ResolvedMod) {
4251  Module::Conflict Conflict;
4252  Conflict.Other = ResolvedMod;
4253  Conflict.Message = Unresolved.String.str();
4254  Unresolved.Mod->Conflicts.push_back(Conflict);
4255  }
4256  continue;
4257 
4258  case UnresolvedModuleRef::Import:
4259  if (ResolvedMod)
4260  Unresolved.Mod->Imports.insert(ResolvedMod);
4261  continue;
4262 
4263  case UnresolvedModuleRef::Export:
4264  if (ResolvedMod || Unresolved.IsWildcard)
4265  Unresolved.Mod->Exports.push_back(
4266  Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard));
4267  continue;
4268  }
4269  }
4270  UnresolvedModuleRefs.clear();
4271 
4272  if (Imported)
4273  Imported->append(ImportedModules.begin(),
4274  ImportedModules.end());
4275 
4276  // FIXME: How do we load the 'use'd modules? They may not be submodules.
4277  // Might be unnecessary as use declarations are only used to build the
4278  // module itself.
4279 
4280  if (ContextObj)
4281  InitializeContext();
4282 
4283  if (SemaObj)
4284  UpdateSema();
4285 
4286  if (DeserializationListener)
4287  DeserializationListener->ReaderInitialized(this);
4288 
4289  ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule();
4290  if (PrimaryModule.OriginalSourceFileID.isValid()) {
4291  // If this AST file is a precompiled preamble, then set the
4292  // preamble file ID of the source manager to the file source file
4293  // from which the preamble was built.
4294  if (Type == MK_Preamble) {
4295  SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID);
4296  } else if (Type == MK_MainFile) {
4297  SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID);
4298  }
4299  }
4300 
4301  // For any Objective-C class definitions we have already loaded, make sure
4302  // that we load any additional categories.
4303  if (ContextObj) {
4304  for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) {
4305  loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(),
4306  ObjCClassesLoaded[I],
4307  PreviousGeneration);
4308  }
4309  }
4310 
4311  if (PP.getHeaderSearchInfo()
4312  .getHeaderSearchOpts()
4313  .ModulesValidateOncePerBuildSession) {
4314  // Now we are certain that the module and all modules it depends on are
4315  // up to date. Create or update timestamp files for modules that are
4316  // located in the module cache (not for PCH files that could be anywhere
4317  // in the filesystem).
4318  for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
4319  ImportedModule &M = Loaded[I];
4320  if (M.Mod->Kind == MK_ImplicitModule) {
4321  updateModuleTimestamp(*M.Mod);
4322  }
4323  }
4324  }
4325 
4326  return Success;
4327 }
4328 
4329 static ASTFileSignature readASTFileSignature(StringRef PCH);
4330 
4331 /// Whether \p Stream doesn't start with the AST/PCH file magic number 'CPCH'.
4332 static llvm::Error doesntStartWithASTFileMagic(BitstreamCursor &Stream) {
4333  // FIXME checking magic headers is done in other places such as
4334  // SerializedDiagnosticReader and GlobalModuleIndex, but error handling isn't
4335  // always done the same. Unify it all with a helper.
4336  if (!Stream.canSkipToPos(4))
4337  return llvm::createStringError(std::errc::illegal_byte_sequence,
4338  "file too small to contain AST file magic");
4339  for (unsigned C : {'C', 'P', 'C', 'H'})
4340  if (Expected<llvm::SimpleBitstreamCursor::word_t> Res = Stream.Read(8)) {
4341  if (Res.get() != C)
4342  return llvm::createStringError(
4343  std::errc::illegal_byte_sequence,
4344  "file doesn't start with AST file magic");
4345  } else
4346  return Res.takeError();
4347  return llvm::Error::success();
4348 }
4349 
4351  switch (Kind) {
4352  case MK_PCH:
4353  return 0; // PCH
4354  case MK_ImplicitModule:
4355  case MK_ExplicitModule:
4356  case MK_PrebuiltModule:
4357  return 1; // module
4358  case MK_MainFile:
4359  case MK_Preamble:
4360  return 2; // main source file
4361  }
4362  llvm_unreachable("unknown module kind");
4363 }
4364 
4366 ASTReader::ReadASTCore(StringRef FileName,
4367  ModuleKind Type,
4368  SourceLocation ImportLoc,
4369  ModuleFile *ImportedBy,
4371  off_t ExpectedSize, time_t ExpectedModTime,
4372  ASTFileSignature ExpectedSignature,
4373  unsigned ClientLoadCapabilities) {
4374  ModuleFile *M;
4375  std::string ErrorStr;
4377  = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy,
4378  getGeneration(), ExpectedSize, ExpectedModTime,
4379  ExpectedSignature, readASTFileSignature,
4380  M, ErrorStr);
4381 
4382  switch (AddResult) {
4384  Diag(diag::remark_module_import)
4385  << M->ModuleName << M->FileName << (ImportedBy ? true : false)
4386  << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
4387  return Success;
4388 
4390  // Load module file below.
4391  break;
4392 
4394  // The module file was missing; if the client can handle that, return
4395  // it.
4396  if (ClientLoadCapabilities & ARR_Missing)
4397  return Missing;
4398 
4399  // Otherwise, return an error.
4400  Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type)
4401  << FileName << !ErrorStr.empty()
4402  << ErrorStr;
4403  return Failure;
4404 
4406  // We couldn't load the module file because it is out-of-date. If the
4407  // client can handle out-of-date, return it.
4408  if (ClientLoadCapabilities & ARR_OutOfDate)
4409  return OutOfDate;
4410 
4411  // Otherwise, return an error.
4412  Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type)
4413  << FileName << !ErrorStr.empty()
4414  << ErrorStr;
4415  return Failure;
4416  }
4417 
4418  assert(M && "Missing module file");
4419 
4420  bool ShouldFinalizePCM = false;
4421  auto FinalizeOrDropPCM = llvm::make_scope_exit([&]() {
4422  auto &MC = getModuleManager().getModuleCache();
4423  if (ShouldFinalizePCM)
4424  MC.finalizePCM(FileName);
4425  else
4426  MC.tryToDropPCM(FileName);
4427  });
4428  ModuleFile &F = *M;
4429  BitstreamCursor &Stream = F.Stream;
4430  Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer));
4431  F.SizeInBits = F.Buffer->getBufferSize() * 8;
4432 
4433  // Sniff for the signature.
4434  if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
4435  Diag(diag::err_module_file_invalid)
4436  << moduleKindForDiagnostic(Type) << FileName << std::move(Err);
4437  return Failure;
4438  }
4439 
4440  // This is used for compatibility with older PCH formats.
4441  bool HaveReadControlBlock = false;
4442  while (true) {
4443  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
4444  if (!MaybeEntry) {
4445  Error(MaybeEntry.takeError());
4446  return Failure;
4447  }
4448  llvm::BitstreamEntry Entry = MaybeEntry.get();
4449 
4450  switch (Entry.Kind) {
4452  case llvm::BitstreamEntry::Record:
4453  case llvm::BitstreamEntry::EndBlock:
4454  Error("invalid record at top-level of AST file");
4455  return Failure;
4456 
4457  case llvm::BitstreamEntry::SubBlock:
4458  break;
4459  }
4460 
4461  switch (Entry.ID) {
4462  case CONTROL_BLOCK_ID:
4463  HaveReadControlBlock = true;
4464  switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) {
4465  case Success:
4466  // Check that we didn't try to load a non-module AST file as a module.
4467  //
4468  // FIXME: Should we also perform the converse check? Loading a module as
4469  // a PCH file sort of works, but it's a bit wonky.
4470  if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule ||
4471  Type == MK_PrebuiltModule) &&
4472  F.ModuleName.empty()) {
4473  auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure;
4474  if (Result != OutOfDate ||
4475  (ClientLoadCapabilities & ARR_OutOfDate) == 0)
4476  Diag(diag::err_module_file_not_module) << FileName;
4477  return Result;
4478  }
4479  break;
4480 
4481  case Failure: return Failure;
4482  case Missing: return Missing;
4483  case OutOfDate: return OutOfDate;
4484  case VersionMismatch: return VersionMismatch;
4485  case ConfigurationMismatch: return ConfigurationMismatch;
4486  case HadErrors: return HadErrors;
4487  }
4488  break;
4489 
4490  case AST_BLOCK_ID:
4491  if (!HaveReadControlBlock) {
4492  if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
4493  Diag(diag::err_pch_version_too_old);
4494  return VersionMismatch;
4495  }
4496 
4497  // Record that we've loaded this module.
4498  Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc));
4499  ShouldFinalizePCM = true;
4500  return Success;
4501 
4503  // This block is handled using look-ahead during ReadControlBlock. We
4504  // shouldn't get here!
4505  Error("malformed block record in AST file");
4506  return Failure;
4507 
4508  default:
4509  if (llvm::Error Err = Stream.SkipBlock()) {
4510  Error(std::move(Err));
4511  return Failure;
4512  }
4513  break;
4514  }
4515  }
4516 
4517  llvm_unreachable("unexpected break; expected return");
4518 }
4519 
4521 ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
4522  unsigned ClientLoadCapabilities) {
4523  const HeaderSearchOptions &HSOpts =
4524  PP.getHeaderSearchInfo().getHeaderSearchOpts();
4525  bool AllowCompatibleConfigurationMismatch =
4527 
4528  ASTReadResult Result = readUnhashedControlBlockImpl(
4529  &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch,
4530  Listener.get(),
4531  WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions);
4532 
4533  // If F was directly imported by another module, it's implicitly validated by
4534  // the importing module.
4535  if (DisableValidation || WasImportedBy ||
4536  (AllowConfigurationMismatch && Result == ConfigurationMismatch))
4537  return Success;
4538 
4539  if (Result == Failure) {
4540  Error("malformed block record in AST file");
4541  return Failure;
4542  }
4543 
4544  if (Result == OutOfDate && F.Kind == MK_ImplicitModule) {
4545  // If this module has already been finalized in the ModuleCache, we're stuck
4546  // with it; we can only load a single version of each module.
4547  //
4548  // This can happen when a module is imported in two contexts: in one, as a
4549  // user module; in another, as a system module (due to an import from
4550  // another module marked with the [system] flag). It usually indicates a
4551  // bug in the module map: this module should also be marked with [system].
4552  //
4553  // If -Wno-system-headers (the default), and the first import is as a
4554  // system module, then validation will fail during the as-user import,
4555  // since -Werror flags won't have been validated. However, it's reasonable
4556  // to treat this consistently as a system module.
4557  //
4558  // If -Wsystem-headers, the PCM on disk was built with
4559  // -Wno-system-headers, and the first import is as a user module, then
4560  // validation will fail during the as-system import since the PCM on disk
4561  // doesn't guarantee that -Werror was respected. However, the -Werror
4562  // flags were checked during the initial as-user import.
4563  if (getModuleManager().getModuleCache().isPCMFinal(F.FileName)) {
4564  Diag(diag::warn_module_system_bit_conflict) << F.FileName;
4565  return Success;
4566  }
4567  }
4568 
4569  return Result;
4570 }
4571 
4572 ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl(
4573  ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities,
4574  bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
4575  bool ValidateDiagnosticOptions) {
4576  // Initialize a stream.
4577  BitstreamCursor Stream(StreamData);
4578 
4579  // Sniff for the signature.
4580  if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
4581  // FIXME this drops the error on the floor.
4582  consumeError(std::move(Err));
4583  return Failure;
4584  }
4585 
4586  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
4588  return Failure;
4589 
4590  // Read all of the records in the options block.
4591  RecordData Record;
4592  ASTReadResult Result = Success;
4593  while (true) {
4594  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
4595  if (!MaybeEntry) {
4596  // FIXME this drops the error on the floor.
4597  consumeError(MaybeEntry.takeError());
4598  return Failure;
4599  }
4600  llvm::BitstreamEntry Entry = MaybeEntry.get();
4601 
4602  switch (Entry.Kind) {
4604  case llvm::BitstreamEntry::SubBlock:
4605  return Failure;
4606 
4607  case llvm::BitstreamEntry::EndBlock:
4608  return Result;
4609 
4610  case llvm::BitstreamEntry::Record:
4611  // The interesting case.
4612  break;
4613  }
4614 
4615  // Read and process a record.
4616  Record.clear();
4617  Expected<unsigned> MaybeRecordType = Stream.readRecord(Entry.ID, Record);
4618  if (!MaybeRecordType) {
4619  // FIXME this drops the error.
4620  return Failure;
4621  }
4622  switch ((UnhashedControlBlockRecordTypes)MaybeRecordType.get()) {
4623  case SIGNATURE:
4624  if (F)
4625  std::copy(Record.begin(), Record.end(), F->Signature.data());
4626  break;
4627  case DIAGNOSTIC_OPTIONS: {
4628  bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
4629  if (Listener && ValidateDiagnosticOptions &&
4630  !AllowCompatibleConfigurationMismatch &&
4631  ParseDiagnosticOptions(Record, Complain, *Listener))
4632  Result = OutOfDate; // Don't return early. Read the signature.
4633  break;
4634  }
4635  case DIAG_PRAGMA_MAPPINGS:
4636  if (!F)
4637  break;
4638  if (F->PragmaDiagMappings.empty())
4639  F->PragmaDiagMappings.swap(Record);
4640  else
4641  F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(),
4642  Record.begin(), Record.end());
4643  break;
4644  }
4645  }
4646 }
4647 
4648 /// Parse a record and blob containing module file extension metadata.
4650  const SmallVectorImpl<uint64_t> &Record,
4651  StringRef Blob,
4652  ModuleFileExtensionMetadata &Metadata) {
4653  if (Record.size() < 4) return true;
4654 
4655  Metadata.MajorVersion = Record[0];
4656  Metadata.MinorVersion = Record[1];
4657 
4658  unsigned BlockNameLen = Record[2];
4659  unsigned UserInfoLen = Record[3];
4660 
4661  if (BlockNameLen + UserInfoLen > Blob.size()) return true;
4662 
4663  Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen);
4664  Metadata.UserInfo = std::string(Blob.data() + BlockNameLen,
4665  Blob.data() + BlockNameLen + UserInfoLen);
4666  return false;
4667 }
4668 
4669 ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) {
4670  BitstreamCursor &Stream = F.Stream;
4671 
4672  RecordData Record;
4673  while (true) {
4674  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
4675  if (!MaybeEntry) {
4676  Error(MaybeEntry.takeError());
4677  return Failure;
4678  }
4679  llvm::BitstreamEntry Entry = MaybeEntry.get();
4680 
4681  switch (Entry.Kind) {
4682  case llvm::BitstreamEntry::SubBlock:
4683  if (llvm::Error Err = Stream.SkipBlock()) {
4684  Error(std::move(Err));
4685  return Failure;
4686  }
4687  continue;
4688 
4689  case llvm::BitstreamEntry::EndBlock:
4690  return Success;
4691 
4693  return HadErrors;
4694 
4695  case llvm::BitstreamEntry::Record:
4696  break;
4697  }
4698 
4699  Record.clear();
4700  StringRef Blob;
4701  Expected<unsigned> MaybeRecCode =
4702  Stream.readRecord(Entry.ID, Record, &Blob);
4703  if (!MaybeRecCode) {
4704  Error(MaybeRecCode.takeError());
4705  return Failure;
4706  }
4707  switch (MaybeRecCode.get()) {
4708  case EXTENSION_METADATA: {
4709  ModuleFileExtensionMetadata Metadata;
4710  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
4711  return Failure;
4712 
4713  // Find a module file extension with this block name.
4714  auto Known = ModuleFileExtensions.find(Metadata.BlockName);
4715  if (Known == ModuleFileExtensions.end()) break;
4716 
4717  // Form a reader.
4718  if (auto Reader = Known->second->createExtensionReader(Metadata, *this,
4719  F, Stream)) {
4720  F.ExtensionReaders.push_back(std::move(Reader));
4721  }
4722 
4723  break;
4724  }
4725  }
4726  }
4727 
4728  return Success;
4729 }
4730 
4732  assert(ContextObj && "no context to initialize");
4733  ASTContext &Context = *ContextObj;
4734 
4735  // If there's a listener, notify them that we "read" the translation unit.
4736  if (DeserializationListener)
4737  DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID,
4738  Context.getTranslationUnitDecl());
4739 
4740  // FIXME: Find a better way to deal with collisions between these
4741  // built-in types. Right now, we just ignore the problem.
4742 
4743  // Load the special types.
4744  if (SpecialTypes.size() >= NumSpecialTypeIDs) {
4745  if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
4746  if (!Context.CFConstantStringTypeDecl)
4747  Context.setCFConstantStringType(GetType(String));
4748  }
4749 
4750  if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
4751  QualType FileType = GetType(File);
4752  if (FileType.isNull()) {
4753  Error("FILE type is NULL");
4754  return;
4755  }
4756 
4757  if (!Context.FILEDecl) {
4758  if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
4759  Context.setFILEDecl(Typedef->getDecl());
4760  else {
4761  const TagType *Tag = FileType->getAs<TagType>();
4762  if (!Tag) {
4763  Error("Invalid FILE type in AST file");
4764  return;
4765  }
4766  Context.setFILEDecl(Tag->getDecl());
4767  }
4768  }
4769  }
4770 
4771  if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
4772  QualType Jmp_bufType = GetType(Jmp_buf);
4773  if (Jmp_bufType.isNull()) {
4774  Error("jmp_buf type is NULL");
4775  return;
4776  }
4777 
4778  if (!Context.jmp_bufDecl) {
4779  if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
4780  Context.setjmp_bufDecl(Typedef->getDecl());
4781  else {
4782  const TagType *Tag = Jmp_bufType->getAs<TagType>();
4783  if (!Tag) {
4784  Error("Invalid jmp_buf type in AST file");
4785  return;
4786  }
4787  Context.setjmp_bufDecl(Tag->getDecl());
4788  }
4789  }
4790  }
4791 
4792  if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
4793  QualType Sigjmp_bufType = GetType(Sigjmp_buf);
4794  if (Sigjmp_bufType.isNull()) {
4795  Error("sigjmp_buf type is NULL");
4796  return;
4797  }
4798 
4799  if (!Context.sigjmp_bufDecl) {
4800  if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
4801  Context.setsigjmp_bufDecl(Typedef->getDecl());
4802  else {
4803  const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
4804  assert(Tag && "Invalid sigjmp_buf type in AST file");
4805  Context.setsigjmp_bufDecl(Tag->getDecl());
4806  }
4807  }
4808  }
4809 
4810  if (unsigned ObjCIdRedef
4811  = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
4812  if (Context.ObjCIdRedefinitionType.isNull())
4813  Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef);
4814  }
4815 
4816  if (unsigned ObjCClassRedef
4817  = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
4818  if (Context.ObjCClassRedefinitionType.isNull())
4819  Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef);
4820  }
4821 
4822  if (unsigned ObjCSelRedef
4823  = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
4824  if (Context.ObjCSelRedefinitionType.isNull())
4825  Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef);
4826  }
4827 
4828  if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
4829  QualType Ucontext_tType = GetType(Ucontext_t);
4830  if (Ucontext_tType.isNull()) {
4831  Error("ucontext_t type is NULL");
4832  return;
4833  }
4834 
4835  if (!Context.ucontext_tDecl) {
4836  if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>())
4837  Context.setucontext_tDecl(Typedef->getDecl());
4838  else {
4839  const TagType *Tag = Ucontext_tType->getAs<TagType>();
4840  assert(Tag && "Invalid ucontext_t type in AST file");
4841  Context.setucontext_tDecl(Tag->getDecl());
4842  }
4843  }
4844  }
4845  }
4846 
4847  ReadPragmaDiagnosticMappings(Context.getDiagnostics());
4848 
4849  // If there were any CUDA special declarations, deserialize them.
4850  if (!CUDASpecialDeclRefs.empty()) {
4851  assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!");
4852  Context.setcudaConfigureCallDecl(
4853  cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0])));
4854  }
4855 
4856  // Re-export any modules that were imported by a non-module AST file.
4857  // FIXME: This does not make macro-only imports visible again.
4858  for (auto &Import : ImportedModules) {
4859  if (Module *Imported = getSubmodule(Import.ID)) {
4860  makeModuleVisible(Imported, Module::AllVisible,
4861  /*ImportLoc=*/Import.ImportLoc);
4862  if (Import.ImportLoc.isValid())
4863  PP.makeModuleVisible(Imported, Import.ImportLoc);
4864  // FIXME: should we tell Sema to make the module visible too?
4865  }
4866  }
4867  ImportedModules.clear();
4868 }
4869 
4871  // Nothing to do for now.
4872 }
4873 
4874 /// Reads and return the signature record from \p PCH's control block, or
4875 /// else returns 0.
4877  BitstreamCursor Stream(PCH);
4878  if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
4879  // FIXME this drops the error on the floor.
4880  consumeError(std::move(Err));
4881  return ASTFileSignature();
4882  }
4883 
4884  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
4886  return ASTFileSignature();
4887 
4888  // Scan for SIGNATURE inside the diagnostic options block.
4889  ASTReader::RecordData Record;
4890  while (true) {
4891  Expected<llvm::BitstreamEntry> MaybeEntry =
4892  Stream.advanceSkippingSubblocks();
4893  if (!MaybeEntry) {
4894  // FIXME this drops the error on the floor.
4895  consumeError(MaybeEntry.takeError());
4896  return ASTFileSignature();
4897  }
4898  llvm::BitstreamEntry Entry = MaybeEntry.get();
4899 
4900  if (Entry.Kind != llvm::BitstreamEntry::Record)
4901  return ASTFileSignature();
4902 
4903  Record.clear();
4904  StringRef Blob;
4905  Expected<unsigned> MaybeRecord = Stream.readRecord(Entry.ID, Record, &Blob);
4906  if (!MaybeRecord) {
4907  // FIXME this drops the error on the floor.
4908  consumeError(MaybeRecord.takeError());
4909  return ASTFileSignature();
4910  }
4911  if (SIGNATURE == MaybeRecord.get())
4912  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
4913  (uint32_t)Record[3], (uint32_t)Record[4]}}};
4914  }
4915 }
4916 
4917 /// Retrieve the name of the original source file name
4918 /// directly from the AST file, without actually loading the AST
4919 /// file.
4921  const std::string &ASTFileName, FileManager &FileMgr,
4922  const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) {
4923  // Open the AST file.
4924  auto Buffer = FileMgr.getBufferForFile(ASTFileName);
4925  if (!Buffer) {
4926  Diags.Report(diag::err_fe_unable_to_read_pch_file)
4927  << ASTFileName << Buffer.getError().message();
4928  return std::string();
4929  }
4930 
4931  // Initialize the stream
4932  BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer));
4933 
4934  // Sniff for the signature.
4935  if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
4936  Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName << std::move(Err);
4937  return std::string();
4938  }
4939 
4940  // Scan for the CONTROL_BLOCK_ID block.
4941  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) {
4942  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4943  return std::string();
4944  }
4945 
4946  // Scan for ORIGINAL_FILE inside the control block.
4947  RecordData Record;
4948  while (true) {
4949  Expected<llvm::BitstreamEntry> MaybeEntry =
4950  Stream.advanceSkippingSubblocks();
4951  if (!MaybeEntry) {
4952  // FIXME this drops errors on the floor.
4953  consumeError(MaybeEntry.takeError());
4954  return std::string();
4955  }
4956  llvm::BitstreamEntry Entry = MaybeEntry.get();
4957 
4958  if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
4959  return std::string();
4960 
4961  if (Entry.Kind != llvm::BitstreamEntry::Record) {
4962  Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
4963  return std::string();
4964  }
4965 
4966  Record.clear();
4967  StringRef Blob;
4968  Expected<unsigned> MaybeRecord = Stream.readRecord(Entry.ID, Record, &Blob);
4969  if (!MaybeRecord) {
4970  // FIXME this drops the errors on the floor.
4971  consumeError(MaybeRecord.takeError());
4972  return std::string();
4973  }
4974  if (ORIGINAL_FILE == MaybeRecord.get())
4975  return Blob.str();
4976  }
4977 }
4978 
4979 namespace {
4980 
4981  class SimplePCHValidator : public ASTReaderListener {
4982  const LangOptions &ExistingLangOpts;
4983  const TargetOptions &ExistingTargetOpts;
4984  const PreprocessorOptions &ExistingPPOpts;
4985  std::string ExistingModuleCachePath;
4986  FileManager &FileMgr;
4987 
4988  public:
4989  SimplePCHValidator(const LangOptions &ExistingLangOpts,
4990  const TargetOptions &ExistingTargetOpts,
4991  const PreprocessorOptions &ExistingPPOpts,
4992  StringRef ExistingModuleCachePath,
4993  FileManager &FileMgr)
4994  : ExistingLangOpts(ExistingLangOpts),
4995  ExistingTargetOpts(ExistingTargetOpts),
4996  ExistingPPOpts(ExistingPPOpts),
4997  ExistingModuleCachePath(ExistingModuleCachePath),
4998  FileMgr(FileMgr) {}
4999 
5000  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
5001  bool AllowCompatibleDifferences) override {
5002  return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr,
5003  AllowCompatibleDifferences);
5004  }
5005 
5006  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
5007  bool AllowCompatibleDifferences) override {
5008  return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr,
5009  AllowCompatibleDifferences);
5010  }
5011 
5012  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
5013  StringRef SpecificModuleCachePath,
5014  bool Complain) override {
5015  return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
5016  ExistingModuleCachePath,
5017  nullptr, ExistingLangOpts);
5018  }
5019 
5020  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
5021  bool Complain,
5022  std::string &SuggestedPredefines) override {
5023  return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr,
5024  SuggestedPredefines, ExistingLangOpts);
5025  }
5026  };
5027 
5028 } // namespace
5029 
5031  StringRef Filename, FileManager &FileMgr,
5032  const PCHContainerReader &PCHContainerRdr,
5033  bool FindModuleFileExtensions,
5034  ASTReaderListener &Listener, bool ValidateDiagnosticOptions) {
5035  // Open the AST file.
5036  // FIXME: This allows use of the VFS; we do not allow use of the
5037  // VFS when actually loading a module.
5038  auto Buffer = FileMgr.getBufferForFile(Filename);
5039  if (!Buffer) {
5040  return true;
5041  }
5042 
5043  // Initialize the stream
5044  StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer);
5045  BitstreamCursor Stream(Bytes);
5046 
5047  // Sniff for the signature.
5048  if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
5049  consumeError(std::move(Err)); // FIXME this drops errors on the floor.
5050  return true;
5051  }
5052 
5053  // Scan for the CONTROL_BLOCK_ID block.
5054  if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID))
5055  return true;
5056 
5057  bool NeedsInputFiles = Listener.needsInputFileVisitation();
5058  bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation();
5059  bool NeedsImports = Listener.needsImportVisitation();
5060  BitstreamCursor InputFilesCursor;
5061 
5062  RecordData Record;
5063  std::string ModuleDir;
5064  bool DoneWithControlBlock = false;
5065  while (!DoneWithControlBlock) {
5066  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
5067  if (!MaybeEntry) {
5068  // FIXME this drops the error on the floor.
5069  consumeError(MaybeEntry.takeError());
5070  return true;
5071  }
5072  llvm::BitstreamEntry Entry = MaybeEntry.get();
5073 
5074  switch (Entry.Kind) {
5075  case llvm::BitstreamEntry::SubBlock: {
5076  switch (Entry.ID) {
5077  case OPTIONS_BLOCK_ID: {
5078  std::string IgnoredSuggestedPredefines;
5079  if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate,
5080  /*AllowCompatibleConfigurationMismatch*/ false,
5081  Listener, IgnoredSuggestedPredefines) != Success)
5082  return true;
5083  break;
5084  }
5085 
5086  case INPUT_FILES_BLOCK_ID:
5087  InputFilesCursor = Stream;
5088  if (llvm::Error Err = Stream.SkipBlock()) {
5089  // FIXME this drops the error on the floor.
5090  consumeError(std::move(Err));
5091  return true;
5092  }
5093  if (NeedsInputFiles &&
5094  ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))
5095  return true;
5096  break;
5097 
5098  default:
5099  if (llvm::Error Err = Stream.SkipBlock()) {
5100  // FIXME this drops the error on the floor.
5101  consumeError(std::move(Err));
5102  return true;
5103  }
5104  break;
5105  }
5106 
5107  continue;
5108  }
5109 
5110  case llvm::BitstreamEntry::EndBlock:
5111  DoneWithControlBlock = true;
5112  break;
5113 
5115  return true;
5116 
5117  case llvm::BitstreamEntry::Record:
5118  break;
5119  }
5120 
5121  if (DoneWithControlBlock) break;
5122 
5123  Record.clear();
5124  StringRef Blob;
5125  Expected<unsigned> MaybeRecCode =
5126  Stream.readRecord(Entry.ID, Record, &Blob);
5127  if (!MaybeRecCode) {
5128  // FIXME this drops the error.
5129  return Failure;
5130  }
5131  switch ((ControlRecordTypes)MaybeRecCode.get()) {
5132  case METADATA:
5133  if (Record[0] != VERSION_MAJOR)
5134  return true;
5135  if (Listener.ReadFullVersionInformation(Blob))
5136  return true;
5137  break;
5138  case MODULE_NAME:
5139  Listener.ReadModuleName(Blob);
5140  break;
5141  case MODULE_DIRECTORY:
5142  ModuleDir = Blob;
5143  break;
5144  case MODULE_MAP_FILE: {
5145  unsigned Idx = 0;
5146  auto Path = ReadString(Record, Idx);
5147  ResolveImportedPath(Path, ModuleDir);
5148  Listener.ReadModuleMapFile(Path);
5149  break;
5150  }
5151  case INPUT_FILE_OFFSETS: {
5152  if (!NeedsInputFiles)
5153  break;
5154 
5155  unsigned NumInputFiles = Record[0];
5156  unsigned NumUserFiles = Record[1];
5157  const llvm::support::unaligned_uint64_t *InputFileOffs =
5158  (const llvm::support::unaligned_uint64_t *)Blob.data();
5159  for (unsigned I = 0; I != NumInputFiles; ++I) {
5160  // Go find this input file.
5161  bool isSystemFile = I >= NumUserFiles;
5162 
5163  if (isSystemFile && !NeedsSystemInputFiles)
5164  break; // the rest are system input files
5165 
5166  BitstreamCursor &Cursor = InputFilesCursor;
5167  SavedStreamPosition SavedPosition(Cursor);
5168  if (llvm::Error Err = Cursor.JumpToBit(InputFileOffs[I])) {
5169  // FIXME this drops errors on the floor.
5170  consumeError(std::move(Err));
5171  }
5172 
5173  Expected<unsigned> MaybeCode = Cursor.ReadCode();
5174  if (!MaybeCode) {
5175  // FIXME this drops errors on the floor.
5176  consumeError(MaybeCode.takeError());
5177  }
5178  unsigned Code = MaybeCode.get();
5179 
5180  RecordData Record;
5181  StringRef Blob;
5182  bool shouldContinue = false;
5183  Expected<unsigned> MaybeRecordType =
5184  Cursor.readRecord(Code, Record, &Blob);
5185  if (!MaybeRecordType) {
5186  // FIXME this drops errors on the floor.
5187  consumeError(MaybeRecordType.takeError());
5188  }
5189  switch ((InputFileRecordTypes)MaybeRecordType.get()) {
5190  case INPUT_FILE:
5191  bool Overridden = static_cast<bool>(Record[3]);
5192  std::string Filename = Blob;
5193  ResolveImportedPath(Filename, ModuleDir);
5194  shouldContinue = Listener.visitInputFile(
5195  Filename, isSystemFile, Overridden, /*IsExplicitModule*/false);
5196  break;
5197  }
5198  if (!shouldContinue)
5199  break;
5200  }
5201  break;
5202  }
5203 
5204  case IMPORTS: {
5205  if (!NeedsImports)
5206  break;
5207 
5208  unsigned Idx = 0, N = Record.size();
5209  while (Idx < N) {
5210  // Read information about the AST file.
5211  Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
5212  std::string ModuleName = ReadString(Record, Idx);
5213  std::string Filename = ReadString(Record, Idx);
5214  ResolveImportedPath(Filename, ModuleDir);
5215  Listener.visitImport(ModuleName, Filename);
5216  }
5217  break;
5218  }
5219 
5220  default:
5221  // No other validation to perform.
5222  break;
5223  }
5224  }
5225 
5226  // Look for module file extension blocks, if requested.
5227  if (FindModuleFileExtensions) {
5228  BitstreamCursor SavedStream = Stream;
5229  while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) {
5230  bool DoneWithExtensionBlock = false;
5231  while (!DoneWithExtensionBlock) {
5232  Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance();
5233  if (!MaybeEntry) {
5234  // FIXME this drops the error.
5235  return true;
5236  }
5237  llvm::BitstreamEntry Entry = MaybeEntry.get();
5238 
5239  switch (Entry.Kind) {
5240  case llvm::BitstreamEntry::SubBlock:
5241  if (llvm::Error Err = Stream.SkipBlock()) {
5242  // FIXME this drops the error on the floor.
5243  consumeError(std::move(Err));
5244  return true;
5245  }
5246  continue;
5247 
5248  case llvm::BitstreamEntry::EndBlock:
5249  DoneWithExtensionBlock = true;
5250  continue;
5251 
5253  return true;
5254 
5255  case llvm::BitstreamEntry::Record:
5256  break;
5257  }
5258 
5259  Record.clear();
5260  StringRef Blob;
5261  Expected<unsigned> MaybeRecCode =
5262  Stream.readRecord(Entry.ID, Record, &Blob);
5263  if (!MaybeRecCode) {
5264  // FIXME this drops the error.
5265  return true;
5266  }
5267  switch (MaybeRecCode.get()) {
5268  case EXTENSION_METADATA: {
5269  ModuleFileExtensionMetadata Metadata;
5270  if (parseModuleFileExtensionMetadata(Record, Blob, Metadata))
5271  return true;
5272 
5273  Listener.readModuleFileExtension(Metadata);
5274  break;
5275  }
5276  }
5277  }
5278  }
5279  Stream = SavedStream;
5280  }
5281 
5282  // Scan for the UNHASHED_CONTROL_BLOCK_ID block.
5283  if (readUnhashedControlBlockImpl(
5284  nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate,
5285  /*AllowCompatibleConfigurationMismatch*/ false, &Listener,
5286  ValidateDiagnosticOptions) != Success)
5287  return true;
5288 
5289  return false;
5290 }
5291 
5293  const PCHContainerReader &PCHContainerRdr,
5294  const LangOptions &LangOpts,
5295  const TargetOptions &TargetOpts,
5296  const PreprocessorOptions &PPOpts,
5297  StringRef ExistingModuleCachePath) {
5298  SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts,
5299  ExistingModuleCachePath, FileMgr);
5300  return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr,
5301  /*FindModuleFileExtensions=*/false,
5302  validator,
5303  /*ValidateDiagnosticOptions=*/true);
5304 }
5305 
5307 ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
5308  // Enter the submodule block.
5309  if (llvm::Error Err = F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) {
5310  Error(std::move(Err));
5311  return Failure;
5312  }
5313 
5314  ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
5315  bool First = true;
5316  Module *CurrentModule = nullptr;
5317  RecordData Record;
5318  while (true) {
5319  Expected<llvm::BitstreamEntry> MaybeEntry =
5320  F.Stream.advanceSkippingSubblocks();
5321  if (!MaybeEntry) {
5322  Error(MaybeEntry.takeError());
5323  return Failure;
5324  }
5325  llvm::BitstreamEntry Entry = MaybeEntry.get();
5326 
5327  switch (Entry.Kind) {
5328  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
5330  Error("malformed block record in AST file");
5331  return Failure;
5332  case llvm::BitstreamEntry::EndBlock:
5333  return Success;
5334  case llvm::BitstreamEntry::Record:
5335  // The interesting case.
5336  break;
5337  }
5338 
5339  // Read a record.
5340  StringRef Blob;
5341  Record.clear();
5342  Expected<unsigned> MaybeKind = F.Stream.readRecord(Entry.ID, Record, &Blob);
5343  if (!MaybeKind) {
5344  Error(MaybeKind.takeError());
5345  return Failure;
5346  }
5347  unsigned Kind = MaybeKind.get();
5348 
5349  if ((Kind == SUBMODULE_METADATA) != First) {
5350  Error("submodule metadata record should be at beginning of block");
5351  return Failure;
5352  }
5353  First = false;
5354 
5355  // Submodule information is only valid if we have a current module.
5356  // FIXME: Should we error on these cases?
5357  if (!CurrentModule && Kind != SUBMODULE_METADATA &&
5358  Kind != SUBMODULE_DEFINITION)
5359  continue;
5360 
5361  switch (Kind) {
5362  default: // Default behavior: ignore.
5363  break;
5364 
5365  case SUBMODULE_DEFINITION: {
5366  if (Record.size() < 12) {
5367  Error("malformed module definition");
5368  return Failure;
5369  }
5370 
5371  StringRef Name = Blob;
5372  unsigned Idx = 0;
5373  SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);
5374  SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);
5375  Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++];
5376  bool IsFramework = Record[Idx++];
5377  bool IsExplicit = Record[Idx++];
5378  bool IsSystem = Record[Idx++];
5379  bool IsExternC = Record[Idx++];
5380  bool InferSubmodules = Record[Idx++];
5381  bool InferExplicitSubmodules = Record[Idx++];
5382  bool InferExportWildcard = Record[Idx++];
5383  bool ConfigMacrosExhaustive = Record[Idx++];
5384  bool ModuleMapIsPrivate = Record[Idx++];
5385 
5386  Module *ParentModule = nullptr;
5387  if (Parent)
5388  ParentModule = getSubmodule(Parent);
5389 
5390  // Retrieve this (sub)module from the module map, creating it if
5391  // necessary.
5392  CurrentModule =
5393  ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit)
5394  .first;
5395 
5396  // FIXME: set the definition loc for CurrentModule, or call
5397  // ModMap.setInferredModuleAllowedBy()
5398 
5399  SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS;
5400  if (GlobalIndex >= SubmodulesLoaded.size() ||
5401  SubmodulesLoaded[GlobalIndex]) {
5402  Error("too many submodules");
5403  return Failure;
5404  }
5405 
5406  if (!ParentModule) {
5407  if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
5408  // Don't emit module relocation error if we have -fno-validate-pch
5409  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
5410  CurFile != F.File) {
5411  if (!Diags.isDiagnosticInFlight()) {
5412  Diag(diag::err_module_file_conflict)
5413  << CurrentModule->getTopLevelModuleName()
5414  << CurFile->getName()
5415  << F.File->getName();
5416  }
5417  return Failure;
5418  }
5419  }
5420 
5421  CurrentModule->setASTFile(F.File);
5422  CurrentModule->PresumedModuleMapFile = F.ModuleMapPath;
5423  }
5424 
5425  CurrentModule->Kind = Kind;
5426  CurrentModule->Signature = F.Signature;
5427  CurrentModule->IsFromModuleFile = true;
5428  CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
5429  CurrentModule->IsExternC = IsExternC;
5430  CurrentModule->InferSubmodules = InferSubmodules;
5431  CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules;
5432  CurrentModule->InferExportWildcard = InferExportWildcard;
5433  CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive;
5434  CurrentModule->ModuleMapIsPrivate = ModuleMapIsPrivate;
5435  if (DeserializationListener)
5436  DeserializationListener->ModuleRead(GlobalID, CurrentModule);
5437 
5438  SubmodulesLoaded[GlobalIndex] = CurrentModule;
5439 
5440  // Clear out data that will be replaced by what is in the module file.
5441  CurrentModule->LinkLibraries.clear();
5442  CurrentModule->ConfigMacros.clear();
5443  CurrentModule->UnresolvedConflicts.clear();
5444  CurrentModule->Conflicts.clear();
5445 
5446  // The module is available unless it's missing a requirement; relevant
5447  // requirements will be (re-)added by SUBMODULE_REQUIRES records.
5448  // Missing headers that were present when the module was built do not
5449  // make it unavailable -- if we got this far, this must be an explicitly
5450  // imported module file.
5451  CurrentModule->Requirements.clear();
5452  CurrentModule->MissingHeaders.clear();
5453  CurrentModule->IsMissingRequirement =
5454  ParentModule && ParentModule->IsMissingRequirement;
5455  CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement;
5456  break;
5457  }
5458 
5460  std::string Filename = Blob;
5461  ResolveImportedPath(F, Filename);
5462  if (auto *Umbrella = PP.getFileManager().getFile(Filename)) {
5463  if (!CurrentModule->getUmbrellaHeader())
5464  ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob);
5465  else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) {
5466  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
5467  Error("mismatched umbrella headers in submodule");
5468  return OutOfDate;
5469  }
5470  }
5471  break;
5472  }
5473 
5474  case SUBMODULE_HEADER:
5477  // We lazily associate headers with their modules via the HeaderInfo table.
5478  // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead
5479  // of complete filenames or remove it entirely.
5480  break;
5481 
5484  // FIXME: Textual headers are not marked in the HeaderInfo table. Load
5485  // them here.
5486  break;
5487 
5488  case SUBMODULE_TOPHEADER:
5489  CurrentModule->addTopHeaderFilename(Blob);
5490  break;
5491 
5492  case SUBMODULE_UMBRELLA_DIR: {
5493  std::string Dirname = Blob;
5494  ResolveImportedPath(F, Dirname);
5495  if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) {
5496  if (!CurrentModule->getUmbrellaDir())
5497  ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob);
5498  else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) {
5499  if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
5500  Error("mismatched umbrella directories in submodule");
5501  return OutOfDate;
5502  }
5503  }
5504  break;
5505  }
5506 
5507  case SUBMODULE_METADATA: {
5508  F.BaseSubmoduleID = getTotalNumSubmodules();
5509  F.LocalNumSubmodules = Record[0];
5510  unsigned LocalBaseSubmoduleID = Record[1];
5511  if (F.LocalNumSubmodules > 0) {
5512  // Introduce the global -> local mapping for submodules within this
5513  // module.
5514  GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F));
5515 
5516  // Introduce the local -> global mapping for submodules within this
5517  // module.
5519  std::make_pair(LocalBaseSubmoduleID,
5520  F.BaseSubmoduleID - LocalBaseSubmoduleID));
5521 
5522  SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules);
5523  }
5524  break;
5525  }
5526 
5527  case SUBMODULE_IMPORTS:
5528  for (unsigned Idx = 0; Idx != Record.size(); ++Idx) {
5529  UnresolvedModuleRef Unresolved;
5530  Unresolved.File = &F;
5531  Unresolved.Mod = CurrentModule;
5532  Unresolved.ID = Record[Idx];
5533  Unresolved.Kind = UnresolvedModuleRef::Import;
5534  Unresolved.IsWildcard = false;
5535  UnresolvedModuleRefs.push_back(Unresolved);
5536  }
5537  break;
5538 
5539  case SUBMODULE_EXPORTS:
5540  for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) {
5541  UnresolvedModuleRef Unresolved;
5542  Unresolved.File = &F;
5543  Unresolved.Mod = CurrentModule;
5544  Unresolved.ID = Record[Idx];
5545  Unresolved.Kind = UnresolvedModuleRef::Export;
5546  Unresolved.IsWildcard = Record[Idx + 1];
5547  UnresolvedModuleRefs.push_back(Unresolved);
5548  }
5549 
5550  // Once we've loaded the set of exports, there's no reason to keep
5551  // the parsed, unresolved exports around.
5552  CurrentModule->UnresolvedExports.clear();
5553  break;
5554 
5555  case SUBMODULE_REQUIRES:
5556  CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(),
5557  PP.getTargetInfo());
5558  break;
5559 
5561  ModMap.resolveLinkAsDependencies(CurrentModule);
5562  CurrentModule->LinkLibraries.push_back(
5563  Module::LinkLibrary(Blob, Record[0]));
5564  break;
5565 
5567  CurrentModule->ConfigMacros.push_back(Blob.str());
5568  break;
5569 
5570  case SUBMODULE_CONFLICT: {
5571  UnresolvedModuleRef Unresolved;
5572  Unresolved.File = &F;
5573  Unresolved.Mod = CurrentModule;
5574  Unresolved.ID = Record[0];
5575  Unresolved.Kind = UnresolvedModuleRef::Conflict;
5576  Unresolved.IsWildcard = false;
5577  Unresolved.String = Blob;
5578  UnresolvedModuleRefs.push_back(Unresolved);
5579  break;
5580  }
5581 
5582  case SUBMODULE_INITIALIZERS: {
5583  if (!ContextObj)
5584  break;
5586  for (auto &ID : Record)
5587  Inits.push_back(getGlobalDeclID(F, ID));
5588  ContextObj->addLazyModuleInitializers(CurrentModule, Inits);
5589  break;
5590  }
5591 
5592  case SUBMODULE_EXPORT_AS:
5593  CurrentModule->ExportAsModule = Blob.str();
5594  ModMap.addLinkAsDependency(CurrentModule);
5595  break;
5596  }
5597  }
5598 }
5599 
5600 /// Parse the record that corresponds to a LangOptions data
5601 /// structure.
5602 ///
5603 /// This routine parses the language options from the AST file and then gives
5604 /// them to the AST listener if one is set.
5605 ///
5606 /// \returns true if the listener deems the file unacceptable, false otherwise.
5607 bool ASTReader::ParseLanguageOptions(const RecordData &Record,
5608  bool Complain,
5609  ASTReaderListener &Listener,
5610  bool AllowCompatibleDifferences) {
5611  LangOptions LangOpts;
5612  unsigned Idx = 0;
5613 #define LANGOPT(Name, Bits, Default, Description) \
5614  LangOpts.Name = Record[Idx++];
5615 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
5616  LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
5617 #include "clang/Basic/LangOptions.def"
5618 #define SANITIZER(NAME, ID) \
5619  LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]);
5620 #include "clang/Basic/Sanitizers.def"
5621 
5622  for (unsigned N = Record[Idx++]; N; --N)
5623  LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx));
5624 
5625  ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++];
5626  VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx);
5627  LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion);
5628 
5629  LangOpts.CurrentModule = ReadString(Record, Idx);
5630 
5631  // Comment options.
5632  for (unsigned N = Record[Idx++]; N; --N) {
5633  LangOpts.CommentOpts.BlockCommandNames.push_back(
5634  ReadString(Record, Idx));
5635  }
5636  LangOpts.CommentOpts.ParseAllComments = Record[Idx++];
5637 
5638  // OpenMP offloading options.
5639  for (unsigned N = Record[Idx++]; N; --N) {
5640  LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx)));
5641  }
5642 
5643  LangOpts.OMPHostIRFile = ReadString(Record, Idx);
5644 
5645  return Listener.ReadLanguageOptions(LangOpts, Complain,
5646  AllowCompatibleDifferences);
5647 }
5648 
5649 bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain,
5650  ASTReaderListener &Listener,
5651  bool AllowCompatibleDifferences) {
5652  unsigned Idx = 0;
5653  TargetOptions TargetOpts;
5654  TargetOpts.Triple = ReadString(Record, Idx);
5655  TargetOpts.CPU = ReadString(Record, Idx);
5656  TargetOpts.ABI = ReadString(Record, Idx);
5657  for (unsigned N = Record[Idx++]; N; --N) {
5658  TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx));
5659  }
5660  for (unsigned N = Record[Idx++]; N; --N) {
5661  TargetOpts.Features.push_back(ReadString(Record, Idx));
5662  }
5663 
5664  return Listener.ReadTargetOptions(TargetOpts, Complain,
5665  AllowCompatibleDifferences);
5666 }
5667 
5668 bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain,
5669  ASTReaderListener &Listener) {
5671  unsigned Idx = 0;
5672 #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++];
5673 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
5674  DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));
5675 #include "clang/Basic/DiagnosticOptions.def"
5676 
5677  for (unsigned N = Record[Idx++]; N; --N)
5678  DiagOpts->Warnings.push_back(ReadString(Record, Idx));
5679  for (unsigned N = Record[Idx++]; N; --N)
5680  DiagOpts->Remarks.push_back(ReadString(Record, Idx));
5681 
5682  return Listener.ReadDiagnosticOptions(DiagOpts, Complain);
5683 }
5684 
5685 bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain,
5686  ASTReaderListener &Listener) {
5687  FileSystemOptions FSOpts;
5688  unsigned Idx = 0;
5689  FSOpts.WorkingDir = ReadString(Record, Idx);
5690  return Listener.ReadFileSystemOptions(FSOpts, Complain);
5691 }
5692 
5693 bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record,
5694  bool Complain,
5695  ASTReaderListener &Listener) {
5696  HeaderSearchOptions HSOpts;
5697  unsigned Idx = 0;
5698  HSOpts.Sysroot = ReadString(Record, Idx);
5699 
5700  // Include entries.
5701  for (unsigned N = Record[Idx++]; N; --N) {
5702  std::string Path = ReadString(Record, Idx);
5704  = static_cast<frontend::IncludeDirGroup>(Record[Idx++]);
5705  bool IsFramework = Record[Idx++];
5706  bool IgnoreSysRoot = Record[Idx++];
5707  HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework,
5708  IgnoreSysRoot);
5709  }
5710 
5711  // System header prefixes.
5712  for (unsigned N = Record[Idx++]; N; --N) {
5713  std::string Prefix = ReadString(Record, Idx);
5714  bool IsSystemHeader = Record[Idx++];
5715  HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
5716  }
5717 
5718  HSOpts.ResourceDir = ReadString(Record, Idx);
5719  HSOpts.ModuleCachePath = ReadString(Record, Idx);
5720  HSOpts.ModuleUserBuildPath = ReadString(Record, Idx);
5721  HSOpts.DisableModuleHash = Record[Idx++];
5722  HSOpts.ImplicitModuleMaps = Record[Idx++];
5723  HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++];
5724  HSOpts.UseBuiltinIncludes = Record[Idx++];
5725  HSOpts.UseStandardSystemIncludes = Record[Idx++];
5726  HSOpts.UseStandardCXXIncludes = Record[Idx++];
5727  HSOpts.UseLibcxx = Record[Idx++];
5728  std::string SpecificModuleCachePath = ReadString(Record, Idx);
5729 
5730  return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath,
5731  Complain);
5732 }
5733 
5734 bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
5735  bool Complain,
5736  ASTReaderListener &Listener,
5737  std::string &SuggestedPredefines) {
5738  PreprocessorOptions PPOpts;
5739  unsigned Idx = 0;
5740 
5741  // Macro definitions/undefs
5742  for (unsigned N = Record[Idx++]; N; --N) {
5743  std::string Macro = ReadString(Record, Idx);
5744  bool IsUndef = Record[Idx++];
5745  PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef));
5746  }
5747 
5748  // Includes
5749  for (unsigned N = Record[Idx++]; N; --N) {
5750  PPOpts.Includes.push_back(ReadString(Record, Idx));
5751  }
5752 
5753  // Macro Includes
5754  for (unsigned N = Record[Idx++]; N; --N) {
5755  PPOpts.MacroIncludes.push_back(ReadString(Record, Idx));
5756  }
5757 
5758  PPOpts.UsePredefines = Record[Idx++];
5759  PPOpts.DetailedRecord = Record[Idx++];
5760  PPOpts.ImplicitPCHInclude = ReadString(Record, Idx);
5761  PPOpts.ObjCXXARCStandardLibrary =
5762  static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]);
5763  SuggestedPredefines.clear();
5764  return Listener.ReadPreprocessorOptions(PPOpts, Complain,
5765  SuggestedPredefines);
5766 }
5767 
5768 std::pair<ModuleFile *, unsigned>
5769 ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) {
5771  I = GlobalPreprocessedEntityMap.find(GlobalIndex);
5772  assert(I != GlobalPreprocessedEntityMap.end() &&
5773  "Corrupted global preprocessed entity map");
5774  ModuleFile *M = I->second;
5775  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID;
5776  return std::make_pair(M, LocalIndex);
5777 }
5778 
5779 llvm::iterator_range<PreprocessingRecord::iterator>
5780 ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const {
5781  if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord())
5782  return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID,
5784 
5785  return llvm::make_range(PreprocessingRecord::iterator(),
5787 }
5788 
5789 llvm::iterator_range<ASTReader::ModuleDeclIterator>
5791  return llvm::make_range(
5792  ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls),
5793  ModuleDeclIterator(this, &Mod,
5794  Mod.FileSortedDecls + Mod.NumFileSortedDecls));
5795 }
5796 
5798  auto I = GlobalSkippedRangeMap.find(GlobalIndex);
5799  assert(I != GlobalSkippedRangeMap.end() &&
5800  "Corrupted global skipped range map");
5801  ModuleFile *M = I->second;
5802  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedSkippedRangeID;
5803  assert(LocalIndex < M->NumPreprocessedSkippedRanges);
5804  PPSkippedRange RawRange = M->PreprocessedSkippedRangeOffsets[LocalIndex];
5805  SourceRange Range(TranslateSourceLocation(*M, RawRange.getBegin()),
5806  TranslateSourceLocation(*M, RawRange.getEnd()));
5807  assert(Range.isValid());
5808  return Range;
5809 }
5810 
5812  PreprocessedEntityID PPID = Index+1;
5813  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
5814  ModuleFile &M = *PPInfo.first;
5815  unsigned LocalIndex = PPInfo.second;
5816  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
5817 
5818  if (!PP.getPreprocessingRecord()) {
5819  Error("no preprocessing record");
5820  return nullptr;
5821  }
5822 
5824  if (llvm::Error Err =
5825  M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset)) {
5826  Error(std::move(Err));
5827  return nullptr;
5828  }
5829 
5830  Expected<llvm::BitstreamEntry> MaybeEntry =
5831  M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
5832  if (!MaybeEntry) {
5833  Error(MaybeEntry.takeError());
5834  return nullptr;
5835  }
5836  llvm::BitstreamEntry Entry = MaybeEntry.get();
5837 
5838  if (Entry.Kind != llvm::BitstreamEntry::Record)
5839  return nullptr;
5840 
5841  // Read the record.
5842  SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()),
5843  TranslateSourceLocation(M, PPOffs.getEnd()));
5844  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
5845  StringRef Blob;
5846  RecordData Record;
5847  Expected<unsigned> MaybeRecType =
5848  M.PreprocessorDetailCursor.readRecord(Entry.ID, Record, &Blob);
5849  if (!MaybeRecType) {
5850  Error(MaybeRecType.takeError());
5851  return nullptr;
5852  }
5853  switch ((PreprocessorDetailRecordTypes)MaybeRecType.get()) {
5854  case PPD_MACRO_EXPANSION: {
5855  bool isBuiltin = Record[0];
5856  IdentifierInfo *Name = nullptr;
5857  MacroDefinitionRecord *Def = nullptr;
5858  if (isBuiltin)
5859  Name = getLocalIdentifier(M, Record[1]);
5860  else {
5861  PreprocessedEntityID GlobalID =
5862  getGlobalPreprocessedEntityID(M, Record[1]);
5863  Def = cast<MacroDefinitionRecord>(
5864  PPRec.getLoadedPreprocessedEntity(GlobalID - 1));
5865  }
5866 
5867  MacroExpansion *ME;
5868  if (isBuiltin)
5869  ME = new (PPRec) MacroExpansion(Name, Range);
5870  else
5871  ME = new (PPRec) MacroExpansion(Def, Range);
5872 
5873  return ME;
5874  }
5875 
5876  case PPD_MACRO_DEFINITION: {
5877  // Decode the identifier info and then check again; if the macro is
5878  // still defined and associated with the identifier,
5879  IdentifierInfo *II = getLocalIdentifier(M, Record[0]);
5880  MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range);
5881 
5882  if (DeserializationListener)
5883  DeserializationListener->MacroDefinitionRead(PPID, MD);
5884 
5885  return MD;
5886  }
5887 
5888  case PPD_INCLUSION_DIRECTIVE: {
5889  const char *FullFileNameStart = Blob.data() + Record[0];
5890  StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
5891  const FileEntry *File = nullptr;
5892  if (!FullFileName.empty())
5893  File = PP.getFileManager().getFile(FullFileName);
5894 
5895  // FIXME: Stable encoding
5897  = static_cast<InclusionDirective::InclusionKind>(Record[2]);
5899  = new (PPRec) InclusionDirective(PPRec, Kind,
5900  StringRef(Blob.data(), Record[0]),
5901  Record[1], Record[3],
5902  File,
5903  Range);
5904  return ID;
5905  }
5906  }
5907 
5908  llvm_unreachable("Invalid PreprocessorDetailRecordTypes");
5909 }
5910 
5911 /// Find the next module that contains entities and return the ID
5912 /// of the first entry.
5913 ///
5914 /// \param SLocMapI points at a chunk of a module that contains no
5915 /// preprocessed entities or the entities it contains are not the ones we are
5916 /// looking for.
5917 PreprocessedEntityID ASTReader::findNextPreprocessedEntity(
5918  GlobalSLocOffsetMapType::const_iterator SLocMapI) const {
5919  ++SLocMapI;
5920  for (GlobalSLocOffsetMapType::const_iterator
5921  EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) {
5922  ModuleFile &M = *SLocMapI->second;
5924  return M.BasePreprocessedEntityID;
5925  }
5926 
5927  return getTotalNumPreprocessedEntities();
5928 }
5929 
5930 namespace {
5931 
5932 struct PPEntityComp {
5933  const ASTReader &Reader;
5934  ModuleFile &M;
5935 
5936  PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) {}
5937 
5938  bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const {
5939  SourceLocation LHS = getLoc(L);
5940  SourceLocation RHS = getLoc(R);
5941  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5942  }
5943 
5944  bool operator()(const PPEntityOffset &L, SourceLocation RHS) const {
5945  SourceLocation LHS = getLoc(L);
5946  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5947  }
5948 
5949  bool operator()(SourceLocation LHS, const PPEntityOffset &R) const {
5950  SourceLocation RHS = getLoc(R);
5951  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
5952  }
5953 
5954  SourceLocation getLoc(const PPEntityOffset &PPE) const {
5955  return Reader.TranslateSourceLocation(M, PPE.getBegin());
5956  }
5957 };
5958 
5959 } // namespace
5960 
5961 PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc,
5962  bool EndsAfter) const {
5963  if (SourceMgr.isLocalSourceLocation(Loc))
5964  return getTotalNumPreprocessedEntities();
5965 
5966  GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find(
5967  SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
5968  assert(SLocMapI != GlobalSLocOffsetMap.end() &&
5969  "Corrupted global sloc offset map");
5970 
5971  if (SLocMapI->second->NumPreprocessedEntities == 0)
5972  return findNextPreprocessedEntity(SLocMapI);
5973 
5974  ModuleFile &M = *SLocMapI->second;
5975 
5976  using pp_iterator = const PPEntityOffset *;
5977 
5978  pp_iterator pp_begin = M.PreprocessedEntityOffsets;
5979  pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities;
5980 
5981  size_t Count = M.NumPreprocessedEntities;
5982  size_t Half;
5983  pp_iterator First = pp_begin;
5984  pp_iterator PPI;
5985 
5986  if (EndsAfter) {
5987  PPI = std::upper_bound(pp_begin, pp_end, Loc,
5988  PPEntityComp(*this, M));
5989  } else {
5990  // Do a binary search manually instead of using std::lower_bound because
5991  // The end locations of entities may be unordered (when a macro expansion
5992  // is inside another macro argument), but for this case it is not important
5993  // whether we get the first macro expansion or its containing macro.
5994  while (Count > 0) {
5995  Half = Count / 2;
5996  PPI = First;
5997  std::advance(PPI, Half);
5998  if (SourceMgr.isBeforeInTranslationUnit(
5999  TranslateSourceLocation(M, PPI->getEnd()), Loc)) {
6000  First = PPI;
6001  ++First;
6002  Count = Count - Half - 1;
6003  } else
6004  Count = Half;
6005  }
6006  }
6007 
6008  if (PPI == pp_end)
6009  return findNextPreprocessedEntity(SLocMapI);
6010 
6011  return M.BasePreprocessedEntityID + (PPI - pp_begin);
6012 }
6013 
6014 /// Returns a pair of [Begin, End) indices of preallocated
6015 /// preprocessed entities that \arg Range encompasses.
6016 std::pair<unsigned, unsigned>
6018  if (Range.isInvalid())
6019  return std::make_pair(0,0);
6020  assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
6021 
6022  PreprocessedEntityID BeginID =
6023  findPreprocessedEntity(Range.getBegin(), false);
6024  PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true);
6025  return std::make_pair(BeginID, EndID);
6026 }
6027 
6028 /// Optionally returns true or false if the preallocated preprocessed
6029 /// entity with index \arg Index came from file \arg FID.
6031  FileID FID) {
6032  if (FID.isInvalid())
6033  return false;
6034 
6035  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
6036  ModuleFile &M = *PPInfo.first;
6037  unsigned LocalIndex = PPInfo.second;
6038  const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
6039 
6040  SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin());
6041  if (Loc.isInvalid())
6042  return false;
6043 
6044  if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID))
6045  return true;
6046  else
6047  return false;
6048 }
6049 
6050 namespace {
6051 
6052  /// Visitor used to search for information about a header file.
6053  class HeaderFileInfoVisitor {
6054  const FileEntry *FE;
6056 
6057  public:
6058  explicit HeaderFileInfoVisitor(const FileEntry *FE) : FE(FE) {}
6059 
6060  bool operator()(ModuleFile &M) {
6062  = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable);
6063  if (!Table)
6064  return false;
6065 
6066  // Look in the on-disk hash table for an entry for this file name.
6067  HeaderFileInfoLookupTable::iterator Pos = Table->find(FE);
6068  if (Pos == Table->end())
6069  return false;
6070 
6071  HFI = *Pos;
6072  return true;
6073  }
6074 
6075  Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; }
6076  };
6077 
6078 } // namespace
6079 
6081  HeaderFileInfoVisitor Visitor(FE);
6082  ModuleMgr.visit(Visitor);
6083  if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo())
6084  return *HFI;
6085 
6086  return HeaderFileInfo();
6087 }
6088 
6090  using DiagState = DiagnosticsEngine::DiagState;
6091  SmallVector<DiagState *, 32> DiagStates;
6092 
6093  for (ModuleFile &F : ModuleMgr) {
6094  unsigned Idx = 0;
6095  auto &Record = F.PragmaDiagMappings;
6096  if (Record.empty())
6097  continue;
6098 
6099  DiagStates.clear();
6100 
6101  auto ReadDiagState =
6102  [&](const DiagState &BasedOn, SourceLocation Loc,
6103  bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * {
6104  unsigned BackrefID = Record[Idx++];
6105  if (BackrefID != 0)
6106  return DiagStates[BackrefID - 1];
6107 
6108  // A new DiagState was created here.
6109  Diag.DiagStates.push_back(BasedOn);
6110  DiagState *NewState = &Diag.DiagStates.back();
6111  DiagStates.push_back(NewState);
6112  unsigned Size = Record[Idx++];
6113  assert(Idx + Size * 2 <= Record.size() &&
6114  "Invalid data, not enough diag/map pairs");
6115  while (Size--) {
6116  unsigned DiagID = Record[Idx++];
6117  DiagnosticMapping NewMapping =
6118  DiagnosticMapping::deserialize(Record[Idx++]);
6119  if (!NewMapping.isPragma() && !IncludeNonPragmaStates)
6120  continue;
6121 
6122  DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID);
6123 
6124  // If this mapping was specified as a warning but the severity was
6125  // upgraded due to diagnostic settings, simulate the current diagnostic
6126  // settings (and use a warning).
6127  if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) {
6129  NewMapping.setUpgradedFromWarning(false);
6130  }
6131 
6132  Mapping = NewMapping;
6133  }
6134  return NewState;
6135  };
6136 
6137  // Read the first state.
6138  DiagState *FirstState;
6139  if (F.Kind == MK_ImplicitModule) {
6140  // Implicitly-built modules are reused with different diagnostic
6141  // settings. Use the initial diagnostic state from Diag to simulate this
6142  // compilation's diagnostic settings.
6143  FirstState = Diag.DiagStatesByLoc.FirstDiagState;
6144  DiagStates.push_back(FirstState);
6145 
6146  // Skip the initial diagnostic state from the serialized module.
6147  assert(Record[1] == 0 &&
6148  "Invalid data, unexpected backref in initial state");
6149  Idx = 3 + Record[2] * 2;
6150  assert(Idx < Record.size() &&
6151  "Invalid data, not enough state change pairs in initial state");
6152  } else if (F.isModule()) {
6153  // For an explicit module, preserve the flags from the module build
6154  // command line (-w, -Weverything, -Werror, ...) along with any explicit
6155  // -Wblah flags.
6156  unsigned Flags = Record[Idx++];
6157  DiagState Initial;
6158  Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1;
6159  Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1;
6160  Initial.WarningsAsErrors = Flags & 1; Flags >>= 1;
6161  Initial.EnableAllWarnings = Flags & 1; Flags >>= 1;
6162  Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1;
6163  Initial.ExtBehavior = (diag::Severity)Flags;
6164  FirstState = ReadDiagState(Initial, SourceLocation(), true);
6165 
6166  assert(F.OriginalSourceFileID.isValid());
6167 
6168  // Set up the root buffer of the module to start with the initial
6169  // diagnostic state of the module itself, to cover files that contain no
6170  // explicit transitions (for which we did not serialize anything).
6171  Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID]
6172  .StateTransitions.push_back({FirstState, 0});
6173  } else {
6174  // For prefix ASTs, start with whatever the user configured on the
6175  // command line.
6176  Idx++; // Skip flags.
6177  FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState,
6178  SourceLocation(), false);
6179  }
6180 
6181  // Read the state transitions.
6182  unsigned NumLocations = Record[Idx++];
6183  while (NumLocations--) {
6184  assert(Idx < Record.size() &&
6185  "Invalid data, missing pragma diagnostic states");
6186  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
6187  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
6188  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
6189  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
6190  unsigned Transitions = Record[Idx++];
6191 
6192  // Note that we don't need to set up Parent/ParentOffset here, because
6193  // we won't be changing the diagnostic state within imported FileIDs
6194  // (other than perhaps appending to the main source file, which has no
6195  // parent).
6196  auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
6197  F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
6198  for (unsigned I = 0; I != Transitions; ++I) {
6199  unsigned Offset = Record[Idx++];
6200  auto *State =
6201  ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false);
6202  F.StateTransitions.push_back({State, Offset});
6203  }
6204  }
6205 
6206  // Read the final state.
6207  assert(Idx < Record.size() &&
6208  "Invalid data, missing final pragma diagnostic state");
6209  SourceLocation CurStateLoc =
6210  ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
6211  auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false);
6212 
6213  if (!F.isModule()) {
6214  Diag.DiagStatesByLoc.CurDiagState = CurState;
6215  Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc;
6216 
6217  // Preserve the property that the imaginary root file describes the
6218  // current state.
6219  FileID NullFile;
6220  auto &T = Diag.DiagStatesByLoc.Files[NullFile].StateTransitions;
6221  if (T.empty())
6222  T.push_back({CurState, 0});
6223  else
6224  T[0].State = CurState;
6225  }
6226 
6227  // Don't try to read these mappings again.
6228  Record.clear();
6229  }
6230 }
6231 
6232 /// Get the correct cursor and offset for loading a type.
6233 ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
6234  GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index);
6235  assert(I != GlobalTypeMap.end() && "Corrupted global type map");
6236  ModuleFile *M = I->second;
6237  return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]);
6238 }
6239 
6240 /// Read and return the type with the given index..
6241 ///
6242 /// The index is the type ID, shifted and minus the number of predefs. This
6243 /// routine actually reads the record corresponding to the type at the given
6244 /// location. It is a helper routine for GetType, which deals with reading type
6245 /// IDs.
6246 QualType ASTReader::readTypeRecord(unsigned Index) {
6247  assert(ContextObj && "reading type with no AST context");
6248  ASTContext &Context = *ContextObj;
6249  RecordLocation Loc = TypeCursorForIndex(Index);
6250  BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
6251 
6252  // Keep track of where we are in the stream, then jump back there
6253  // after reading this type.
6254  SavedStreamPosition SavedPosition(DeclsCursor);
6255 
6256  ReadingKindTracker ReadingKind(Read_Type, *this);
6257 
6258  // Note that we are loading a type record.
6259  Deserializing AType(this);
6260 
6261  unsigned Idx = 0;
6262  if (llvm::Error Err = DeclsCursor.JumpToBit(Loc.Offset)) {
6263  Error(std::move(Err));
6264  return QualType();
6265  }
6266  RecordData Record;
6267  Expected<unsigned> MaybeCode = DeclsCursor.ReadCode();
6268  if (!MaybeCode) {
6269  Error(MaybeCode.takeError());
6270  return QualType();
6271  }
6272  unsigned Code = MaybeCode.get();
6273 
6274  Expected<unsigned> MaybeTypeCode = DeclsCursor.readRecord(Code, Record);
6275  if (!MaybeTypeCode) {
6276  Error(MaybeTypeCode.takeError());
6277  return QualType();
6278  }
6279  switch ((TypeCode)MaybeTypeCode.get()) {
6280  case TYPE_EXT_QUAL: {
6281  if (Record.size() != 2) {
6282  Error("Incorrect encoding of extended qualifier type");
6283  return QualType();
6284  }
6285  QualType Base = readType(*Loc.F, Record, Idx);
6286  Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]);
6287  return Context.getQualifiedType(Base, Quals);
6288  }
6289 
6290  case TYPE_COMPLEX: {
6291  if (Record.size() != 1) {
6292  Error("Incorrect encoding of complex type");
6293  return QualType();
6294  }
6295  QualType ElemType = readType(*Loc.F, Record, Idx);
6296  return Context.getComplexType(ElemType);
6297  }
6298 
6299  case TYPE_POINTER: {
6300  if (Record.size() != 1) {
6301  Error("Incorrect encoding of pointer type");
6302  return QualType();
6303  }
6304  QualType PointeeType = readType(*Loc.F, Record, Idx);
6305  return Context.getPointerType(PointeeType);
6306  }
6307 
6308  case TYPE_DECAYED: {
6309  if (Record.size() != 1) {
6310  Error("Incorrect encoding of decayed type");
6311  return QualType();
6312  }
6313  QualType OriginalType = readType(*Loc.F, Record, Idx);
6314  QualType DT = Context.getAdjustedParameterType(OriginalType);
6315  if (!isa<DecayedType>(DT))
6316  Error("Decayed type does not decay");
6317  return DT;
6318  }
6319 
6320  case TYPE_ADJUSTED: {
6321  if (Record.size() != 2) {
6322  Error("Incorrect encoding of adjusted type");
6323  return QualType();
6324  }
6325  QualType OriginalTy = readType(*Loc.F, Record, Idx);
6326  QualType AdjustedTy = readType(*Loc.F, Record, Idx);
6327  return Context.getAdjustedType(OriginalTy, AdjustedTy);
6328  }
6329 
6330  case TYPE_BLOCK_POINTER: {
6331  if (Record.size() != 1) {
6332  Error("Incorrect encoding of block pointer type");
6333  return QualType();
6334  }
6335  QualType PointeeType = readType(*Loc.F, Record, Idx);
6336  return Context.getBlockPointerType(PointeeType);
6337  }
6338 
6339  case TYPE_LVALUE_REFERENCE: {
6340  if (Record.size() != 2) {
6341  Error("Incorrect encoding of lvalue reference type");
6342  return QualType();
6343  }
6344  QualType PointeeType = readType(*Loc.F, Record, Idx);
6345  return Context.getLValueReferenceType(PointeeType, Record[1]);
6346  }
6347 
6348  case TYPE_RVALUE_REFERENCE: {
6349  if (Record.size() != 1) {
6350  Error("Incorrect encoding of rvalue reference type");
6351  return QualType();
6352  }
6353  QualType PointeeType = readType(*Loc.F, Record, Idx);
6354  return Context.getRValueReferenceType(PointeeType);
6355  }
6356 
6357  case TYPE_MEMBER_POINTER: {
6358  if (Record.size() != 2) {
6359  Error("Incorrect encoding of member pointer type");
6360  return QualType();
6361  }
6362  QualType PointeeType = readType(*Loc.F, Record, Idx);
6363  QualType ClassType = readType(*Loc.F, Record, Idx);
6364  if (PointeeType.isNull() || ClassType.isNull())
6365  return QualType();
6366 
6367  return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr());
6368  }
6369 
6370  case TYPE_CONSTANT_ARRAY: {
6371  QualType ElementType = readType(*Loc.F, Record, Idx);
6373  unsigned IndexTypeQuals = Record[2];
6374  unsigned Idx = 3;
6375  llvm::APInt Size = ReadAPInt(Record, Idx);
6376  return Context.getConstantArrayType(ElementType, Size,
6377  ASM, IndexTypeQuals);
6378  }
6379 
6380  case TYPE_INCOMPLETE_ARRAY: {
6381  QualType ElementType = readType(*Loc.F, Record, Idx);
6383  unsigned IndexTypeQuals = Record[2];
6384  return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
6385  }
6386 
6387  case TYPE_VARIABLE_ARRAY: {
6388  QualType ElementType = readType(*Loc.F, Record, Idx);
6390  unsigned IndexTypeQuals = Record[2];
6391  SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]);
6392  SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]);
6393  return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F),
6394  ASM, IndexTypeQuals,
6395  SourceRange(LBLoc, RBLoc));
6396  }
6397 
6398  case TYPE_VECTOR: {
6399  if (Record.size() != 3) {
6400  Error("incorrect encoding of vector type in AST file");
6401  return QualType();
6402  }
6403 
6404  QualType ElementType = readType(*Loc.F, Record, Idx);
6405  unsigned NumElements = Record[1];
6406  unsigned VecKind = Record[2];
6407  return Context.getVectorType(ElementType, NumElements,
6408  (VectorType::VectorKind)VecKind);
6409  }
6410 
6411  case TYPE_EXT_VECTOR: {
6412  if (Record.size() != 3) {
6413  Error("incorrect encoding of extended vector type in AST file");
6414  return QualType();
6415  }
6416 
6417  QualType ElementType = readType(*Loc.F, Record, Idx);
6418  unsigned NumElements = Record[1];
6419  return Context.getExtVectorType(ElementType, NumElements);
6420  }
6421 
6422  case TYPE_FUNCTION_NO_PROTO: {
6423  if (Record.size() != 8) {
6424  Error("incorrect encoding of no-proto function type");
6425  return QualType();
6426  }
6427  QualType ResultType = readType(*Loc.F, Record, Idx);
6428  FunctionType::ExtInfo Info(Record[1], Record[2], Record[3],
6429  (CallingConv)Record[4], Record[5], Record[6],
6430  Record[7]);
6431  return Context.getFunctionNoProtoType(ResultType, Info);
6432  }
6433 
6434  case TYPE_FUNCTION_PROTO: {
6435  QualType ResultType = readType(*Loc.F, Record, Idx);
6436 
6438  EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1],
6439  /*hasregparm*/ Record[2],
6440  /*regparm*/ Record[3],
6441  static_cast<CallingConv>(Record[4]),
6442  /*produces*/ Record[5],
6443  /*nocallersavedregs*/ Record[6],
6444  /*nocfcheck*/ Record[7]);
6445 
6446  unsigned Idx = 8;
6447 
6448  EPI.Variadic = Record[Idx++];
6449  EPI.HasTrailingReturn = Record[Idx++];
6450  EPI.TypeQuals = Qualifiers::fromOpaqueValue(Record[Idx++]);
6451  EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]);
6452  SmallVector<QualType, 8> ExceptionStorage;
6453  readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx);
6454 
6455  unsigned NumParams = Record[Idx++];
6456  SmallVector<QualType, 16> ParamTypes;
6457  for (unsigned I = 0; I != NumParams; ++I)
6458  ParamTypes.push_back(readType(*Loc.F, Record, Idx));
6459 
6461  if (Idx != Record.size()) {
6462  for (unsigned I = 0; I != NumParams; ++I)
6463  ExtParameterInfos.push_back(
6465  ::getFromOpaqueValue(Record[Idx++]));
6466  EPI.ExtParameterInfos = ExtParameterInfos.data();
6467  }
6468 
6469  assert(Idx == Record.size());
6470 
6471  return Context.getFunctionType(ResultType, ParamTypes, EPI);
6472  }
6473 
6474  case TYPE_UNRESOLVED_USING: {
6475  unsigned Idx = 0;
6476  return Context.getTypeDeclType(
6477  ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx));
6478  }
6479 
6480  case TYPE_TYPEDEF: {
6481  if (Record.size() != 2) {
6482  Error("incorrect encoding of typedef type");
6483  return QualType();
6484  }
6485  unsigned Idx = 0;
6486  TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx);
6487  QualType Canonical = readType(*Loc.F, Record, Idx);
6488  if (!Canonical.isNull())
6489  Canonical = Context.getCanonicalType(Canonical);
6490  return Context.getTypedefType(Decl, Canonical);
6491  }
6492 
6493  case TYPE_TYPEOF_EXPR:
6494  return Context.getTypeOfExprType(ReadExpr(*Loc.F));
6495 
6496  case TYPE_TYPEOF: {
6497  if (Record.size() != 1) {
6498  Error("incorrect encoding of typeof(type) in AST file");
6499  return QualType();
6500  }
6501  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6502  return Context.getTypeOfType(UnderlyingType);
6503  }
6504 
6505  case TYPE_DECLTYPE: {
6506  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6507  return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType);
6508  }
6509 
6510  case TYPE_UNARY_TRANSFORM: {
6511  QualType BaseType = readType(*Loc.F, Record, Idx);
6512  QualType UnderlyingType = readType(*Loc.F, Record, Idx);
6514  return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind);
6515  }
6516 
6517  case TYPE_AUTO: {
6518  QualType Deduced = readType(*Loc.F, Record, Idx);
6519  AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++];
6520  bool IsDependent = false, IsPack = false;
6521  if (Deduced.isNull()) {
6522  IsDependent = Record[Idx] > 0;
6523  IsPack = Record[Idx] > 1;
6524  ++Idx;
6525  }
6526  return Context.getAutoType(Deduced, Keyword, IsDependent, IsPack);
6527  }
6528 
6530  TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
6531  QualType Deduced = readType(*Loc.F, Record, Idx);
6532  bool IsDependent = Deduced.isNull() ? Record[Idx++] : false;
6533  return Context.getDeducedTemplateSpecializationType(Name, Deduced,
6534  IsDependent);
6535  }
6536 
6537  case TYPE_RECORD: {
6538  if (Record.size() != 2) {
6539  Error("incorrect encoding of record type");
6540  return QualType();
6541  }
6542  unsigned Idx = 0;
6543  bool IsDependent = Record[Idx++];
6544  RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx);
6545  RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl());
6546  QualType T = Context.getRecordType(RD);
6547  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6548  return T;
6549  }
6550 
6551  case TYPE_ENUM: {
6552  if (Record.size() != 2) {
6553  Error("incorrect encoding of enum type");
6554  return QualType();
6555  }
6556  unsigned Idx = 0;
6557  bool IsDependent = Record[Idx++];
6558  QualType T
6559  = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx));
6560  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6561  return T;
6562  }
6563 
6564  case TYPE_ATTRIBUTED: {
6565  if (Record.size() != 3) {
6566  Error("incorrect encoding of attributed type");
6567  return QualType();
6568  }
6569  QualType modifiedType = readType(*Loc.F, Record, Idx);
6570  QualType equivalentType = readType(*Loc.F, Record, Idx);
6571  AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]);
6572  return Context.getAttributedType(kind, modifiedType, equivalentType);
6573  }
6574 
6575  case TYPE_PAREN: {
6576  if (Record.size() != 1) {
6577  Error("incorrect encoding of paren type");
6578  return QualType();
6579  }
6580  QualType InnerType = readType(*Loc.F, Record, Idx);
6581  return Context.getParenType(InnerType);
6582  }
6583 
6584  case TYPE_MACRO_QUALIFIED: {
6585  if (Record.size() != 2) {
6586  Error("incorrect encoding of macro defined type");
6587  return QualType();
6588  }
6589  QualType UnderlyingTy = readType(*Loc.F, Record, Idx);
6590  IdentifierInfo *MacroII = GetIdentifierInfo(*Loc.F, Record, Idx);
6591  return Context.getMacroQualifiedType(UnderlyingTy, MacroII);
6592  }
6593 
6594  case TYPE_PACK_EXPANSION: {
6595  if (Record.size() != 2) {
6596  Error("incorrect encoding of pack expansion type");
6597  return QualType();
6598  }
6599  QualType Pattern = readType(*Loc.F, Record, Idx);
6600  if (Pattern.isNull())
6601  return QualType();
6602  Optional<unsigned> NumExpansions;
6603  if (Record[1])
6604  NumExpansions = Record[1] - 1;
6605  return Context.getPackExpansionType(Pattern, NumExpansions);
6606  }
6607 
6608  case TYPE_ELABORATED: {
6609  unsigned Idx = 0;
6610  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6611  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6612  QualType NamedType = readType(*Loc.F, Record, Idx);
6613  TagDecl *OwnedTagDecl = ReadDeclAs<TagDecl>(*Loc.F, Record, Idx);
6614  return Context.getElaboratedType(Keyword, NNS, NamedType, OwnedTagDecl);
6615  }
6616 
6617  case TYPE_OBJC_INTERFACE: {
6618  unsigned Idx = 0;
6619  ObjCInterfaceDecl *ItfD
6620  = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx);
6621  return Context.getObjCInterfaceType(ItfD->getCanonicalDecl());
6622  }
6623 
6624  case TYPE_OBJC_TYPE_PARAM: {
6625  unsigned Idx = 0;
6627  = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx);
6628  unsigned NumProtos = Record[Idx++];
6630  for (unsigned I = 0; I != NumProtos; ++I)
6631  Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx));
6632  return Context.getObjCTypeParamType(Decl, Protos);
6633  }
6634 
6635  case TYPE_OBJC_OBJECT: {
6636  unsigned Idx = 0;
6637  QualType Base = readType(*Loc.F, Record, Idx);
6638  unsigned NumTypeArgs = Record[Idx++];
6639  SmallVector<QualType, 4> TypeArgs;
6640  for (unsigned I = 0; I != NumTypeArgs; ++I)
6641  TypeArgs.push_back(readType(*Loc.F, Record, Idx));
6642  unsigned NumProtos = Record[Idx++];
6644  for (unsigned I = 0; I != NumProtos; ++I)
6645  Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx));
6646  bool IsKindOf = Record[Idx++];
6647  return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf);
6648  }
6649 
6650  case TYPE_OBJC_OBJECT_POINTER: {
6651  unsigned Idx = 0;
6652  QualType Pointee = readType(*Loc.F, Record, Idx);
6653  return Context.getObjCObjectPointerType(Pointee);
6654  }
6655 
6657  unsigned Idx = 0;
6658  QualType Parm = readType(*Loc.F, Record, Idx);
6659  QualType Replacement = readType(*Loc.F, Record, Idx);
6660  return Context.getSubstTemplateTypeParmType(
6661  cast<TemplateTypeParmType>(Parm),
6662  Context.getCanonicalType(Replacement));
6663  }
6664 
6666  unsigned Idx = 0;
6667  QualType Parm = readType(*Loc.F, Record, Idx);
6668  TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx);
6669  return Context.getSubstTemplateTypeParmPackType(
6670  cast<TemplateTypeParmType>(Parm),
6671  ArgPack);
6672  }
6673 
6674  case TYPE_INJECTED_CLASS_NAME: {
6675  CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx);
6676  QualType TST = readType(*Loc.F, Record, Idx); // probably derivable
6677  // FIXME: ASTContext::getInjectedClassNameType is not currently suitable
6678  // for AST reading, too much interdependencies.
6679  const Type *T = nullptr;
6680  for (auto *DI = D; DI; DI = DI->getPreviousDecl()) {
6681  if (const Type *Existing = DI->getTypeForDecl()) {
6682  T = Existing;
6683  break;
6684  }
6685  }
6686  if (!T) {
6687  T = new (Context, TypeAlignment) InjectedClassNameType(D, TST);
6688  for (auto *DI = D; DI; DI = DI->getPreviousDecl())
6689  DI->setTypeForDecl(T);
6690  }
6691  return QualType(T, 0);
6692  }
6693 
6694  case TYPE_TEMPLATE_TYPE_PARM: {
6695  unsigned Idx = 0;
6696  unsigned Depth = Record[Idx++];
6697  unsigned Index = Record[Idx++];
6698  bool Pack = Record[Idx++];
6700  = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx);
6701  return Context.getTemplateTypeParmType(Depth, Index, Pack, D);
6702  }
6703 
6704  case TYPE_DEPENDENT_NAME: {
6705  unsigned Idx = 0;
6706  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6707  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6708  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
6709  QualType Canon = readType(*Loc.F, Record, Idx);
6710  if (!Canon.isNull())
6711  Canon = Context.getCanonicalType(Canon);
6712  return Context.getDependentNameType(Keyword, NNS, Name, Canon);
6713  }
6714 
6716  unsigned Idx = 0;
6717  ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
6718  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
6719  const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx);
6720  unsigned NumArgs = Record[Idx++];
6722  Args.reserve(NumArgs);
6723  while (NumArgs--)
6724  Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx));
6725  return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name,
6726  Args);
6727  }
6728 
6730  unsigned Idx = 0;
6731 
6732  // ArrayType
6733  QualType ElementType = readType(*Loc.F, Record, Idx);
6735  = (ArrayType::ArraySizeModifier)Record[Idx++];
6736  unsigned IndexTypeQuals = Record[Idx++];
6737 
6738  // DependentSizedArrayType
6739  Expr *NumElts = ReadExpr(*Loc.F);
6740  SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx);
6741 
6742  return Context.getDependentSizedArrayType(ElementType, NumElts, ASM,
6743  IndexTypeQuals, Brackets);
6744  }
6745 
6747  unsigned Idx = 0;
6748  bool IsDependent = Record[Idx++];
6749  TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
6751  ReadTemplateArgumentList(Args, *Loc.F, Record, Idx);
6752  QualType Underlying = readType(*Loc.F, Record, Idx);
6753  QualType T;
6754  if (Underlying.isNull())
6755  T = Context.getCanonicalTemplateSpecializationType(Name, Args);
6756  else
6757  T = Context.getTemplateSpecializationType(Name, Args, Underlying);
6758  const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
6759  return T;
6760  }
6761 
6762  case TYPE_ATOMIC: {
6763  if (Record.size() != 1) {
6764  Error("Incorrect encoding of atomic type");
6765  return QualType();
6766  }
6767  QualType ValueType = readType(*Loc.F, Record, Idx);
6768  return Context.getAtomicType(ValueType);
6769  }
6770 
6771  case TYPE_PIPE: {
6772  if (Record.size() != 2) {
6773  Error("Incorrect encoding of pipe type");
6774  return QualType();
6775  }
6776 
6777  // Reading the pipe element type.
6778  QualType ElementType = readType(*Loc.F, Record, Idx);
6779  unsigned ReadOnly = Record[1];
6780  return Context.getPipeType(ElementType, ReadOnly);
6781  }
6782 
6784  unsigned Idx = 0;
6785  QualType ElementType = readType(*Loc.F, Record, Idx);
6786  Expr *SizeExpr = ReadExpr(*Loc.F);
6787  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6788  unsigned VecKind = Record[Idx];
6789 
6790  return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc,
6791  (VectorType::VectorKind)VecKind);
6792  }
6793 
6795  unsigned Idx = 0;
6796 
6797  // DependentSizedExtVectorType
6798  QualType ElementType = readType(*Loc.F, Record, Idx);
6799  Expr *SizeExpr = ReadExpr(*Loc.F);
6800  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6801 
6802  return Context.getDependentSizedExtVectorType(ElementType, SizeExpr,
6803  AttrLoc);
6804  }
6805 
6807  unsigned Idx = 0;
6808 
6809  // DependentAddressSpaceType
6810  QualType PointeeType = readType(*Loc.F, Record, Idx);
6811  Expr *AddrSpaceExpr = ReadExpr(*Loc.F);
6812  SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
6813 
6814  return Context.getDependentAddressSpaceType(PointeeType, AddrSpaceExpr,
6815  AttrLoc);
6816  }
6817  }
6818  llvm_unreachable("Invalid TypeCode!");
6819 }
6820 
6821 void ASTReader::readExceptionSpec(ModuleFile &ModuleFile,
6822  SmallVectorImpl<QualType> &Exceptions,
6824  const RecordData &Record, unsigned &Idx) {
6826  static_cast<ExceptionSpecificationType>(Record[Idx++]);
6827  ESI.Type = EST;
6828  if (EST == EST_Dynamic) {
6829  for (unsigned I = 0, N = Record[Idx++]; I != N; ++I)
6830  Exceptions.push_back(readType(ModuleFile, Record, Idx));
6831  ESI.Exceptions = Exceptions;
6832  } else if (isComputedNoexcept(EST)) {
6833  ESI.NoexceptExpr = ReadExpr(ModuleFile);
6834  } else if (EST == EST_Uninstantiated) {
6835  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6836  ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6837  } else if (EST == EST_Unevaluated) {
6838  ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx);
6839  }
6840 }
6841 
6842 namespace clang {
6843 
6844 class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
6845  ModuleFile *F;
6846  ASTReader *Reader;
6847  const ASTReader::RecordData &Record;
6848  unsigned &Idx;
6849 
6850  SourceLocation ReadSourceLocation() {
6851  return Reader->ReadSourceLocation(*F, Record, Idx);
6852  }
6853 
6854  TypeSourceInfo *GetTypeSourceInfo() {
6855  return Reader->GetTypeSourceInfo(*F, Record, Idx);
6856  }
6857 
6858  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() {
6859  return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
6860  }
6861 
6862  Attr *ReadAttr() {
6863  return Reader->ReadAttr(*F, Record, Idx);
6864  }
6865 
6866 public:
6867  TypeLocReader(ModuleFile &F, ASTReader &Reader,
6868  const ASTReader::RecordData &Record, unsigned &Idx)
6869  : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {}
6870 
6871  // We want compile-time assurance that we've enumerated all of
6872  // these, so unfortunately we have to declare them first, then
6873  // define them out-of-line.
6874 #define ABSTRACT_TYPELOC(CLASS, PARENT)
6875 #define TYPELOC(CLASS, PARENT) \
6876  void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
6877 #include "clang/AST/TypeLocNodes.def"
6878 
6879  void VisitFunctionTypeLoc(FunctionTypeLoc);
6880  void VisitArrayTypeLoc(ArrayTypeLoc);
6881 };
6882 
6883 } // namespace clang
6884 
6885 void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
6886  // nothing to do
6887 }
6888 
6889 void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
6890  TL.setBuiltinLoc(ReadSourceLocation());
6891  if (TL.needsExtraLocalData()) {
6892  TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++]));
6893  TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++]));
6894  TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++]));
6895  TL.setModeAttr(Record[Idx++]);
6896  }
6897 }
6898 
6899 void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) {
6900  TL.setNameLoc(ReadSourceLocation());
6901 }
6902 
6903 void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
6904  TL.setStarLoc(ReadSourceLocation());
6905 }
6906 
6907 void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
6908  // nothing to do
6909 }
6910 
6911 void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
6912  // nothing to do
6913 }
6914 
6915 void TypeLocReader::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
6916  TL.setExpansionLoc(ReadSourceLocation());
6917 }
6918 
6919 void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
6920  TL.setCaretLoc(ReadSourceLocation());
6921 }
6922 
6923 void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
6924  TL.setAmpLoc(ReadSourceLocation());
6925 }
6926 
6927 void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
6928  TL.setAmpAmpLoc(ReadSourceLocation());
6929 }
6930 
6931 void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
6932  TL.setStarLoc(ReadSourceLocation());
6933  TL.setClassTInfo(GetTypeSourceInfo());
6934 }
6935 
6937  TL.setLBracketLoc(ReadSourceLocation());
6938  TL.setRBracketLoc(ReadSourceLocation());
6939  if (Record[Idx++])
6940  TL.setSizeExpr(Reader->ReadExpr(*F));
6941  else
6942  TL.setSizeExpr(nullptr);
6943 }
6944 
6945 void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
6946  VisitArrayTypeLoc(TL);
6947 }
6948 
6949 void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
6950  VisitArrayTypeLoc(TL);
6951 }
6952 
6953 void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
6954  VisitArrayTypeLoc(TL);
6955 }
6956 
6957 void TypeLocReader::VisitDependentSizedArrayTypeLoc(
6959  VisitArrayTypeLoc(TL);
6960 }
6961 
6962 void TypeLocReader::VisitDependentAddressSpaceTypeLoc(
6964 
6965  TL.setAttrNameLoc(ReadSourceLocation());
6967  range.setBegin(ReadSourceLocation());
6968  range.setEnd(ReadSourceLocation());
6969  TL.setAttrOperandParensRange(range);
6970  TL.setAttrExprOperand(Reader->ReadExpr(*F));
6971 }
6972 
6973 void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
6975  TL.setNameLoc(ReadSourceLocation());
6976 }
6977 
6978 void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
6979  TL.setNameLoc(ReadSourceLocation());
6980 }
6981 
6982 void TypeLocReader::VisitDependentVectorTypeLoc(
6984  TL.setNameLoc(ReadSourceLocation());
6985 }
6986 
6987 void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
6988  TL.setNameLoc(ReadSourceLocation());
6989 }
6990 
6992  TL.setLocalRangeBegin(ReadSourceLocation());
6993  TL.setLParenLoc(ReadSourceLocation());
6994  TL.setRParenLoc(ReadSourceLocation());
6995  TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx),
6996  Reader->ReadSourceLocation(*F, Record, Idx)));
6997  TL.setLocalRangeEnd(ReadSourceLocation());
6998  for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) {
6999  TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx));
7000  }
7001 }
7002 
7003 void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
7004  VisitFunctionTypeLoc(TL);
7005 }
7006 
7007 void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
7008  VisitFunctionTypeLoc(TL);
7009 }
7010 
7011 void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
7012  TL.setNameLoc(ReadSourceLocation());
7013 }
7014 
7015 void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
7016  TL.setNameLoc(ReadSourceLocation());
7017 }
7018 
7019 void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
7020  TL.setTypeofLoc(ReadSourceLocation());
7021  TL.setLParenLoc(ReadSourceLocation());
7022  TL.setRParenLoc(ReadSourceLocation());
7023 }
7024 
7025 void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
7026  TL.setTypeofLoc(ReadSourceLocation());
7027  TL.setLParenLoc(ReadSourceLocation());
7028  TL.setRParenLoc(ReadSourceLocation());
7029  TL.setUnderlyingTInfo(GetTypeSourceInfo());
7030 }
7031 
7032 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
7033  TL.setNameLoc(ReadSourceLocation());
7034 }
7035 
7036 void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
7037  TL.setKWLoc(ReadSourceLocation());
7038  TL.setLParenLoc(ReadSourceLocation());
7039  TL.setRParenLoc(ReadSourceLocation());
7040  TL.setUnderlyingTInfo(GetTypeSourceInfo());
7041 }
7042 
7043 void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) {
7044  TL.setNameLoc(ReadSourceLocation());
7045 }
7046 
7047 void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
7049  TL.setTemplateNameLoc(ReadSourceLocation());
7050 }
7051 
7052 void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) {
7053  TL.setNameLoc(ReadSourceLocation());
7054 }
7055 
7056 void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) {
7057  TL.setNameLoc(ReadSourceLocation());
7058 }
7059 
7060 void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
7061  TL.setAttr(ReadAttr());
7062 }
7063 
7064 void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
7065  TL.setNameLoc(ReadSourceLocation());
7066 }
7067 
7068 void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc(
7070  TL.setNameLoc(ReadSourceLocation());
7071 }
7072 
7073 void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc(
7075  TL.setNameLoc(ReadSourceLocation());
7076 }
7077 
7078 void TypeLocReader::VisitTemplateSpecializationTypeLoc(
7080  TL.setTemplateKeywordLoc(ReadSourceLocation());
7081  TL.setTemplateNameLoc(ReadSourceLocation());
7082  TL.setLAngleLoc(ReadSourceLocation());
7083  TL.setRAngleLoc(ReadSourceLocation());
7084  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
7085  TL.setArgLocInfo(
7086  i,
7087  Reader->GetTemplateArgumentLocInfo(
7088  *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx));
7089 }
7090 
7091 void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) {
7092  TL.setLParenLoc(ReadSourceLocation());
7093  TL.setRParenLoc(ReadSourceLocation());
7094 }
7095 
7096 void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
7097  TL.setElaboratedKeywordLoc(ReadSourceLocation());
7098  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
7099 }
7100 
7101 void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
7102  TL.setNameLoc(ReadSourceLocation());
7103 }
7104 
7105 void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
7106  TL.setElaboratedKeywordLoc(ReadSourceLocation());
7107  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
7108  TL.setNameLoc(ReadSourceLocation());
7109 }
7110 
7111 void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc(
7113  TL.setElaboratedKeywordLoc(ReadSourceLocation());
7114  TL.setQualifierLoc(ReadNestedNameSpecifierLoc());
7115  TL.setTemplateKeywordLoc(ReadSourceLocation());
7116  TL.setTemplateNameLoc(ReadSourceLocation());
7117  TL.setLAngleLoc(ReadSourceLocation());
7118  TL.setRAngleLoc(ReadSourceLocation());
7119  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
7120  TL.setArgLocInfo(
7121  I,
7122  Reader->GetTemplateArgumentLocInfo(
7123  *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx));
7124 }
7125 
7126 void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
7127  TL.setEllipsisLoc(ReadSourceLocation());
7128 }
7129 
7130 void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
7131  TL.setNameLoc(ReadSourceLocation());
7132 }
7133 
7134 void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
7135  if (TL.getNumProtocols()) {
7136  TL.setProtocolLAngleLoc(ReadSourceLocation());
7137  TL.setProtocolRAngleLoc(ReadSourceLocation());
7138  }
7139  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
7140  TL.setProtocolLoc(i, ReadSourceLocation());
7141 }
7142 
7143 void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
7144  TL.setHasBaseTypeAsWritten(Record[Idx++]);
7145  TL.setTypeArgsLAngleLoc(ReadSourceLocation());
7146  TL.setTypeArgsRAngleLoc(ReadSourceLocation());
7147  for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i)
7148  TL.setTypeArgTInfo(i, GetTypeSourceInfo());
7149  TL.setProtocolLAngleLoc(ReadSourceLocation());
7150  TL.setProtocolRAngleLoc(ReadSourceLocation());
7151  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
7152  TL.setProtocolLoc(i, ReadSourceLocation());
7153 }
7154 
7155 void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
7156  TL.setStarLoc(ReadSourceLocation());
7157 }
7158 
7159 void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
7160  TL.setKWLoc(ReadSourceLocation());
7161  TL.setLParenLoc(ReadSourceLocation());
7162  TL.setRParenLoc(ReadSourceLocation());
7163 }
7164 
7165 void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) {
7166  TL.setKWLoc(ReadSourceLocation());
7167 }
7168 
7169 void ASTReader::ReadTypeLoc(ModuleFile &F, const ASTReader::RecordData &Record,
7170  unsigned &Idx, TypeLoc TL) {
7171  TypeLocReader TLR(F, *this, Record, Idx);
7172  for (; !TL.isNull(); TL = TL.getNextTypeLoc())
7173  TLR.Visit(TL);
7174 }
7175 
7178  unsigned &Idx) {
7179  QualType InfoTy = readType(F, Record, Idx);
7180  if (InfoTy.isNull())
7181  return nullptr;
7182 
7183  TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy);
7184  ReadTypeLoc(F, Record, Idx, TInfo->getTypeLoc());
7185  return TInfo;
7186 }
7187 
7189  assert(ContextObj && "reading type with no AST context");
7190  ASTContext &Context = *ContextObj;
7191 
7192  unsigned FastQuals = ID & Qualifiers::FastMask;
7193  unsigned Index = ID >> Qualifiers::FastWidth;
7194 
7195  if (Index < NUM_PREDEF_TYPE_IDS) {
7196  QualType T;
7197  switch ((PredefinedTypeIDs)Index) {
7198  case PREDEF_TYPE_NULL_ID:
7199  return QualType();
7200  case PREDEF_TYPE_VOID_ID:
7201  T = Context.VoidTy;
7202  break;
7203  case PREDEF_TYPE_BOOL_ID:
7204  T = Context.BoolTy;
7205  break;
7206  case PREDEF_TYPE_CHAR_U_ID:
7207  case PREDEF_TYPE_CHAR_S_ID:
7208  // FIXME: Check that the signedness of CharTy is correct!
7209  T = Context.CharTy;
7210  break;
7211  case PREDEF_TYPE_UCHAR_ID:
7212  T = Context.UnsignedCharTy;
7213  break;
7214  case PREDEF_TYPE_USHORT_ID:
7215  T = Context.UnsignedShortTy;
7216  break;
7217  case PREDEF_TYPE_UINT_ID:
7218  T = Context.UnsignedIntTy;
7219  break;
7220  case PREDEF_TYPE_ULONG_ID:
7221  T = Context.UnsignedLongTy;
7222  break;
7224  T = Context.UnsignedLongLongTy;
7225  break;
7227  T = Context.UnsignedInt128Ty;
7228  break;
7229  case PREDEF_TYPE_SCHAR_ID:
7230  T = Context.SignedCharTy;
7231  break;
7232  case PREDEF_TYPE_WCHAR_ID:
7233  T = Context.WCharTy;
7234  break;
7235  case PREDEF_TYPE_SHORT_ID:
7236  T = Context.ShortTy;
7237  break;
7238  case PREDEF_TYPE_INT_ID:
7239  T = Context.IntTy;
7240  break;
7241  case PREDEF_TYPE_LONG_ID:
7242  T = Context.LongTy;
7243  break;
7245  T = Context.LongLongTy;
7246  break;
7247  case PREDEF_TYPE_INT128_ID:
7248  T = Context.Int128Ty;
7249  break;
7250  case PREDEF_TYPE_HALF_ID:
7251  T = Context.HalfTy;
7252  break;
7253  case PREDEF_TYPE_FLOAT_ID:
7254  T = Context.FloatTy;
7255  break;
7256  case PREDEF_TYPE_DOUBLE_ID:
7257  T = Context.DoubleTy;
7258  break;
7260  T = Context.LongDoubleTy;
7261  break;
7263  T = Context.ShortAccumTy;
7264  break;
7265  case PREDEF_TYPE_ACCUM_ID:
7266  T = Context.AccumTy;
7267  break;
7269  T = Context.LongAccumTy;
7270  break;
7272  T = Context.UnsignedShortAccumTy;
7273  break;
7274  case PREDEF_TYPE_UACCUM_ID:
7275  T = Context.UnsignedAccumTy;
7276  break;
7278  T = Context.UnsignedLongAccumTy;
7279  break;
7281  T = Context.ShortFractTy;
7282  break;
7283  case PREDEF_TYPE_FRACT_ID:
7284  T = Context.FractTy;
7285  break;
7287  T = Context.LongFractTy;
7288  break;
7290  T = Context.UnsignedShortFractTy;
7291  break;
7292  case PREDEF_TYPE_UFRACT_ID:
7293  T = Context.UnsignedFractTy;
7294  break;
7296  T = Context.UnsignedLongFractTy;
7297  break;
7299  T = Context.SatShortAccumTy;
7300  break;
7302  T = Context.SatAccumTy;
7303  break;
7305  T = Context.SatLongAccumTy;
7306  break;
7308  T = Context.SatUnsignedShortAccumTy;
7309  break;
7311  T = Context.SatUnsignedAccumTy;
7312  break;
7314  T = Context.SatUnsignedLongAccumTy;
7315  break;
7317  T = Context.SatShortFractTy;
7318  break;
7320  T = Context.SatFractTy;
7321  break;
7323  T = Context.SatLongFractTy;
7324  break;
7326  T = Context.SatUnsignedShortFractTy;
7327  break;
7329  T = Context.SatUnsignedFractTy;
7330  break;
7332  T = Context.SatUnsignedLongFractTy;
7333  break;
7335  T = Context.Float16Ty;
7336  break;
7338  T = Context.Float128Ty;
7339  break;
7341  T = Context.OverloadTy;
7342  break;
7344  T = Context.BoundMemberTy;
7345  break;
7347  T = Context.PseudoObjectTy;
7348  break;
7350  T = Context.DependentTy;
7351  break;
7353  T = Context.UnknownAnyTy;
7354  break;
7356  T = Context.NullPtrTy;
7357  break;
7358  case PREDEF_TYPE_CHAR8_ID:
7359  T = Context.Char8Ty;
7360  break;
7361  case PREDEF_TYPE_CHAR16_ID:
7362  T = Context.Char16Ty;
7363  break;
7364  case PREDEF_TYPE_CHAR32_ID:
7365  T = Context.Char32Ty;
7366  break;
7367  case PREDEF_TYPE_OBJC_ID:
7368  T = Context.ObjCBuiltinIdTy;
7369  break;
7371  T = Context.ObjCBuiltinClassTy;
7372  break;
7373  case PREDEF_TYPE_OBJC_SEL:
7374  T = Context.ObjCBuiltinSelTy;
7375  break;
7376 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7377  case PREDEF_TYPE_##Id##_ID: \
7378  T = Context.SingletonId; \
7379  break;
7380 #include "clang/Basic/OpenCLImageTypes.def"
7381 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
7382  case PREDEF_TYPE_##Id##_ID: \
7383  T = Context.Id##Ty; \
7384  break;
7385 #include "clang/Basic/OpenCLExtensionTypes.def"
7387  T = Context.OCLSamplerTy;
7388  break;
7389  case PREDEF_TYPE_EVENT_ID:
7390  T = Context.OCLEventTy;
7391  break;
7393  T = Context.OCLClkEventTy;
7394  break;
7395  case PREDEF_TYPE_QUEUE_ID:
7396  T = Context.OCLQueueTy;
7397  break;
7399  T = Context.OCLReserveIDTy;
7400  break;
7402  T = Context.getAutoDeductType();
7403  break;
7405  T = Context.getAutoRRefDeductType();
7406  break;
7408  T = Context.ARCUnbridgedCastTy;
7409  break;
7411  T = Context.BuiltinFnTy;
7412  break;
7414  T = Context.OMPArraySectionTy;
7415  break;
7416  }
7417 
7418  assert(!T.isNull() && "Unknown predefined type");
7419  return T.withFastQualifiers(FastQuals);
7420  }
7421 
7422  Index -= NUM_PREDEF_TYPE_IDS;
7423  assert(Index < TypesLoaded.size() && "Type index out-of-range");
7424  if (TypesLoaded[Index].isNull()) {
7425  TypesLoaded[Index] = readTypeRecord(Index);
7426  if (TypesLoaded[Index].isNull())
7427  return QualType();
7428 
7429  TypesLoaded[Index]->setFromAST();
7430  if (DeserializationListener)
7431  DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
7432  TypesLoaded[Index]);
7433  }
7434 
7435  return TypesLoaded[Index].withFastQualifiers(FastQuals);
7436 }
7437 
7438 QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) {
7439  return GetType(getGlobalTypeID(F, LocalID));
7440 }
7441 
7443 ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const {
7444  unsigned FastQuals = LocalID & Qualifiers::FastMask;
7445  unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
7446 
7447  if (LocalIndex < NUM_PREDEF_TYPE_IDS)
7448  return LocalID;
7449 
7450  if (!F.ModuleOffsetMap.empty())
7451  ReadModuleOffsetMap(F);
7452 
7454  = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS);
7455  assert(I != F.TypeRemap.end() && "Invalid index into type index remap");
7456 
7457  unsigned GlobalIndex = LocalIndex + I->second;
7458  return (GlobalIndex << Qualifiers::FastWidth) | FastQuals;
7459 }
7460 
7464  const RecordData &Record,
7465  unsigned &Index) {
7466  switch (Kind) {
7468  return ReadExpr(F);
7470  return GetTypeSourceInfo(F, Record, Index);
7472  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
7473  Index);
7474  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
7475  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
7476  SourceLocation());
7477  }
7479  NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record,
7480  Index);
7481  SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index);
7482  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index);
7483  return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
7484  EllipsisLoc);
7485  }
7491  // FIXME: Is this right?
7492  return TemplateArgumentLocInfo();
7493  }
7494  llvm_unreachable("unexpected template argument loc");
7495 }
7496 
7499  const RecordData &Record, unsigned &Index) {
7500  TemplateArgument Arg = ReadTemplateArgument(F, Record, Index);
7501 
7502  if (Arg.getKind() == TemplateArgument::Expression) {
7503  if (Record[Index++]) // bool InfoHasSameExpr.
7505  }
7506  return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(),
7507  Record, Index));
7508 }
7509 
7512  const RecordData &Record,
7513  unsigned &Index) {
7514  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index);
7515  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index);
7516  unsigned NumArgsAsWritten = Record[Index++];
7517  TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
7518  for (unsigned i = 0; i != NumArgsAsWritten; ++i)
7519  TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index));
7520  return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo);
7521 }
7522 
7524  return GetDecl(ID);
7525 }
7526 
7528  if (NumCurrentElementsDeserializing) {
7529  // We arrange to not care about the complete redeclaration chain while we're
7530  // deserializing. Just remember that the AST has marked this one as complete
7531  // but that it's not actually complete yet, so we know we still need to
7532  // complete it later.
7533  PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D));
7534  return;
7535  }
7536 
7537  const DeclContext *DC = D->getDeclContext()->getRedeclContext();
7538 
7539  // If this is a named declaration, complete it by looking it up
7540  // within its context.
7541  //
7542  // FIXME: Merging a function definition should merge
7543  // all mergeable entities within it.
7544  if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) ||
7545  isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) {
7546  if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) {
7547  if (!getContext().getLangOpts().CPlusPlus &&
7548  isa<TranslationUnitDecl>(DC)) {
7549  // Outside of C++, we don't have a lookup table for the TU, so update
7550  // the identifier instead. (For C++ modules, we don't store decls
7551  // in the serialized identifier table, so we do the lookup in the TU.)
7552  auto *II = Name.getAsIdentifierInfo();
7553  assert(II && "non-identifier name in C?");
7554  if (II->isOutOfDate())
7555  updateOutOfDateIdentifier(*II);
7556  } else
7557  DC->lookup(Name);
7558  } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) {
7559  // Find all declarations of this kind from the relevant context.
7560  for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) {
7561  auto *DC = cast<DeclContext>(DCDecl);
7562  SmallVector<Decl*, 8> Decls;
7563  FindExternalLexicalDecls(
7564  DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls);
7565  }
7566  }
7567  }
7568 
7569  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
7570  CTSD->getSpecializedTemplate()->LoadLazySpecializations();
7571  if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
7572  VTSD->getSpecializedTemplate()->LoadLazySpecializations();
7573  if (auto *FD = dyn_cast<FunctionDecl>(D)) {
7574  if (auto *Template = FD->getPrimaryTemplate())
7575  Template->LoadLazySpecializations();
7576  }
7577 }
7578 
7581  RecordLocation Loc = getLocalBitOffset(Offset);
7582  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
7583  SavedStreamPosition SavedPosition(Cursor);
7584  if (llvm::Error Err = Cursor.JumpToBit(Loc.Offset)) {
7585  Error(std::move(Err));
7586  return nullptr;
7587  }
7588  ReadingKindTracker ReadingKind(Read_Decl, *this);
7589 
7590  RecordData Record;
7591  Expected<unsigned> MaybeCode = Cursor.ReadCode();
7592  if (!MaybeCode) {
7593  Error(MaybeCode.takeError());
7594  return nullptr;
7595  }
7596  unsigned Code = MaybeCode.get();
7597 
7598  Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record);
7599  if (!MaybeRecCode) {
7600  Error(MaybeRecCode.takeError());
7601  return nullptr;
7602  }
7603  if (MaybeRecCode.get() != DECL_CXX_CTOR_INITIALIZERS) {
7604  Error("malformed AST file: missing C++ ctor initializers");
7605  return nullptr;
7606  }
7607 
7608  unsigned Idx = 0;
7609  return ReadCXXCtorInitializers(*Loc.F, Record, Idx);
7610 }
7611 
7613  assert(ContextObj && "reading base specifiers with no AST context");
7614  ASTContext &Context = *ContextObj;
7615 
7616  RecordLocation Loc = getLocalBitOffset(Offset);
7617  BitstreamCursor &Cursor = Loc.F->DeclsCursor;
7618  SavedStreamPosition SavedPosition(Cursor);
7619  if (llvm::Error Err = Cursor.JumpToBit(Loc.Offset)) {
7620  Error(std::move(Err));
7621  return nullptr;
7622  }
7623  ReadingKindTracker ReadingKind(Read_Decl, *this);
7624  RecordData Record;
7625 
7626  Expected<unsigned> MaybeCode = Cursor.ReadCode();
7627  if (!MaybeCode) {
7628  Error(MaybeCode.takeError());
7629  return nullptr;
7630  }
7631  unsigned Code = MaybeCode.get();
7632 
7633  Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record);
7634  if (!MaybeRecCode) {
7635  Error(MaybeCode.takeError());
7636  return nullptr;
7637  }
7638  unsigned RecCode = MaybeRecCode.get();
7639 
7640  if (RecCode != DECL_CXX_BASE_SPECIFIERS) {
7641  Error("malformed AST file: missing C++ base specifiers");
7642  return nullptr;
7643  }
7644 
7645  unsigned Idx = 0;
7646  unsigned NumBases = Record[Idx++];
7647  void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases);
7648  CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases];
7649  for (unsigned I = 0; I != NumBases; ++I)
7650  Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx);
7651  return Bases;
7652 }
7653 
7655 ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const {
7656  if (LocalID < NUM_PREDEF_DECL_IDS)
7657  return LocalID;
7658 
7659  if (!F.ModuleOffsetMap.empty())
7660  ReadModuleOffsetMap(F);
7661 
7663  = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS);
7664  assert(I != F.DeclRemap.end() && "Invalid index into decl index remap");
7665 
7666  return LocalID + I->second;
7667 }
7668 
7670  ModuleFile &M) const {
7671  // Predefined decls aren't from any module.
7672  if (ID < NUM_PREDEF_DECL_IDS)
7673  return false;
7674 
7675  return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID &&
7676  ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls;
7677 }
7678 
7679 ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) {
7680  if (!D->isFromASTFile())
7681  return nullptr;
7682  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID());
7683  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
7684  return I->second;
7685 }
7686 
7688  if (ID < NUM_PREDEF_DECL_IDS)
7689  return SourceLocation();
7690 
7691  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7692 
7693  if (Index > DeclsLoaded.size()) {
7694  Error("declaration ID out-of-range for AST file");
7695  return SourceLocation();
7696  }
7697 
7698  if (Decl *D = DeclsLoaded[Index])
7699  return D->getLocation();
7700 
7701  SourceLocation Loc;
7702  DeclCursorForID(ID, Loc);
7703  return Loc;
7704 }
7705 
7707  switch (ID) {
7708  case PREDEF_DECL_NULL_ID:
7709  return nullptr;
7710 
7712  return Context.getTranslationUnitDecl();
7713 
7715  return Context.getObjCIdDecl();
7716 
7718  return Context.getObjCSelDecl();
7719 
7721  return Context.getObjCClassDecl();
7722 
7724  return Context.getObjCProtocolDecl();
7725 
7727  return Context.getInt128Decl();
7728 
7730  return Context.getUInt128Decl();
7731 
7733  return Context.getObjCInstanceTypeDecl();
7734 
7736  return Context.getBuiltinVaListDecl();
7737 
7739  return Context.getVaListTagDecl();
7740 
7742  return Context.getBuiltinMSVaListDecl();
7743 
7745  return Context.getExternCContextDecl();
7746 
7748  return Context.getMakeIntegerSeqDecl();
7749 
7751  return Context.getCFConstantStringDecl();
7752 
7754  return Context.getCFConstantStringTagDecl();
7755 
7757  return Context.getTypePackElementDecl();
7758  }
7759  llvm_unreachable("PredefinedDeclIDs unknown enum value");
7760 }
7761 
7763  assert(ContextObj && "reading decl with no AST context");
7764  if (ID < NUM_PREDEF_DECL_IDS) {
7765  Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID);
7766  if (D) {
7767  // Track that we have merged the declaration with ID \p ID into the
7768  // pre-existing predefined declaration \p D.
7769  auto &Merged = KeyDecls[D->getCanonicalDecl()];
7770  if (Merged.empty())
7771  Merged.push_back(ID);
7772  }
7773  return D;
7774  }
7775 
7776  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7777 
7778  if (Index >= DeclsLoaded.size()) {
7779  assert(0 && "declaration ID out-of-range for AST file");
7780  Error("declaration ID out-of-range for AST file");
7781  return nullptr;
7782  }
7783 
7784  return DeclsLoaded[Index];
7785 }
7786 
7788  if (ID < NUM_PREDEF_DECL_IDS)
7789  return GetExistingDecl(ID);
7790 
7791  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
7792 
7793  if (Index >= DeclsLoaded.size()) {
7794  assert(0 && "declaration ID out-of-range for AST file");
7795  Error("declaration ID out-of-range for AST file");
7796  return nullptr;
7797  }
7798 
7799  if (!DeclsLoaded[Index]) {
7800  ReadDeclRecord(ID);
7801  if (DeserializationListener)
7802  DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
7803  }
7804 
7805  return DeclsLoaded[Index];
7806 }
7807 
7809  DeclID GlobalID) {
7810  if (GlobalID < NUM_PREDEF_DECL_IDS)
7811  return GlobalID;
7812 
7813  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID);
7814  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
7815  ModuleFile *Owner = I->second;
7816 
7817  llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos
7818  = M.GlobalToLocalDeclIDs.find(Owner);
7819  if (Pos == M.GlobalToLocalDeclIDs.end())
7820  return 0;
7821 
7822  return GlobalID - Owner->BaseDeclID + Pos->second;
7823 }
7824 
7826  const RecordData &Record,
7827  unsigned &Idx) {
7828  if (Idx >= Record.size()) {
7829  Error("Corrupted AST file");
7830  return 0;
7831  }
7832 
7833  return getGlobalDeclID(F, Record[Idx++]);
7834 }
7835 
7836 /// Resolve the offset of a statement into a statement.
7837 ///
7838 /// This operation will read a new statement from the external
7839 /// source each time it is called, and is meant to be used via a
7840 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
7842  // Switch case IDs are per Decl.
7843  ClearSwitchCaseIDs();
7844 
7845  // Offset here is a global offset across the entire chain.
7846  RecordLocation Loc = getLocalBitOffset(Offset);
7847  if (llvm::Error Err = Loc.F->DeclsCursor.JumpToBit(Loc.Offset)) {
7848  Error(std::move(Err));
7849  return nullptr;
7850  }
7851  assert(NumCurrentElementsDeserializing == 0 &&
7852  "should not be called while already deserializing");
7853  Deserializing D(this);
7854  return ReadStmtFromStream(*Loc.F);
7855 }
7856 
7858  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
7859  SmallVectorImpl<Decl *> &Decls) {
7860  bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {};
7861 
7862  auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) {
7863  assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries");
7864  for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) {
7865  auto K = (Decl::Kind)+LexicalDecls[I];
7866  if (!IsKindWeWant(K))
7867  continue;
7868 
7869  auto ID = (serialization::DeclID)+LexicalDecls[I + 1];
7870 
7871  // Don't add predefined declarations to the lexical context more
7872  // than once.
7873  if (ID < NUM_PREDEF_DECL_IDS) {
7874  if (PredefsVisited[ID])
7875  continue;
7876 
7877  PredefsVisited[ID] = true;
7878  }
7879 
7880  if (Decl *D = GetLocalDecl(*M, ID)) {
7881  assert(D->getKind() == K && "wrong kind for lexical decl");
7882  if (!DC->isDeclInLexicalTraversal(D))
7883  Decls.push_back(D);
7884  }
7885  }
7886  };
7887 
7888  if (isa<TranslationUnitDecl>(DC)) {
7889  for (auto Lexical : TULexicalDecls)
7890  Visit(Lexical.first, Lexical.second);
7891  } else {
7892  auto I = LexicalDecls.find(DC);
7893  if (I != LexicalDecls.end())
7894  Visit(I->second.first, I->second.second);
7895  }
7896 
7897  ++NumLexicalDeclContextsRead;
7898 }
7899 
7900 namespace {
7901 
7902 class DeclIDComp {
7903  ASTReader &Reader;
7904  ModuleFile &Mod;
7905 
7906 public:
7907  DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {}
7908 
7909  bool operator()(LocalDeclID L, LocalDeclID R) const {
7910  SourceLocation LHS = getLocation(L);
7911  SourceLocation RHS = getLocation(R);
7912  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7913  }
7914 
7915  bool operator()(SourceLocation LHS, LocalDeclID R) const {
7916  SourceLocation RHS = getLocation(R);
7917  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7918  }
7919 
7920  bool operator()(LocalDeclID L, SourceLocation RHS) const {
7921  SourceLocation LHS = getLocation(L);
7922  return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
7923  }
7924 
7925  SourceLocation getLocation(LocalDeclID ID) const {
7926  return Reader.getSourceManager().getFileLoc(
7927  Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID)));
7928  }
7929 };
7930 
7931 } // namespace
7932 
7934  unsigned Offset, unsigned Length,
7935  SmallVectorImpl<Decl *> &Decls) {
7936  SourceManager &SM = getSourceManager();
7937 
7938  llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File);
7939  if (I == FileDeclIDs.end())
7940  return;
7941 
7942  FileDeclsInfo &DInfo = I->second;
7943  if (DInfo.Decls.empty())
7944  return;
7945 
7947  BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset);
7948  SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length);
7949 
7950  DeclIDComp DIDComp(*this, *DInfo.Mod);
7952  llvm::lower_bound(DInfo.Decls, BeginLoc, DIDComp);
7953  if (BeginIt != DInfo.Decls.begin())
7954  --BeginIt;
7955 
7956  // If we are pointing at a top-level decl inside an objc container, we need
7957  // to backtrack until we find it otherwise we will fail to report that the
7958  // region overlaps with an objc container.
7959  while (BeginIt != DInfo.Decls.begin() &&
7960  GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt))
7961  ->isTopLevelDeclInObjCContainer())
7962  --BeginIt;
7963 
7965  llvm::upper_bound(DInfo.Decls, EndLoc, DIDComp);
7966  if (EndIt != DInfo.Decls.end())
7967  ++EndIt;
7968 
7970  DIt = BeginIt; DIt != EndIt; ++DIt)
7971  Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt)));
7972 }
7973 
7974 bool
7976  DeclarationName Name) {
7977  assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
7978  "DeclContext has no visible decls in storage");
7979  if (!Name)
7980  return false;
7981 
7982  auto It = Lookups.find(DC);
7983  if (It == Lookups.end())
7984  return false;
7985 
7986  Deserializing LookupResults(this);
7987 
7988  // Load the list of declarations.
7990  for (DeclID ID : It->second.Table.find(Name)) {
7991  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
7992  if (ND->getDeclName() == Name)
7993  Decls.push_back(ND);
7994  }
7995 
7996  ++NumVisibleDeclContextsRead;
7997  SetExternalVisibleDeclsForName(DC, Name, Decls);
7998  return !Decls.empty();
7999 }
8000 
8002  if (!DC->hasExternalVisibleStorage())
8003  return;
8004 
8005  auto It = Lookups.find(DC);
8006  assert(It != Lookups.end() &&
8007  "have external visible storage but no lookup tables");
8008 
8009  DeclsMap Decls;
8010 
8011  for (DeclID ID : It->second.Table.findAll()) {
8012  NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
8013  Decls[ND->getDeclName()].push_back(ND);
8014  }
8015 
8016  ++NumVisibleDeclContextsRead;
8017 
8018  for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
8019  SetExternalVisibleDeclsForName(DC, I->first, I->second);
8020  }
8021  const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false);
8022 }
8023 
8026  auto I = Lookups.find(Primary);
8027  return I == Lookups.end() ? nullptr : &I->second;
8028 }
8029 
8030 /// Under non-PCH compilation the consumer receives the objc methods
8031 /// before receiving the implementation, and codegen depends on this.
8032 /// We simulate this by deserializing and passing to consumer the methods of the
8033 /// implementation before passing the deserialized implementation decl.
8035  ASTConsumer *Consumer) {
8036  assert(ImplD && Consumer);
8037 
8038  for (auto *I : ImplD->methods())
8039  Consumer->HandleInterestingDecl(DeclGroupRef(I));
8040 
8041  Consumer->HandleInterestingDecl(DeclGroupRef(ImplD));
8042 }
8043 
8044 void ASTReader::PassInterestingDeclToConsumer(Decl *D) {
8045  if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
8046  PassObjCImplDeclToConsumer(ImplD, Consumer);
8047  else
8048  Consumer->HandleInterestingDecl(DeclGroupRef(D));
8049 }
8050 
8052  this->Consumer = Consumer;
8053 
8054  if (Consumer)
8055  PassInterestingDeclsToConsumer();
8056 
8057  if (DeserializationListener)
8058  DeserializationListener->ReaderInitialized(this);
8059 }
8060 
8062  std::fprintf(stderr, "*** AST File Statistics:\n");
8063 
8064  unsigned NumTypesLoaded
8065  = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(),
8066  QualType());
8067  unsigned NumDeclsLoaded
8068  = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(),
8069  (Decl *)nullptr);
8070  unsigned NumIdentifiersLoaded
8071  = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(),
8072  IdentifiersLoaded.end(),
8073  (IdentifierInfo *)nullptr);
8074  unsigned NumMacrosLoaded
8075  = MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
8076  MacrosLoaded.end(),
8077  (MacroInfo *)nullptr);
8078  unsigned NumSelectorsLoaded
8079  = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
8080  SelectorsLoaded.end(),
8081  Selector());
8082 
8083  if (unsigned TotalNumSLocEntries = getTotalNumSLocs())
8084  std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n",
8085  NumSLocEntriesRead, TotalNumSLocEntries,
8086  ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100));
8087  if (!TypesLoaded.empty())
8088  std::fprintf(stderr, " %u/%u types read (%f%%)\n",
8089  NumTypesLoaded, (unsigned)TypesLoaded.size(),
8090  ((float)NumTypesLoaded/TypesLoaded.size() * 100));
8091  if (!DeclsLoaded.empty())
8092  std::fprintf(stderr, " %u/%u declarations read (%f%%)\n",
8093  NumDeclsLoaded, (unsigned)DeclsLoaded.size(),
8094  ((float)NumDeclsLoaded/DeclsLoaded.size() * 100));
8095  if (!IdentifiersLoaded.empty())
8096  std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n",
8097  NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(),
8098  ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100));
8099  if (!MacrosLoaded.empty())
8100  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
8101  NumMacrosLoaded, (unsigned)MacrosLoaded.size(),
8102  ((float)NumMacrosLoaded/MacrosLoaded.size() * 100));
8103  if (!SelectorsLoaded.empty())
8104  std::fprintf(stderr, " %u/%u selectors read (%f%%)\n",
8105  NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(),
8106  ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100));
8107  if (TotalNumStatements)
8108  std::fprintf(stderr, " %u/%u statements read (%f%%)\n",
8109  NumStatementsRead, TotalNumStatements,
8110  ((float)NumStatementsRead/TotalNumStatements * 100));
8111  if (TotalNumMacros)
8112  std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
8113  NumMacrosRead, TotalNumMacros,
8114  ((float)NumMacrosRead/TotalNumMacros * 100));
8115  if (TotalLexicalDeclContexts)
8116  std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n",
8117  NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
8118  ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
8119  * 100));
8120  if (TotalVisibleDeclContexts)
8121  std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n",
8122  NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
8123  ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
8124  * 100));
8125  if (TotalNumMethodPoolEntries)
8126  std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n",
8127  NumMethodPoolEntriesRead, TotalNumMethodPoolEntries,
8128  ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries
8129  * 100));
8130  if (NumMethodPoolLookups)
8131  std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n",
8132  NumMethodPoolHits, NumMethodPoolLookups,
8133  ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0));
8134  if (NumMethodPoolTableLookups)
8135  std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n",
8136  NumMethodPoolTableHits, NumMethodPoolTableLookups,
8137  ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups
8138  * 100.0));
8139  if (NumIdentifierLookupHits)
8140  std::fprintf(stderr,
8141  " %u / %u identifier table lookups succeeded (%f%%)\n",
8142  NumIdentifierLookupHits, NumIdentifierLookups,
8143  (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
8144 
8145  if (GlobalIndex) {
8146  std::fprintf(stderr, "\n");
8147  GlobalIndex->printStats();
8148  }
8149 
8150  std::fprintf(stderr, "\n");
8151  dump();
8152  std::fprintf(stderr, "\n");
8153 }
8154 
8155 template<typename Key, typename ModuleFile, unsigned InitialCapacity>
8156 LLVM_DUMP_METHOD static void
8157 dumpModuleIDMap(StringRef Name,
8158  const ContinuousRangeMap<Key, ModuleFile *,
8159  InitialCapacity> &Map) {
8160  if (Map.begin() == Map.end())
8161  return;
8162 
8164 
8165  llvm::errs() << Name << ":\n";
8166  for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
8167  I != IEnd; ++I) {
8168  llvm::errs() << " " << I->first << " -> " << I->second->FileName
8169  << "\n";
8170  }
8171 }
8172 
8173 LLVM_DUMP_METHOD void ASTReader::dump() {
8174  llvm::errs() << "*** PCH/ModuleFile Remappings:\n";
8175  dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
8176  dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
8177  dumpModuleIDMap("Global type map", GlobalTypeMap);
8178  dumpModuleIDMap("Global declaration map", GlobalDeclMap);
8179  dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
8180  dumpModuleIDMap("Global macro map", GlobalMacroMap);
8181  dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
8182  dumpModuleIDMap("Global selector map", GlobalSelectorMap);
8183  dumpModuleIDMap("Global preprocessed entity map",
8184  GlobalPreprocessedEntityMap);
8185 
8186  llvm::errs() << "\n*** PCH/Modules Loaded:";
8187  for (ModuleFile &M : ModuleMgr)
8188  M.dump();
8189 }
8190 
8191 /// Return the amount of memory used by memory buffers, breaking down
8192 /// by heap-backed versus mmap'ed memory.
8194  for (ModuleFile &I : ModuleMgr) {
8195  if (llvm::MemoryBuffer *buf = I.Buffer) {
8196  size_t bytes = buf->getBufferSize();
8197  switch (buf->getBufferKind()) {
8198  case llvm::MemoryBuffer::MemoryBuffer_Malloc:
8199  sizes.malloc_bytes += bytes;
8200  break;
8201  case llvm::MemoryBuffer::MemoryBuffer_MMap:
8202  sizes.mmap_bytes += bytes;
8203  break;
8204  }
8205  }
8206  }
8207 }
8208 
8210  SemaObj = &S;
8211  S.addExternalSource(this);
8212 
8213  // Makes sure any declarations that were deserialized "too early"
8214  // still get added to the identifier's declaration chains.
8215  for (uint64_t ID : PreloadedDeclIDs) {
8216  NamedDecl *D = cast<NamedDecl>(GetDecl(ID));
8217  pushExternalDeclIntoScope(D, D->getDeclName());
8218  }
8219  PreloadedDeclIDs.clear();
8220 
8221  // FIXME: What happens if these are changed by a module import?
8222  if (!FPPragmaOptions.empty()) {
8223  assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
8224  SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]);
8225  }
8226 
8227  SemaObj->OpenCLFeatures.copy(OpenCLExtensions);
8228  SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap;
8229  SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap;
8230 
8231  UpdateSema();
8232 }
8233 
8235  assert(SemaObj && "no Sema to update");
8236 
8237  // Load the offsets of the declarations that Sema references.
8238  // They will be lazily deserialized when needed.
8239  if (!SemaDeclRefs.empty()) {
8240  assert(SemaDeclRefs.size() % 3 == 0);
8241  for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) {
8242  if (!SemaObj->StdNamespace)
8243  SemaObj->StdNamespace = SemaDeclRefs[I];
8244  if (!SemaObj->StdBadAlloc)
8245  SemaObj->StdBadAlloc = SemaDeclRefs[I+1];
8246  if (!SemaObj->StdAlignValT)
8247  SemaObj->StdAlignValT = SemaDeclRefs[I+2];
8248  }
8249  SemaDeclRefs.clear();
8250  }
8251 
8252  // Update the state of pragmas. Use the same API as if we had encountered the
8253  // pragma in the source.
8254  if(OptimizeOffPragmaLocation.isValid())
8255  SemaObj->ActOnPragmaOptimize(/* On = */ false, OptimizeOffPragmaLocation);
8256  if (PragmaMSStructState != -1)
8257  SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState);
8258  if (PointersToMembersPragmaLocation.isValid()) {
8259  SemaObj->ActOnPragmaMSPointersToMembers(
8261  PragmaMSPointersToMembersState,
8262  PointersToMembersPragmaLocation);
8263  }
8264  SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
8265 
8266  if (PragmaPackCurrentValue) {
8267  // The bottom of the stack might have a default value. It must be adjusted
8268  // to the current value to ensure that the packing state is preserved after
8269  // popping entries that were included/imported from a PCH/module.
8270  bool DropFirst = false;
8271  if (!PragmaPackStack.empty() &&
8272  PragmaPackStack.front().Location.isInvalid()) {
8273  assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue &&
8274  "Expected a default alignment value");
8275  SemaObj->PackStack.Stack.emplace_back(
8276  PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue,
8277  SemaObj->PackStack.CurrentPragmaLocation,
8278  PragmaPackStack.front().PushLocation);
8279  DropFirst = true;
8280  }
8281  for (const auto &Entry :
8282  llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0))
8283  SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value,
8284  Entry.Location, Entry.PushLocation);
8285  if (PragmaPackCurrentLocation.isInvalid()) {
8286  assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue &&
8287  "Expected a default alignment value");
8288  // Keep the current values.
8289  } else {
8290  SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue;
8291  SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation;
8292  }
8293  }
8294 }
8295 
8296 IdentifierInfo *ASTReader::get(StringRef Name) {
8297  // Note that we are loading an identifier.
8298  Deserializing AnIdentifier(this);
8299 
8300  IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0,
8301  NumIdentifierLookups,
8302  NumIdentifierLookupHits);
8303 
8304  // We don't need to do identifier table lookups in C++ modules (we preload
8305  // all interesting declarations, and don't need to use the scope for name
8306  // lookups). Perform the lookup in PCH files, though, since we don't build
8307  // a complete initial identifier table if we're carrying on from a PCH.
8308  if (PP.getLangOpts().CPlusPlus) {
8309  for (auto F : ModuleMgr.pch_modules())
8310  if (Visitor(*F))
8311  break;
8312  } else {
8313  // If there is a global index, look there first to determine which modules
8314  // provably do not have any results for this identifier.
8316  GlobalModuleIndex::HitSet *HitsPtr = nullptr;
8317  if (!loadGlobalIndex()) {
8318  if (GlobalIndex->lookupIdentifier(Name, Hits)) {
8319  HitsPtr = &Hits;
8320  }
8321  }
8322 
8323  ModuleMgr.visit(Visitor, HitsPtr);
8324  }
8325 
8326  IdentifierInfo *II = Visitor.getIdentifierInfo();
8327  markIdentifierUpToDate(II);
8328  return II;
8329 }
8330 
8331 namespace clang {
8332 
8333  /// An identifier-lookup iterator that enumerates all of the
8334  /// identifiers stored within a set of AST files.
8336  /// The AST reader whose identifiers are being enumerated.
8337  const ASTReader &Reader;
8338 
8339  /// The current index into the chain of AST files stored in
8340  /// the AST reader.
8341  unsigned Index;
8342 
8343  /// The current position within the identifier lookup table
8344  /// of the current AST file.
8345  ASTIdentifierLookupTable::key_iterator Current;
8346 
8347  /// The end position within the identifier lookup table of
8348  /// the current AST file.
8349  ASTIdentifierLookupTable::key_iterator End;
8350 
8351  /// Whether to skip any modules in the ASTReader.
8352  bool SkipModules;
8353 
8354  public:
8355  explicit ASTIdentifierIterator(const ASTReader &Reader,
8356  bool SkipModules = false);
8357 
8358  StringRef Next() override;
8359  };
8360 
8361 } // namespace clang
8362 
8364  bool SkipModules)
8365  : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) {
8366 }
8367 
8369  while (Current == End) {
8370  // If we have exhausted all of our AST files, we're done.
8371  if (Index == 0)
8372  return StringRef();
8373 
8374  --Index;
8375  ModuleFile &F = Reader.ModuleMgr[Index];
8376  if (SkipModules && F.isModule())
8377  continue;
8378 
8379  ASTIdentifierLookupTable *IdTable =
8381  Current = IdTable->key_begin();
8382  End = IdTable->key_end();
8383  }
8384 
8385  // We have any identifiers remaining in the current AST file; return
8386  // the next one.
8387  StringRef Result = *Current;
8388  ++Current;
8389  return Result;
8390 }
8391 
8392 namespace {
8393 
8394 /// A utility for appending two IdentifierIterators.
8395 class ChainedIdentifierIterator : public IdentifierIterator {
8396  std::unique_ptr<IdentifierIterator> Current;
8397  std::unique_ptr<IdentifierIterator> Queued;
8398 
8399 public:
8400  ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First,
8401  std::unique_ptr<IdentifierIterator> Second)
8402  : Current(std::move(First)), Queued(std::move(Second)) {}
8403 
8404  StringRef Next() override {
8405  if (!Current)
8406  return StringRef();
8407 
8408  StringRef result = Current->Next();
8409  if (!result.empty())
8410  return result;
8411 
8412  // Try the queued iterator, which may itself be empty.
8413  Current.reset();
8414  std::swap(Current, Queued);
8415  return Next();
8416  }
8417 };
8418 
8419 } // namespace
8420 
8422  if (!loadGlobalIndex()) {
8423  std::unique_ptr<IdentifierIterator> ReaderIter(
8424  new ASTIdentifierIterator(*this, /*SkipModules=*/true));
8425  std::unique_ptr<IdentifierIterator> ModulesIter(
8426  GlobalIndex->createIdentifierIterator());
8427  return new ChainedIdentifierIterator(std::move(ReaderIter),
8428  std::move(ModulesIter));
8429  }
8430 
8431  return new ASTIdentifierIterator(*this);
8432 }
8433 
8434 namespace clang {
8435 namespace serialization {
8436 
8438  ASTReader &Reader;
8439  Selector Sel;
8440  unsigned PriorGeneration;
8441  unsigned InstanceBits = 0;
8442  unsigned FactoryBits = 0;
8443  bool InstanceHasMoreThanOneDecl = false;
8444  bool FactoryHasMoreThanOneDecl = false;
8445  SmallVector<ObjCMethodDecl *, 4> InstanceMethods;
8446  SmallVector<ObjCMethodDecl *, 4> FactoryMethods;
8447 
8448  public:
8450  unsigned PriorGeneration)
8451  : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) {}
8452 
8453  bool operator()(ModuleFile &M) {
8454  if (!M.SelectorLookupTable)
8455  return false;
8456 
8457  // If we've already searched this module file, skip it now.
8458  if (M.Generation <= PriorGeneration)
8459  return true;
8460 
8461  ++Reader.NumMethodPoolTableLookups;
8462  ASTSelectorLookupTable *PoolTable
8464  ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel);
8465  if (Pos == PoolTable->end())
8466  return false;
8467 
8468  ++Reader.NumMethodPoolTableHits;
8469  ++Reader.NumSelectorsRead;
8470  // FIXME: Not quite happy with the statistics here. We probably should
8471  // disable this tracking when called via LoadSelector.
8472  // Also, should entries without methods count as misses?
8473  ++Reader.NumMethodPoolEntriesRead;
8475  if (Reader.DeserializationListener)
8476  Reader.DeserializationListener->SelectorRead(Data.ID, Sel);
8477 
8478  InstanceMethods.append(Data.Instance.begin(), Data.Instance.end());
8479  FactoryMethods.append(Data.Factory.begin(), Data.Factory.end());
8480  InstanceBits = Data.InstanceBits;
8481  FactoryBits = Data.FactoryBits;
8482  InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl;
8483  FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl;
8484  return true;
8485  }
8486 
8487  /// Retrieve the instance methods found by this visitor.
8489  return InstanceMethods;
8490  }
8491 
8492  /// Retrieve the instance methods found by this visitor.
8494  return FactoryMethods;
8495  }
8496 
8497  unsigned getInstanceBits() const { return InstanceBits; }
8498  unsigned getFactoryBits() const { return FactoryBits; }
8499 
8501  return InstanceHasMoreThanOneDecl;
8502  }
8503 
8504  bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; }
8505  };
8506 
8507 } // namespace serialization
8508 } // namespace clang
8509 
8510 /// Add the given set of methods to the method list.
8512  ObjCMethodList &List) {
8513  for (unsigned I = 0, N = Methods.size(); I != N; ++I) {
8514  S.addMethodToGlobalList(&List, Methods[I]);
8515  }
8516 }
8517 
8519  // Get the selector generation and update it to the current generation.
8520  unsigned &Generation = SelectorGeneration[Sel];
8521  unsigned PriorGeneration = Generation;
8522  Generation = getGeneration();
8523  SelectorOutOfDate[Sel] = false;
8524 
8525  // Search for methods defined with this selector.
8526  ++NumMethodPoolLookups;
8527  ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration);
8528  ModuleMgr.visit(Visitor);
8529 
8530  if (Visitor.getInstanceMethods().empty() &&
8531  Visitor.getFactoryMethods().empty())
8532  return;
8533 
8534  ++NumMethodPoolHits;
8535 
8536  if (!getSema())
8537  return;
8538 
8539  Sema &S = *getSema();
8540  Sema::GlobalMethodPool::iterator Pos
8541  = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first;
8542 
8543  Pos->second.first.setBits(Visitor.getInstanceBits());
8544  Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
8545  Pos->second.second.setBits(Visitor.getFactoryBits());
8546  Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl());
8547 
8548  // Add methods to the global pool *after* setting hasMoreThanOneDecl, since
8549  // when building a module we keep every method individually and may need to
8550  // update hasMoreThanOneDecl as we add the methods.
8551  addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first);
8552  addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second);
8553 }
8554 
8556  if (SelectorOutOfDate[Sel])
8557  ReadMethodPool(Sel);
8558 }
8559 
8561  SmallVectorImpl<NamespaceDecl *> &Namespaces) {
8562  Namespaces.clear();
8563 
8564  for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) {
8565  if (NamespaceDecl *Namespace
8566  = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I])))
8567  Namespaces.push_back(Namespace);
8568  }
8569 }
8570 
8572  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
8573  for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) {
8574  NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++]));
8575  SourceLocation Loc =
8576  SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]);
8577  Undefined.insert(std::make_pair(D, Loc));
8578  }
8579 }
8580 
8582  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
8583  Exprs) {
8584  for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) {
8585  FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++]));
8586  uint64_t Count = DelayedDeleteExprs[Idx++];
8587  for (uint64_t C = 0; C < Count; ++C) {
8588  SourceLocation DeleteLoc =
8589  SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]);
8590  const bool IsArrayForm = DelayedDeleteExprs[Idx++];
8591  Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm));
8592  }
8593  }
8594 }
8595 
8597  SmallVectorImpl<VarDecl *> &TentativeDefs) {
8598  for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
8599  VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I]));
8600  if (Var)
8601  TentativeDefs.push_back(Var);
8602  }
8603  TentativeDefinitions.clear();
8604 }
8605 
8608  for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
8609  DeclaratorDecl *D
8610  = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I]));
8611  if (D)
8612  Decls.push_back(D);
8613  }
8614  UnusedFileScopedDecls.clear();
8615 }
8616 
8619  for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) {
8621  = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I]));
8622  if (D)
8623  Decls.push_back(D);
8624  }
8625  DelegatingCtorDecls.clear();
8626 }
8627 
8629  for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) {
8630  TypedefNameDecl *D
8631  = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]));
8632  if (D)
8633  Decls.push_back(D);
8634  }
8635  ExtVectorDecls.clear();
8636 }
8637 
8640  for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N;
8641  ++I) {
8642  TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>(
8643  GetDecl(UnusedLocalTypedefNameCandidates[I]));
8644  if (D)
8645  Decls.insert(D);
8646  }
8647  UnusedLocalTypedefNameCandidates.clear();
8648 }
8649 
8651  SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) {
8652  if (ReferencedSelectorsData.empty())
8653  return;
8654 
8655  // If there are @selector references added them to its pool. This is for
8656  // implementation of -Wselector.
8657  unsigned int DataSize = ReferencedSelectorsData.size()-1;
8658  unsigned I = 0;
8659  while (I < DataSize) {
8660  Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]);
8661  SourceLocation SelLoc
8662  = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]);
8663  Sels.push_back(std::make_pair(Sel, SelLoc));
8664  }
8665  ReferencedSelectorsData.clear();
8666 }
8667 
8669  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) {
8670  if (WeakUndeclaredIdentifiers.empty())
8671  return;
8672 
8673  for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) {
8674  IdentifierInfo *WeakId
8675  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
8676  IdentifierInfo *AliasId
8677  = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]);
8678  SourceLocation Loc
8679  = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]);
8680  bool Used = WeakUndeclaredIdentifiers[I++];
8681  WeakInfo WI(AliasId, Loc);
8682  WI.setUsed(Used);
8683  WeakIDs.push_back(std::make_pair(WeakId, WI));
8684  }
8685  WeakUndeclaredIdentifiers.clear();
8686 }
8687 
8689  for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) {
8690  ExternalVTableUse VT;
8691  VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++]));
8692  VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]);
8693  VT.DefinitionRequired = VTableUses[Idx++];
8694  VTables.push_back(VT);
8695  }
8696 
8697  VTableUses.clear();
8698 }
8699 
8701  SmallVectorImpl<std::pair<ValueDecl *, SourceLocation>> &Pending) {
8702  for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) {
8703  ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));
8704  SourceLocation Loc
8705  = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);
8706 
8707  Pending.push_back(std::make_pair(D, Loc));
8708  }
8709  PendingInstantiations.clear();
8710 }
8711 
8713  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
8714  &LPTMap) {
8715  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
8716  /* In loop */) {
8717  FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++]));
8718 
8719  auto LT = llvm::make_unique<LateParsedTemplate>();
8720  LT->D = GetDecl(LateParsedTemplates[Idx++]);
8721 
8722  ModuleFile *F = getOwningModuleFile(LT->D);
8723  assert(F && "No module");
8724 
8725  unsigned TokN = LateParsedTemplates[Idx++];
8726  LT->Toks.reserve(TokN);
8727  for (unsigned T = 0; T < TokN; ++T)
8728  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
8729 
8730  LPTMap.insert(std::make_pair(FD, std::move(LT)));
8731  }
8732 
8733  LateParsedTemplates.clear();
8734 }
8735 
8737  // It would be complicated to avoid reading the methods anyway. So don't.
8738  ReadMethodPool(Sel);
8739 }
8740 
8742  assert(ID && "Non-zero identifier ID required");
8743  assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range");
8744  IdentifiersLoaded[ID - 1] = II;
8745  if (DeserializationListener)
8746  DeserializationListener->IdentifierRead(ID, II);
8747 }
8748 
8749 /// Set the globally-visible declarations associated with the given
8750 /// identifier.
8751 ///
8752 /// If the AST reader is currently in a state where the given declaration IDs
8753 /// cannot safely be resolved, they are queued until it is safe to resolve
8754 /// them.
8755 ///
8756 /// \param II an IdentifierInfo that refers to one or more globally-visible
8757 /// declarations.
8758 ///
8759 /// \param DeclIDs the set of declaration IDs with the name @p II that are
8760 /// visible at global scope.
8761 ///
8762 /// \param Decls if non-null, this vector will be populated with the set of
8763 /// deserialized declarations. These declarations will not be pushed into
8764 /// scope.
8765 void
8767  const SmallVectorImpl<uint32_t> &DeclIDs,
8768  SmallVectorImpl<Decl *> *Decls) {
8769  if (NumCurrentElementsDeserializing && !Decls) {
8770  PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end());
8771  return;
8772  }
8773 
8774  for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) {
8775  if (!SemaObj) {
8776  // Queue this declaration so that it will be added to the
8777  // translation unit scope and identifier's declaration chain
8778  // once a Sema object is known.
8779  PreloadedDeclIDs.push_back(DeclIDs[I]);
8780  continue;
8781  }
8782 
8783  NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I]));
8784 
8785  // If we're simply supposed to record the declarations, do so now.
8786  if (Decls) {
8787  Decls->push_back(D);
8788  continue;
8789  }
8790 
8791  // Introduce this declaration into the translation-unit scope
8792  // and add it to the declaration chain for this identifier, so
8793  // that (unqualified) name lookup will find it.
8794  pushExternalDeclIntoScope(D, II);
8795  }
8796 }
8797 
8799  if (ID == 0)
8800  return nullptr;
8801 
8802  if (IdentifiersLoaded.empty()) {
8803  Error("no identifier table in AST file");
8804  return nullptr;
8805  }
8806 
8807  ID -= 1;
8808  if (!IdentifiersLoaded[ID]) {
8809  GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
8810  assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
8811  ModuleFile *M = I->second;
8812  unsigned Index = ID - M->BaseIdentifierID;
8813  const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index];
8814 
8815  // All of the strings in the AST file are preceded by a 16-bit length.
8816  // Extract that 16-bit length to avoid having to execute strlen().
8817  // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as
8818  // unsigned integers. This is important to avoid integer overflow when
8819  // we cast them to 'unsigned'.
8820  const unsigned char *StrLenPtr = (const unsigned char*) Str - 2;
8821  unsigned StrLen = (((unsigned) StrLenPtr[0])
8822  | (((unsigned) StrLenPtr[1]) << 8)) - 1;
8823  auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen));
8824  IdentifiersLoaded[ID] = &II;
8825  markIdentifierFromAST(*this, II);
8826  if (DeserializationListener)
8827  DeserializationListener->IdentifierRead(ID + 1, &II);
8828  }
8829 
8830  return IdentifiersLoaded[ID];
8831 }
8832 
8833 IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
8834  return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
8835 }
8836 
8837 IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
8838  if (LocalID < NUM_PREDEF_IDENT_IDS)
8839  return LocalID;
8840 
8841  if (!M.ModuleOffsetMap.empty())
8842  ReadModuleOffsetMap(M);
8843 
8845  = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS);
8846  assert(I != M.IdentifierRemap.end()
8847  && "Invalid index into identifier index remap");
8848 
8849  return LocalID + I->second;
8850 }
8851 
8853  if (ID == 0)
8854  return nullptr;
8855 
8856  if (MacrosLoaded.empty()) {
8857  Error("no macro table in AST file");
8858  return nullptr;
8859  }
8860 
8861  ID -= NUM_PREDEF_MACRO_IDS;
8862  if (!MacrosLoaded[ID]) {
8864  = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS);
8865  assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
8866  ModuleFile *M = I->second;
8867  unsigned Index = ID - M->BaseMacroID;
8868  MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]);
8869 
8870  if (DeserializationListener)
8871  DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS,
8872  MacrosLoaded[ID]);
8873  }
8874 
8875  return MacrosLoaded[ID];
8876 }
8877 
8878 MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) {
8879  if (LocalID < NUM_PREDEF_MACRO_IDS)
8880  return LocalID;
8881 
8882  if (!M.ModuleOffsetMap.empty())
8883  ReadModuleOffsetMap(M);
8884 
8886  = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS);
8887  assert(I != M.MacroRemap.end() && "Invalid index into macro index remap");
8888 
8889  return LocalID + I->second;
8890 }
8891 
8893 ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) {
8894  if (LocalID < NUM_PREDEF_SUBMODULE_IDS)
8895  return LocalID;
8896 
8897  if (!M.ModuleOffsetMap.empty())
8898  ReadModuleOffsetMap(M);
8899 
8902  assert(I != M.SubmoduleRemap.end()
8903  && "Invalid index into submodule index remap");
8904 
8905  return LocalID + I->second;
8906 }
8907 
8909  if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) {
8910  assert(GlobalID == 0 && "Unhandled global submodule ID");
8911  return nullptr;
8912  }
8913 
8914  if (GlobalID > SubmodulesLoaded.size()) {
8915  Error("submodule ID out of range in AST file");
8916  return nullptr;
8917  }
8918 
8919  return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS];
8920 }
8921 
8923  return getSubmodule(ID);
8924 }
8925 
8927  ModuleFile *MF = getOwningModuleFile(D);
8928  return MF && MF->PCHHasObjectFile;
8929 }
8930 
8931 ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) {
8932  if (ID & 1) {
8933  // It's a module, look it up by submodule ID.
8934  auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1));
8935  return I == GlobalSubmoduleMap.end() ? nullptr : I->second;
8936  } else {
8937  // It's a prefix (preamble, PCH, ...). Look it up by index.
8938  unsigned IndexFromEnd = ID >> 1;
8939  assert(IndexFromEnd && "got reference to unknown module file");
8940  return getModuleManager().pch_modules().end()[-IndexFromEnd];
8941  }
8942 }
8943 
8944 unsigned ASTReader::getModuleFileID(ModuleFile *F) {
8945  if (!F)
8946  return 1;
8947 
8948  // For a file representing a module, use the submodule ID of the top-level
8949  // module as the file ID. For any other kind of file, the number of such
8950  // files loaded beforehand will be the same on reload.
8951  // FIXME: Is this true even if we have an explicit module file and a PCH?
8952  if (F->isModule())
8953  return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1;
8954 
8955  auto PCHModules = getModuleManager().pch_modules();
8956  auto I = llvm::find(PCHModules, F);
8957  assert(I != PCHModules.end() && "emitting reference to unknown file");
8958  return (I - PCHModules.end()) << 1;
8959 }
8960 
8963  if (const Module *M = getSubmodule(ID))
8965 
8966  // If there is only a single PCH, return it instead.
8967  // Chained PCH are not supported.
8968  const auto &PCHChain = ModuleMgr.pch_modules();
8969  if (std::distance(std::begin(PCHChain), std::end(PCHChain))) {
8970  ModuleFile &MF = ModuleMgr.getPrimaryModule();
8971  StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName);
8972  StringRef FileName = llvm::sys::path::filename(MF.FileName);
8973  return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName,
8974  MF.Signature);
8975  }
8976  return None;
8977 }
8978 
8980  auto I = DefinitionSource.find(FD);
8981  if (I == DefinitionSource.end())
8982  return EK_ReplyHazy;
8983  return I->second ? EK_Never : EK_Always;
8984 }
8985 
8986 Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
8987  return DecodeSelector(getGlobalSelectorID(M, LocalID));
8988 }
8989 
8991  if (ID == 0)
8992  return Selector();
8993 
8994  if (ID > SelectorsLoaded.size()) {
8995  Error("selector ID out of range in AST file");
8996  return Selector();
8997  }
8998 
8999  if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) {
9000  // Load this selector from the selector table.
9001  GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
9002  assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
9003  ModuleFile &M = *I->second;
9004  ASTSelectorLookupTrait Trait(*this, M);
9005  unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS;
9006  SelectorsLoaded[ID - 1] =
9007  Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0);
9008  if (DeserializationListener)
9009  DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
9010  }
9011 
9012  return SelectorsLoaded[ID - 1];
9013 }
9014 
9016  return DecodeSelector(ID);
9017 }
9018 
9020  // ID 0 (the null selector) is considered an external selector.
9021  return getTotalNumSelectors() + 1;
9022 }
9023 
9025 ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const {
9026  if (LocalID < NUM_PREDEF_SELECTOR_IDS)
9027  return LocalID;
9028 
9029  if (!M.ModuleOffsetMap.empty())
9030  ReadModuleOffsetMap(M);
9031 
9034  assert(I != M.SelectorRemap.end()
9035  && "Invalid index into selector index remap");
9036 
9037  return LocalID + I->second;
9038 }
9039 
9042  const RecordData &Record, unsigned &Idx) {
9043  ASTContext &Context = getContext();
9045  switch (Kind) {
9047  return DeclarationName(GetIdentifierInfo(F, Record, Idx));
9048 
9052  return DeclarationName(ReadSelector(F, Record, Idx));
9053 
9055  return Context.DeclarationNames.getCXXConstructorName(
9056  Context.getCanonicalType(readType(F, Record, Idx)));
9057 
9059  return Context.DeclarationNames.getCXXDestructorName(
9060  Context.getCanonicalType(readType(F, Record, Idx)));
9061 
9064  ReadDeclAs<TemplateDecl>(F, Record, Idx));
9065 
9068  Context.getCanonicalType(readType(F, Record, Idx)));
9069 
9071  return Context.DeclarationNames.getCXXOperatorName(
9072  (OverloadedOperatorKind)Record[Idx++]);
9073 
9076  GetIdentifierInfo(F, Record, Idx));
9077 
9080  }
9081 
9082  llvm_unreachable("Invalid NameKind!");
9083 }
9084 
9086  DeclarationNameLoc &DNLoc,
9087  DeclarationName Name,
9088  const RecordData &Record, unsigned &Idx) {
9089  switch (Name.getNameKind()) {
9093  DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx);
9094  break;
9095 
9098  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
9100  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
9101  break;
9102 
9105  = ReadSourceLocation(F, Record, Idx).getRawEncoding();
9106  break;
9107 
9114  break;
9115  }
9116 }
9117 
9119  DeclarationNameInfo &NameInfo,
9120  const RecordData &Record, unsigned &Idx) {
9121  NameInfo.setName(ReadDeclarationName(F, Record, Idx));
9122  NameInfo.setLoc(ReadSourceLocation(F, Record, Idx));
9123  DeclarationNameLoc DNLoc;
9124  ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx);
9125  NameInfo.setInfo(DNLoc);
9126 }
9127 
9129  const RecordData &Record, unsigned &Idx) {
9130  Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
9131  unsigned NumTPLists = Record[Idx++];
9132  Info.NumTemplParamLists = NumTPLists;
9133  if (NumTPLists) {
9134  Info.TemplParamLists =
9135  new (getContext()) TemplateParameterList *[NumTPLists];
9136  for (unsigned i = 0; i != NumTPLists; ++i)
9137  Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx);
9138  }
9139 }
9140 
9142 ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record,
9143  unsigned &Idx) {
9144  ASTContext &Context = getContext();
9146  switch (Kind) {
9148  return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx));
9149 
9151  unsigned size = Record[Idx++];
9152  UnresolvedSet<8> Decls;
9153  while (size--)
9154  Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx));
9155 
9156  return Context.getOverloadedTemplateName(Decls.begin(), Decls.end());
9157  }
9158 
9160  DeclarationName Name = ReadDeclarationName(F, Record, Idx);
9161  return Context.getAssumedTemplateName(Name);
9162  }
9163 
9165  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
9166  bool hasTemplKeyword = Record[Idx++];
9167  TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx);
9168  return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template);
9169  }
9170 
9172  NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx);
9173  if (Record[Idx++]) // isIdentifier
9174  return Context.getDependentTemplateName(NNS,
9175  GetIdentifierInfo(F, Record,
9176  Idx));
9177  return Context.getDependentTemplateName(NNS,
9178  (OverloadedOperatorKind)Record[Idx++]);
9179  }
9180 
9183  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
9184  if (!param) return TemplateName();
9185  TemplateName replacement = ReadTemplateName(F, Record, Idx);
9186  return Context.getSubstTemplateTemplateParm(param, replacement);
9187  }
9188 
9191  = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx);
9192  if (!Param)
9193  return TemplateName();
9194 
9195  TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx);
9196  if (ArgPack.getKind() != TemplateArgument::Pack)
9197  return TemplateName();
9198 
9199  return Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9200  }
9201  }
9202 
9203  llvm_unreachable("Unhandled template name kind!");
9204 }
9205 
9207  const RecordData &Record,
9208  unsigned &Idx,
9209  bool Canonicalize) {
9210  ASTContext &Context = getContext();
9211  if (Canonicalize) {
9212  // The caller wants a canonical template argument. Sometimes the AST only
9213  // wants template arguments in canonical form (particularly as the template
9214  // argument lists of template specializations) so ensure we preserve that
9215  // canonical form across serialization.
9216  TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false);
9217  return Context.getCanonicalTemplateArgument(Arg);
9218  }
9219 
9221  switch (Kind) {
9223  return TemplateArgument();
9225  return TemplateArgument(readType(F, Record, Idx));
9227  ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx);
9228  return TemplateArgument(D, readType(F, Record, Idx));
9229  }
9231  return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true);
9233  llvm::APSInt Value = ReadAPSInt(Record, Idx);
9234  QualType T = readType(F, Record, Idx);
9235  return TemplateArgument(Context, Value, T);
9236  }
9238  return TemplateArgument(ReadTemplateName(F, Record, Idx));
9240  TemplateName Name = ReadTemplateName(F, Record, Idx);
9241  Optional<unsigned> NumTemplateExpansions;
9242  if (unsigned NumExpansions = Record[Idx++])
9243  NumTemplateExpansions = NumExpansions - 1;
9244  return TemplateArgument(Name, NumTemplateExpansions);
9245  }
9247  return TemplateArgument(ReadExpr(F));
9248  case TemplateArgument::Pack: {
9249  unsigned NumArgs = Record[Idx++];
9250  TemplateArgument *Args = new (Context) TemplateArgument[NumArgs];
9251  for (unsigned I = 0; I != NumArgs; ++I)
9252  Args[I] = ReadTemplateArgument(F, Record, Idx);
9253  return TemplateArgument(llvm::makeArrayRef(Args, NumArgs));
9254  }
9255  }
9256 
9257  llvm_unreachable("Unhandled template argument kind!");
9258 }
9259 
9262  const RecordData &Record, unsigned &Idx) {
9263  SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx);
9264  SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx);
9265  SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx);
9266 
9267  unsigned NumParams = Record[Idx++];
9269  Params.reserve(NumParams);
9270  while (NumParams--)
9271  Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx));
9272 
9273  // TODO: Concepts
9275  getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr);
9276  return TemplateParams;
9277 }
9278 
9279 void
9282  ModuleFile &F, const RecordData &Record,
9283  unsigned &Idx, bool Canonicalize) {
9284  unsigned NumTemplateArgs = Record[Idx++];
9285  TemplArgs.reserve(NumTemplateArgs);
9286  while (NumTemplateArgs--)
9287  TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize));
9288 }
9289 
9290 /// Read a UnresolvedSet structure.
9292  const RecordData &Record, unsigned &Idx) {
9293  unsigned NumDecls = Record[Idx++];
9294  Set.reserve(getContext(), NumDecls);
9295  while (NumDecls--) {
9296  DeclID ID = ReadDeclID(F, Record, Idx);
9297  AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
9298  Set.addLazyDecl(getContext(), ID, AS);
9299  }
9300 }
9301 
9304  const RecordData &Record, unsigned &Idx) {
9305  bool isVirtual = static_cast<bool>(Record[Idx++]);
9306  bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
9307  AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
9308  bool inheritConstructors = static_cast<bool>(Record[Idx++]);
9309  TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx);
9310  SourceRange Range = ReadSourceRange(F, Record, Idx);
9311  SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx);
9312  CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo,
9313  EllipsisLoc);
9314  Result.setInheritConstructors(inheritConstructors);
9315  return Result;
9316 }
9317 
9319 ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
9320  unsigned &Idx) {
9321  ASTContext &Context = getContext();
9322  unsigned NumInitializers = Record[Idx++];
9323  assert(NumInitializers && "wrote ctor initializers but have no inits");
9324  auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers];
9325  for (unsigned i = 0; i != NumInitializers; ++i) {
9326  TypeSourceInfo *TInfo = nullptr;
9327  bool IsBaseVirtual = false;
9328  FieldDecl *Member = nullptr;
9329  IndirectFieldDecl *IndirectMember = nullptr;
9330 
9331  CtorInitializerType Type = (CtorInitializerType)Record[Idx++];
9332  switch (Type) {
9333  case CTOR_INITIALIZER_BASE:
9334  TInfo = GetTypeSourceInfo(F, Record, Idx);
9335  IsBaseVirtual = Record[Idx++];
9336  break;
9337 
9339  TInfo = GetTypeSourceInfo(F, Record, Idx);
9340  break;
9341 
9343  Member = ReadDeclAs<FieldDecl>(F, Record, Idx);
9344  break;
9345 
9347  IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx);
9348  break;
9349  }
9350 
9351  SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx);
9352  Expr *Init = ReadExpr(F);
9353  SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx);
9354  SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx);
9355 
9356  CXXCtorInitializer *BOMInit;
9357  if (Type == CTOR_INITIALIZER_BASE)
9358  BOMInit = new (Context)
9359  CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init,
9360  RParenLoc, MemberOrEllipsisLoc);
9361  else if (Type == CTOR_INITIALIZER_DELEGATING)
9362  BOMInit = new (Context)
9363  CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc);
9364  else if (Member)
9365  BOMInit = new (Context)
9366  CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc,
9367  Init, RParenLoc);
9368  else
9369  BOMInit = new (Context)
9370  CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc,
9371  LParenLoc, Init, RParenLoc);
9372 
9373  if (/*IsWritten*/Record[Idx++]) {
9374  unsigned SourceOrder = Record[Idx++];
9375  BOMInit->setSourceOrder(SourceOrder);
9376  }
9377 
9378  CtorInitializers[i] = BOMInit;
9379  }
9380 
9381  return CtorInitializers;
9382 }
9383 
9386  const RecordData &Record, unsigned &Idx) {
9387  ASTContext &Context = getContext();
9388  unsigned N = Record[Idx++];
9389  NestedNameSpecifier *NNS = nullptr, *Prev = nullptr;
9390  for (unsigned I = 0; I != N; ++I) {
9392  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
9393  switch (Kind) {
9395  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
9396  NNS = NestedNameSpecifier::Create(Context, Prev, II);
9397  break;
9398  }
9399 
9401  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
9402  NNS = NestedNameSpecifier::Create(Context, Prev, NS);
9403  break;
9404  }
9405 
9407  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
9408  NNS = NestedNameSpecifier::Create(Context, Prev, Alias);
9409  break;
9410  }
9411 
9414  const Type *T = readType(F, Record, Idx).getTypePtrOrNull();
9415  if (!T)
9416  return nullptr;
9417 
9418  bool Template = Record[Idx++];
9419  NNS = NestedNameSpecifier::Create(Context, Prev, Template, T);
9420  break;
9421  }
9422 
9424  NNS = NestedNameSpecifier::GlobalSpecifier(Context);
9425  // No associated value, and there can't be a prefix.
9426  break;
9427 
9429  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
9430  NNS = NestedNameSpecifier::SuperSpecifier(Context, RD);
9431  break;
9432  }
9433  }
9434  Prev = NNS;
9435  }
9436  return NNS;
9437 }
9438 
9441  unsigned &Idx) {
9442  ASTContext &Context = getContext();
9443  unsigned N = Record[Idx++];
9445  for (unsigned I = 0; I != N; ++I) {
9447  = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
9448  switch (Kind) {
9450  IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx);
9451  SourceRange Range = ReadSourceRange(F, Record, Idx);
9452  Builder.Extend(Context, II, Range.getBegin(), Range.getEnd());
9453  break;
9454  }
9455 
9457  NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx);
9458  SourceRange Range = ReadSourceRange(F, Record, Idx);
9459  Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd());
9460  break;
9461  }
9462 
9464  NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx);
9465  SourceRange Range = ReadSourceRange(F, Record, Idx);
9466  Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd());
9467  break;
9468  }
9469 
9472  bool Template = Record[Idx++];
9473  TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx);
9474  if (!T)
9475  return NestedNameSpecifierLoc();
9476  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
9477 
9478  // FIXME: 'template' keyword location not saved anywhere, so we fake it.
9479  Builder.Extend(Context,
9480  Template? T->getTypeLoc().getBeginLoc() : SourceLocation(),
9481  T->getTypeLoc(), ColonColonLoc);
9482  break;
9483  }
9484 
9486  SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx);
9487  Builder.MakeGlobal(Context, ColonColonLoc);
9488  break;
9489  }
9490 
9492  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx);
9493  SourceRange Range = ReadSourceRange(F, Record, Idx);
9494  Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd());
9495  break;
9496  }
9497  }
9498  }
9499 
9500  return Builder.getWithLocInContext(Context);
9501 }
9502 
9504 ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record,
9505  unsigned &Idx) {
9506  SourceLocation beg = ReadSourceLocation(F, Record, Idx);
9507  SourceLocation end = ReadSourceLocation(F, Record, Idx);
9508  return SourceRange(beg, end);
9509 }
9510 
9511 static FixedPointSemantics
9513  unsigned &Idx) {
9514  unsigned Width = Record[Idx++];
9515  unsigned Scale = Record[Idx++];
9516  uint64_t Tmp = Record[Idx++];
9517  bool IsSigned = Tmp & 0x1;
9518  bool IsSaturated = Tmp & 0x2;
9519  bool HasUnsignedPadding = Tmp & 0x4;
9520  return FixedPointSemantics(Width, Scale, IsSigned, IsSaturated,
9521  HasUnsignedPadding);
9522 }
9523 
9524 APValue ASTReader::ReadAPValue(const RecordData &Record, unsigned &Idx) {
9525  unsigned Kind = Record[Idx++];
9526  switch (Kind) {
9527  case APValue::None:
9528  return APValue();
9530  return APValue::IndeterminateValue();
9531  case APValue::Int:
9532  return APValue(ReadAPSInt(Record, Idx));
9533  case APValue::Float: {
9534  const llvm::fltSemantics &FloatSema = llvm::APFloatBase::EnumToSemantics(
9535  static_cast<llvm::APFloatBase::Semantics>(Record[Idx++]));
9536  return APValue(ReadAPFloat(Record, FloatSema, Idx));
9537  }
9538  case APValue::FixedPoint: {
9539  FixedPointSemantics FPSema = ReadFixedPointSemantics(Record, Idx);
9540  return APValue(APFixedPoint(ReadAPInt(Record, Idx), FPSema));
9541  }
9542  case APValue::ComplexInt: {
9543  llvm::APSInt First = ReadAPSInt(Record, Idx);
9544  return APValue(std::move(First), ReadAPSInt(Record, Idx));
9545  }
9546  case APValue::ComplexFloat: {
9547  const llvm::fltSemantics &FloatSema1 = llvm::APFloatBase::EnumToSemantics(
9548  static_cast<llvm::APFloatBase::Semantics>(Record[Idx++]));
9549  llvm::APFloat First = ReadAPFloat(Record, FloatSema1, Idx);
9550  const llvm::fltSemantics &FloatSema2 = llvm::APFloatBase::EnumToSemantics(
9551  static_cast<llvm::APFloatBase::Semantics>(Record[Idx++]));
9552  return APValue(std::move(First), ReadAPFloat(Record, FloatSema2, Idx));
9553  }
9554  case APValue::LValue:
9555  case APValue::Vector:
9556  case APValue::Array:
9557  case APValue::Struct:
9558  case APValue::Union:
9561  // TODO : Handle all these APValue::ValueKind.
9562  return APValue();
9563  }
9564  llvm_unreachable("Invalid APValue::ValueKind");
9565 }
9566 
9567 /// Read an integral value
9568 llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) {
9569  unsigned BitWidth = Record[Idx++];
9570  unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
9571  llvm::APInt Result(BitWidth, NumWords, &Record[Idx]);
9572  Idx += NumWords;
9573  return Result;
9574 }
9575 
9576 /// Read a signed integral value
9577 llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) {
9578  bool isUnsigned = Record[Idx++];
9579  return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned);
9580 }
9581 
9582 /// Read a floating-point value
9583 llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record,
9584  const llvm::fltSemantics &Sem,
9585  unsigned &Idx) {
9586  return llvm::APFloat(Sem, ReadAPInt(Record, Idx));
9587 }
9588 
9589 // Read a string
9590 std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) {
9591  unsigned Len = Record[Idx++];
9592  std::string Result(Record.data() + Idx, Record.data() + Idx + Len);
9593  Idx += Len;
9594  return Result;
9595 }
9596 
9597 std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record,
9598  unsigned &Idx) {
9599  std::string Filename = ReadString(Record, Idx);
9600  ResolveImportedPath(F, Filename);
9601  return Filename;
9602 }
9603 
9604 std::string ASTReader::ReadPath(StringRef BaseDirectory,
9605  const RecordData &Record, unsigned &Idx) {
9606  std::string Filename = ReadString(Record, Idx);
9607  if (!BaseDirectory.empty())
9608  ResolveImportedPath(Filename, BaseDirectory);
9609  return Filename;
9610 }
9611 
9612 VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record,
9613  unsigned &Idx) {
9614  unsigned Major = Record[Idx++];
9615  unsigned Minor = Record[Idx++];
9616  unsigned Subminor = Record[Idx++];
9617  if (Minor == 0)
9618  return VersionTuple(Major);
9619  if (Subminor == 0)
9620  return VersionTuple(Major, Minor - 1);
9621  return VersionTuple(Major, Minor - 1, Subminor - 1);
9622 }
9623 
9625  const RecordData &Record,
9626  unsigned &Idx) {
9627  CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx);
9628  return CXXTemporary::Create(getContext(), Decl);
9629 }
9630 
9631 DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const {
9632  return Diag(CurrentImportLoc, DiagID);
9633 }
9634 
9635 DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const {
9636  return Diags.Report(Loc, DiagID);
9637 }
9638 
9639 /// Retrieve the identifier table associated with the
9640 /// preprocessor.
9642  return PP.getIdentifierTable();
9643 }
9644 
9645 /// Record that the given ID maps to the given switch-case
9646 /// statement.
9648  assert((*CurrSwitchCaseStmts)[ID] == nullptr &&
9649  "Already have a SwitchCase with this ID");
9650  (*CurrSwitchCaseStmts)[ID] = SC;
9651 }
9652 
9653 /// Retrieve the switch-case statement with the given ID.
9655  assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID");
9656  return (*CurrSwitchCaseStmts)[ID];
9657 }
9658 
9660  CurrSwitchCaseStmts->clear();
9661 }
9662 
9664  ASTContext &Context = getContext();
9665  std::vector<RawComment *> Comments;
9666  for (SmallVectorImpl<std::pair<BitstreamCursor,
9667  serialization::ModuleFile *>>::iterator
9668  I = CommentsCursors.begin(),
9669  E = CommentsCursors.end();
9670  I != E; ++I) {
9671  Comments.clear();
9672  BitstreamCursor &Cursor = I->first;
9673  serialization::ModuleFile &F = *I->second;
9674  SavedStreamPosition SavedPosition(Cursor);
9675 
9676  RecordData Record;
9677  while (true) {
9678  Expected<llvm::BitstreamEntry> MaybeEntry =
9679  Cursor.advanceSkippingSubblocks(
9680  BitstreamCursor::AF_DontPopBlockAtEnd);
9681  if (!MaybeEntry) {
9682  Error(MaybeEntry.takeError());
9683  return;
9684  }
9685  llvm::BitstreamEntry Entry = MaybeEntry.get();
9686 
9687  switch (Entry.Kind) {
9688  case llvm::BitstreamEntry::SubBlock: // Handled for us already.
9690  Error("malformed block record in AST file");
9691  return;
9692  case llvm::BitstreamEntry::EndBlock:
9693  goto NextCursor;
9694  case llvm::BitstreamEntry::Record:
9695  // The interesting case.
9696  break;
9697  }
9698 
9699  // Read a record.
9700  Record.clear();
9701  Expected<unsigned> MaybeComment = Cursor.readRecord(Entry.ID, Record);
9702  if (!MaybeComment) {
9703  Error(MaybeComment.takeError());
9704  return;
9705  }
9706  switch ((CommentRecordTypes)MaybeComment.get()) {
9707  case COMMENTS_RAW_COMMENT: {
9708  unsigned Idx = 0;
9709  SourceRange SR = ReadSourceRange(F, Record, Idx);
9711  (RawComment::CommentKind) Record[Idx++];
9712  bool IsTrailingComment = Record[Idx++];
9713  bool IsAlmostTrailingComment = Record[Idx++];
9714  Comments.push_back(new (Context) RawComment(
9715  SR, Kind, IsTrailingComment, IsAlmostTrailingComment));
9716  break;
9717  }
9718  }
9719  }
9720  NextCursor:
9721  // De-serialized SourceLocations get negative FileIDs for other modules,
9722  // potentially invalidating the original order. Sort it again.
9723  llvm::sort(Comments, BeforeThanCompare<RawComment>(SourceMgr));
9724  Context.Comments.addDeserializedComments(Comments);
9725  }
9726 }
9727 
9729  bool IncludeSystem, bool Complain,
9730  llvm::function_ref<void(const serialization::InputFile &IF,
9731  bool isSystem)> Visitor) {
9732  unsigned NumUserInputs = MF.NumUserInputFiles;
9733  unsigned NumInputs = MF.InputFilesLoaded.size();
9734  assert(NumUserInputs <= NumInputs);
9735  unsigned N = IncludeSystem ? NumInputs : NumUserInputs;
9736  for (unsigned I = 0; I < N; ++I) {
9737  bool IsSystem = I >= NumUserInputs;
9738  InputFile IF = getInputFile(MF, I+1, Complain);
9739  Visitor(IF, IsSystem);
9740  }
9741 }
9742 
9745  llvm::function_ref<void(const FileEntry *FE)> Visitor) {
9746  unsigned NumInputs = MF.InputFilesLoaded.size();
9747  for (unsigned I = 0; I < NumInputs; ++I) {
9748  InputFileInfo IFI = readInputFileInfo(MF, I + 1);
9749  if (IFI.TopLevelModuleMap)
9750  // FIXME: This unnecessarily re-reads the InputFileInfo.
9751  if (auto *FE = getInputFile(MF, I + 1).getFile())
9752  Visitor(FE);
9753  }
9754 }
9755 
9757  // If we know the owning module, use it.
9758  if (Module *M = D->getImportedOwningModule())
9759  return M->getFullModuleName();
9760 
9761  // Otherwise, use the name of the top-level module the decl is within.
9762  if (ModuleFile *M = getOwningModuleFile(D))
9763  return M->ModuleName;
9764 
9765  // Not from a module.
9766  return {};
9767 }
9768 
9769 void ASTReader::finishPendingActions() {
9770  while (!PendingIdentifierInfos.empty() || !PendingFunctionTypes.empty() ||
9771  !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() ||
9772  !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
9773  !PendingUpdateRecords.empty()) {
9774  // If any identifiers with corresponding top-level declarations have
9775  // been loaded, load those declarations now.
9776  using TopLevelDeclsMap =
9777  llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2>>;
9778  TopLevelDeclsMap TopLevelDecls;
9779 
9780  while (!PendingIdentifierInfos.empty()) {
9781  IdentifierInfo *II = PendingIdentifierInfos.back().first;
9782  SmallVector<uint32_t, 4> DeclIDs =
9783  std::move(PendingIdentifierInfos.back().second);
9784  PendingIdentifierInfos.pop_back();
9785 
9786  SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]);
9787  }
9788 
9789  // Load each function type that we deferred loading because it was a
9790  // deduced type that might refer to a local type declared within itself.
9791  for (unsigned I = 0; I != PendingFunctionTypes.size(); ++I) {
9792  auto *FD = PendingFunctionTypes[I].first;
9793  FD->setType(GetType(PendingFunctionTypes[I].second));
9794 
9795  // If we gave a function a deduced return type, remember that we need to
9796  // propagate that along the redeclaration chain.
9797  auto *DT = FD->getReturnType()->getContainedDeducedType();
9798  if (DT && DT->isDeduced())
9799  PendingDeducedTypeUpdates.insert(
9800  {FD->getCanonicalDecl(), FD->getReturnType()});
9801  }
9802  PendingFunctionTypes.clear();
9803 
9804  // For each decl chain that we wanted to complete while deserializing, mark
9805  // it as "still needs to be completed".
9806  for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
9807  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
9808  }
9809  PendingIncompleteDeclChains.clear();
9810 
9811  // Load pending declaration chains.
9812  for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
9813  loadPendingDeclChain(PendingDeclChains[I].first,
9814  PendingDeclChains[I].second);
9815  PendingDeclChains.clear();
9816 
9817  // Make the most recent of the top-level declarations visible.
9818  for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(),
9819  TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) {
9820  IdentifierInfo *II = TLD->first;
9821  for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) {
9822  pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II);
9823  }
9824  }
9825 
9826  // Load any pending macro definitions.
9827  for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
9828  IdentifierInfo *II = PendingMacroIDs.begin()[I].first;
9830  GlobalIDs.swap(PendingMacroIDs.begin()[I].second);
9831  // Initialize the macro history from chained-PCHs ahead of module imports.
9832  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
9833  ++IDIdx) {
9834  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
9835  if (!Info.M->isModule())
9836  resolvePendingMacro(II, Info);
9837  }
9838  // Handle module imports.
9839  for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
9840  ++IDIdx) {
9841  const PendingMacroInfo &Info = GlobalIDs[IDIdx];
9842  if (Info.M->isModule())
9843  resolvePendingMacro(II, Info);
9844  }
9845  }
9846  PendingMacroIDs.clear();
9847 
9848  // Wire up the DeclContexts for Decls that we delayed setting until
9849  // recursive loading is completed.
9850  while (!PendingDeclContextInfos.empty()) {
9851  PendingDeclContextInfo Info = PendingDeclContextInfos.front();
9852  PendingDeclContextInfos.pop_front();
9853  DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC));
9854  DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC));
9855  Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext());
9856  }
9857 
9858  // Perform any pending declaration updates.
9859  while (!PendingUpdateRecords.empty()) {
9860  auto Update = PendingUpdateRecords.pop_back_val();
9861  ReadingKindTracker ReadingKind(Read_Decl, *this);
9862  loadDeclUpdateRecords(Update);
9863  }
9864  }
9865 
9866  // At this point, all update records for loaded decls are in place, so any
9867  // fake class definitions should have become real.
9868  assert(PendingFakeDefinitionData.empty() &&
9869  "faked up a class definition but never saw the real one");
9870 
9871  // If we deserialized any C++ or Objective-C class definitions, any
9872  // Objective-C protocol definitions, or any redeclarable templates, make sure
9873  // that all redeclarations point to the definitions. Note that this can only
9874  // happen now, after the redeclaration chains have been fully wired.
9875  for (Decl *D : PendingDefinitions) {
9876  if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
9877  if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) {
9878  // Make sure that the TagType points at the definition.
9879  const_cast<TagType*>(TagT)->decl = TD;
9880  }
9881 
9882  if (auto RD = dyn_cast<CXXRecordDecl>(D)) {
9883  for (auto *R = getMostRecentExistingDecl(RD); R;
9884  R = R->getPreviousDecl()) {
9885  assert((R == D) ==
9886  cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() &&
9887  "declaration thinks it's the definition but it isn't");
9888  cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData;
9889  }
9890  }
9891 
9892  continue;
9893  }
9894 
9895  if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) {
9896  // Make sure that the ObjCInterfaceType points at the definition.
9897  const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl))
9898  ->Decl = ID;
9899 
9900  for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl())
9901  cast<ObjCInterfaceDecl>(R)->Data = ID->Data;
9902 
9903  continue;
9904  }
9905 
9906  if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) {
9907  for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl())
9908  cast<ObjCProtocolDecl>(R)->Data = PD->Data;
9909 
9910  continue;
9911  }
9912 
9913  auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl();
9914  for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl())
9915  cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common;
9916  }
9917  PendingDefinitions.clear();
9918 
9919  // Load the bodies of any functions or methods we've encountered. We do
9920  // this now (delayed) so that we can be sure that the declaration chains
9921  // have been fully wired up (hasBody relies on this).
9922  // FIXME: We shouldn't require complete redeclaration chains here.
9923  for (PendingBodiesMap::iterator PB = PendingBodies.begin(),
9924  PBEnd = PendingBodies.end();
9925  PB != PBEnd; ++PB) {
9926  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) {
9927  // For a function defined inline within a class template, force the
9928  // canonical definition to be the one inside the canonical definition of
9929  // the template. This ensures that we instantiate from a correct view
9930  // of the template.
9931  //
9932  // Sadly we can't do this more generally: we can't be sure that all
9933  // copies of an arbitrary class definition will have the same members
9934  // defined (eg, some member functions may not be instantiated, and some
9935  // special members may or may not have been implicitly defined).
9936  if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
9937  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
9938  continue;
9939 
9940  // FIXME: Check for =delete/=default?
9941  // FIXME: Complain about ODR violations here?
9942  const FunctionDecl *Defn = nullptr;
9943  if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) {
9944  FD->setLazyBody(PB->second);
9945  } else {
9946  auto *NonConstDefn = const_cast<FunctionDecl*>(Defn);
9947  mergeDefinitionVisibility(NonConstDefn, FD);
9948 
9949  if (!FD->isLateTemplateParsed() &&
9950  !NonConstDefn->isLateTemplateParsed() &&
9951  FD->getODRHash() != NonConstDefn->getODRHash()) {
9952  if (!isa<CXXMethodDecl>(FD)) {
9953  PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn);
9954  } else if (FD->getLexicalParent()->isFileContext() &&
9955  NonConstDefn->getLexicalParent()->isFileContext()) {
9956  // Only diagnose out-of-line method definitions. If they are
9957  // in class definitions, then an error will be generated when
9958  // processing the class bodies.
9959  PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn);
9960  }
9961  }
9962  }
9963  continue;
9964  }
9965 
9966  ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first);
9967  if (!getContext().getLangOpts().Modules || !MD->hasBody())
9968  MD->setLazyBody(PB->second);
9969  }
9970  PendingBodies.clear();
9971 
9972  // Do some cleanup.
9973  for (auto *ND : PendingMergedDefinitionsToDeduplicate)
9974  getContext().deduplicateMergedDefinitonsFor(ND);
9975  PendingMergedDefinitionsToDeduplicate.clear();
9976 }
9977 
9978 void ASTReader::diagnoseOdrViolations() {
9979  if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() &&
9980  PendingFunctionOdrMergeFailures.empty() &&
9981  PendingEnumOdrMergeFailures.empty())
9982  return;
9983 
9984  // Trigger the import of the full definition of each class that had any
9985  // odr-merging problems, so we can produce better diagnostics for them.
9986  // These updates may in turn find and diagnose some ODR failures, so take
9987  // ownership of the set first.
9988  auto OdrMergeFailures = std::move(PendingOdrMergeFailures);
9989  PendingOdrMergeFailures.clear();
9990  for (auto &Merge : OdrMergeFailures) {
9991  Merge.first->buildLookup();
9992  Merge.first->decls_begin();
9993  Merge.first->bases_begin();
9994  Merge.first->vbases_begin();
9995  for (auto &RecordPair : Merge.second) {
9996  auto *RD = RecordPair.first;
9997  RD->decls_begin();
9998  RD->bases_begin();
9999  RD->vbases_begin();
10000  }
10001  }
10002 
10003  // Trigger the import of functions.
10004  auto FunctionOdrMergeFailures = std::move(PendingFunctionOdrMergeFailures);
10005  PendingFunctionOdrMergeFailures.clear();
10006  for (auto &Merge : FunctionOdrMergeFailures) {
10007  Merge.first->buildLookup();
10008  Merge.first->decls_begin();
10009  Merge.first->getBody();
10010  for (auto &FD : Merge.second) {
10011  FD->buildLookup();
10012  FD->decls_begin();
10013  FD->getBody();
10014  }
10015  }
10016 
10017  // Trigger the import of enums.
10018  auto EnumOdrMergeFailures = std::move(PendingEnumOdrMergeFailures);
10019  PendingEnumOdrMergeFailures.clear();
10020  for (auto &Merge : EnumOdrMergeFailures) {
10021  Merge.first->decls_begin();
10022  for (auto &Enum : Merge.second) {
10023  Enum->decls_begin();
10024  }
10025  }
10026 
10027  // For each declaration from a merged context, check that the canonical
10028  // definition of that context also contains a declaration of the same
10029  // entity.
10030  //
10031  // Caution: this loop does things that might invalidate iterators into
10032  // PendingOdrMergeChecks. Don't turn this into a range-based for loop!
10033  while (!PendingOdrMergeChecks.empty()) {
10034  NamedDecl *D = PendingOdrMergeChecks.pop_back_val();
10035 
10036  // FIXME: Skip over implicit declarations for now. This matters for things
10037  // like implicitly-declared special member functions. This isn't entirely
10038  // correct; we can end up with multiple unmerged declarations of the same
10039  // implicit entity.
10040  if (D->isImplicit())
10041  continue;
10042 
10043  DeclContext *CanonDef = D->getDeclContext();
10044 
10045  bool Found = false;
10046  const Decl *DCanon = D->getCanonicalDecl();
10047 
10048  for (auto RI : D->redecls()) {
10049  if (RI->getLexicalDeclContext() == CanonDef) {
10050  Found = true;
10051  break;
10052  }
10053  }
10054  if (Found)
10055  continue;
10056 
10057  // Quick check failed, time to do the slow thing. Note, we can't just
10058  // look up the name of D in CanonDef here, because the member that is
10059  // in CanonDef might not be found by name lookup (it might have been
10060  // replaced by a more recent declaration in the lookup table), and we
10061  // can't necessarily find it in the redeclaration chain because it might
10062  // be merely mergeable, not redeclarable.
10064  for (auto *CanonMember : CanonDef->decls()) {
10065  if (CanonMember->getCanonicalDecl() == DCanon) {
10066  // This can happen if the declaration is merely mergeable and not
10067  // actually redeclarable (we looked for redeclarations earlier).
10068  //
10069  // FIXME: We should be able to detect this more efficiently, without
10070  // pulling in all of the members of CanonDef.
10071  Found = true;
10072  break;
10073  }
10074  if (auto *ND = dyn_cast<NamedDecl>(CanonMember))
10075  if (ND->getDeclName() == D->getDeclName())
10076  Candidates.push_back(ND);
10077  }
10078 
10079  if (!Found) {
10080  // The AST doesn't like TagDecls becoming invalid after they've been
10081  // completed. We only really need to mark FieldDecls as invalid here.
10082  if (!isa<TagDecl>(D))
10083  D->setInvalidDecl();
10084 
10085  // Ensure we don't accidentally recursively enter deserialization while
10086  // we're producing our diagnostic.
10087  Deserializing RecursionGuard(this);
10088 
10089  std::string CanonDefModule =
10090  getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef));
10091  Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl)
10092  << D << getOwningModuleNameForDiagnostic(D)
10093  << CanonDef << CanonDefModule.empty() << CanonDefModule;
10094 
10095  if (Candidates.empty())
10096  Diag(cast<Decl>(CanonDef)->getLocation(),
10097  diag::note_module_odr_violation_no_possible_decls) << D;
10098  else {
10099  for (unsigned I = 0, N = Candidates.size(); I != N; ++I)
10100  Diag(Candidates[I]->getLocation(),
10101  diag::note_module_odr_violation_possible_decl)
10102  << Candidates[I];
10103  }
10104 
10105  DiagnosedOdrMergeFailures.insert(CanonDef);
10106  }
10107  }
10108 
10109  if (OdrMergeFailures.empty() && FunctionOdrMergeFailures.empty() &&
10110  EnumOdrMergeFailures.empty())
10111  return;
10112 
10113  // Ensure we don't accidentally recursively enter deserialization while
10114  // we're producing our diagnostics.
10115  Deserializing RecursionGuard(this);
10116 
10117  // Common code for hashing helpers.
10118  ODRHash Hash;
10119  auto ComputeQualTypeODRHash = [&Hash](QualType Ty) {
10120  Hash.clear();
10121  Hash.AddQualType(Ty);
10122  return Hash.CalculateHash();
10123  };
10124 
10125  auto ComputeODRHash = [&Hash](const Stmt *S) {
10126  assert(S);
10127  Hash.clear();
10128  Hash.AddStmt(S);
10129  return Hash.CalculateHash();
10130  };
10131 
10132  auto ComputeSubDeclODRHash = [&Hash](const Decl *D) {
10133  assert(D);
10134  Hash.clear();
10135  Hash.AddSubDecl(D);
10136  return Hash.CalculateHash();
10137  };
10138 
10139  auto ComputeTemplateArgumentODRHash = [&Hash](const TemplateArgument &TA) {
10140  Hash.clear();
10141  Hash.AddTemplateArgument(TA);
10142  return Hash.CalculateHash();
10143  };
10144 
10145  auto ComputeTemplateParameterListODRHash =
10146  [&Hash](const TemplateParameterList *TPL) {
10147  assert(TPL);
10148  Hash.clear();
10149  Hash.AddTemplateParameterList(TPL);
10150  return Hash.CalculateHash();
10151  };
10152 
10153  // Issue any pending ODR-failure diagnostics.
10154  for (auto &Merge : OdrMergeFailures) {
10155  // If we've already pointed out a specific problem with this class, don't
10156  // bother issuing a general "something's different" diagnostic.
10157  if (!DiagnosedOdrMergeFailures.insert(Merge.first).second)
10158  continue;
10159 
10160  bool Diagnosed = false;
10161  CXXRecordDecl *FirstRecord = Merge.first;
10162  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord);
10163  for (auto &RecordPair : Merge.second) {
10164  CXXRecordDecl *SecondRecord = RecordPair.first;
10165  // Multiple different declarations got merged together; tell the user
10166  // where they came from.
10167  if (FirstRecord == SecondRecord)
10168  continue;
10169 
10170  std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord);
10171 
10172  auto *FirstDD = FirstRecord->DefinitionData;
10173  auto *SecondDD = RecordPair.second;
10174 
10175  assert(FirstDD && SecondDD && "Definitions without DefinitionData");
10176 
10177  // Diagnostics from DefinitionData are emitted here.
10178  if (FirstDD != SecondDD) {
10179  enum ODRDefinitionDataDifference {
10180  NumBases,
10181  NumVBases,
10182  BaseType,
10183  BaseVirtual,
10184  BaseAccess,
10185  };
10186  auto ODRDiagError = [FirstRecord, &FirstModule,
10187  this](SourceLocation Loc, SourceRange Range,
10188  ODRDefinitionDataDifference DiffType) {
10189  return Diag(Loc, diag::err_module_odr_violation_definition_data)
10190  << FirstRecord << FirstModule.empty() << FirstModule << Range
10191  << DiffType;
10192  };
10193  auto ODRDiagNote = [&SecondModule,
10194  this](SourceLocation Loc, SourceRange Range,
10195  ODRDefinitionDataDifference DiffType) {
10196  return Diag(Loc, diag::note_module_odr_violation_definition_data)
10197  << SecondModule << Range << DiffType;
10198  };
10199 
10200  unsigned FirstNumBases = FirstDD->NumBases;
10201  unsigned FirstNumVBases = FirstDD->NumVBases;
10202  unsigned SecondNumBases = SecondDD->NumBases;
10203  unsigned SecondNumVBases = SecondDD->NumVBases;
10204 
10205  auto GetSourceRange = [](struct CXXRecordDecl::DefinitionData *DD) {
10206  unsigned NumBases = DD->NumBases;
10207  if (NumBases == 0) return SourceRange();
10208  auto bases = DD->bases();
10209  return SourceRange(bases[0].getBeginLoc(),
10210  bases[NumBases - 1].getEndLoc());
10211  };
10212 
10213  if (FirstNumBases != SecondNumBases) {
10214  ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD),
10215  NumBases)
10216  << FirstNumBases;
10217  ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD),
10218  NumBases)
10219  << SecondNumBases;
10220  Diagnosed = true;
10221  break;
10222  }
10223 
10224  if (FirstNumVBases != SecondNumVBases) {
10225  ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD),
10226  NumVBases)
10227  << FirstNumVBases;
10228  ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD),
10229  NumVBases)
10230  << SecondNumVBases;
10231  Diagnosed = true;
10232  break;
10233  }
10234 
10235  auto FirstBases = FirstDD->bases();
10236  auto SecondBases = SecondDD->bases();
10237  unsigned i = 0;
10238  for (i = 0; i < FirstNumBases; ++i) {
10239  auto FirstBase = FirstBases[i];
10240  auto SecondBase = SecondBases[i];
10241  if (ComputeQualTypeODRHash(FirstBase.getType()) !=
10242  ComputeQualTypeODRHash(SecondBase.getType())) {
10243  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
10244  BaseType)
10245  << (i + 1) << FirstBase.getType();
10246  ODRDiagNote(SecondRecord->getLocation(),
10247  SecondBase.getSourceRange(), BaseType)
10248  << (i + 1) << SecondBase.getType();
10249  break;
10250  }
10251 
10252  if (FirstBase.isVirtual() != SecondBase.isVirtual()) {
10253  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
10254  BaseVirtual)
10255  << (i + 1) << FirstBase.isVirtual() << FirstBase.getType();
10256  ODRDiagNote(SecondRecord->getLocation(),
10257  SecondBase.getSourceRange(), BaseVirtual)
10258  << (i + 1) << SecondBase.isVirtual() << SecondBase.getType();
10259  break;
10260  }
10261 
10262  if (FirstBase.getAccessSpecifierAsWritten() !=
10263  SecondBase.getAccessSpecifierAsWritten()) {
10264  ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(),
10265  BaseAccess)
10266  << (i + 1) << FirstBase.getType()
10267  << (int)FirstBase.getAccessSpecifierAsWritten();
10268  ODRDiagNote(SecondRecord->getLocation(),
10269  SecondBase.getSourceRange(), BaseAccess)
10270  << (i + 1) << SecondBase.getType()
10271  << (int)SecondBase.getAccessSpecifierAsWritten();
10272  break;
10273  }
10274  }
10275 
10276  if (i != FirstNumBases) {
10277  Diagnosed = true;
10278  break;
10279  }
10280  }
10281 
10282  using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>;
10283 
10284  const ClassTemplateDecl *FirstTemplate =
10285  FirstRecord->getDescribedClassTemplate();
10286  const ClassTemplateDecl *SecondTemplate =
10287  SecondRecord->getDescribedClassTemplate();
10288 
10289  assert(!FirstTemplate == !SecondTemplate &&
10290  "Both pointers should be null or non-null");
10291 
10292  enum ODRTemplateDifference {
10293  ParamEmptyName,
10294  ParamName,
10295  ParamSingleDefaultArgument,
10296  ParamDifferentDefaultArgument,
10297  };
10298 
10299  if (FirstTemplate && SecondTemplate) {
10300  DeclHashes FirstTemplateHashes;
10301  DeclHashes SecondTemplateHashes;
10302 
10303  auto PopulateTemplateParameterHashs =
10304  [&ComputeSubDeclODRHash](DeclHashes &Hashes,
10305  const ClassTemplateDecl *TD) {
10306  for (auto *D : TD->getTemplateParameters()->asArray()) {
10307  Hashes.emplace_back(D, ComputeSubDeclODRHash(D));
10308  }
10309  };
10310 
10311  PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate);
10312  PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate);
10313 
10314  assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() &&
10315  "Number of template parameters should be equal.");
10316 
10317  auto FirstIt = FirstTemplateHashes.begin();
10318  auto FirstEnd = FirstTemplateHashes.end();
10319  auto SecondIt = SecondTemplateHashes.begin();
10320  for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) {
10321  if (FirstIt->second == SecondIt->second)
10322  continue;
10323 
10324  auto ODRDiagError = [FirstRecord, &FirstModule,
10325  this](SourceLocation Loc, SourceRange Range,
10326  ODRTemplateDifference DiffType) {
10327  return Diag(Loc, diag::err_module_odr_violation_template_parameter)
10328  << FirstRecord << FirstModule.empty() << FirstModule << Range
10329  << DiffType;
10330  };
10331  auto ODRDiagNote = [&SecondModule,
10332  this](SourceLocation Loc, SourceRange Range,
10333  ODRTemplateDifference DiffType) {
10334  return Diag(Loc, diag::note_module_odr_violation_template_parameter)
10335  << SecondModule << Range << DiffType;
10336  };
10337 
10338  const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first);
10339  const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first);
10340 
10341  assert(FirstDecl->getKind() == SecondDecl->getKind() &&
10342  "Parameter Decl's should be the same kind.");
10343 
10344  DeclarationName FirstName = FirstDecl->getDeclName();
10345  DeclarationName SecondName = SecondDecl->getDeclName();
10346 
10347  if (FirstName != SecondName) {
10348  const bool FirstNameEmpty =
10349  FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo();
10350  const bool SecondNameEmpty =
10351  SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo();
10352  assert((!FirstNameEmpty || !SecondNameEmpty) &&
10353  "Both template parameters cannot be unnamed.");
10354  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
10355  FirstNameEmpty ? ParamEmptyName : ParamName)
10356  << FirstName;
10357  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
10358  SecondNameEmpty ? ParamEmptyName : ParamName)
10359  << SecondName;
10360  break;
10361  }
10362 
10363  switch (FirstDecl->getKind()) {
10364  default:
10365  llvm_unreachable("Invalid template parameter type.");
10366  case Decl::TemplateTypeParm: {
10367  const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl);
10368  const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl);
10369  const bool HasFirstDefaultArgument =
10370  FirstParam->hasDefaultArgument() &&
10371  !FirstParam->defaultArgumentWasInherited();
10372  const bool HasSecondDefaultArgument =
10373  SecondParam->hasDefaultArgument() &&
10374  !SecondParam->defaultArgumentWasInherited();
10375 
10376  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
10377  ODRDiagError(FirstDecl->getLocation(),
10378  FirstDecl->getSourceRange(),
10379  ParamSingleDefaultArgument)
10380  << HasFirstDefaultArgument;
10381  ODRDiagNote(SecondDecl->getLocation(),
10382  SecondDecl->getSourceRange(),
10383  ParamSingleDefaultArgument)
10384  << HasSecondDefaultArgument;
10385  break;
10386  }
10387 
10388  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
10389  "Expecting default arguments.");
10390 
10391  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
10392  ParamDifferentDefaultArgument);
10393  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
10394  ParamDifferentDefaultArgument);
10395 
10396  break;
10397  }
10398  case Decl::NonTypeTemplateParm: {
10399  const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl);
10400  const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl);
10401  const bool HasFirstDefaultArgument =
10402  FirstParam->hasDefaultArgument() &&
10403  !FirstParam->defaultArgumentWasInherited();
10404  const bool HasSecondDefaultArgument =
10405  SecondParam->hasDefaultArgument() &&
10406  !SecondParam->defaultArgumentWasInherited();
10407 
10408  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
10409  ODRDiagError(FirstDecl->getLocation(),
10410  FirstDecl->getSourceRange(),
10411  ParamSingleDefaultArgument)
10412  << HasFirstDefaultArgument;
10413  ODRDiagNote(SecondDecl->getLocation(),
10414  SecondDecl->getSourceRange(),
10415  ParamSingleDefaultArgument)
10416  << HasSecondDefaultArgument;
10417  break;
10418  }
10419 
10420  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
10421  "Expecting default arguments.");
10422 
10423  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
10424  ParamDifferentDefaultArgument);
10425  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
10426  ParamDifferentDefaultArgument);
10427 
10428  break;
10429  }
10430  case Decl::TemplateTemplateParm: {
10431  const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl);
10432  const auto *SecondParam =
10433  cast<TemplateTemplateParmDecl>(SecondDecl);
10434  const bool HasFirstDefaultArgument =
10435  FirstParam->hasDefaultArgument() &&
10436  !FirstParam->defaultArgumentWasInherited();
10437  const bool HasSecondDefaultArgument =
10438  SecondParam->hasDefaultArgument() &&
10439  !SecondParam->defaultArgumentWasInherited();
10440 
10441  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
10442  ODRDiagError(FirstDecl->getLocation(),
10443  FirstDecl->getSourceRange(),
10444  ParamSingleDefaultArgument)
10445  << HasFirstDefaultArgument;
10446  ODRDiagNote(SecondDecl->getLocation(),
10447  SecondDecl->getSourceRange(),
10448  ParamSingleDefaultArgument)
10449  << HasSecondDefaultArgument;
10450  break;
10451  }
10452 
10453  assert(HasFirstDefaultArgument && HasSecondDefaultArgument &&
10454  "Expecting default arguments.");
10455 
10456  ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(),
10457  ParamDifferentDefaultArgument);
10458  ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(),
10459  ParamDifferentDefaultArgument);
10460 
10461  break;
10462  }
10463  }
10464 
10465  break;
10466  }
10467 
10468  if (FirstIt != FirstEnd) {
10469  Diagnosed = true;
10470  break;
10471  }
10472  }
10473 
10474  DeclHashes FirstHashes;
10475  DeclHashes SecondHashes;
10476 
10477  auto PopulateHashes = [&ComputeSubDeclODRHash, FirstRecord](
10478  DeclHashes &Hashes, CXXRecordDecl *Record) {
10479  for (auto *D : Record->decls()) {
10480  // Due to decl merging, the first CXXRecordDecl is the parent of
10481  // Decls in both records.
10482  if (!ODRHash::isWhitelistedDecl(D, FirstRecord))
10483  continue;
10484  Hashes.emplace_back(D, ComputeSubDeclODRHash(D));
10485  }
10486  };
10487  PopulateHashes(FirstHashes, FirstRecord);
10488  PopulateHashes(SecondHashes, SecondRecord);
10489 
10490  // Used with err_module_odr_violation_mismatch_decl and
10491  // note_module_odr_violation_mismatch_decl
10492  // This list should be the same Decl's as in ODRHash::isWhiteListedDecl
10493  enum {
10494  EndOfClass,
10495  PublicSpecifer,
10496  PrivateSpecifer,
10497  ProtectedSpecifer,
10498  StaticAssert,
10499  Field,
10500  CXXMethod,
10501  TypeAlias,
10502  TypeDef,
10503  Var,
10504  Friend,
10505  FunctionTemplate,
10506  Other
10507  } FirstDiffType = Other,
10508  SecondDiffType = Other;
10509 
10510  auto DifferenceSelector = [](Decl *D) {
10511  assert(D && "valid Decl required");
10512  switch (D->getKind()) {
10513  default:
10514  return Other;
10515  case Decl::AccessSpec:
10516  switch (D->getAccess()) {
10517  case AS_public:
10518  return PublicSpecifer;
10519  case AS_private:
10520  return PrivateSpecifer;
10521  case AS_protected:
10522  return ProtectedSpecifer;
10523  case AS_none:
10524  break;
10525  }
10526  llvm_unreachable("Invalid access specifier");
10527  case Decl::StaticAssert:
10528  return StaticAssert;
10529  case Decl::Field:
10530  return Field;
10531  case Decl::CXXMethod:
10532  case Decl::CXXConstructor:
10533  case Decl::CXXDestructor:
10534  return CXXMethod;
10535  case Decl::TypeAlias:
10536  return TypeAlias;
10537  case Decl::Typedef:
10538  return TypeDef;
10539  case Decl::Var:
10540  return Var;
10541  case Decl::Friend:
10542  return Friend;
10543  case Decl::FunctionTemplate:
10544  return FunctionTemplate;
10545  }
10546  };
10547 
10548  Decl *FirstDecl = nullptr;
10549  Decl *SecondDecl = nullptr;
10550  auto FirstIt = FirstHashes.begin();
10551  auto SecondIt = SecondHashes.begin();
10552 
10553  // If there is a diagnoseable difference, FirstDiffType and
10554  // SecondDiffType will not be Other and FirstDecl and SecondDecl will be
10555  // filled in if not EndOfClass.
10556  while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) {
10557  if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() &&
10558  FirstIt->second == SecondIt->second) {
10559  ++FirstIt;
10560  ++SecondIt;
10561  continue;
10562  }
10563 
10564  FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first;
10565  SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first;
10566 
10567  FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass;
10568  SecondDiffType =
10569  SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass;
10570 
10571  break;
10572  }
10573 
10574  if (FirstDiffType == Other || SecondDiffType == Other) {
10575  // Reaching this point means an unexpected Decl was encountered
10576  // or no difference was detected. This causes a generic error
10577  // message to be emitted.
10578  Diag(FirstRecord->getLocation(),
10579  diag::err_module_odr_violation_different_definitions)
10580  << FirstRecord << FirstModule.empty() << FirstModule;
10581 
10582  if (FirstDecl) {
10583  Diag(FirstDecl->getLocation(), diag::note_first_module_difference)
10584  << FirstRecord << FirstDecl->getSourceRange();
10585  }
10586 
10587  Diag(SecondRecord->getLocation(),
10588  diag::note_module_odr_violation_different_definitions)
10589  << SecondModule;
10590 
10591  if (SecondDecl) {
10592  Diag(SecondDecl->getLocation(), diag::note_second_module_difference)
10593  << SecondDecl->getSourceRange();
10594  }
10595 
10596  Diagnosed = true;
10597  break;
10598  }
10599 
10600  if (FirstDiffType != SecondDiffType) {
10601  SourceLocation FirstLoc;
10602  SourceRange FirstRange;
10603  if (FirstDiffType == EndOfClass) {
10604  FirstLoc = FirstRecord->getBraceRange().getEnd();
10605  } else {
10606  FirstLoc = FirstIt->first->getLocation();
10607  FirstRange = FirstIt->first->getSourceRange();
10608  }
10609  Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl)
10610  << FirstRecord << FirstModule.empty() << FirstModule << FirstRange
10611  << FirstDiffType;
10612 
10613  SourceLocation SecondLoc;
10614  SourceRange SecondRange;
10615  if (SecondDiffType == EndOfClass) {
10616  SecondLoc = SecondRecord->getBraceRange().getEnd();
10617  } else {
10618  SecondLoc = SecondDecl->getLocation();
10619  SecondRange = SecondDecl->getSourceRange();
10620  }
10621  Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl)
10622  << SecondModule << SecondRange << SecondDiffType;
10623  Diagnosed = true;
10624  break;
10625  }
10626 
10627  assert(FirstDiffType == SecondDiffType);
10628 
10629  // Used with err_module_odr_violation_mismatch_decl_diff and
10630  // note_module_odr_violation_mismatch_decl_diff
10631  enum ODRDeclDifference {
10632  StaticAssertCondition,
10633  StaticAssertMessage,
10634  StaticAssertOnlyMessage,
10635  FieldName,
10636  FieldTypeName,
10637  FieldSingleBitField,
10638  FieldDifferentWidthBitField,
10639  FieldSingleMutable,
10640  FieldSingleInitializer,
10641  FieldDifferentInitializers,
10642  MethodName,
10643  MethodDeleted,
10644  MethodDefaulted,
10645  MethodVirtual,
10646  MethodStatic,
10647  MethodVolatile,
10648  MethodConst,
10649  MethodInline,
10650  MethodNumberParameters,
10651  MethodParameterType,
10652  MethodParameterName,
10653  MethodParameterSingleDefaultArgument,
10654  MethodParameterDifferentDefaultArgument,
10655  MethodNoTemplateArguments,
10656  MethodDifferentNumberTemplateArguments,
10657  MethodDifferentTemplateArgument,
10658  MethodSingleBody,
10659  MethodDifferentBody,
10660  TypedefName,
10661  TypedefType,
10662  VarName,
10663  VarType,
10664  VarSingleInitializer,
10665  VarDifferentInitializer,
10666  VarConstexpr,
10667  FriendTypeFunction,
10668  FriendType,
10669  FriendFunction,
10670  FunctionTemplateDifferentNumberParameters,
10671  FunctionTemplateParameterDifferentKind,
10672  FunctionTemplateParameterName,
10673  FunctionTemplateParameterSingleDefaultArgument,
10674  FunctionTemplateParameterDifferentDefaultArgument,
10675  FunctionTemplateParameterDifferentType,
10676  FunctionTemplatePackParameter,
10677  };
10678 
10679  // These lambdas have the common portions of the ODR diagnostics. This
10680  // has the same return as Diag(), so addition parameters can be passed
10681  // in with operator<<
10682  auto ODRDiagError = [FirstRecord, &FirstModule, this](
10683  SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) {
10684  return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff)
10685  << FirstRecord << FirstModule.empty() << FirstModule << Range
10686  << DiffType;
10687  };
10688  auto ODRDiagNote = [&SecondModule, this](
10689  SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) {
10690  return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff)
10691  << SecondModule << Range << DiffType;
10692  };
10693 
10694  switch (FirstDiffType) {
10695  case Other:
10696  case EndOfClass:
10697  case PublicSpecifer:
10698  case PrivateSpecifer:
10699  case ProtectedSpecifer:
10700  llvm_unreachable("Invalid diff type");
10701 
10702  case StaticAssert: {
10703  StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl);
10704  StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl);
10705 
10706  Expr *FirstExpr = FirstSA->getAssertExpr();
10707  Expr *SecondExpr = SecondSA->getAssertExpr();
10708  unsigned FirstODRHash = ComputeODRHash(FirstExpr);
10709  unsigned SecondODRHash = ComputeODRHash(SecondExpr);
10710  if (FirstODRHash != SecondODRHash) {
10711  ODRDiagError(FirstExpr->getBeginLoc(), FirstExpr->getSourceRange(),
10712  StaticAssertCondition);
10713  ODRDiagNote(SecondExpr->getBeginLoc(), SecondExpr->getSourceRange(),
10714  StaticAssertCondition);
10715  Diagnosed = true;
10716  break;
10717  }
10718 
10719  StringLiteral *FirstStr = FirstSA->getMessage();
10720  StringLiteral *SecondStr = SecondSA->getMessage();
10721  assert((FirstStr || SecondStr) && "Both messages cannot be empty");
10722  if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) {
10723  SourceLocation FirstLoc, SecondLoc;
10724  SourceRange FirstRange, SecondRange;
10725  if (FirstStr) {
10726  FirstLoc = FirstStr->getBeginLoc();
10727  FirstRange = FirstStr->getSourceRange();
10728  } else {
10729  FirstLoc = FirstSA->getBeginLoc();
10730  FirstRange = FirstSA->getSourceRange();
10731  }
10732  if (SecondStr) {
10733  SecondLoc = SecondStr->getBeginLoc();
10734  SecondRange = SecondStr->getSourceRange();
10735  } else {
10736  SecondLoc = SecondSA->getBeginLoc();
10737  SecondRange = SecondSA->getSourceRange();
10738  }
10739  ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage)
10740  << (FirstStr == nullptr);
10741  ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage)
10742  << (SecondStr == nullptr);
10743  Diagnosed = true;
10744  break;
10745  }
10746 
10747  if (FirstStr && SecondStr &&
10748  FirstStr->getString() != SecondStr->getString()) {
10749  ODRDiagError(FirstStr->getBeginLoc(), FirstStr->getSourceRange(),
10750  StaticAssertMessage);
10751  ODRDiagNote(SecondStr->getBeginLoc(), SecondStr->getSourceRange(),
10752  StaticAssertMessage);
10753  Diagnosed = true;
10754  break;
10755  }
10756  break;
10757  }
10758  case Field: {
10759  FieldDecl *FirstField = cast<FieldDecl>(FirstDecl);
10760  FieldDecl *SecondField = cast<FieldDecl>(SecondDecl);
10761  IdentifierInfo *FirstII = FirstField->getIdentifier();
10762  IdentifierInfo *SecondII = SecondField->getIdentifier();
10763  if (FirstII->getName() != SecondII->getName()) {
10764  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10765  FieldName)
10766  << FirstII;
10767  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10768  FieldName)
10769  << SecondII;
10770 
10771  Diagnosed = true;
10772  break;
10773  }
10774 
10775  assert(getContext().hasSameType(FirstField->getType(),
10776  SecondField->getType()));
10777 
10778  QualType FirstType = FirstField->getType();
10779  QualType SecondType = SecondField->getType();
10780  if (ComputeQualTypeODRHash(FirstType) !=
10781  ComputeQualTypeODRHash(SecondType)) {
10782  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10783  FieldTypeName)
10784  << FirstII << FirstType;
10785  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10786  FieldTypeName)
10787  << SecondII << SecondType;
10788 
10789  Diagnosed = true;
10790  break;
10791  }
10792 
10793  const bool IsFirstBitField = FirstField->isBitField();
10794  const bool IsSecondBitField = SecondField->isBitField();
10795  if (IsFirstBitField != IsSecondBitField) {
10796  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10797  FieldSingleBitField)
10798  << FirstII << IsFirstBitField;
10799  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10800  FieldSingleBitField)
10801  << SecondII << IsSecondBitField;
10802  Diagnosed = true;
10803  break;
10804  }
10805 
10806  if (IsFirstBitField && IsSecondBitField) {
10807  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10808  FieldDifferentWidthBitField)
10809  << FirstII << FirstField->getBitWidth()->getSourceRange();
10810  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10811  FieldDifferentWidthBitField)
10812  << SecondII << SecondField->getBitWidth()->getSourceRange();
10813  Diagnosed = true;
10814  break;
10815  }
10816 
10817  const bool IsFirstMutable = FirstField->isMutable();
10818  const bool IsSecondMutable = SecondField->isMutable();
10819  if (IsFirstMutable != IsSecondMutable) {
10820  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10821  FieldSingleMutable)
10822  << FirstII << IsFirstMutable;
10823  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10824  FieldSingleMutable)
10825  << SecondII << IsSecondMutable;
10826  Diagnosed = true;
10827  break;
10828  }
10829 
10830  const Expr *FirstInitializer = FirstField->getInClassInitializer();
10831  const Expr *SecondInitializer = SecondField->getInClassInitializer();
10832  if ((!FirstInitializer && SecondInitializer) ||
10833  (FirstInitializer && !SecondInitializer)) {
10834  ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
10835  FieldSingleInitializer)
10836  << FirstII << (FirstInitializer != nullptr);
10837  ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(),
10838  FieldSingleInitializer)
10839  << SecondII << (SecondInitializer != nullptr);
10840  Diagnosed = true;
10841  break;
10842  }
10843 
10844  if (FirstInitializer && SecondInitializer) {
10845  unsigned FirstInitHash = ComputeODRHash(FirstInitializer);
10846  unsigned SecondInitHash = ComputeODRHash(SecondInitializer);
10847  if (FirstInitHash != SecondInitHash) {
10848  ODRDiagError(FirstField->getLocation(),
10849  FirstField->getSourceRange(),
10850  FieldDifferentInitializers)
10851  << FirstII << FirstInitializer->getSourceRange();
10852  ODRDiagNote(SecondField->getLocation(),
10853  SecondField->getSourceRange(),
10854  FieldDifferentInitializers)
10855  << SecondII << SecondInitializer->getSourceRange();
10856  Diagnosed = true;
10857  break;
10858  }
10859  }
10860 
10861  break;
10862  }
10863  case CXXMethod: {
10864  enum {
10865  DiagMethod,
10866  DiagConstructor,
10867  DiagDestructor,
10868  } FirstMethodType,
10869  SecondMethodType;
10870  auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) {
10871  if (isa<CXXConstructorDecl>(D)) return DiagConstructor;
10872  if (isa<CXXDestructorDecl>(D)) return DiagDestructor;
10873  return DiagMethod;
10874  };
10875  const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl);
10876  const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl);
10877  FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod);
10878  SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod);
10879  auto FirstName = FirstMethod->getDeclName();
10880  auto SecondName = SecondMethod->getDeclName();
10881  if (FirstMethodType != SecondMethodType || FirstName != SecondName) {
10882  ODRDiagError(FirstMethod->getLocation(),
10883  FirstMethod->getSourceRange(), MethodName)
10884  << FirstMethodType << FirstName;
10885  ODRDiagNote(SecondMethod->getLocation(),
10886  SecondMethod->getSourceRange(), MethodName)
10887  << SecondMethodType << SecondName;
10888 
10889  Diagnosed = true;
10890  break;
10891  }
10892 
10893  const bool FirstDeleted = FirstMethod->isDeletedAsWritten();
10894  const bool SecondDeleted = SecondMethod->isDeletedAsWritten();
10895  if (FirstDeleted != SecondDeleted) {
10896  ODRDiagError(FirstMethod->getLocation(),
10897  FirstMethod->getSourceRange(), MethodDeleted)
10898  << FirstMethodType << FirstName << FirstDeleted;
10899 
10900  ODRDiagNote(SecondMethod->getLocation(),
10901  SecondMethod->getSourceRange(), MethodDeleted)
10902  << SecondMethodType << SecondName << SecondDeleted;
10903  Diagnosed = true;
10904  break;
10905  }
10906 
10907  const bool FirstDefaulted = FirstMethod->isExplicitlyDefaulted();
10908  const bool SecondDefaulted = SecondMethod->isExplicitlyDefaulted();
10909  if (FirstDefaulted != SecondDefaulted) {
10910  ODRDiagError(FirstMethod->getLocation(),
10911  FirstMethod->getSourceRange(), MethodDefaulted)
10912  << FirstMethodType << FirstName << FirstDefaulted;
10913 
10914  ODRDiagNote(SecondMethod->getLocation(),
10915  SecondMethod->getSourceRange(), MethodDefaulted)
10916  << SecondMethodType << SecondName << SecondDefaulted;
10917  Diagnosed = true;
10918  break;
10919  }
10920 
10921  const bool FirstVirtual = FirstMethod->isVirtualAsWritten();
10922  const bool SecondVirtual = SecondMethod->isVirtualAsWritten();
10923  const bool FirstPure = FirstMethod->isPure();
10924  const bool SecondPure = SecondMethod->isPure();
10925  if ((FirstVirtual || SecondVirtual) &&
10926  (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) {
10927  ODRDiagError(FirstMethod->getLocation(),
10928  FirstMethod->getSourceRange(), MethodVirtual)
10929  << FirstMethodType << FirstName << FirstPure << FirstVirtual;
10930  ODRDiagNote(SecondMethod->getLocation(),
10931  SecondMethod->getSourceRange(), MethodVirtual)
10932  << SecondMethodType << SecondName << SecondPure << SecondVirtual;
10933  Diagnosed = true;
10934  break;
10935  }
10936 
10937  // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging,
10938  // FirstDecl is the canonical Decl of SecondDecl, so the storage
10939  // class needs to be checked instead.
10940  const auto FirstStorage = FirstMethod->getStorageClass();
10941  const auto SecondStorage = SecondMethod->getStorageClass();
10942  const bool FirstStatic = FirstStorage == SC_Static;
10943  const bool SecondStatic = SecondStorage == SC_Static;
10944  if (FirstStatic != SecondStatic) {
10945  ODRDiagError(FirstMethod->getLocation(),
10946  FirstMethod->getSourceRange(), MethodStatic)
10947  << FirstMethodType << FirstName << FirstStatic;
10948  ODRDiagNote(SecondMethod->getLocation(),
10949  SecondMethod->getSourceRange(), MethodStatic)
10950  << SecondMethodType << SecondName << SecondStatic;
10951  Diagnosed = true;
10952  break;
10953  }
10954 
10955  const bool FirstVolatile = FirstMethod->isVolatile();
10956  const bool SecondVolatile = SecondMethod->isVolatile();
10957  if (FirstVolatile != SecondVolatile) {
10958  ODRDiagError(FirstMethod->getLocation(),
10959  FirstMethod->getSourceRange(), MethodVolatile)
10960  << FirstMethodType << FirstName << FirstVolatile;
10961  ODRDiagNote(SecondMethod->getLocation(),
10962  SecondMethod->getSourceRange(), MethodVolatile)
10963  << SecondMethodType << SecondName << SecondVolatile;
10964  Diagnosed = true;
10965  break;
10966  }
10967 
10968  const bool FirstConst = FirstMethod->isConst();
10969  const bool SecondConst = SecondMethod->isConst();
10970  if (FirstConst != SecondConst) {
10971  ODRDiagError(FirstMethod->getLocation(),
10972  FirstMethod->getSourceRange(), MethodConst)
10973  << FirstMethodType << FirstName << FirstConst;
10974  ODRDiagNote(SecondMethod->getLocation(),
10975  SecondMethod->getSourceRange(), MethodConst)
10976  << SecondMethodType << SecondName << SecondConst;
10977  Diagnosed = true;
10978  break;
10979  }
10980 
10981  const bool FirstInline = FirstMethod->isInlineSpecified();
10982  const bool SecondInline = SecondMethod->isInlineSpecified();
10983  if (FirstInline != SecondInline) {
10984  ODRDiagError(FirstMethod->getLocation(),
10985  FirstMethod->getSourceRange(), MethodInline)
10986  << FirstMethodType << FirstName << FirstInline;
10987  ODRDiagNote(SecondMethod->getLocation(),
10988  SecondMethod->getSourceRange(), MethodInline)
10989  << SecondMethodType << SecondName << SecondInline;
10990  Diagnosed = true;
10991  break;
10992  }
10993 
10994  const unsigned FirstNumParameters = FirstMethod->param_size();
10995  const unsigned SecondNumParameters = SecondMethod->param_size();
10996  if (FirstNumParameters != SecondNumParameters) {
10997  ODRDiagError(FirstMethod->getLocation(),
10998  FirstMethod->getSourceRange(), MethodNumberParameters)
10999  << FirstMethodType << FirstName << FirstNumParameters;
11000  ODRDiagNote(SecondMethod->getLocation(),
11001  SecondMethod->getSourceRange(), MethodNumberParameters)
11002  << SecondMethodType << SecondName << SecondNumParameters;
11003  Diagnosed = true;
11004  break;
11005  }
11006 
11007  // Need this status boolean to know when break out of the switch.
11008  bool ParameterMismatch = false;
11009  for (unsigned I = 0; I < FirstNumParameters; ++I) {
11010  const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I);
11011  const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I);
11012 
11013  QualType FirstParamType = FirstParam->getType();
11014  QualType SecondParamType = SecondParam->getType();
11015  if (FirstParamType != SecondParamType &&
11016  ComputeQualTypeODRHash(FirstParamType) !=
11017  ComputeQualTypeODRHash(SecondParamType)) {
11018  if (const DecayedType *ParamDecayedType =
11019  FirstParamType->getAs<DecayedType>()) {
11020  ODRDiagError(FirstMethod->getLocation(),
11021  FirstMethod->getSourceRange(), MethodParameterType)
11022  << FirstMethodType << FirstName << (I + 1) << FirstParamType
11023  << true << ParamDecayedType->getOriginalType();
11024  } else {
11025  ODRDiagError(FirstMethod->getLocation(),
11026  FirstMethod->getSourceRange(), MethodParameterType)
11027  << FirstMethodType << FirstName << (I + 1) << FirstParamType
11028  << false;
11029  }
11030 
11031  if (const DecayedType *ParamDecayedType =
11032  SecondParamType->getAs<DecayedType>()) {
11033  ODRDiagNote(SecondMethod->getLocation(),
11034  SecondMethod->getSourceRange(), MethodParameterType)
11035  << SecondMethodType << SecondName << (I + 1)
11036  << SecondParamType << true
11037  << ParamDecayedType->getOriginalType();
11038  } else {
11039  ODRDiagNote(SecondMethod->getLocation(),
11040  SecondMethod->getSourceRange(), MethodParameterType)
11041  << SecondMethodType << SecondName << (I + 1)
11042  << SecondParamType << false;
11043  }
11044  ParameterMismatch = true;
11045  break;
11046  }
11047 
11048  DeclarationName FirstParamName = FirstParam->getDeclName();
11049  DeclarationName SecondParamName = SecondParam->getDeclName();
11050  if (FirstParamName != SecondParamName) {
11051  ODRDiagError(FirstMethod->getLocation(),
11052  FirstMethod->getSourceRange(), MethodParameterName)
11053  << FirstMethodType << FirstName << (I + 1) << FirstParamName;
11054  ODRDiagNote(SecondMethod->getLocation(),
11055  SecondMethod->getSourceRange(), MethodParameterName)
11056  << SecondMethodType << SecondName << (I + 1) << SecondParamName;
11057  ParameterMismatch = true;
11058  break;
11059  }
11060 
11061  const Expr *FirstInit = FirstParam->getInit();
11062  const Expr *SecondInit = SecondParam->getInit();
11063  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
11064  ODRDiagError(FirstMethod->getLocation(),
11065  FirstMethod->getSourceRange(),
11066  MethodParameterSingleDefaultArgument)
11067  << FirstMethodType << FirstName << (I + 1)
11068  << (FirstInit == nullptr)
11069  << (FirstInit ? FirstInit->getSourceRange() : SourceRange());
11070  ODRDiagNote(SecondMethod->getLocation(),
11071  SecondMethod->getSourceRange(),
11072  MethodParameterSingleDefaultArgument)
11073  << SecondMethodType << SecondName << (I + 1)
11074  << (SecondInit == nullptr)
11075  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
11076  ParameterMismatch = true;
11077  break;
11078  }
11079 
11080  if (FirstInit && SecondInit &&
11081  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
11082  ODRDiagError(FirstMethod->getLocation(),
11083  FirstMethod->getSourceRange(),
11084  MethodParameterDifferentDefaultArgument)
11085  << FirstMethodType << FirstName << (I + 1)
11086  << FirstInit->getSourceRange();
11087  ODRDiagNote(SecondMethod->getLocation(),
11088  SecondMethod->getSourceRange(),
11089  MethodParameterDifferentDefaultArgument)
11090  << SecondMethodType << SecondName << (I + 1)
11091  << SecondInit->getSourceRange();
11092  ParameterMismatch = true;
11093  break;
11094 
11095  }
11096  }
11097 
11098  if (ParameterMismatch) {
11099  Diagnosed = true;
11100  break;
11101  }
11102 
11103  const auto *FirstTemplateArgs =
11104  FirstMethod->getTemplateSpecializationArgs();
11105  const auto *SecondTemplateArgs =
11106  SecondMethod->getTemplateSpecializationArgs();
11107 
11108  if ((FirstTemplateArgs && !SecondTemplateArgs) ||
11109  (!FirstTemplateArgs && SecondTemplateArgs)) {
11110  ODRDiagError(FirstMethod->getLocation(),
11111  FirstMethod->getSourceRange(), MethodNoTemplateArguments)
11112  << FirstMethodType << FirstName << (FirstTemplateArgs != nullptr);
11113  ODRDiagNote(SecondMethod->getLocation(),
11114  SecondMethod->getSourceRange(), MethodNoTemplateArguments)
11115  << SecondMethodType << SecondName
11116  << (SecondTemplateArgs != nullptr);
11117 
11118  Diagnosed = true;
11119  break;
11120  }
11121 
11122  if (FirstTemplateArgs && SecondTemplateArgs) {
11123  // Remove pack expansions from argument list.
11124  auto ExpandTemplateArgumentList =
11125  [](const TemplateArgumentList *TAL) {
11127  for (const TemplateArgument &TA : TAL->asArray()) {
11128  if (TA.getKind() != TemplateArgument::Pack) {
11129  ExpandedList.push_back(&TA);
11130  continue;
11131  }
11132  for (const TemplateArgument &PackTA : TA.getPackAsArray()) {
11133  ExpandedList.push_back(&PackTA);
11134  }
11135  }
11136  return ExpandedList;
11137  };
11139  ExpandTemplateArgumentList(FirstTemplateArgs);
11141  ExpandTemplateArgumentList(SecondTemplateArgs);
11142 
11143  if (FirstExpandedList.size() != SecondExpandedList.size()) {
11144  ODRDiagError(FirstMethod->getLocation(),
11145  FirstMethod->getSourceRange(),
11146  MethodDifferentNumberTemplateArguments)
11147  << FirstMethodType << FirstName
11148  << (unsigned)FirstExpandedList.size();
11149  ODRDiagNote(SecondMethod->getLocation(),
11150  SecondMethod->getSourceRange(),
11151  MethodDifferentNumberTemplateArguments)
11152  << SecondMethodType << SecondName
11153  << (unsigned)SecondExpandedList.size();
11154 
11155  Diagnosed = true;
11156  break;
11157  }
11158 
11159  bool TemplateArgumentMismatch = false;
11160  for (unsigned i = 0, e = FirstExpandedList.size(); i != e; ++i) {
11161  const TemplateArgument &FirstTA = *FirstExpandedList[i],
11162  &SecondTA = *SecondExpandedList[i];
11163  if (ComputeTemplateArgumentODRHash(FirstTA) ==
11164  ComputeTemplateArgumentODRHash(SecondTA)) {
11165  continue;
11166  }
11167 
11168  ODRDiagError(FirstMethod->getLocation(),
11169  FirstMethod->getSourceRange(),
11170  MethodDifferentTemplateArgument)
11171  << FirstMethodType << FirstName << FirstTA << i + 1;
11172  ODRDiagNote(SecondMethod->getLocation(),
11173  SecondMethod->getSourceRange(),
11174  MethodDifferentTemplateArgument)
11175  << SecondMethodType << SecondName << SecondTA << i + 1;
11176 
11177  TemplateArgumentMismatch = true;
11178  break;
11179  }
11180 
11181  if (TemplateArgumentMismatch) {
11182  Diagnosed = true;
11183  break;
11184  }
11185  }
11186 
11187  // Compute the hash of the method as if it has no body.
11188  auto ComputeCXXMethodODRHash = [&Hash](const CXXMethodDecl *D) {
11189  Hash.clear();
11190  Hash.AddFunctionDecl(D, true /*SkipBody*/);
11191  return Hash.CalculateHash();
11192  };
11193 
11194  // Compare the hash generated to the hash stored. A difference means
11195  // that a body was present in the original source. Due to merging,
11196  // the stardard way of detecting a body will not work.
11197  const bool HasFirstBody =
11198  ComputeCXXMethodODRHash(FirstMethod) != FirstMethod->getODRHash();
11199  const bool HasSecondBody =
11200  ComputeCXXMethodODRHash(SecondMethod) != SecondMethod->getODRHash();
11201 
11202  if (HasFirstBody != HasSecondBody) {
11203  ODRDiagError(FirstMethod->getLocation(),
11204  FirstMethod->getSourceRange(), MethodSingleBody)
11205  << FirstMethodType << FirstName << HasFirstBody;
11206  ODRDiagNote(SecondMethod->getLocation(),
11207  SecondMethod->getSourceRange(), MethodSingleBody)
11208  << SecondMethodType << SecondName << HasSecondBody;
11209  Diagnosed = true;
11210  break;
11211  }
11212 
11213  if (HasFirstBody && HasSecondBody) {
11214  ODRDiagError(FirstMethod->getLocation(),
11215  FirstMethod->getSourceRange(), MethodDifferentBody)
11216  << FirstMethodType << FirstName;
11217  ODRDiagNote(SecondMethod->getLocation(),
11218  SecondMethod->getSourceRange(), MethodDifferentBody)
11219  << SecondMethodType << SecondName;
11220  Diagnosed = true;
11221  break;
11222  }
11223 
11224  break;
11225  }
11226  case TypeAlias:
11227  case TypeDef: {
11228  TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl);
11229  TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl);
11230  auto FirstName = FirstTD->getDeclName();
11231  auto SecondName = SecondTD->getDeclName();
11232  if (FirstName != SecondName) {
11233  ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(),
11234  TypedefName)
11235  << (FirstDiffType == TypeAlias) << FirstName;
11236  ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(),
11237  TypedefName)
11238  << (FirstDiffType == TypeAlias) << SecondName;
11239  Diagnosed = true;
11240  break;
11241  }
11242 
11243  QualType FirstType = FirstTD->getUnderlyingType();
11244  QualType SecondType = SecondTD->getUnderlyingType();
11245  if (ComputeQualTypeODRHash(FirstType) !=
11246  ComputeQualTypeODRHash(SecondType)) {
11247  ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(),
11248  TypedefType)
11249  << (FirstDiffType == TypeAlias) << FirstName << FirstType;
11250  ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(),
11251  TypedefType)
11252  << (FirstDiffType == TypeAlias) << SecondName << SecondType;
11253  Diagnosed = true;
11254  break;
11255  }
11256  break;
11257  }
11258  case Var: {
11259  VarDecl *FirstVD = cast<VarDecl>(FirstDecl);
11260  VarDecl *SecondVD = cast<VarDecl>(SecondDecl);
11261  auto FirstName = FirstVD->getDeclName();
11262  auto SecondName = SecondVD->getDeclName();
11263  if (FirstName != SecondName) {
11264  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
11265  VarName)
11266  << FirstName;
11267  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
11268  VarName)
11269  << SecondName;
11270  Diagnosed = true;
11271  break;
11272  }
11273 
11274  QualType FirstType = FirstVD->getType();
11275  QualType SecondType = SecondVD->getType();
11276  if (ComputeQualTypeODRHash(FirstType) !=
11277  ComputeQualTypeODRHash(SecondType)) {
11278  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
11279  VarType)
11280  << FirstName << FirstType;
11281  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
11282  VarType)
11283  << SecondName << SecondType;
11284  Diagnosed = true;
11285  break;
11286  }
11287 
11288  const Expr *FirstInit = FirstVD->getInit();
11289  const Expr *SecondInit = SecondVD->getInit();
11290  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
11291  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
11292  VarSingleInitializer)
11293  << FirstName << (FirstInit == nullptr)
11294  << (FirstInit ? FirstInit->getSourceRange(): SourceRange());
11295  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
11296  VarSingleInitializer)
11297  << SecondName << (SecondInit == nullptr)
11298  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
11299  Diagnosed = true;
11300  break;
11301  }
11302 
11303  if (FirstInit && SecondInit &&
11304  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
11305  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
11306  VarDifferentInitializer)
11307  << FirstName << FirstInit->getSourceRange();
11308  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
11309  VarDifferentInitializer)
11310  << SecondName << SecondInit->getSourceRange();
11311  Diagnosed = true;
11312  break;
11313  }
11314 
11315  const bool FirstIsConstexpr = FirstVD->isConstexpr();
11316  const bool SecondIsConstexpr = SecondVD->isConstexpr();
11317  if (FirstIsConstexpr != SecondIsConstexpr) {
11318  ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(),
11319  VarConstexpr)
11320  << FirstName << FirstIsConstexpr;
11321  ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(),
11322  VarConstexpr)
11323  << SecondName << SecondIsConstexpr;
11324  Diagnosed = true;
11325  break;
11326  }
11327  break;
11328  }
11329  case Friend: {
11330  FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl);
11331  FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl);
11332 
11333  NamedDecl *FirstND = FirstFriend->getFriendDecl();
11334  NamedDecl *SecondND = SecondFriend->getFriendDecl();
11335 
11336  TypeSourceInfo *FirstTSI = FirstFriend->getFriendType();
11337  TypeSourceInfo *SecondTSI = SecondFriend->getFriendType();
11338 
11339  if (FirstND && SecondND) {
11340  ODRDiagError(FirstFriend->getFriendLoc(),
11341  FirstFriend->getSourceRange(), FriendFunction)
11342  << FirstND;
11343  ODRDiagNote(SecondFriend->getFriendLoc(),
11344  SecondFriend->getSourceRange(), FriendFunction)
11345  << SecondND;
11346 
11347  Diagnosed = true;
11348  break;
11349  }
11350 
11351  if (FirstTSI && SecondTSI) {
11352  QualType FirstFriendType = FirstTSI->getType();
11353  QualType SecondFriendType = SecondTSI->getType();
11354  assert(ComputeQualTypeODRHash(FirstFriendType) !=
11355  ComputeQualTypeODRHash(SecondFriendType));
11356  ODRDiagError(FirstFriend->getFriendLoc(),
11357  FirstFriend->getSourceRange(), FriendType)
11358  << FirstFriendType;
11359  ODRDiagNote(SecondFriend->getFriendLoc(),
11360  SecondFriend->getSourceRange(), FriendType)
11361  << SecondFriendType;
11362  Diagnosed = true;
11363  break;
11364  }
11365 
11366  ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(),
11367  FriendTypeFunction)
11368  << (FirstTSI == nullptr);
11369  ODRDiagNote(SecondFriend->getFriendLoc(),
11370  SecondFriend->getSourceRange(), FriendTypeFunction)
11371  << (SecondTSI == nullptr);
11372 
11373  Diagnosed = true;
11374  break;
11375  }
11376  case FunctionTemplate: {
11377  FunctionTemplateDecl *FirstTemplate =
11378  cast<FunctionTemplateDecl>(FirstDecl);
11379  FunctionTemplateDecl *SecondTemplate =
11380  cast<FunctionTemplateDecl>(SecondDecl);
11381 
11382  TemplateParameterList *FirstTPL =
11383  FirstTemplate->getTemplateParameters();
11384  TemplateParameterList *SecondTPL =
11385  SecondTemplate->getTemplateParameters();
11386 
11387  if (FirstTPL->size() != SecondTPL->size()) {
11388  ODRDiagError(FirstTemplate->getLocation(),
11389  FirstTemplate->getSourceRange(),
11390  FunctionTemplateDifferentNumberParameters)
11391  << FirstTemplate << FirstTPL->size();
11392  ODRDiagNote(SecondTemplate->getLocation(),
11393  SecondTemplate->getSourceRange(),
11394  FunctionTemplateDifferentNumberParameters)
11395  << SecondTemplate << SecondTPL->size();
11396 
11397  Diagnosed = true;
11398  break;
11399  }
11400 
11401  bool ParameterMismatch = false;
11402  for (unsigned i = 0, e = FirstTPL->size(); i != e; ++i) {
11403  NamedDecl *FirstParam = FirstTPL->getParam(i);
11404  NamedDecl *SecondParam = SecondTPL->getParam(i);
11405 
11406  if (FirstParam->getKind() != SecondParam->getKind()) {
11407  enum {
11408  TemplateTypeParameter,
11409  NonTypeTemplateParameter,
11410  TemplateTemplateParameter,
11411  };
11412  auto GetParamType = [](NamedDecl *D) {
11413  switch (D->getKind()) {
11414  default:
11415  llvm_unreachable("Unexpected template parameter type");
11416  case Decl::TemplateTypeParm:
11417  return TemplateTypeParameter;
11418  case Decl::NonTypeTemplateParm:
11419  return NonTypeTemplateParameter;
11420  case Decl::TemplateTemplateParm:
11421  return TemplateTemplateParameter;
11422  }
11423  };
11424 
11425  ODRDiagError(FirstTemplate->getLocation(),
11426  FirstTemplate->getSourceRange(),
11427  FunctionTemplateParameterDifferentKind)
11428  << FirstTemplate << (i + 1) << GetParamType(FirstParam);
11429  ODRDiagNote(SecondTemplate->getLocation(),
11430  SecondTemplate->getSourceRange(),
11431  FunctionTemplateParameterDifferentKind)
11432  << SecondTemplate << (i + 1) << GetParamType(SecondParam);
11433 
11434  ParameterMismatch = true;
11435  break;
11436  }
11437 
11438  if (FirstParam->getName() != SecondParam->getName()) {
11439  ODRDiagError(FirstTemplate->getLocation(),
11440  FirstTemplate->getSourceRange(),
11441  FunctionTemplateParameterName)
11442  << FirstTemplate << (i + 1) << (bool)FirstParam->getIdentifier()
11443  << FirstParam;
11444  ODRDiagNote(SecondTemplate->getLocation(),
11445  SecondTemplate->getSourceRange(),
11446  FunctionTemplateParameterName)
11447  << SecondTemplate << (i + 1)
11448  << (bool)SecondParam->getIdentifier() << SecondParam;
11449  ParameterMismatch = true;
11450  break;
11451  }
11452 
11453  if (isa<TemplateTypeParmDecl>(FirstParam) &&
11454  isa<TemplateTypeParmDecl>(SecondParam)) {
11455  TemplateTypeParmDecl *FirstTTPD =
11456  cast<TemplateTypeParmDecl>(FirstParam);
11457  TemplateTypeParmDecl *SecondTTPD =
11458  cast<TemplateTypeParmDecl>(SecondParam);
11459  bool HasFirstDefaultArgument =
11460  FirstTTPD->hasDefaultArgument() &&
11461  !FirstTTPD->defaultArgumentWasInherited();
11462  bool HasSecondDefaultArgument =
11463  SecondTTPD->hasDefaultArgument() &&
11464  !SecondTTPD->defaultArgumentWasInherited();
11465  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
11466  ODRDiagError(FirstTemplate->getLocation(),
11467  FirstTemplate->getSourceRange(),
11468  FunctionTemplateParameterSingleDefaultArgument)
11469  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
11470  ODRDiagNote(SecondTemplate->getLocation(),
11471  SecondTemplate->getSourceRange(),
11472  FunctionTemplateParameterSingleDefaultArgument)
11473  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
11474  ParameterMismatch = true;
11475  break;
11476  }
11477 
11478  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
11479  QualType FirstType = FirstTTPD->getDefaultArgument();
11480  QualType SecondType = SecondTTPD->getDefaultArgument();
11481  if (ComputeQualTypeODRHash(FirstType) !=
11482  ComputeQualTypeODRHash(SecondType)) {
11483  ODRDiagError(FirstTemplate->getLocation(),
11484  FirstTemplate->getSourceRange(),
11485  FunctionTemplateParameterDifferentDefaultArgument)
11486  << FirstTemplate << (i + 1) << FirstType;
11487  ODRDiagNote(SecondTemplate->getLocation(),
11488  SecondTemplate->getSourceRange(),
11489  FunctionTemplateParameterDifferentDefaultArgument)
11490  << SecondTemplate << (i + 1) << SecondType;
11491  ParameterMismatch = true;
11492  break;
11493  }
11494  }
11495 
11496  if (FirstTTPD->isParameterPack() !=
11497  SecondTTPD->isParameterPack()) {
11498  ODRDiagError(FirstTemplate->getLocation(),
11499  FirstTemplate->getSourceRange(),
11500  FunctionTemplatePackParameter)
11501  << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack();
11502  ODRDiagNote(SecondTemplate->getLocation(),
11503  SecondTemplate->getSourceRange(),
11504  FunctionTemplatePackParameter)
11505  << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack();
11506  ParameterMismatch = true;
11507  break;
11508  }
11509  }
11510 
11511  if (isa<TemplateTemplateParmDecl>(FirstParam) &&
11512  isa<TemplateTemplateParmDecl>(SecondParam)) {
11513  TemplateTemplateParmDecl *FirstTTPD =
11514  cast<TemplateTemplateParmDecl>(FirstParam);
11515  TemplateTemplateParmDecl *SecondTTPD =
11516  cast<TemplateTemplateParmDecl>(SecondParam);
11517 
11518  TemplateParameterList *FirstTPL =
11519  FirstTTPD->getTemplateParameters();
11520  TemplateParameterList *SecondTPL =
11521  SecondTTPD->getTemplateParameters();
11522 
11523  if (ComputeTemplateParameterListODRHash(FirstTPL) !=
11524  ComputeTemplateParameterListODRHash(SecondTPL)) {
11525  ODRDiagError(FirstTemplate->getLocation(),
11526  FirstTemplate->getSourceRange(),
11527  FunctionTemplateParameterDifferentType)
11528  << FirstTemplate << (i + 1);
11529  ODRDiagNote(SecondTemplate->getLocation(),
11530  SecondTemplate->getSourceRange(),
11531  FunctionTemplateParameterDifferentType)
11532  << SecondTemplate << (i + 1);
11533  ParameterMismatch = true;
11534  break;
11535  }
11536 
11537  bool HasFirstDefaultArgument =
11538  FirstTTPD->hasDefaultArgument() &&
11539  !FirstTTPD->defaultArgumentWasInherited();
11540  bool HasSecondDefaultArgument =
11541  SecondTTPD->hasDefaultArgument() &&
11542  !SecondTTPD->defaultArgumentWasInherited();
11543  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
11544  ODRDiagError(FirstTemplate->getLocation(),
11545  FirstTemplate->getSourceRange(),
11546  FunctionTemplateParameterSingleDefaultArgument)
11547  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
11548  ODRDiagNote(SecondTemplate->getLocation(),
11549  SecondTemplate->getSourceRange(),
11550  FunctionTemplateParameterSingleDefaultArgument)
11551  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
11552  ParameterMismatch = true;
11553  break;
11554  }
11555 
11556  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
11557  TemplateArgument FirstTA =
11558  FirstTTPD->getDefaultArgument().getArgument();
11559  TemplateArgument SecondTA =
11560  SecondTTPD->getDefaultArgument().getArgument();
11561  if (ComputeTemplateArgumentODRHash(FirstTA) !=
11562  ComputeTemplateArgumentODRHash(SecondTA)) {
11563  ODRDiagError(FirstTemplate->getLocation(),
11564  FirstTemplate->getSourceRange(),
11565  FunctionTemplateParameterDifferentDefaultArgument)
11566  << FirstTemplate << (i + 1) << FirstTA;
11567  ODRDiagNote(SecondTemplate->getLocation(),
11568  SecondTemplate->getSourceRange(),
11569  FunctionTemplateParameterDifferentDefaultArgument)
11570  << SecondTemplate << (i + 1) << SecondTA;
11571  ParameterMismatch = true;
11572  break;
11573  }
11574  }
11575 
11576  if (FirstTTPD->isParameterPack() !=
11577  SecondTTPD->isParameterPack()) {
11578  ODRDiagError(FirstTemplate->getLocation(),
11579  FirstTemplate->getSourceRange(),
11580  FunctionTemplatePackParameter)
11581  << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack();
11582  ODRDiagNote(SecondTemplate->getLocation(),
11583  SecondTemplate->getSourceRange(),
11584  FunctionTemplatePackParameter)
11585  << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack();
11586  ParameterMismatch = true;
11587  break;
11588  }
11589  }
11590 
11591  if (isa<NonTypeTemplateParmDecl>(FirstParam) &&
11592  isa<NonTypeTemplateParmDecl>(SecondParam)) {
11593  NonTypeTemplateParmDecl *FirstNTTPD =
11594  cast<NonTypeTemplateParmDecl>(FirstParam);
11595  NonTypeTemplateParmDecl *SecondNTTPD =
11596  cast<NonTypeTemplateParmDecl>(SecondParam);
11597 
11598  QualType FirstType = FirstNTTPD->getType();
11599  QualType SecondType = SecondNTTPD->getType();
11600  if (ComputeQualTypeODRHash(FirstType) !=
11601  ComputeQualTypeODRHash(SecondType)) {
11602  ODRDiagError(FirstTemplate->getLocation(),
11603  FirstTemplate->getSourceRange(),
11604  FunctionTemplateParameterDifferentType)
11605  << FirstTemplate << (i + 1);
11606  ODRDiagNote(SecondTemplate->getLocation(),
11607  SecondTemplate->getSourceRange(),
11608  FunctionTemplateParameterDifferentType)
11609  << SecondTemplate << (i + 1);
11610  ParameterMismatch = true;
11611  break;
11612  }
11613 
11614  bool HasFirstDefaultArgument =
11615  FirstNTTPD->hasDefaultArgument() &&
11616  !FirstNTTPD->defaultArgumentWasInherited();
11617  bool HasSecondDefaultArgument =
11618  SecondNTTPD->hasDefaultArgument() &&
11619  !SecondNTTPD->defaultArgumentWasInherited();
11620  if (HasFirstDefaultArgument != HasSecondDefaultArgument) {
11621  ODRDiagError(FirstTemplate->getLocation(),
11622  FirstTemplate->getSourceRange(),
11623  FunctionTemplateParameterSingleDefaultArgument)
11624  << FirstTemplate << (i + 1) << HasFirstDefaultArgument;
11625  ODRDiagNote(SecondTemplate->getLocation(),
11626  SecondTemplate->getSourceRange(),
11627  FunctionTemplateParameterSingleDefaultArgument)
11628  << SecondTemplate << (i + 1) << HasSecondDefaultArgument;
11629  ParameterMismatch = true;
11630  break;
11631  }
11632 
11633  if (HasFirstDefaultArgument && HasSecondDefaultArgument) {
11634  Expr *FirstDefaultArgument = FirstNTTPD->getDefaultArgument();
11635  Expr *SecondDefaultArgument = SecondNTTPD->getDefaultArgument();
11636  if (ComputeODRHash(FirstDefaultArgument) !=
11637  ComputeODRHash(SecondDefaultArgument)) {
11638  ODRDiagError(FirstTemplate->getLocation(),
11639  FirstTemplate->getSourceRange(),
11640  FunctionTemplateParameterDifferentDefaultArgument)
11641  << FirstTemplate << (i + 1) << FirstDefaultArgument;
11642  ODRDiagNote(SecondTemplate->getLocation(),
11643  SecondTemplate->getSourceRange(),
11644  FunctionTemplateParameterDifferentDefaultArgument)
11645  << SecondTemplate << (i + 1) << SecondDefaultArgument;
11646  ParameterMismatch = true;
11647  break;
11648  }
11649  }
11650 
11651  if (FirstNTTPD->isParameterPack() !=
11652  SecondNTTPD->isParameterPack()) {
11653  ODRDiagError(FirstTemplate->getLocation(),
11654  FirstTemplate->getSourceRange(),
11655  FunctionTemplatePackParameter)
11656  << FirstTemplate << (i + 1) << FirstNTTPD->isParameterPack();
11657  ODRDiagNote(SecondTemplate->getLocation(),
11658  SecondTemplate->getSourceRange(),
11659  FunctionTemplatePackParameter)
11660  << SecondTemplate << (i + 1)
11661  << SecondNTTPD->isParameterPack();
11662  ParameterMismatch = true;
11663  break;
11664  }
11665  }
11666  }
11667 
11668  if (ParameterMismatch) {
11669  Diagnosed = true;
11670  break;
11671  }
11672 
11673  break;
11674  }
11675  }
11676 
11677  if (Diagnosed)
11678  continue;
11679 
11680  Diag(FirstDecl->getLocation(),
11681  diag::err_module_odr_violation_mismatch_decl_unknown)
11682  << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType
11683  << FirstDecl->getSourceRange();
11684  Diag(SecondDecl->getLocation(),
11685  diag::note_module_odr_violation_mismatch_decl_unknown)
11686  << SecondModule << FirstDiffType << SecondDecl->getSourceRange();
11687  Diagnosed = true;
11688  }
11689 
11690  if (!Diagnosed) {
11691  // All definitions are updates to the same declaration. This happens if a
11692  // module instantiates the declaration of a class template specialization
11693  // and two or more other modules instantiate its definition.
11694  //
11695  // FIXME: Indicate which modules had instantiations of this definition.
11696  // FIXME: How can this even happen?
11697  Diag(Merge.first->getLocation(),
11698  diag::err_module_odr_violation_different_instantiations)
11699  << Merge.first;
11700  }
11701  }
11702 
11703  // Issue ODR failures diagnostics for functions.
11704  for (auto &Merge : FunctionOdrMergeFailures) {
11705  enum ODRFunctionDifference {
11706  ReturnType,
11707  ParameterName,
11708  ParameterType,
11709  ParameterSingleDefaultArgument,
11710  ParameterDifferentDefaultArgument,
11711  FunctionBody,
11712  };
11713 
11714  FunctionDecl *FirstFunction = Merge.first;
11715  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstFunction);
11716 
11717  bool Diagnosed = false;
11718  for (auto &SecondFunction : Merge.second) {
11719 
11720  if (FirstFunction == SecondFunction)
11721  continue;
11722 
11723  std::string SecondModule =
11724  getOwningModuleNameForDiagnostic(SecondFunction);
11725 
11726  auto ODRDiagError = [FirstFunction, &FirstModule,
11727  this](SourceLocation Loc, SourceRange Range,
11728  ODRFunctionDifference DiffType) {
11729  return Diag(Loc, diag::err_module_odr_violation_function)
11730  << FirstFunction << FirstModule.empty() << FirstModule << Range
11731  << DiffType;
11732  };
11733  auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc,
11734  SourceRange Range,
11735  ODRFunctionDifference DiffType) {
11736  return Diag(Loc, diag::note_module_odr_violation_function)
11737  << SecondModule << Range << DiffType;
11738  };
11739 
11740  if (ComputeQualTypeODRHash(FirstFunction->getReturnType()) !=
11741  ComputeQualTypeODRHash(SecondFunction->getReturnType())) {
11742  ODRDiagError(FirstFunction->getReturnTypeSourceRange().getBegin(),
11743  FirstFunction->getReturnTypeSourceRange(), ReturnType)
11744  << FirstFunction->getReturnType();
11745  ODRDiagNote(SecondFunction->getReturnTypeSourceRange().getBegin(),
11746  SecondFunction->getReturnTypeSourceRange(), ReturnType)
11747  << SecondFunction->getReturnType();
11748  Diagnosed = true;
11749  break;
11750  }
11751 
11752  assert(FirstFunction->param_size() == SecondFunction->param_size() &&
11753  "Merged functions with different number of parameters");
11754 
11755  auto ParamSize = FirstFunction->param_size();
11756  bool ParameterMismatch = false;
11757  for (unsigned I = 0; I < ParamSize; ++I) {
11758  auto *FirstParam = FirstFunction->getParamDecl(I);
11759  auto *SecondParam = SecondFunction->getParamDecl(I);
11760 
11761  assert(getContext().hasSameType(FirstParam->getType(),
11762  SecondParam->getType()) &&
11763  "Merged function has different parameter types.");
11764 
11765  if (FirstParam->getDeclName() != SecondParam->getDeclName()) {
11766  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11767  ParameterName)
11768  << I + 1 << FirstParam->getDeclName();
11769  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11770  ParameterName)
11771  << I + 1 << SecondParam->getDeclName();
11772  ParameterMismatch = true;
11773  break;
11774  };
11775 
11776  QualType FirstParamType = FirstParam->getType();
11777  QualType SecondParamType = SecondParam->getType();
11778  if (FirstParamType != SecondParamType &&
11779  ComputeQualTypeODRHash(FirstParamType) !=
11780  ComputeQualTypeODRHash(SecondParamType)) {
11781  if (const DecayedType *ParamDecayedType =
11782  FirstParamType->getAs<DecayedType>()) {
11783  ODRDiagError(FirstParam->getLocation(),
11784  FirstParam->getSourceRange(), ParameterType)
11785  << (I + 1) << FirstParamType << true
11786  << ParamDecayedType->getOriginalType();
11787  } else {
11788  ODRDiagError(FirstParam->getLocation(),
11789  FirstParam->getSourceRange(), ParameterType)
11790  << (I + 1) << FirstParamType << false;
11791  }
11792 
11793  if (const DecayedType *ParamDecayedType =
11794  SecondParamType->getAs<DecayedType>()) {
11795  ODRDiagNote(SecondParam->getLocation(),
11796  SecondParam->getSourceRange(), ParameterType)
11797  << (I + 1) << SecondParamType << true
11798  << ParamDecayedType->getOriginalType();
11799  } else {
11800  ODRDiagNote(SecondParam->getLocation(),
11801  SecondParam->getSourceRange(), ParameterType)
11802  << (I + 1) << SecondParamType << false;
11803  }
11804  ParameterMismatch = true;
11805  break;
11806  }
11807 
11808  const Expr *FirstInit = FirstParam->getInit();
11809  const Expr *SecondInit = SecondParam->getInit();
11810  if ((FirstInit == nullptr) != (SecondInit == nullptr)) {
11811  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11812  ParameterSingleDefaultArgument)
11813  << (I + 1) << (FirstInit == nullptr)
11814  << (FirstInit ? FirstInit->getSourceRange() : SourceRange());
11815  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11816  ParameterSingleDefaultArgument)
11817  << (I + 1) << (SecondInit == nullptr)
11818  << (SecondInit ? SecondInit->getSourceRange() : SourceRange());
11819  ParameterMismatch = true;
11820  break;
11821  }
11822 
11823  if (FirstInit && SecondInit &&
11824  ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
11825  ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(),
11826  ParameterDifferentDefaultArgument)
11827  << (I + 1) << FirstInit->getSourceRange();
11828  ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(),
11829  ParameterDifferentDefaultArgument)
11830  << (I + 1) << SecondInit->getSourceRange();
11831  ParameterMismatch = true;
11832  break;
11833  }
11834 
11835  assert(ComputeSubDeclODRHash(FirstParam) ==
11836  ComputeSubDeclODRHash(SecondParam) &&
11837  "Undiagnosed parameter difference.");
11838  }
11839 
11840  if (ParameterMismatch) {
11841  Diagnosed = true;
11842  break;
11843  }
11844 
11845  // If no error has been generated before now, assume the problem is in
11846  // the body and generate a message.
11847  ODRDiagError(FirstFunction->getLocation(),
11848  FirstFunction->getSourceRange(), FunctionBody);
11849  ODRDiagNote(SecondFunction->getLocation(),
11850  SecondFunction->getSourceRange(), FunctionBody);
11851  Diagnosed = true;
11852  break;
11853  }
11854  (void)Diagnosed;
11855  assert(Diagnosed && "Unable to emit ODR diagnostic.");
11856  }
11857 
11858  // Issue ODR failures diagnostics for enums.
11859  for (auto &Merge : EnumOdrMergeFailures) {
11860  enum ODREnumDifference {
11861  SingleScopedEnum,
11862  EnumTagKeywordMismatch,
11863  SingleSpecifiedType,
11864  DifferentSpecifiedTypes,
11865  DifferentNumberEnumConstants,
11866  EnumConstantName,
11867  EnumConstantSingleInitilizer,
11868  EnumConstantDifferentInitilizer,
11869  };
11870 
11871  // If we've already pointed out a specific problem with this enum, don't
11872  // bother issuing a general "something's different" diagnostic.
11873  if (!DiagnosedOdrMergeFailures.insert(Merge.first).second)
11874  continue;
11875 
11876  EnumDecl *FirstEnum = Merge.first;
11877  std::string FirstModule = getOwningModuleNameForDiagnostic(FirstEnum);
11878 
11879  using DeclHashes =
11881  auto PopulateHashes = [&ComputeSubDeclODRHash, FirstEnum](
11882  DeclHashes &Hashes, EnumDecl *Enum) {
11883  for (auto *D : Enum->decls()) {
11884  // Due to decl merging, the first EnumDecl is the parent of
11885  // Decls in both records.
11886  if (!ODRHash::isWhitelistedDecl(D, FirstEnum))
11887  continue;
11888  assert(isa<EnumConstantDecl>(D) && "Unexpected Decl kind");
11889  Hashes.emplace_back(cast<EnumConstantDecl>(D),
11890  ComputeSubDeclODRHash(D));
11891  }
11892  };
11893  DeclHashes FirstHashes;
11894  PopulateHashes(FirstHashes, FirstEnum);
11895  bool Diagnosed = false;
11896  for (auto &SecondEnum : Merge.second) {
11897 
11898  if (FirstEnum == SecondEnum)
11899  continue;
11900 
11901  std::string SecondModule =
11902  getOwningModuleNameForDiagnostic(SecondEnum);
11903 
11904  auto ODRDiagError = [FirstEnum, &FirstModule,
11905  this](SourceLocation Loc, SourceRange Range,
11906  ODREnumDifference DiffType) {
11907  return Diag(Loc, diag::err_module_odr_violation_enum)
11908  << FirstEnum << FirstModule.empty() << FirstModule << Range
11909  << DiffType;
11910  };
11911  auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc,
11912  SourceRange Range,
11913  ODREnumDifference DiffType) {
11914  return Diag(Loc, diag::note_module_odr_violation_enum)
11915  << SecondModule << Range << DiffType;
11916  };
11917 
11918  if (FirstEnum->isScoped() != SecondEnum->isScoped()) {
11919  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11920  SingleScopedEnum)
11921  << FirstEnum->isScoped();
11922  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11923  SingleScopedEnum)
11924  << SecondEnum->isScoped();
11925  Diagnosed = true;
11926  continue;
11927  }
11928 
11929  if (FirstEnum->isScoped() && SecondEnum->isScoped()) {
11930  if (FirstEnum->isScopedUsingClassTag() !=
11931  SecondEnum->isScopedUsingClassTag()) {
11932  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11933  EnumTagKeywordMismatch)
11934  << FirstEnum->isScopedUsingClassTag();
11935  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11936  EnumTagKeywordMismatch)
11937  << SecondEnum->isScopedUsingClassTag();
11938  Diagnosed = true;
11939  continue;
11940  }
11941  }
11942 
11943  QualType FirstUnderlyingType =
11944  FirstEnum->getIntegerTypeSourceInfo()
11945  ? FirstEnum->getIntegerTypeSourceInfo()->getType()
11946  : QualType();
11947  QualType SecondUnderlyingType =
11948  SecondEnum->getIntegerTypeSourceInfo()
11949  ? SecondEnum->getIntegerTypeSourceInfo()->getType()
11950  : QualType();
11951  if (FirstUnderlyingType.isNull() != SecondUnderlyingType.isNull()) {
11952  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11953  SingleSpecifiedType)
11954  << !FirstUnderlyingType.isNull();
11955  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11956  SingleSpecifiedType)
11957  << !SecondUnderlyingType.isNull();
11958  Diagnosed = true;
11959  continue;
11960  }
11961 
11962  if (!FirstUnderlyingType.isNull() && !SecondUnderlyingType.isNull()) {
11963  if (ComputeQualTypeODRHash(FirstUnderlyingType) !=
11964  ComputeQualTypeODRHash(SecondUnderlyingType)) {
11965  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11966  DifferentSpecifiedTypes)
11967  << FirstUnderlyingType;
11968  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11969  DifferentSpecifiedTypes)
11970  << SecondUnderlyingType;
11971  Diagnosed = true;
11972  continue;
11973  }
11974  }
11975 
11976  DeclHashes SecondHashes;
11977  PopulateHashes(SecondHashes, SecondEnum);
11978 
11979  if (FirstHashes.size() != SecondHashes.size()) {
11980  ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(),
11981  DifferentNumberEnumConstants)
11982  << (int)FirstHashes.size();
11983  ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(),
11984  DifferentNumberEnumConstants)
11985  << (int)SecondHashes.size();
11986  Diagnosed = true;
11987  continue;
11988  }
11989 
11990  for (unsigned I = 0; I < FirstHashes.size(); ++I) {
11991  if (FirstHashes[I].second == SecondHashes[I].second)
11992  continue;
11993  const EnumConstantDecl *FirstEnumConstant = FirstHashes[I].first;
11994  const EnumConstantDecl *SecondEnumConstant = SecondHashes[I].first;
11995 
11996  if (FirstEnumConstant->getDeclName() !=
11997  SecondEnumConstant->getDeclName()) {
11998 
11999  ODRDiagError(FirstEnumConstant->getLocation(),
12000  FirstEnumConstant->getSourceRange(), EnumConstantName)
12001  << I + 1 << FirstEnumConstant;
12002  ODRDiagNote(SecondEnumConstant->getLocation(),
12003  SecondEnumConstant->getSourceRange(), EnumConstantName)
12004  << I + 1 << SecondEnumConstant;
12005  Diagnosed = true;
12006  break;
12007  }
12008 
12009  const Expr *FirstInit = FirstEnumConstant->getInitExpr();
12010  const Expr *SecondInit = SecondEnumConstant->getInitExpr();
12011  if (!FirstInit && !SecondInit)
12012  continue;
12013 
12014  if (!FirstInit || !SecondInit) {
12015  ODRDiagError(FirstEnumConstant->getLocation(),
12016  FirstEnumConstant->getSourceRange(),
12017  EnumConstantSingleInitilizer)
12018  << I + 1 << FirstEnumConstant << (FirstInit != nullptr);
12019  ODRDiagNote(SecondEnumConstant->getLocation(),
12020  SecondEnumConstant->getSourceRange(),
12021  EnumConstantSingleInitilizer)
12022  << I + 1 << SecondEnumConstant << (SecondInit != nullptr);
12023  Diagnosed = true;
12024  break;
12025  }
12026 
12027  if (ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
12028  ODRDiagError(FirstEnumConstant->getLocation(),
12029  FirstEnumConstant->getSourceRange(),
12030  EnumConstantDifferentInitilizer)
12031  << I + 1 << FirstEnumConstant;
12032  ODRDiagNote(SecondEnumConstant->getLocation(),
12033  SecondEnumConstant->getSourceRange(),
12034  EnumConstantDifferentInitilizer)
12035  << I + 1 << SecondEnumConstant;
12036  Diagnosed = true;
12037  break;
12038  }
12039  }
12040  }
12041 
12042  (void)Diagnosed;
12043  assert(Diagnosed && "Unable to emit ODR diagnostic.");
12044  }
12045 }
12046 
12048  if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get())
12049  ReadTimer->startTimer();
12050 }
12051 
12053  assert(NumCurrentElementsDeserializing &&
12054  "FinishedDeserializing not paired with StartedDeserializing");
12055  if (NumCurrentElementsDeserializing == 1) {
12056  // We decrease NumCurrentElementsDeserializing only after pending actions
12057  // are finished, to avoid recursively re-calling finishPendingActions().
12058  finishPendingActions();
12059  }
12060  --NumCurrentElementsDeserializing;
12061 
12062  if (NumCurrentElementsDeserializing == 0) {
12063  // Propagate exception specification and deduced type updates along
12064  // redeclaration chains.
12065  //
12066  // We do this now rather than in finishPendingActions because we want to
12067  // be able to walk the complete redeclaration chains of the updated decls.
12068  while (!PendingExceptionSpecUpdates.empty() ||
12069  !PendingDeducedTypeUpdates.empty()) {
12070  auto ESUpdates = std::move(PendingExceptionSpecUpdates);
12071  PendingExceptionSpecUpdates.clear();
12072  for (auto Update : ESUpdates) {
12073  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
12074  auto *FPT = Update.second->getType()->castAs<FunctionProtoType>();
12075  auto ESI = FPT->getExtProtoInfo().ExceptionSpec;
12076  if (auto *Listener = getContext().getASTMutationListener())
12077  Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second));
12078  for (auto *Redecl : Update.second->redecls())
12079  getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
12080  }
12081 
12082  auto DTUpdates = std::move(PendingDeducedTypeUpdates);
12083  PendingDeducedTypeUpdates.clear();
12084  for (auto Update : DTUpdates) {
12085  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
12086  // FIXME: If the return type is already deduced, check that it matches.
12087  getContext().adjustDeducedFunctionResultType(Update.first,
12088  Update.second);
12089  }
12090  }
12091 
12092  if (ReadTimer)
12093  ReadTimer->stopTimer();
12094 
12095  diagnoseOdrViolations();
12096 
12097  // We are not in recursive loading, so it's safe to pass the "interesting"
12098  // decls to the consumer.
12099  if (Consumer)
12100  PassInterestingDeclsToConsumer();
12101  }
12102 }
12103 
12104 void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) {
12105  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
12106  // Remove any fake results before adding any real ones.
12107  auto It = PendingFakeLookupResults.find(II);
12108  if (It != PendingFakeLookupResults.end()) {
12109  for (auto *ND : It->second)
12110  SemaObj->IdResolver.RemoveDecl(ND);
12111  // FIXME: this works around module+PCH performance issue.
12112  // Rather than erase the result from the map, which is O(n), just clear
12113  // the vector of NamedDecls.
12114  It->second.clear();
12115  }
12116  }
12117 
12118  if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) {
12119  SemaObj->TUScope->AddDecl(D);
12120  } else if (SemaObj->TUScope) {
12121  // Adding the decl to IdResolver may have failed because it was already in
12122  // (even though it was not added in scope). If it is already in, make sure
12123  // it gets in the scope as well.
12124  if (std::find(SemaObj->IdResolver.begin(Name),
12125  SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end())
12126  SemaObj->TUScope->AddDecl(D);
12127  }
12128 }
12129 
12131  ASTContext *Context,
12132  const PCHContainerReader &PCHContainerRdr,
12133  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
12134  StringRef isysroot, bool DisableValidation,
12135  bool AllowASTWithCompilerErrors,
12136  bool AllowConfigurationMismatch, bool ValidateSystemInputs,
12137  bool UseGlobalIndex,
12138  std::unique_ptr<llvm::Timer> ReadTimer)
12139  : Listener(DisableValidation
12141  : cast<ASTReaderListener>(new PCHValidator(PP, *this))),
12142  SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
12143  PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP),
12144  ContextObj(Context), ModuleMgr(PP.getFileManager(), ModuleCache,
12145  PCHContainerRdr, PP.getHeaderSearchInfo()),
12146  DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot),
12147  DisableValidation(DisableValidation),
12148  AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
12149  AllowConfigurationMismatch(AllowConfigurationMismatch),
12150  ValidateSystemInputs(ValidateSystemInputs),
12151  UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) {
12152  SourceMgr.setExternalSLocEntrySource(this);
12153 
12154  for (const auto &Ext : Extensions) {
12155  auto BlockName = Ext->getExtensionMetadata().BlockName;
12156  auto Known = ModuleFileExtensions.find(BlockName);
12157  if (Known != ModuleFileExtensions.end()) {
12158  Diags.Report(diag::warn_duplicate_module_file_extension)
12159  << BlockName;
12160  continue;
12161  }
12162 
12163  ModuleFileExtensions.insert({BlockName, Ext});
12164  }
12165 }
12166 
12168  if (OwnsDeserializationListener)
12169  delete DeserializationListener;
12170 }
12171 
12173  return SemaObj ? SemaObj->IdResolver : DummyIdResolver;
12174 }
12175 
12177  unsigned AbbrevID) {
12178  Idx = 0;
12179  Record.clear();
12180  return Cursor.readRecord(AbbrevID, Record);
12181 }
12182 //===----------------------------------------------------------------------===//
12183 //// OMPClauseReader implementation
12184 ////===----------------------------------------------------------------------===//
12185 
12187  OMPClause *C;
12188  switch (Record.readInt()) {
12189  case OMPC_if:
12190  C = new (Context) OMPIfClause();
12191  break;
12192  case OMPC_final:
12193  C = new (Context) OMPFinalClause();
12194  break;
12195  case OMPC_num_threads:
12196  C = new (Context) OMPNumThreadsClause();
12197  break;
12198  case OMPC_safelen:
12199  C = new (Context) OMPSafelenClause();
12200  break;
12201  case OMPC_simdlen:
12202  C = new (Context) OMPSimdlenClause();
12203  break;
12204  case OMPC_allocator:
12205  C = new (Context) OMPAllocatorClause();
12206  break;
12207  case OMPC_collapse:
12208  C = new (Context) OMPCollapseClause();
12209  break;
12210  case OMPC_default:
12211  C = new (Context) OMPDefaultClause();
12212  break;
12213  case OMPC_proc_bind:
12214  C = new (Context) OMPProcBindClause();
12215  break;
12216  case OMPC_schedule:
12217  C = new (Context) OMPScheduleClause();
12218  break;
12219  case OMPC_ordered:
12220  C = OMPOrderedClause::CreateEmpty(Context, Record.readInt());
12221  break;
12222  case OMPC_nowait:
12223  C = new (Context) OMPNowaitClause();
12224  break;
12225  case OMPC_untied:
12226  C = new (Context) OMPUntiedClause();
12227  break;
12228  case OMPC_mergeable:
12229  C = new (Context) OMPMergeableClause();
12230  break;
12231  case OMPC_read:
12232  C = new (Context) OMPReadClause();
12233  break;
12234  case OMPC_write:
12235  C = new (Context) OMPWriteClause();
12236  break;
12237  case OMPC_update:
12238  C = new (Context) OMPUpdateClause();
12239  break;
12240  case OMPC_capture:
12241  C = new (Context) OMPCaptureClause();
12242  break;
12243  case OMPC_seq_cst:
12244  C = new (Context) OMPSeqCstClause();
12245  break;
12246  case OMPC_threads:
12247  C = new (Context) OMPThreadsClause();
12248  break;
12249  case OMPC_simd:
12250  C = new (Context) OMPSIMDClause();
12251  break;
12252  case OMPC_nogroup:
12253  C = new (Context) OMPNogroupClause();
12254  break;
12255  case OMPC_unified_address:
12256  C = new (Context) OMPUnifiedAddressClause();
12257  break;
12258  case OMPC_unified_shared_memory:
12259  C = new (Context) OMPUnifiedSharedMemoryClause();
12260  break;
12261  case OMPC_reverse_offload:
12262  C = new (Context) OMPReverseOffloadClause();
12263  break;
12264  case OMPC_dynamic_allocators:
12265  C = new (Context) OMPDynamicAllocatorsClause();
12266  break;
12267  case OMPC_atomic_default_mem_order:
12268  C = new (Context) OMPAtomicDefaultMemOrderClause();
12269  break;
12270  case OMPC_private:
12271  C = OMPPrivateClause::CreateEmpty(Context, Record.readInt());
12272  break;
12273  case OMPC_firstprivate:
12274  C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt());
12275  break;
12276  case OMPC_lastprivate:
12277  C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt());
12278  break;
12279  case OMPC_shared:
12280  C = OMPSharedClause::CreateEmpty(Context, Record.readInt());
12281  break;
12282  case OMPC_reduction:
12283  C = OMPReductionClause::CreateEmpty(Context, Record.readInt());
12284  break;
12285  case OMPC_task_reduction:
12286  C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt());
12287  break;
12288  case OMPC_in_reduction:
12289  C = OMPInReductionClause::CreateEmpty(Context, Record.readInt());
12290  break;
12291  case OMPC_linear:
12292  C = OMPLinearClause::CreateEmpty(Context, Record.readInt());
12293  break;
12294  case OMPC_aligned:
12295  C = OMPAlignedClause::CreateEmpty(Context, Record.readInt());
12296  break;
12297  case OMPC_copyin:
12298  C = OMPCopyinClause::CreateEmpty(Context, Record.readInt());
12299  break;
12300  case OMPC_copyprivate:
12301  C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt());
12302  break;
12303  case OMPC_flush:
12304  C = OMPFlushClause::CreateEmpty(Context, Record.readInt());
12305  break;
12306  case OMPC_depend: {
12307  unsigned NumVars = Record.readInt();
12308  unsigned NumLoops = Record.readInt();
12309  C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops);
12310  break;
12311  }
12312  case OMPC_device:
12313  C = new (Context) OMPDeviceClause();
12314  break;
12315  case OMPC_map: {
12317  Sizes.NumVars = Record.readInt();
12318  Sizes.NumUniqueDeclarations = Record.readInt();
12319  Sizes.NumComponentLists = Record.readInt();
12320  Sizes.NumComponents = Record.readInt();
12321  C = OMPMapClause::CreateEmpty(Context, Sizes);
12322  break;
12323  }
12324  case OMPC_num_teams:
12325  C = new (Context) OMPNumTeamsClause();
12326  break;
12327  case OMPC_thread_limit:
12328  C = new (Context) OMPThreadLimitClause();
12329  break;
12330  case OMPC_priority:
12331  C = new (Context) OMPPriorityClause();
12332  break;
12333  case OMPC_grainsize:
12334  C = new (Context) OMPGrainsizeClause();
12335  break;
12336  case OMPC_num_tasks:
12337  C = new (Context) OMPNumTasksClause();
12338  break;
12339  case OMPC_hint:
12340  C = new (Context) OMPHintClause();
12341  break;
12342  case OMPC_dist_schedule:
12343  C = new (Context) OMPDistScheduleClause();
12344  break;
12345  case OMPC_defaultmap:
12346  C = new (Context) OMPDefaultmapClause();
12347  break;
12348  case OMPC_to: {
12350  Sizes.NumVars = Record.readInt();
12351  Sizes.NumUniqueDeclarations = Record.readInt();
12352  Sizes.NumComponentLists = Record.readInt();
12353  Sizes.NumComponents = Record.readInt();
12354  C = OMPToClause::CreateEmpty(Context, Sizes);
12355  break;
12356  }
12357  case OMPC_from: {
12359  Sizes.NumVars = Record.readInt();
12360  Sizes.NumUniqueDeclarations = Record.readInt();
12361  Sizes.NumComponentLists = Record.readInt();
12362  Sizes.NumComponents = Record.readInt();
12363  C = OMPFromClause::CreateEmpty(Context, Sizes);
12364  break;
12365  }
12366  case OMPC_use_device_ptr: {
12368  Sizes.NumVars = Record.readInt();
12369  Sizes.NumUniqueDeclarations = Record.readInt();
12370  Sizes.NumComponentLists = Record.readInt();
12371  Sizes.NumComponents = Record.readInt();
12372  C = OMPUseDevicePtrClause::CreateEmpty(Context, Sizes);
12373  break;
12374  }
12375  case OMPC_is_device_ptr: {
12377  Sizes.NumVars = Record.readInt();
12378  Sizes.NumUniqueDeclarations = Record.readInt();
12379  Sizes.NumComponentLists = Record.readInt();
12380  Sizes.NumComponents = Record.readInt();
12381  C = OMPIsDevicePtrClause::CreateEmpty(Context, Sizes);
12382  break;
12383  }
12384  case OMPC_allocate:
12385  C = OMPAllocateClause::CreateEmpty(Context, Record.readInt());
12386  break;
12387  }
12388  Visit(C);
12389  C->setLocStart(Record.readSourceLocation());
12390  C->setLocEnd(Record.readSourceLocation());
12391 
12392  return C;
12393 }
12394 
12396  C->setPreInitStmt(Record.readSubStmt(),
12397  static_cast<OpenMPDirectiveKind>(Record.readInt()));
12398 }
12399 
12401  VisitOMPClauseWithPreInit(C);
12402  C->setPostUpdateExpr(Record.readSubExpr());
12403 }
12404 
12405 void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) {
12406  VisitOMPClauseWithPreInit(C);
12407  C->setNameModifier(static_cast<OpenMPDirectiveKind>(Record.readInt()));
12408  C->setNameModifierLoc(Record.readSourceLocation());
12409  C->setColonLoc(Record.readSourceLocation());
12410  C->setCondition(Record.readSubExpr());
12411  C->setLParenLoc(Record.readSourceLocation());
12412 }
12413 
12414 void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) {
12415  C->setCondition(Record.readSubExpr());
12416  C->setLParenLoc(Record.readSourceLocation());
12417 }
12418 
12419 void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
12420  VisitOMPClauseWithPreInit(C);
12421  C->setNumThreads(Record.readSubExpr());
12422  C->setLParenLoc(Record.readSourceLocation());
12423 }
12424 
12425 void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) {
12426  C->setSafelen(Record.readSubExpr());
12427  C->setLParenLoc(Record.readSourceLocation());
12428 }
12429 
12430 void OMPClauseReader::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
12431  C->setSimdlen(Record.readSubExpr());
12432  C->setLParenLoc(Record.readSourceLocation());
12433 }
12434 
12435 void OMPClauseReader::VisitOMPAllocatorClause(OMPAllocatorClause *C) {
12436  C->setAllocator(Record.readExpr());
12437  C->setLParenLoc(Record.readSourceLocation());
12438 }
12439 
12440 void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
12441  C->setNumForLoops(Record.readSubExpr());
12442  C->setLParenLoc(Record.readSourceLocation());
12443 }
12444 
12445 void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
12446  C->setDefaultKind(
12447  static_cast<OpenMPDefaultClauseKind>(Record.readInt()));
12448  C->setLParenLoc(Record.readSourceLocation());
12449  C->setDefaultKindKwLoc(Record.readSourceLocation());
12450 }
12451 
12452 void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
12453  C->setProcBindKind(
12454  static_cast<OpenMPProcBindClauseKind>(Record.readInt()));
12455  C->setLParenLoc(Record.readSourceLocation());
12456  C->setProcBindKindKwLoc(Record.readSourceLocation());
12457 }
12458 
12459 void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
12460  VisitOMPClauseWithPreInit(C);
12461  C->setScheduleKind(
12462  static_cast<OpenMPScheduleClauseKind>(Record.readInt()));
12463  C->setFirstScheduleModifier(
12464  static_cast<OpenMPScheduleClauseModifier>(Record.readInt()));
12465  C->setSecondScheduleModifier(
12466  static_cast<OpenMPScheduleClauseModifier>(Record.readInt()));
12467  C->setChunkSize(Record.readSubExpr());
12468  C->setLParenLoc(Record.readSourceLocation());
12469  C->setFirstScheduleModifierLoc(Record.readSourceLocation());
12470  C->setSecondScheduleModifierLoc(Record.readSourceLocation());
12471  C->setScheduleKindLoc(Record.readSourceLocation());
12472  C->setCommaLoc(Record.readSourceLocation());
12473 }
12474 
12475 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *C) {
12476  C->setNumForLoops(Record.readSubExpr());
12477  for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I)
12478  C->setLoopNumIterations(I, Record.readSubExpr());
12479  for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I)
12480  C->setLoopCounter(I, Record.readSubExpr());
12481  C->setLParenLoc(Record.readSourceLocation());
12482 }
12483 
12484 void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
12485 
12486 void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}
12487 
12488 void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
12489 
12490 void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {}
12491 
12492 void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {}
12493 
12494 void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {}
12495 
12496 void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {}
12497 
12498 void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
12499 
12500 void OMPClauseReader::VisitOMPThreadsClause(OMPThreadsClause *) {}
12501 
12502 void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {}
12503 
12504 void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {}
12505 
12506 void OMPClauseReader::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {}
12507 
12508 void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause(
12510 
12511 void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {}
12512 
12513 void
12514 OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) {
12515 }
12516 
12517 void OMPClauseReader::VisitOMPAtomicDefaultMemOrderClause(
12519  C->setAtomicDefaultMemOrderKind(
12520  static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Record.readInt()));
12521  C->setLParenLoc(Record.readSourceLocation());
12522  C->setAtomicDefaultMemOrderKindKwLoc(Record.readSourceLocation());
12523 }
12524 
12525 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
12526  C->setLParenLoc(Record.readSourceLocation());
12527  unsigned NumVars = C->varlist_size();
12529  Vars.reserve(NumVars);
12530  for (unsigned i = 0; i != NumVars; ++i)
12531  Vars.push_back(Record.readSubExpr());
12532  C->setVarRefs(Vars);
12533  Vars.clear();
12534  for (unsigned i = 0; i != NumVars; ++i)
12535  Vars.push_back(Record.readSubExpr());
12536  C->setPrivateCopies(Vars);
12537 }
12538 
12539 void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
12540  VisitOMPClauseWithPreInit(C);
12541  C->setLParenLoc(Record.readSourceLocation());
12542  unsigned NumVars = C->varlist_size();
12544  Vars.reserve(NumVars);
12545  for (unsigned i = 0; i != NumVars; ++i)
12546  Vars.push_back(Record.readSubExpr());
12547  C->setVarRefs(Vars);
12548  Vars.clear();
12549  for (unsigned i = 0; i != NumVars; ++i)
12550  Vars.push_back(Record.readSubExpr());
12551  C->setPrivateCopies(Vars);
12552  Vars.clear();
12553  for (unsigned i = 0; i != NumVars; ++i)
12554  Vars.push_back(Record.readSubExpr());
12555  C->setInits(Vars);
12556 }
12557 
12558 void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
12559  VisitOMPClauseWithPostUpdate(C);
12560  C->setLParenLoc(Record.readSourceLocation());
12561  unsigned NumVars = C->varlist_size();
12563  Vars.reserve(NumVars);
12564  for (unsigned i = 0; i != NumVars; ++i)
12565  Vars.push_back(Record.readSubExpr());
12566  C->setVarRefs(Vars);
12567  Vars.clear();
12568  for (unsigned i = 0; i != NumVars; ++i)
12569  Vars.push_back(Record.readSubExpr());
12570  C->setPrivateCopies(Vars);
12571  Vars.clear();
12572  for (unsigned i = 0; i != NumVars; ++i)
12573  Vars.push_back(Record.readSubExpr());
12574  C->setSourceExprs(Vars);
12575  Vars.clear();
12576  for (unsigned i = 0; i != NumVars; ++i)
12577  Vars.push_back(Record.readSubExpr());
12578  C->setDestinationExprs(Vars);
12579  Vars.clear();
12580  for (unsigned i = 0; i != NumVars; ++i)
12581  Vars.push_back(Record.readSubExpr());
12582  C->setAssignmentOps(Vars);
12583 }
12584 
12585 void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
12586  C->setLParenLoc(Record.readSourceLocation());
12587  unsigned NumVars = C->varlist_size();
12589  Vars.reserve(NumVars);
12590  for (unsigned i = 0; i != NumVars; ++i)
12591  Vars.push_back(Record.readSubExpr());
12592  C->setVarRefs(Vars);
12593 }
12594 
12595 void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) {
12596  VisitOMPClauseWithPostUpdate(C);
12597  C->setLParenLoc(Record.readSourceLocation());
12598  C->setColonLoc(Record.readSourceLocation());
12599  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12600  DeclarationNameInfo DNI;
12601  Record.readDeclarationNameInfo(DNI);
12602  C->setQualifierLoc(NNSL);
12603  C->setNameInfo(DNI);
12604 
12605  unsigned NumVars = C->varlist_size();
12607  Vars.reserve(NumVars);
12608  for (unsigned i = 0; i != NumVars; ++i)
12609  Vars.push_back(Record.readSubExpr());
12610  C->setVarRefs(Vars);
12611  Vars.clear();
12612  for (unsigned i = 0; i != NumVars; ++i)
12613  Vars.push_back(Record.readSubExpr());
12614  C->setPrivates(Vars);
12615  Vars.clear();
12616  for (unsigned i = 0; i != NumVars; ++i)
12617  Vars.push_back(Record.readSubExpr());
12618  C->setLHSExprs(Vars);
12619  Vars.clear();
12620  for (unsigned i = 0; i != NumVars; ++i)
12621  Vars.push_back(Record.readSubExpr());
12622  C->setRHSExprs(Vars);
12623  Vars.clear();
12624  for (unsigned i = 0; i != NumVars; ++i)
12625  Vars.push_back(Record.readSubExpr());
12626  C->setReductionOps(Vars);
12627 }
12628 
12629 void OMPClauseReader::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
12630  VisitOMPClauseWithPostUpdate(C);
12631  C->setLParenLoc(Record.readSourceLocation());
12632  C->setColonLoc(Record.readSourceLocation());
12633  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12634  DeclarationNameInfo DNI;
12635  Record.readDeclarationNameInfo(DNI);
12636  C->setQualifierLoc(NNSL);
12637  C->setNameInfo(DNI);
12638 
12639  unsigned NumVars = C->varlist_size();
12641  Vars.reserve(NumVars);
12642  for (unsigned I = 0; I != NumVars; ++I)
12643  Vars.push_back(Record.readSubExpr());
12644  C->setVarRefs(Vars);
12645  Vars.clear();
12646  for (unsigned I = 0; I != NumVars; ++I)
12647  Vars.push_back(Record.readSubExpr());
12648  C->setPrivates(Vars);
12649  Vars.clear();
12650  for (unsigned I = 0; I != NumVars; ++I)
12651  Vars.push_back(Record.readSubExpr());
12652  C->setLHSExprs(Vars);
12653  Vars.clear();
12654  for (unsigned I = 0; I != NumVars; ++I)
12655  Vars.push_back(Record.readSubExpr());
12656  C->setRHSExprs(Vars);
12657  Vars.clear();
12658  for (unsigned I = 0; I != NumVars; ++I)
12659  Vars.push_back(Record.readSubExpr());
12660  C->setReductionOps(Vars);
12661 }
12662 
12663 void OMPClauseReader::VisitOMPInReductionClause(OMPInReductionClause *C) {
12664  VisitOMPClauseWithPostUpdate(C);
12665  C->setLParenLoc(Record.readSourceLocation());
12666  C->setColonLoc(Record.readSourceLocation());
12667  NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc();
12668  DeclarationNameInfo DNI;
12669  Record.readDeclarationNameInfo(DNI);
12670  C->setQualifierLoc(NNSL);
12671  C->setNameInfo(DNI);
12672 
12673  unsigned NumVars = C->varlist_size();
12675  Vars.reserve(NumVars);
12676  for (unsigned I = 0; I != NumVars; ++I)
12677  Vars.push_back(Record.readSubExpr());
12678  C->setVarRefs(Vars);
12679  Vars.clear();
12680  for (unsigned I = 0; I != NumVars; ++I)
12681  Vars.push_back(Record.readSubExpr());
12682  C->setPrivates(Vars);
12683  Vars.clear();
12684  for (unsigned I = 0; I != NumVars; ++I)
12685  Vars.push_back(Record.readSubExpr());
12686  C->setLHSExprs(Vars);
12687  Vars.clear();
12688  for (unsigned I = 0; I != NumVars; ++I)
12689  Vars.push_back(Record.readSubExpr());
12690  C->setRHSExprs(Vars);
12691  Vars.clear();
12692  for (unsigned I = 0; I != NumVars; ++I)
12693  Vars.push_back(Record.readSubExpr());
12694  C->setReductionOps(Vars);
12695  Vars.clear();
12696  for (unsigned I = 0; I != NumVars; ++I)
12697  Vars.push_back(Record.readSubExpr());
12698  C->setTaskgroupDescriptors(Vars);
12699 }
12700 
12701 void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) {
12702  VisitOMPClauseWithPostUpdate(C);
12703  C->setLParenLoc(Record.readSourceLocation());
12704  C->setColonLoc(Record.readSourceLocation());
12705  C->setModifier(static_cast<OpenMPLinearClauseKind>(Record.readInt()));
12706  C->setModifierLoc(Record.readSourceLocation());
12707  unsigned NumVars = C->varlist_size();
12709  Vars.reserve(NumVars);
12710  for (unsigned i = 0; i != NumVars; ++i)
12711  Vars.push_back(Record.readSubExpr());
12712  C->setVarRefs(Vars);
12713  Vars.clear();
12714  for (unsigned i = 0; i != NumVars; ++i)
12715  Vars.push_back(Record.readSubExpr());
12716  C->setPrivates(Vars);
12717  Vars.clear();
12718  for (unsigned i = 0; i != NumVars; ++i)
12719  Vars.push_back(Record.readSubExpr());
12720  C->setInits(Vars);
12721  Vars.clear();
12722  for (unsigned i = 0; i != NumVars; ++i)
12723  Vars.push_back(Record.readSubExpr());
12724  C->setUpdates(Vars);
12725  Vars.clear();
12726  for (unsigned i = 0; i != NumVars; ++i)
12727  Vars.push_back(Record.readSubExpr());
12728  C->setFinals(Vars);
12729  C->setStep(Record.readSubExpr());
12730  C->setCalcStep(Record.readSubExpr());
12731 }
12732 
12733 void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) {
12734  C->setLParenLoc(Record.readSourceLocation());
12735  C->setColonLoc(Record.readSourceLocation());
12736  unsigned NumVars = C->varlist_size();
12738  Vars.reserve(NumVars);
12739  for (unsigned i = 0; i != NumVars; ++i)
12740  Vars.push_back(Record.readSubExpr());
12741  C->setVarRefs(Vars);
12742  C->setAlignment(Record.readSubExpr());
12743 }
12744 
12745 void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) {
12746  C->setLParenLoc(Record.readSourceLocation());
12747  unsigned NumVars = C->varlist_size();
12749  Exprs.reserve(NumVars);
12750  for (unsigned i = 0; i != NumVars; ++i)
12751  Exprs.push_back(Record.readSubExpr());
12752  C->setVarRefs(Exprs);
12753  Exprs.clear();
12754  for (unsigned i = 0; i != NumVars; ++i)
12755  Exprs.push_back(Record.readSubExpr());
12756  C->setSourceExprs(Exprs);
12757  Exprs.clear();
12758  for (unsigned i = 0; i != NumVars; ++i)
12759  Exprs.push_back(Record.readSubExpr());
12760  C->setDestinationExprs(Exprs);
12761  Exprs.clear();
12762  for (unsigned i = 0; i != NumVars; ++i)
12763  Exprs.push_back(Record.readSubExpr());
12764  C->setAssignmentOps(Exprs);
12765 }
12766 
12767 void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
12768  C->setLParenLoc(Record.readSourceLocation());
12769  unsigned NumVars = C->varlist_size();
12771  Exprs.reserve(NumVars);
12772  for (unsigned i = 0; i != NumVars; ++i)
12773  Exprs.push_back(Record.readSubExpr());
12774  C->setVarRefs(Exprs);
12775  Exprs.clear();
12776  for (unsigned i = 0; i != NumVars; ++i)
12777  Exprs.push_back(Record.readSubExpr());
12778  C->setSourceExprs(Exprs);
12779  Exprs.clear();
12780  for (unsigned i = 0; i != NumVars; ++i)
12781  Exprs.push_back(Record.readSubExpr());
12782  C->setDestinationExprs(Exprs);
12783  Exprs.clear();
12784  for (unsigned i = 0; i != NumVars; ++i)
12785  Exprs.push_back(Record.readSubExpr());
12786  C->setAssignmentOps(Exprs);
12787 }
12788 
12789 void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) {
12790  C->setLParenLoc(Record.readSourceLocation());
12791  unsigned NumVars = C->varlist_size();
12793  Vars.reserve(NumVars);
12794  for (unsigned i = 0; i != NumVars; ++i)
12795  Vars.push_back(Record.readSubExpr());
12796  C->setVarRefs(Vars);
12797 }
12798 
12799 void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) {
12800  C->setLParenLoc(Record.readSourceLocation());
12801  C->setDependencyKind(
12802  static_cast<OpenMPDependClauseKind>(Record.readInt()));
12803  C->setDependencyLoc(Record.readSourceLocation());
12804  C->setColonLoc(Record.readSourceLocation());
12805  unsigned NumVars = C->varlist_size();
12807  Vars.reserve(NumVars);
12808  for (unsigned I = 0; I != NumVars; ++I)
12809  Vars.push_back(Record.readSubExpr());
12810  C->setVarRefs(Vars);
12811  for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
12812  C->setLoopData(I, Record.readSubExpr());
12813 }
12814 
12815 void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) {
12816  VisitOMPClauseWithPreInit(C);
12817  C->setDevice(Record.readSubExpr());
12818  C->setLParenLoc(Record.readSourceLocation());
12819 }
12820 
12821 void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) {
12822  C->setLParenLoc(Record.readSourceLocation());
12823  for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
12824  C->setMapTypeModifier(
12825  I, static_cast<OpenMPMapModifierKind>(Record.readInt()));
12826  C->setMapTypeModifierLoc(I, Record.readSourceLocation());
12827  }
12828  C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc());
12829  DeclarationNameInfo DNI;
12830  Record.readDeclarationNameInfo(DNI);
12831  C->setMapperIdInfo(DNI);
12832  C->setMapType(
12833  static_cast<OpenMPMapClauseKind>(Record.readInt()));
12834  C->setMapLoc(Record.readSourceLocation());
12835  C->setColonLoc(Record.readSourceLocation());
12836  auto NumVars = C->varlist_size();
12837  auto UniqueDecls = C->getUniqueDeclarationsNum();
12838  auto TotalLists = C->getTotalComponentListNum();
12839  auto TotalComponents = C->getTotalComponentsNum();
12840 
12842  Vars.reserve(NumVars);
12843  for (unsigned i = 0; i != NumVars; ++i)
12844  Vars.push_back(Record.readExpr());
12845  C->setVarRefs(Vars);
12846 
12847  SmallVector<Expr *, 16> UDMappers;
12848  UDMappers.reserve(NumVars);
12849  for (unsigned I = 0; I < NumVars; ++I)
12850  UDMappers.push_back(Record.readExpr());
12851  C->setUDMapperRefs(UDMappers);
12852 
12854  Decls.reserve(UniqueDecls);
12855  for (unsigned i = 0; i < UniqueDecls; ++i)
12856  Decls.push_back(Record.readDeclAs<ValueDecl>());
12857  C->setUniqueDecls(Decls);
12858 
12859  SmallVector<unsigned, 16> ListsPerDecl;
12860  ListsPerDecl.reserve(UniqueDecls);
12861  for (unsigned i = 0; i < UniqueDecls; ++i)
12862  ListsPerDecl.push_back(Record.readInt());
12863  C->setDeclNumLists(ListsPerDecl);
12864 
12865  SmallVector<unsigned, 32> ListSizes;
12866  ListSizes.reserve(TotalLists);
12867  for (unsigned i = 0; i < TotalLists; ++i)
12868  ListSizes.push_back(Record.readInt());
12869  C->setComponentListSizes(ListSizes);
12870 
12872  Components.reserve(TotalComponents);
12873  for (unsigned i = 0; i < TotalComponents; ++i) {
12874  Expr *AssociatedExpr = Record.readExpr();
12875  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12877  AssociatedExpr, AssociatedDecl));
12878  }
12879  C->setComponents(Components, ListSizes);
12880 }
12881 
12882 void OMPClauseReader::VisitOMPAllocateClause(OMPAllocateClause *C) {
12883  C->setLParenLoc(Record.readSourceLocation());
12884  C->setColonLoc(Record.readSourceLocation());
12885  C->setAllocator(Record.readSubExpr());
12886  unsigned NumVars = C->varlist_size();
12888  Vars.reserve(NumVars);
12889  for (unsigned i = 0; i != NumVars; ++i)
12890  Vars.push_back(Record.readSubExpr());
12891  C->setVarRefs(Vars);
12892 }
12893 
12894 void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
12895  VisitOMPClauseWithPreInit(C);
12896  C->setNumTeams(Record.readSubExpr());
12897  C->setLParenLoc(Record.readSourceLocation());
12898 }
12899 
12900 void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
12901  VisitOMPClauseWithPreInit(C);
12902  C->setThreadLimit(Record.readSubExpr());
12903  C->setLParenLoc(Record.readSourceLocation());
12904 }
12905 
12906 void OMPClauseReader::VisitOMPPriorityClause(OMPPriorityClause *C) {
12907  C->setPriority(Record.readSubExpr());
12908  C->setLParenLoc(Record.readSourceLocation());
12909 }
12910 
12911 void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
12912  C->setGrainsize(Record.readSubExpr());
12913  C->setLParenLoc(Record.readSourceLocation());
12914 }
12915 
12916 void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
12917  C->setNumTasks(Record.readSubExpr());
12918  C->setLParenLoc(Record.readSourceLocation());
12919 }
12920 
12921 void OMPClauseReader::VisitOMPHintClause(OMPHintClause *C) {
12922  C->setHint(Record.readSubExpr());
12923  C->setLParenLoc(Record.readSourceLocation());
12924 }
12925 
12926 void OMPClauseReader::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
12927  VisitOMPClauseWithPreInit(C);
12928  C->setDistScheduleKind(
12929  static_cast<OpenMPDistScheduleClauseKind>(Record.readInt()));
12930  C->setChunkSize(Record.readSubExpr());
12931  C->setLParenLoc(Record.readSourceLocation());
12932  C->setDistScheduleKindLoc(Record.readSourceLocation());
12933  C->setCommaLoc(Record.readSourceLocation());
12934 }
12935 
12936 void OMPClauseReader::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
12937  C->setDefaultmapKind(
12938  static_cast<OpenMPDefaultmapClauseKind>(Record.readInt()));
12939  C->setDefaultmapModifier(
12940  static_cast<OpenMPDefaultmapClauseModifier>(Record.readInt()));
12941  C->setLParenLoc(Record.readSourceLocation());
12942  C->setDefaultmapModifierLoc(Record.readSourceLocation());
12943  C->setDefaultmapKindLoc(Record.readSourceLocation());
12944 }
12945 
12946 void OMPClauseReader::VisitOMPToClause(OMPToClause *C) {
12947  C->setLParenLoc(Record.readSourceLocation());
12948  C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc());
12949  DeclarationNameInfo DNI;
12950  Record.readDeclarationNameInfo(DNI);
12951  C->setMapperIdInfo(DNI);
12952  auto NumVars = C->varlist_size();
12953  auto UniqueDecls = C->getUniqueDeclarationsNum();
12954  auto TotalLists = C->getTotalComponentListNum();
12955  auto TotalComponents = C->getTotalComponentsNum();
12956 
12958  Vars.reserve(NumVars);
12959  for (unsigned i = 0; i != NumVars; ++i)
12960  Vars.push_back(Record.readSubExpr());
12961  C->setVarRefs(Vars);
12962 
12963  SmallVector<Expr *, 16> UDMappers;
12964  UDMappers.reserve(NumVars);
12965  for (unsigned I = 0; I < NumVars; ++I)
12966  UDMappers.push_back(Record.readSubExpr());
12967  C->setUDMapperRefs(UDMappers);
12968 
12970  Decls.reserve(UniqueDecls);
12971  for (unsigned i = 0; i < UniqueDecls; ++i)
12972  Decls.push_back(Record.readDeclAs<ValueDecl>());
12973  C->setUniqueDecls(Decls);
12974 
12975  SmallVector<unsigned, 16> ListsPerDecl;
12976  ListsPerDecl.reserve(UniqueDecls);
12977  for (unsigned i = 0; i < UniqueDecls; ++i)
12978  ListsPerDecl.push_back(Record.readInt());
12979  C->setDeclNumLists(ListsPerDecl);
12980 
12981  SmallVector<unsigned, 32> ListSizes;
12982  ListSizes.reserve(TotalLists);
12983  for (unsigned i = 0; i < TotalLists; ++i)
12984  ListSizes.push_back(Record.readInt());
12985  C->setComponentListSizes(ListSizes);
12986 
12988  Components.reserve(TotalComponents);
12989  for (unsigned i = 0; i < TotalComponents; ++i) {
12990  Expr *AssociatedExpr = Record.readSubExpr();
12991  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
12993  AssociatedExpr, AssociatedDecl));
12994  }
12995  C->setComponents(Components, ListSizes);
12996 }
12997 
12998 void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) {
12999  C->setLParenLoc(Record.readSourceLocation());
13000  C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc());
13001  DeclarationNameInfo DNI;
13002  Record.readDeclarationNameInfo(DNI);
13003  C->setMapperIdInfo(DNI);
13004  auto NumVars = C->varlist_size();
13005  auto UniqueDecls = C->getUniqueDeclarationsNum();
13006  auto TotalLists = C->getTotalComponentListNum();
13007  auto TotalComponents = C->getTotalComponentsNum();
13008 
13010  Vars.reserve(NumVars);
13011  for (unsigned i = 0; i != NumVars; ++i)
13012  Vars.push_back(Record.readSubExpr());
13013  C->setVarRefs(Vars);
13014 
13015  SmallVector<Expr *, 16> UDMappers;
13016  UDMappers.reserve(NumVars);
13017  for (unsigned I = 0; I < NumVars; ++I)
13018  UDMappers.push_back(Record.readSubExpr());
13019  C->setUDMapperRefs(UDMappers);
13020 
13022  Decls.reserve(UniqueDecls);
13023  for (unsigned i = 0; i < UniqueDecls; ++i)
13024  Decls.push_back(Record.readDeclAs<ValueDecl>());
13025  C->setUniqueDecls(Decls);
13026 
13027  SmallVector<unsigned, 16> ListsPerDecl;
13028  ListsPerDecl.reserve(UniqueDecls);
13029  for (unsigned i = 0; i < UniqueDecls; ++i)
13030  ListsPerDecl.push_back(Record.readInt());
13031  C->setDeclNumLists(ListsPerDecl);
13032 
13033  SmallVector<unsigned, 32> ListSizes;
13034  ListSizes.reserve(TotalLists);
13035  for (unsigned i = 0; i < TotalLists; ++i)
13036  ListSizes.push_back(Record.readInt());
13037  C->setComponentListSizes(ListSizes);
13038 
13040  Components.reserve(TotalComponents);
13041  for (unsigned i = 0; i < TotalComponents; ++i) {
13042  Expr *AssociatedExpr = Record.readSubExpr();
13043  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
13045  AssociatedExpr, AssociatedDecl));
13046  }
13047  C->setComponents(Components, ListSizes);
13048 }
13049 
13050 void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
13051  C->setLParenLoc(Record.readSourceLocation());
13052  auto NumVars = C->varlist_size();
13053  auto UniqueDecls = C->getUniqueDeclarationsNum();
13054  auto TotalLists = C->getTotalComponentListNum();
13055  auto TotalComponents = C->getTotalComponentsNum();
13056 
13058  Vars.reserve(NumVars);
13059  for (unsigned i = 0; i != NumVars; ++i)
13060  Vars.push_back(Record.readSubExpr());
13061  C->setVarRefs(Vars);
13062  Vars.clear();
13063  for (unsigned i = 0; i != NumVars; ++i)
13064  Vars.push_back(Record.readSubExpr());
13065  C->setPrivateCopies(Vars);
13066  Vars.clear();
13067  for (unsigned i = 0; i != NumVars; ++i)
13068  Vars.push_back(Record.readSubExpr());
13069  C->setInits(Vars);
13070 
13072  Decls.reserve(UniqueDecls);
13073  for (unsigned i = 0; i < UniqueDecls; ++i)
13074  Decls.push_back(Record.readDeclAs<ValueDecl>());
13075  C->setUniqueDecls(Decls);
13076 
13077  SmallVector<unsigned, 16> ListsPerDecl;
13078  ListsPerDecl.reserve(UniqueDecls);
13079  for (unsigned i = 0; i < UniqueDecls; ++i)
13080  ListsPerDecl.push_back(Record.readInt());
13081  C->setDeclNumLists(ListsPerDecl);
13082 
13083  SmallVector<unsigned, 32> ListSizes;
13084  ListSizes.reserve(TotalLists);
13085  for (unsigned i = 0; i < TotalLists; ++i)
13086  ListSizes.push_back(Record.readInt());
13087  C->setComponentListSizes(ListSizes);
13088 
13090  Components.reserve(TotalComponents);
13091  for (unsigned i = 0; i < TotalComponents; ++i) {
13092  Expr *AssociatedExpr = Record.readSubExpr();
13093  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
13095  AssociatedExpr, AssociatedDecl));
13096  }
13097  C->setComponents(Components, ListSizes);
13098 }
13099 
13100 void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
13101  C->setLParenLoc(Record.readSourceLocation());
13102  auto NumVars = C->varlist_size();
13103  auto UniqueDecls = C->getUniqueDeclarationsNum();
13104  auto TotalLists = C->getTotalComponentListNum();
13105  auto TotalComponents = C->getTotalComponentsNum();
13106 
13108  Vars.reserve(NumVars);
13109  for (unsigned i = 0; i != NumVars; ++i)
13110  Vars.push_back(Record.readSubExpr());
13111  C->setVarRefs(Vars);
13112  Vars.clear();
13113 
13115  Decls.reserve(UniqueDecls);
13116  for (unsigned i = 0; i < UniqueDecls; ++i)
13117  Decls.push_back(Record.readDeclAs<ValueDecl>());
13118  C->setUniqueDecls(Decls);
13119 
13120  SmallVector<unsigned, 16> ListsPerDecl;
13121  ListsPerDecl.reserve(UniqueDecls);
13122  for (unsigned i = 0; i < UniqueDecls; ++i)
13123  ListsPerDecl.push_back(Record.readInt());
13124  C->setDeclNumLists(ListsPerDecl);
13125 
13126  SmallVector<unsigned, 32> ListSizes;
13127  ListSizes.reserve(TotalLists);
13128  for (unsigned i = 0; i < TotalLists; ++i)
13129  ListSizes.push_back(Record.readInt());
13130  C->setComponentListSizes(ListSizes);
13131 
13133  Components.reserve(TotalComponents);
13134  for (unsigned i = 0; i < TotalComponents; ++i) {
13135  Expr *AssociatedExpr = Record.readSubExpr();
13136  auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
13138  AssociatedExpr, AssociatedDecl));
13139  }
13140  C->setComponents(Components, ListSizes);
13141 }
llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx)
Read an integral value.
Definition: ASTReader.cpp:9568
Decl * GetExistingDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration.
Definition: ASTReader.cpp:7762
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:219
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:1032
void setSourceOrder(int Pos)
Set the source order of this initializer.
Definition: DeclCXX.h:2529
CanQualType SatUnsignedLongFractTy
Definition: ASTContext.h:1036
Defines the clang::ASTContext interface.
The ObjC &#39;SEL&#39; type.
Definition: ASTBitCodes.h:888
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:5292
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:8555
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Finds all the visible declarations with a given name.
Definition: ASTReader.cpp:7975
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons...
Definition: ASTReader.h:380
Record code for the preprocessor options table.
Definition: ASTBitCodes.h:357
std::vector< unsigned > PreloadIdentifierOffsets
Offsets of identifiers that we&#39;re going to preload within IdentifierTableData.
Definition: Module.h:292
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:315
The &#39;unsigned _Accum&#39; type.
Definition: ASTBitCodes.h:954
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
CanQualType LongLongTy
Definition: ASTContext.h:1023
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:1517
void setInfo(const DeclarationNameLoc &Info)
Represents a function declaration or definition.
Definition: Decl.h:1748
ASTFileSignature Signature
The module signature.
Definition: Module.h:107
std::string Name
The name of this module.
Definition: Module.h:67
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:61
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:177
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:1790
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:8421
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:288
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
Definition: ASTContext.h:1754
The &#39;unsigned short _Fract&#39; type.
Definition: ASTBitCodes.h:969
CanQualType AccumTy
Definition: ASTContext.h:1027
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:1052
Record code for potentially unused local typedef names.
Definition: ASTBitCodes.h:618
Record code for map of Objective-C class definition IDs to the ObjC categories in a module that are a...
Definition: ASTBitCodes.h:576
Smart pointer class that efficiently represents Objective-C method names.
static void updateModuleTimestamp(ModuleFile &MF)
Definition: ASTReader.cpp:4034
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:194
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:643
static LLVM_DUMP_METHOD void dumpModuleIDMap(StringRef Name, const ContinuousRangeMap< Key, ModuleFile *, InitialCapacity > &Map)
Definition: ASTReader.cpp:8157
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
Definition: ASTReader.h:196
static void addMethodsToPool(Sema &S, ArrayRef< ObjCMethodDecl *> Methods, ObjCMethodList &List)
Add the given set of methods to the method list.
Definition: ASTReader.cpp:8511
void * getAsOpaquePtr() const
CtorInitializerType
The different kinds of data that can occur in a CtorInitializer.
Definition: ASTBitCodes.h:2010
The &#39;_Float16&#39; type.
Definition: ASTBitCodes.h:936
unsigned BasePreprocessedSkippedRangeID
Base ID for preprocessed skipped ranges local to this module.
Definition: Module.h:339
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:248
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1313
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:697
void SetIdentifierInfo(unsigned ID, IdentifierInfo *II)
Definition: ASTReader.cpp:8741
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:224
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
The &#39;unsigned int&#39; type.
Definition: ASTBitCodes.h:822
The (signed) &#39;long long&#39; type.
Definition: ASTBitCodes.h:849
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
CanQualType UnsignedLongFractTy
Definition: ASTContext.h:1031
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
Definition: ASTReader.h:207
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
SourceManager & getSourceManager() const
Definition: ASTReader.h:1494
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:405
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:365
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4668
Defines the clang::FileManager interface and associated types.
time_t getModificationTime() const
Definition: FileManager.h:89
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:7612
Record code for the source manager line table information, which stores information about #line direc...
Definition: ASTBitCodes.h:572
CanQualType FractTy
Definition: ASTContext.h:1030
SourceRange getBraceRange() const
Definition: Decl.h:3178
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:132
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:810
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.
CanQualType Char32Ty
Definition: ASTContext.h:1022
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:2307
unsigned isPragmaOnce
True if this is a #pragma once file.
Definition: HeaderSearch.h:55
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1409
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:1028
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:167
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1396
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:1244
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:6030
Expr * getBitWidth() const
Definition: Decl.h:2696
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1603
const FileEntry * getFile() const
Definition: Module.h:94
bool getEnableAllWarnings() const
Definition: Diagnostic.h:602
void AddQualType(QualType T)
Definition: ODRHash.cpp:1112
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1423
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:201
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:237
Class that handles pre-initialization statement for some clauses, like &#39;shedule&#39;, &#39;firstprivate&#39; etc...
Definition: OpenMPClause.h:107
ControlRecordTypes
Record types that occur within the control block.
Definition: ASTBitCodes.h:300
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2819
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition: Module.h:508
The fixed point semantics work similarly to llvm::fltSemantics.
Definition: FixedPoint.h:33
unsigned Generation
The generation of which this module file is a part.
Definition: Module.h:174
void ReadComments() override
Loads comments ranges.
Definition: ASTReader.cpp:9663
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:363
C Language Family Type Representation.
Defines the SourceManager interface.
The &#39;unknown any&#39; placeholder type.
Definition: ASTBitCodes.h:891
void setWrittenWidthSpec(TypeSpecifierWidth written)
Definition: TypeLoc.h:625
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:201
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
Definition: ASTContext.h:1778
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:86
RawCommentList Comments
All comments in this translation unit.
Definition: ASTContext.h:727
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:8908
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const
Read a source location from raw form.
Definition: ASTReader.h:2185
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:1938
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:156
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
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:257
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:3224
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:421
CanQualType ObjCBuiltinSelTy
Definition: ASTContext.h:1046
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:7933
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
void VisitFunctionTypeLoc(FunctionTypeLoc)
Definition: ASTReader.cpp:6991
ModuleKind Kind
The type of this module.
Definition: Module.h:119
virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value)
Receives COUNTER value.
Definition: ASTReader.h:203
This represents &#39;if&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:422
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:675
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:8617
An LValueReferenceType record.
Definition: ASTBitCodes.h:1050
The placeholder type for builtin functions.
Definition: ASTBitCodes.h:912
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:472
Defines types useful for describing an Objective-C runtime.
Specifies the submodules that are imported by this submodule.
Definition: ASTBitCodes.h:741
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:125
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl *> &TentativeDefs) override
Read the set of tentative definitions known to the external Sema source.
Definition: ASTReader.cpp:8596
CanQualType ARCUnbridgedCastTy
Definition: ASTContext.h:1045
A record that stores the set of declarations that are lexically stored within a given DeclContext...
Definition: ASTBitCodes.h:1385
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:737
The base class of the type hierarchy.
Definition: Type.h:1433
CanQualType SatUnsignedAccumTy
Definition: ASTContext.h:1033
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:8833
CanQualType LongTy
Definition: ASTContext.h:1023
DiagnosticsEngine & getDiagnostics() const
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:975
unsigned LocalNumObjCCategoriesInMap
The number of redeclaration info entries in ObjCCategoriesMap.
Definition: Module.h:438
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:1665
#define CHECK_TARGET_OPT(Field, Name)
A SubstTemplateTypeParmType record.
Definition: ASTBitCodes.h:1107
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:7787
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1297
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2126
void setFlag(TokenFlags Flag)
Set the specified flag.
Definition: Token.h:236
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:63
Represent a C++ namespace.
Definition: Decl.h:514
Wrapper for source info for typedefs.
Definition: TypeLoc.h:666
static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II)
Definition: ASTReader.cpp:927
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:132
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:112
A container of type source information.
Definition: Decl.h:86
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:184
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:2369
Record code for enabled OpenCL extensions.
Definition: ASTBitCodes.h:555
Record code for the module build directory.
Definition: ASTBitCodes.h:333
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:3940
An ElaboratedType record.
Definition: ASTBitCodes.h:1104
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
Definition: Module.h:383
An UnresolvedUsingType record.
Definition: ASTBitCodes.h:1110
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:820
bool getSuppressSystemWarnings() const
Definition: Diagnostic.h:628
Wrapper for source info for pointers decayed from arrays and functions.
Definition: TypeLoc.h:1198
The &#39;short _Fract&#39; type.
Definition: ASTBitCodes.h:960
ASTFileSignature Signature
The signature of the module file, which may be used instead of the size and modification time to iden...
Definition: Module.h:167
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2355
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:2574
An IncompleteArrayType record.
Definition: ASTBitCodes.h:1062
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:754
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:1272
diag::Severity getExtensionHandlingBehavior() const
Definition: Diagnostic.h:690
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:219
void addPendingMacro(IdentifierInfo *II, ModuleFile *M, uint64_t MacroDirectivesOffset)
Add a macro to deserialize its macro directive history.
Definition: ASTReader.cpp:1918
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2014
Specifies a header that is part of the module but must be textually included.
Definition: ASTBitCodes.h:768
const uint32_t * SLocEntryOffsets
Offsets for all of the source location entries in the AST file.
Definition: Module.h:254
size_t param_size() const
Definition: Decl.h:2305
bool RelocatablePCH
Whether this precompiled header is a relocatable PCH file.
Definition: Module.h:154
CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a C++ base specifier.
Definition: ASTReader.cpp:9303
ARC&#39;s unbridged-cast placeholder type.
Definition: ASTBitCodes.h:906
CanQualType HalfTy
Definition: ASTContext.h:1038
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:1513
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:870
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:403
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:858
static OMPUseDevicePtrClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
static llvm::Error doesntStartWithASTFileMagic(BitstreamCursor &Stream)
Whether Stream doesn&#39;t start with the AST/PCH file magic number &#39;CPCH&#39;.
Definition: ASTReader.cpp:4332
The C++ &#39;char32_t&#39; type.
Definition: ASTBitCodes.h:879
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:1251
The stack of open #ifs/#ifdefs recorded in a preamble.
Definition: ASTBitCodes.h:647
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:276
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:48
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:53
static Qualifiers fromOpaqueValue(unsigned opaque)
Definition: Type.h:243
Represents a variable declaration or definition.
Definition: Decl.h:812
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:644
A block with unhashed content.
Definition: ASTBitCodes.h:296
QualType getReturnType() const
Definition: Decl.h:2329
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Read the contents of a CXXCtorInitializer array.
Definition: ASTReader.cpp:7580
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:585
Wrapper for source info for member pointers.
Definition: TypeLoc.h:1267
void VisitArrayTypeLoc(ArrayTypeLoc)
Definition: ASTReader.cpp:6936
Options for controlling the target.
Definition: TargetOptions.h:26
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:273
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing)...
Definition: DiagnosticIDs.h:79
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6851
Record code for declarations associated with OpenCL extensions.
Definition: ASTBitCodes.h:639
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:7527
CanQualType Float128Ty
Definition: ASTContext.h:1026
The width of the "fast" qualifier mask.
Definition: Type.h:180
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:56
Extra information about a function prototype.
Definition: Type.h:3799
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
CanQualType ShortAccumTy
Definition: ASTContext.h:1027
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2028
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Definition: ASTReader.cpp:8209
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
Definition: Module.h:366
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:1279
The value of the next COUNTER to dispense.
Definition: ASTBitCodes.h:480
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
unsigned getLineTableFilenameID(StringRef Str)
static APValue IndeterminateValue()
Definition: APValue.h:290
Specifies the umbrella header used to create this module, if any.
Definition: ASTBitCodes.h:728
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:603
A namespace, stored as a NamespaceDecl*.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation >> &Sels) override
Definition: ASTReader.cpp:8650
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:77
RangeSelector range(RangeSelector Begin, RangeSelector End)
Selects from the start of Begin and to the end of End.
Record code for header search information.
Definition: ASTBitCodes.h:549
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:1725
void setProtocolRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:784
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
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:661
Used to hold and unique data used to represent #line information.
Record code for the target options table.
Definition: ASTBitCodes.h:348
CanQualType ShortFractTy
Definition: ASTContext.h:1030
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:119
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:157
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. ...
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:451
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:101
Represents a parameter to a function.
Definition: Decl.h:1564
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:52
long i
Definition: xmmintrin.h:1456
int SLocEntryBaseID
The base ID in the source manager&#39;s view of this module.
Definition: Module.h:247
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:466
ContinuousRangeMap< uint32_t, int, 2 > DeclRemap
Remapping table for declaration IDs in this module.
Definition: Module.h:418
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1987
This represents &#39;nogroup&#39; clause in the &#39;#pragma omp ...&#39; directive.
The collection of all-type qualifiers we support.
Definition: Type.h:137
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
Definition: TypeLoc.h:960
This represents &#39;allocator&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:263
void clear()
Definition: ODRHash.cpp:198
SourceLocation ImportLoc
The source location where this module was first imported.
Definition: Module.h:204
This represents &#39;safelen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:661
An UnresolvedSet-like class that might not have been loaded from the external AST source yet...
bool needsExtraLocalData() const
Definition: TypeLoc.h:578
ModuleKind Kind
The kind of this module.
Definition: Module.h:88
The client can handle an AST file that cannot load because it is missing.
Definition: ASTReader.h:1509
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
Definition: Decl.cpp:3285
CanQualType OCLSamplerTy
Definition: ASTContext.h:1051
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:8926
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
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:8571
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
void setIsGNUVarargs()
Definition: MacroInfo.h:204
StringRef ModuleOffsetMap
The module offset map data for this file.
Definition: Module.h:215
Represents a struct/union/class.
Definition: Decl.h:3626
const unsigned VERSION_MAJOR
AST file major version number supported by this version of Clang.
Definition: ASTBitCodes.h:44
unsigned varlist_size() const
Definition: OpenMPClause.h:226
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:297
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:3529
TypedefDecl * getObjCIdDecl() const
Retrieve the typedef corresponding to the predefined id type in Objective-C.
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3800
One of these records is kept for each identifier that is lexed.
A macro directive exported by a module.
Definition: ASTBitCodes.h:701
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context...
Definition: DeclBase.h:2349
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:123
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1393
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:734
std::string ActualOriginalSourceFileName
The actual original source file name that was used to build this AST file.
Definition: Module.h:141
The block containing comments.
Definition: ASTBitCodes.h:269
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:2154
The Objective-C &#39;SEL&#39; type.
Definition: ASTBitCodes.h:1233
StringLiteral * getMessage()
Definition: DeclCXX.h:3908
A library or framework to link against when an entity from this module is used.
Definition: Module.h:325
void finalizeForWriting()
Finalizes the AST reader&#39;s state before writing an AST file to disk.
Definition: ASTReader.cpp:4870
Iteration over the preprocessed entities.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:329
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:738
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
A C++ nested-name-specifier augmented with source location information.
Record the location of a macro definition.
static OMPAllocateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
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:831
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:1378
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:71
void setBuiltinLoc(SourceLocation Loc)
Definition: TypeLoc.h:555
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1619
CanQualType UnsignedFractTy
Definition: ASTContext.h:1031
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:825
Specifies a header that has been explicitly excluded from this submodule.
Definition: ASTBitCodes.h:752
void setRBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1512
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:204
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
SourceLocation getBegin() const
Definition: ASTBitCodes.h:191
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:263
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
Definition: Decl.h:2607
bool isVolatile() const
Definition: DeclCXX.h:2155
This represents clause &#39;lastprivate&#39; in the &#39;#pragma omp ...&#39; directives.
bool isCPlusPlusOperatorKeyword() const
This represents clause &#39;allocate&#39; in the &#39;#pragma omp ...&#39; directives.
Definition: OpenMPClause.h:325
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
The &#39;_Sat unsigned _Accum&#39; type.
Definition: ASTBitCodes.h:990
Definition: Format.h:2274
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:333
Record code for the module map file that was used to build this AST file.
Definition: ASTBitCodes.h:330
One instance of this struct is kept for every file loaded or used.
Definition: SourceManager.h:94
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:780
An ExtVectorType record.
Definition: ASTBitCodes.h:1071
Delete expressions that will be analyzed later.
Definition: ASTBitCodes.h:623
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:1027
method_range methods() const
Definition: DeclObjC.h:1036
Helper class that saves the current stream position and then restores it when destroyed.
Definition: ASTReader.h:2679
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:489
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
CanQualType OCLEventTy
Definition: ASTContext.h:1051
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:138
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2037
TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template name.
Definition: ASTReader.cpp:9142
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:417
The &#39;unsigned long _Fract&#39; type.
Definition: ASTBitCodes.h:975
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
Definition: ASTReader.h:144
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:173
The &#39;long _Fract&#39; type.
Definition: ASTBitCodes.h:966
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
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:1107
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:189
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:688
std::string OriginalDir
The directory that the PCH was originally created in.
Definition: Module.h:149
void setKind(tok::TokenKind K)
Definition: Token.h:93
An AttributedType record.
Definition: ASTBitCodes.h:1140
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:140
llvm::OnDiskChainedHashTable< HeaderFileInfoTrait > HeaderFileInfoLookupTable
The on-disk hash table used for known header files.
An object-like macro definition.
Definition: ASTBitCodes.h:685
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C)
__DEVICE__ int max(int __a, int __b)
void setUnderlyingTInfo(TypeSourceInfo *TInfo)
Definition: TypeLoc.h:1920
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1522
CanQualType OCLReserveIDTy
Definition: ASTContext.h:1052
The signature of a module, which is a hash of the AST content.
Definition: Module.h:54
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:903
Describes one token.
Definition: ASTBitCodes.h:694
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:828
An AdjustedType record.
Definition: ASTBitCodes.h:1158
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Describes a module or submodule.
Definition: Module.h:64
The &#39;short _Accum&#39; type.
Definition: ASTBitCodes.h:942
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:4094
void completeVisibleDeclsMap(const DeclContext *DC) override
Load all external visible decls in the given DeclContext.
Definition: ASTReader.cpp:8001
const llvm::MemoryBuffer * getRawBuffer() const
Get the underlying buffer, returning NULL if the buffer is not yet available.
unsigned LocalNumHeaderFileInfos
The number of local HeaderFileInfo structures.
Definition: Module.h:347
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:495
The &#39;long _Accum&#39; type.
Definition: ASTBitCodes.h:948
CanQualType LongFractTy
Definition: ASTContext.h:1030
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
Definition: ASTReader.cpp:9612
llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Return a descriptor for the corresponding module.
Definition: ASTReader.cpp:8962
unsigned External
Whether this header file info was supplied by an external source, and has not changed since...
Definition: HeaderSearch.h:65
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:467
bool isInvalid() const
const PPEntityOffset * PreprocessedEntityOffsets
Definition: Module.h:335
ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, 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.
Specifies the submodules that are re-exported from this submodule.
Definition: ASTBitCodes.h:745
void setProtocolLoc(unsigned i, SourceLocation Loc)
Definition: TypeLoc.h:797
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition: Decl.h:675
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:311
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2685
Selector getNullarySelector(IdentifierInfo *ID)
The Objective-C &#39;id&#39; type.
Definition: ASTBitCodes.h:1230
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2263
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
Definition: Module.h:254
void setAttr(const Attr *A)
Definition: TypeLoc.h:876
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:523
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:211
virtual void HandleInterestingDecl(DeclGroupRef D)
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: ASTConsumer.cpp:22
PreprocessedEntity * ReadPreprocessedEntity(unsigned Index) override
Read a preallocated preprocessed entity from the external source.
Definition: ASTReader.cpp:5811
void setExpansionLoc(SourceLocation Loc)
Definition: TypeLoc.h:1108
void setCaretLoc(SourceLocation Loc)
Definition: TypeLoc.h:1257
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2150
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:677
bool PCHHasObjectFile
Whether the PCH has a corresponding object file.
Definition: Module.h:160
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:7177
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:908
static void hash_combine(std::size_t &seed, const T &v)
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
unsigned getNumProtocols() const
Definition: TypeLoc.h:788
const unsigned NumSpecialTypeIDs
The number of special type IDs.
Definition: ASTBitCodes.h:1214
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
void setcudaConfigureCallDecl(FunctionDecl *FD)
Definition: ASTContext.h:1273
CanQualType SatShortFractTy
Definition: ASTContext.h:1035
Describes a blob that contains the data for a buffer entry.
Definition: ASTBitCodes.h:667
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:345
The &#39;unsigned short _Accum&#39; type.
Definition: ASTBitCodes.h:951
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:514
void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9128
CanQualType SatUnsignedShortAccumTy
Definition: ASTContext.h:1033
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...
An unqualified-id that has been assumed to name a function template that will be found by ADL...
Definition: TemplateName.h:207
std::string Message
The message provided to the user when there is a conflict.
Definition: Module.h:371
APValue ReadAPValue(const RecordData &Record, unsigned &Idx)
Read an APValue.
Definition: ASTReader.cpp:9524
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:7655
Wrapper for source info for functions.
Definition: TypeLoc.h:1362
Specifies a conflict with another module.
Definition: ASTBitCodes.h:761
The signed 128-bit integer type.
Definition: ASTBitCodes.h:1242
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:9319
llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx)
Read a signed integral value.
Definition: ASTReader.cpp:9577
A UnaryTransformType record.
Definition: ASTBitCodes.h:1149
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:7857
An ObjCObjectType record.
Definition: ASTBitCodes.h:1116
A ConstantArrayType record.
Definition: ASTBitCodes.h:1059
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9597
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:5790
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:840
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:9756
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:8893
Record code for #pragma optimize options.
Definition: ASTBitCodes.h:615
uint32_t BitOffset
Offset in the AST file.
Definition: ASTBitCodes.h:185
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9624
unsigned short NumIncludes
The number of times the file has been included already.
Definition: HeaderSearch.h:90
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Definition: Sema.h:1209
StringRef Data
The serialized bitstream data for this file.
Definition: Module.h:187
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:772
Record code for pending implicit instantiations.
Definition: ASTBitCodes.h:525
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:833
ExtKind hasExternalDefinitions(const Decl *D) override
Definition: ASTReader.cpp:8979
CanQualType PseudoObjectTy
Definition: ASTContext.h:1045
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:894
The internal &#39;__make_integer_seq&#39; template.
Definition: ASTBitCodes.h:1263
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1831
void setLazyBody(uint64_t Offset)
Definition: DeclObjC.h:508
TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument.
Definition: ASTReader.cpp:9206
const TemplateArgument & getArg(unsigned Idx) const
Definition: TemplateBase.h:700
bool isNull() const
Definition: TypeLoc.h:118
Record code for floating point #pragma options.
Definition: ASTBitCodes.h:552
CommentRecordTypes
Record types used within a comments block.
Definition: ASTBitCodes.h:784
Class that handles post-update expression for some clauses, like &#39;lastprivate&#39;, &#39;reduction&#39; etc...
Definition: OpenMPClause.h:143
Defines the Diagnostic-related interfaces.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1386
static internal_key_type ReadKey(const unsigned char *d, unsigned n)
Definition: ASTReader.cpp:898
CanQualType LongDoubleTy
Definition: ASTContext.h:1026
This represents &#39;default&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:853
void setMustBuildLookupTable()
Mark that there are external lexical declarations that we need to include in our lookup table (and th...
Definition: DeclBase.h:2328
void addExternalSource(ExternalSemaSource *E)
Registers an external source.
Definition: Sema.cpp:417
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition: Module.h:222
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:137
Wrapper for source info for ObjC interfaces.
Definition: TypeLoc.h:1051
Record code for the set of known namespaces, which are used for typo correction.
Definition: ASTBitCodes.h:562
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6142
static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps)
Definition: ASTReader.cpp:2390
b
Definition: emmintrin.h:321
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
Definition: ASTReader.cpp:8025
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:583
This represents &#39;final&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:522
This represents &#39;mergeable&#39; clause in the &#39;#pragma omp ...&#39; directive.
The &#39;unsigned short&#39; type.
Definition: ASTBitCodes.h:819
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
Definition: Module.h:415
Present this diagnostic as an error.
const Expr * getInitExpr() const
Definition: Decl.h:2838
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:207
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:828
A BlockPointerType record.
Definition: ASTBitCodes.h:1047
void setProtocolLoc(unsigned i, SourceLocation Loc)
Definition: TypeLoc.h:990
A MemberPointerType record.
Definition: ASTBitCodes.h:1056
ContinuousRangeMap< uint32_t, int, 2 > SLocRemap
Remapping table for source locations in this module.
Definition: Module.h:260
unsigned NumVars
Number of expressions listed.
The &#39;_Sat short _Fract&#39; type.
Definition: ASTBitCodes.h:996
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:957
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo >> &WI) override
Definition: ASTReader.cpp:8668
This represents clause &#39;is_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1385
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag)
Definition: ASTReader.cpp:6089
Represents an ObjC class declaration.
Definition: DeclObjC.h:1171
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:3915
The AST file itself appears corrupted.
Definition: ASTReader.h:386
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:8173
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3785
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 >> &Exprs) override
Definition: ASTReader.cpp:8581
static ASTFileSignature readASTFileSignature(StringRef PCH)
Reads and return the signature record from PCH&#39;s control block, or else returns 0.
Definition: ASTReader.cpp:4876
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:50
A DependentSizedExtVectorType record.
Definition: ASTBitCodes.h:1170
The type of &#39;nullptr&#39;.
Definition: ASTBitCodes.h:873
uint64_t PreprocessorDetailStartOffset
The offset of the start of the preprocessor detail cursor.
Definition: Module.h:326
The &#39;_Sat unsigned long _Fract&#39; type.
Definition: ASTBitCodes.h:1011
CanQualType UnsignedCharTy
Definition: ASTContext.h:1024
Record code for the table of offsets into the block of source-location information.
Definition: ASTBitCodes.h:484
void setAttrNameLoc(SourceLocation loc)
Definition: TypeLoc.h:1704
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:877
void setKWLoc(SourceLocation Loc)
Definition: TypeLoc.h:1908
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.h:212
A SubstTemplateTypeParmPackType record.
Definition: ASTBitCodes.h:1143
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:9590
TypeCode
Record codes for each kind of type.
Definition: ASTBitCodes.h:1036
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:173
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:1602
Class that aids in the construction of nested-name-specifiers along with source-location information ...
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
Definition: FixedPoint.h:95
void getExportedModules(SmallVectorImpl< Module *> &Exported) const
Appends this module&#39;s list of exported modules to Exported.
Definition: Module.cpp:339
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
Definition: Module.h:232
The block containing information about the source manager.
Definition: ASTBitCodes.h:252
NodeId Parent
Definition: ASTDiff.cpp:191
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:930
A VariableArrayType record.
Definition: ASTBitCodes.h:1065
This represents &#39;dynamic_allocators&#39; clause in the &#39;#pragma omp requires&#39; directive.
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:2008
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:328
const unsigned int NUM_PREDEF_PP_ENTITY_IDS
The number of predefined preprocessed entity IDs.
Definition: ASTBitCodes.h:241
StringRef getString() const
Definition: Expr.h:1764
void setUsedForHeaderGuard(bool Val)
Definition: MacroInfo.h:273
ASTRecordTypes
Record types that occur within the AST block itself.
Definition: ASTBitCodes.h:389
HashTableTy::const_iterator iterator
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1045
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:4649
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement into a statement.
Definition: ASTReader.cpp:7841
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition: Decl.h:668
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3719
Defines the major attributes of a submodule, including its name and parent.
Definition: ASTBitCodes.h:724
llvm::BitstreamCursor Stream
The main bitstream cursor for the main block.
Definition: Module.h:190
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:867
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:427
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:231
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:688
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:123
This represents clause &#39;aligned&#39; in the &#39;#pragma omp ...&#39; directives.
ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, unsigned PriorGeneration)
Definition: ASTReader.cpp:8449
ModuleKind
Specifies the kind of module that has been loaded.
Definition: Module.h:42
StringRef Filename
Definition: Format.cpp:1711
A table of skipped ranges within the preprocessing record.
Definition: ASTBitCodes.h:650
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:215
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:572
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:75
bool isValid() const
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2850
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:1524
unsigned LocalNumSLocEntries
The number of source location entries in this AST file.
Definition: Module.h:244
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:24
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2158
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:9728
ArrayRef< ObjCMethodDecl * > getInstanceMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:8488
Record code for the table of offsets of each macro ID.
Definition: ASTBitCodes.h:600
const DirectoryEntry * Entry
Definition: Module.h:168
CanQualType UnsignedAccumTy
Definition: ASTContext.h:1029
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:451
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo)
Definition: ASTReader.cpp:2079
unsigned getNumLoops() const
Get number of loops associated with the clause.
unsigned Offset
Definition: Format.cpp:1713
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2134
__v2du d
Definition: emmintrin.h:413
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:1031
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1499
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
Definition: ASTReader.cpp:9631
ASTReaderListener implementation to validate the information of the PCH file against an initialized P...
Definition: ASTReader.h:288
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:189
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:236
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:436
Specifies some declarations with initializers that must be emitted to initialize the module...
Definition: ASTBitCodes.h:776
An TemplateSpecializationType record.
Definition: ASTBitCodes.h:1122
An ObjCObjectPointerType record.
Definition: ASTBitCodes.h:1098
File is from a prebuilt module path.
Definition: Module.h:59
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:7443
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2377
Type source information for an attributed type.
Definition: TypeLoc.h:851
An ObjCInterfaceType record.
Definition: ASTBitCodes.h:1095
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:2106
HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override
Read the header file information for the given file entry.
Definition: ASTReader.cpp:6080
This represents &#39;proc_bind&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:933
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:671
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:108
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Definition: ASTReader.cpp:8944
Defines the clang::LangOptions interface.
SourceLocation getEnd() const
Definition: ASTBitCodes.h:195
SourceLocation End
Record code for the array of VTable uses.
Definition: ASTBitCodes.h:505
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:813
void setHasCommaPasting()
Definition: MacroInfo.h:218
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:88
void setModeAttr(bool written)
Definition: TypeLoc.h:648
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
Definition: ASTReader.cpp:9654
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:8878
The directory that the PCH was originally created in.
Definition: ASTBitCodes.h:315
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3556
int Id
Definition: ASTDiff.cpp:190
This represents &#39;simdlen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:726
The &#39;_Sat long _Fract&#39; type.
Definition: ASTBitCodes.h:1002
QualType getCanonicalTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args) const
Declaration of a template type parameter.
unsigned NumComponentLists
Number of component lists.
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:265
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
Definition: ASTReader.cpp:8688
The placeholder type for overloaded function sets.
Definition: ASTBitCodes.h:861
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:5120
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:67
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
Definition: ASTReader.h:238
Inits[]
Definition: OpenMPClause.h:150
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:261
QualType getTypeOfExprType(Expr *e) const
GCC extension.
Record code for the table of offsets to entries in the preprocessing record.
Definition: ASTBitCodes.h:502
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2838
ContinuousRangeMap< uint32_t, int, 2 > IdentifierRemap
Remapping table for identifier IDs in this module.
Definition: Module.h:278
Expected< unsigned > readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID)
Reads a record with id AbbrevID from Cursor, resetting the internal state.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
QualType getParenType(QualType NamedType) const
CanQualType OMPArraySectionTy
Definition: ASTContext.h:1053
llvm::BitstreamCursor SLocEntryCursor
Cursor used to read source location entries.
Definition: Module.h:241
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:131
Defines version macros and version-related utility functions for Clang.
The OpenCL &#39;half&#39; / ARM NEON __fp16 type.
Definition: ASTBitCodes.h:903
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:558
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:729
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3552
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:53
The block containing the detailed preprocessing record.
Definition: ASTBitCodes.h:263
ASTReaderListenter implementation to set SuggestedPredefines of ASTReader which is required to use a ...
Definition: ASTReader.h:317
Record code for #pragma diagnostic mappings.
Definition: ASTBitCodes.h:369
#define bool
Definition: stdbool.h:15
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:1581
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:242
DeclContext * getDeclContext()
Definition: DeclBase.h:438
static LineEntry get(unsigned Offs, unsigned Line, int Filename, SrcMgr::CharacteristicKind FileKind, unsigned IncludeOffset)
void setWrittenSignSpec(TypeSpecifierSign written)
Definition: TypeLoc.h:609
llvm::BitstreamCursor InputFilesCursor
The cursor to the start of the input-files block.
Definition: Module.h:220
unsigned LocalNumMacros
The number of macros in this AST file.
Definition: Module.h:301
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a source range.
Definition: ASTReader.cpp:9504
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1502
CanQualType ShortTy
Definition: ASTContext.h:1023
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:312
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2366
TypedefDecl * getInt128Decl() const
Retrieve the declaration for the 128-bit signed integer type.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2271
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
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:342
void clear(SanitizerMask K=SanitizerKind::All)
Disable the sanitizers specified in K.
Definition: Sanitizers.h:167
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:551
QualType getLocalType(ModuleFile &F, unsigned LocalID)
Resolve a local type ID within a given AST file into a type.
Definition: ASTReader.cpp:7438
Information about a module that has been loaded by the ASTReader.
Definition: Module.h:107
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:190
This represents &#39;ordered&#39; clause in the &#39;#pragma omp ...&#39; directive.
The &#39;long double&#39; type.
Definition: ASTBitCodes.h:858
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:366
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:60
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
Definition: ASTReader.cpp:209
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1025
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:442
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1064
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1823
FileID OriginalSourceFileID
The file ID for the original source file that was used to build this AST file.
Definition: Module.h:145
A FunctionProtoType record.
Definition: ASTBitCodes.h:1077
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:157
Describes a source location entry (SLocEntry) for a file.
Definition: ASTBitCodes.h:657
Wrapper for source info for enum types.
Definition: TypeLoc.h:726
A block containing a module file extension.
Definition: ASTBitCodes.h:290
bool isIdentifier() const
Predicate functions for querying what type of name this is.
void setMapperIdInfo(DeclarationNameInfo MapperId)
Set the name of associated user-defined mapper.
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:122
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:1095
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2215
Record code for an update to a decl context&#39;s lookup table.
Definition: ASTBitCodes.h:532
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition: TypeLoc.h:748
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition: TypeLoc.h:1009
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:626
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:421
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:1382
struct CXXOpName CXXOperatorName
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation >> &Pending) override
Definition: ASTReader.cpp:8700
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:1032
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:385
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:791
This represents clause &#39;firstprivate&#39; in the &#39;#pragma omp ...&#39; directives.
static OMPIsDevicePtrClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
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:3970
Selector getSelector() const
Definition: DeclObjC.h:320
Information about a header directive as found in the module map file.
Definition: Module.h:157
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:1398
The result type of a method or function.
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1911
unsigned SLocEntryBaseOffset
The base offset in the source manager&#39;s view of this module.
Definition: Module.h:250
Record code for the table of offsets of each identifier ID.
Definition: ASTBitCodes.h:422
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2046
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:708
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:609
void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9118
A DependentNameType record.
Definition: ASTBitCodes.h:1125
const SourceManager & SM
Definition: Format.cpp:1572
unsigned MajorVersion
The major version of the extension data.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:264
CanQualType SignedCharTy
Definition: ASTContext.h:1023
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:441
The &#39;_Sat unsigned long _Accum&#39; type.
Definition: ASTBitCodes.h:993
The AST file was missing.
Definition: ASTReader.h:389
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:9385
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:894
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:152
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType)
In-memory cache for modules.
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:3989
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:36
void setStarLoc(SourceLocation Loc)
Definition: TypeLoc.h:1275
std::vector< std::unique_ptr< ModuleFileExtensionReader > > ExtensionReaders
The list of extension readers that are attached to this module file.
Definition: Module.h:211
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:137
void setTypeofLoc(SourceLocation Loc)
Definition: TypeLoc.h:1815
SanitizerMask getPPTransparentSanitizers()
Return the sanitizers which do not affect preprocessing.
Definition: Sanitizers.h:185
The Objective-C &#39;Class&#39; type.
Definition: ASTBitCodes.h:1236
This represents &#39;unified_address&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
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:789
void setPostUpdateExpr(Expr *S)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:155
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:171
void makeNamesVisible(const HiddenNames &Names, Module *Owner)
Make the names within this set of hidden names visible.
Definition: ASTReader.cpp:3926
The &#39;_Sat short _Accum&#39; type.
Definition: ASTBitCodes.h:978
StringRef Next() override
Retrieve the next string in the identifier table and advances the iterator for the following string...
Definition: ASTReader.cpp:8368
The &#39;unsigned long long&#39; type.
Definition: ASTBitCodes.h:828
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:224
Wrapper for source info for arrays.
Definition: TypeLoc.h:1495
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:492
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:661
CanQualType OverloadTy
Definition: ASTContext.h:1043
This represents &#39;num_teams&#39; clause in the &#39;#pragma omp ...&#39; directive.
The control block was read successfully.
Definition: ASTReader.h:383
The list of delegating constructor declarations.
Definition: ASTBitCodes.h:558
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:939
Record code for types associated with OpenCL extensions.
Definition: ASTBitCodes.h:636
static bool readBit(unsigned &Bits)
Definition: ASTReader.cpp:914
void setIsFunctionLike()
Function/Object-likeness.
Definition: MacroInfo.h:198
unsigned isModuleHeader
Whether this header is part of a module.
Definition: HeaderSearch.h:68
const unsigned char * SelectorLookupTableData
A pointer to the character data that comprises the selector table.
Definition: Module.h:391
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Definition: MacroInfo.h:290
bool ReadFullVersionInformation(StringRef FullVersion) override
Receives the full Clang version information.
Definition: ASTReader.cpp:145
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:84
#define false
Definition: stdbool.h:17
serialization::TypeID BaseTypeIndex
Base type ID for types local to this module as represented in the global type ID space.
Definition: Module.h:455
CanQualType BuiltinFnTy
Definition: ASTContext.h:1044
ContinuousRangeMap< uint32_t, int, 2 > SelectorRemap
Remapping table for selector IDs in this module.
Definition: Module.h:386
static FixedPointSemantics ReadFixedPointSemantics(const SmallVectorImpl< uint64_t > &Record, unsigned &Idx)
Definition: ASTReader.cpp:9512
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:42
void setASTFile(const FileEntry *File)
Set the serialized AST file for the top-level module of this module.
Definition: Module.h:477
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3775
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:8736
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2142
serialization::IdentID BaseIdentifierID
Base identifier ID for identifiers local to this module.
Definition: Module.h:275
MacroInfo * ReadMacroRecord(ModuleFile &F, uint64_t Offset)
Reads the macro record located at the given offset.
Definition: ASTReader.cpp:1665
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:8560
File is a PCH file treated as the preamble.
Definition: Module.h:53
std::string getTimestampFilename() const
Definition: Module.h:130
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:3898
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3806
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:1008
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:2023
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:83
CanQualType UnsignedLongAccumTy
Definition: ASTContext.h:1029
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1394
File is a PCH file treated as such.
Definition: Module.h:50
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:292
CanQualType Int128Ty
Definition: ASTContext.h:1023
IdentifierInfo * get(StringRef Name) override
Retrieve the IdentifierInfo for the named identifier.
Definition: ASTReader.cpp:8296
void setLength(unsigned Len)
Definition: Token.h:135
Specifies a library or framework to link against.
Definition: ASTBitCodes.h:755
Record code for file ID of the file or buffer that was used to generate the AST file.
Definition: ASTBitCodes.h:319
Represents a C++ temporary.
Definition: ExprCXX.h:1250
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5808
void InitializeContext()
Initializes the ASTContext.
Definition: ASTReader.cpp:4731
Specifies a header that falls into this (sub)module.
Definition: ASTBitCodes.h:731
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:114
ContinuousRangeMap< uint32_t, int, 2 > SubmoduleRemap
Remapping table for submodule IDs in this module.
Definition: Module.h:369
void setUsed(bool Used=true)
Definition: Weak.h:35
Record code for special CUDA declarations.
Definition: ASTBitCodes.h:546
Options for controlling the compiler diagnostics engine.
A list of "interesting" identifiers.
Definition: ASTBitCodes.h:605
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition: Module.h:281
This structure contains all sizes needed for by an OMPMappableExprListClause.
An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files...
Definition: ASTReader.cpp:8335
void setProtocolLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:774
The block of configuration options, used to check that a module is being used in a configuration comp...
Definition: ASTBitCodes.h:287
CanQualType SatFractTy
Definition: ASTContext.h:1035
DeclarationName getName() const
getName - Returns the embedded declaration name.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3097
This represents &#39;schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
PredefinedTypeIDs
Predefined type IDs.
Definition: ASTBitCodes.h:802
All of the names in this module are hidden.
Definition: Module.h:275
File is an implicitly-loaded module.
Definition: Module.h:44
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:623
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:22
This represents clause &#39;shared&#39; in the &#39;#pragma omp ...&#39; directives.
void setProtocolRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:977
The &#39;unsigned char&#39; type.
Definition: ASTBitCodes.h:816
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2754
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
Definition: Module.h:476
ObjCInterfaceDecl * getObjCProtocolDecl() const
Retrieve the Objective-C class declaration corresponding to the predefined Protocol class...
Metadata describing this particular extension.
Definition: ASTBitCodes.h:375
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:203
MacroInfo * getMacro(serialization::MacroID ID)
Retrieve the macro with the given ID.
Definition: ASTReader.cpp:8852
uint64_t SizeInBits
The size of this file, in bits.
Definition: Module.h:181
TemplateParameterList * ReadTemplateParameterList(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template parameter list.
Definition: ASTReader.cpp:9261
An ObjCTypeParamType record.
Definition: ASTBitCodes.h:1164
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:43
The (signed) &#39;long&#39; type.
Definition: ASTBitCodes.h:846
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2114
ModuleReverseIterator rbegin()
Reverse iterator to traverse all loaded modules.
Record code for the offsets of each decl.
Definition: ASTBitCodes.h:414
SourceLocation getFriendLoc() const
Retrieves the location of the &#39;friend&#39; keyword.
Definition: DeclFriend.h:143
void setIdentifierInfo(IdentifierInfo *II)
Definition: Token.h:188
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
Definition: ASTReader.cpp:8518
void * SelectorLookupTable
A pointer to an on-disk hash table of opaque type ASTSelectorLookupTable.
Definition: Module.h:398
Metadata for submodules as a whole.
Definition: ASTBitCodes.h:720
void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL)
Set the nested name specifier of associated user-defined mapper.
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...
static std::pair< GlobalModuleIndex *, llvm::Error > readIndex(llvm::StringRef Path)
Read a global index file for the given directory.
const uint32_t * IdentifierOffsets
Offsets into the identifier table data.
Definition: Module.h:272
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:89
Record code for late parsed template functions.
Definition: ASTBitCodes.h:612
CanQualType FloatTy
Definition: ASTContext.h:1026
const FileEntry * Entry
Definition: Module.h:159
A dependentSizedVectorType record.
Definition: ASTBitCodes.h:1176
The (signed) &#39;short&#39; type.
Definition: ASTBitCodes.h:840
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:2312
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
Definition: MacroInfo.h:126
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4013
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:134
CanQualType SatUnsignedLongAccumTy
Definition: ASTContext.h:1033
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:55
The &#39;_Sat _Accum&#39; type.
Definition: ASTBitCodes.h:981
unsigned LocalNumDecls
The number of declarations in this AST file.
Definition: Module.h:408
void setUpgradedFromWarning(bool Value)
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:50
SourceRange ReadSkippedRange(unsigned Index) override
Read a preallocated skipped range from the external source.
Definition: ASTReader.cpp:5797
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2343
The internal &#39;instancetype&#39; typedef.
Definition: ASTBitCodes.h:1248
CanQualType VoidTy
Definition: ASTContext.h:1014
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3553
OptionsRecordTypes
Record types that occur within the options block inside the control block.
Definition: ASTBitCodes.h:338
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:88
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1856
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
CanQualType Float16Ty
Definition: ASTContext.h:1039
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:2047
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:7669
CanQualType SatLongFractTy
Definition: ASTContext.h:1035
The AST block, which acts as a container around the full AST block.
Definition: ASTBitCodes.h:248
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1384
ArrayRef< ObjCMethodDecl * > getFactoryMethods() const
Retrieve the instance methods found by this visitor.
Definition: ASTReader.cpp:8493
void setVarRefs(ArrayRef< Expr *> VL)
Sets the list of variables for this clause.
Definition: OpenMPClause.h:213
IdentID ReadIdentifierID(const unsigned char *d)
Definition: ASTReader.cpp:920
A DeducedTemplateSpecializationType record.
Definition: ASTBitCodes.h:1167
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2094
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:702
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:85
void setWrittenTypeSpec(TypeSpecifierType written)
Definition: TypeLoc.h:636
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:51
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:3861
void setAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1335
UnhashedControlBlockRecordTypes
Record codes for the unhashed control block.
Definition: ASTBitCodes.h:361
llvm::SetVector< ModuleFile * > ImportedBy
List of modules which depend on this module.
Definition: Module.h:466
void setLBracketLoc(SourceLocation Loc)
Definition: TypeLoc.h:1504
void dump()
Dump debugging output for this module.
Definition: Module.cpp:47
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:1113
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:8766
const serialization::DeclID * FileSortedDecls
Array of file-level DeclIDs sorted by file.
Definition: Module.h:430
Record code for the extra statistics we gather while generating an AST file.
Definition: ASTBitCodes.h:464
static Decl * getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID)
Definition: ASTReader.cpp:7706
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1992
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:2053
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3882
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:235
std::vector< InputFile > InputFilesLoaded
The input files that have been loaded from this AST file.
Definition: Module.h:226
CanQualType SatUnsignedFractTy
Definition: ASTContext.h:1036
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:168
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:9041
The &#39;signed char&#39; type.
Definition: ASTBitCodes.h:834
unsigned LocalNumSubmodules
The number of submodules in this module.
Definition: Module.h:363
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:246
The AST file was writtten with a different language/target configuration.
Definition: ASTReader.h:400
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C)
CanQualType SatUnsignedShortFractTy
Definition: ASTContext.h:1036
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:9025
const char * HeaderFileInfoTableData
Actual data for the on-disk hash table of header file information.
Definition: Module.h:354
void markIdentifierUpToDate(IdentifierInfo *II)
Note that this identifier is up-to-date.
Definition: ASTReader.cpp:2068
const llvm::support::unaligned_uint64_t * InputFileOffsets
Offsets for all of the input file entries in the AST file.
Definition: Module.h:223
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:594
Record code for the signature that identifiers this AST file.
Definition: ASTBitCodes.h:363
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
Definition: ModuleMap.cpp:1175
File is a PCH file treated as the actual main file.
Definition: Module.h:56
llvm::APFloat ReadAPFloat(const RecordData &Record, const llvm::fltSemantics &Sem, unsigned &Idx)
Read a floating-point value.
Definition: ASTReader.cpp:9583
Record code for referenced selector pool.
Definition: ASTBitCodes.h:510
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
Definition: Module.h:65
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:461
std::vector< std::string > MacroIncludes
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2654
CanQualType SatAccumTy
Definition: ASTContext.h:1032
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:5048
ModuleFile * getLocalModuleFile(ModuleFile &M, unsigned ID)
Retrieve the module file with a given local ID within the specified ModuleFile.
Definition: ASTReader.cpp:8931
Record code for the set of non-builtin, special types.
Definition: ASTBitCodes.h:460
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:1401
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:672
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1595
SourceLocation getBegin() const
Definition: ASTBitCodes.h:211
StringRef getName() const
Return the actual identifier string.
void setTypeArgsLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:939
uint64_t InputFilesValidationTimestamp
If non-zero, specifies the time when we last validated input files.
Definition: Module.h:236
CanQualType UnsignedShortTy
Definition: ASTContext.h:1024
const uint32_t * MacroOffsets
Offsets of macros in the preprocessor block.
Definition: Module.h:308
The ObjC &#39;id&#39; type.
Definition: ASTBitCodes.h:882
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:2949
unsigned LocalNumSelectors
The number of selectors new to this file.
Definition: Module.h:376
unsigned getObjCOrBuiltinID() const
const PPSkippedRange * PreprocessedSkippedRangeOffsets
Definition: Module.h:341
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
CanQualType CharTy
Definition: ASTContext.h:1016
unsigned ControllingMacroID
The ID number of the controlling macro.
Definition: HeaderSearch.h:97
Represents a template argument.
Definition: TemplateBase.h:50
Record code for the list of other AST files imported by this AST file.
Definition: ASTBitCodes.h:307
Selector getLocalSelector(ModuleFile &M, unsigned LocalID)
Retrieve a selector from the given module with its local ID number.
Definition: ASTReader.cpp:8986
Describes a macro definition within the preprocessing record.
Definition: ASTBitCodes.h:710
const ASTTemplateArgumentListInfo * ReadASTTemplateArgumentListInfo(ModuleFile &F, const RecordData &Record, unsigned &Index)
Definition: ASTReader.cpp:7511
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
A conflict between two modules.
Definition: Module.h:366
void setClassTInfo(TypeSourceInfo *TI)
Definition: TypeLoc.h:1287
bool ReadSLocEntry(int ID) override
Read the source location entry with index ID.
Definition: ASTReader.cpp:1408
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:1266
Record code for the module name.
Definition: ASTBitCodes.h:326
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:153
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:948
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1046
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:2375
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:836
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:714
The internal &#39;__builtin_ms_va_list&#39; typedef.
Definition: ASTBitCodes.h:1257
llvm::BitstreamCursor DeclsCursor
DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.
Definition: Module.h:405
unsigned IsMissingRequirement
Whether this module is missing a feature from Requirements.
Definition: Module.h:210
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:498
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:1271
Record code for a file sorted array of DeclIDs in a module.
Definition: ASTBitCodes.h:579
void setAmpAmpLoc(SourceLocation Loc)
Definition: TypeLoc.h:1349
CanQualType NullPtrTy
Definition: ASTContext.h:1042
Record code for the array of Objective-C categories (including extensions).
Definition: ASTBitCodes.h:593
void updateOutOfDateIdentifier(IdentifierInfo &II) override
Update an out-of-date identifier.
Definition: ASTReader.cpp:2043
void reserve(ASTContext &C, unsigned N)
Specifies a configuration macro for this module.
Definition: ASTBitCodes.h:758
void ReadDefinedMacros() override
Read the set of macros defined by this external macro source.
Definition: ASTReader.cpp:1925
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:403
static std::string getName(const CallEvent &Call)
PreprocessorDetailRecordTypes
Record types used within a preprocessor detail block.
Definition: ASTBitCodes.h:705
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
static unsigned moduleKindForDiagnostic(ModuleKind Kind)
Definition: ASTReader.cpp:4350
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:27
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:317
CanQualType UnsignedShortAccumTy
Definition: ASTContext.h:1029
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:79
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:2192
Record code for the array of unused file scoped decls.
Definition: ASTBitCodes.h:498
A FunctionNoProtoType record.
Definition: ASTBitCodes.h:1074
off_t getSize() const
Definition: FileManager.h:86
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:987
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:4049
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:354
File is an explicitly-loaded module.
Definition: Module.h:47
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2858
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:430
QualType getUnderlyingType() const
Definition: Decl.h:3004
Interesting information about a specific parameter that can&#39;t simply be reflected in parameter&#39;s type...
Definition: Type.h:3413
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1025
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:1219
AccessSpecifier getAccess() const
Definition: DeclBase.h:473
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:984
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl *> &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
Definition: ASTReader.cpp:8628
The name of a declaration.
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:558
Record code for the Objective-C method pool,.
Definition: ASTBitCodes.h:476
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:294
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:139
Kind getKind() const
Definition: DeclBase.h:432
Specifies a header that is private to this submodule.
Definition: ASTBitCodes.h:764
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:108
Describes a macro expansion within the preprocessing record.
Definition: ASTBitCodes.h:707
This represents &#39;unified_shared_memory&#39; clause in the &#39;#pragma omp requires&#39; directive.
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:3359
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:4029
IdentifierTable & getIdentifierTable()
Retrieve the identifier table associated with the preprocessor.
Definition: ASTReader.cpp:9641
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
IdentifierResolver IdResolver
Definition: Sema.h:872
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:314
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
An RValueReferenceType record.
Definition: ASTBitCodes.h:1053
void ReadDeclarationNameLoc(ModuleFile &F, DeclarationNameLoc &DNLoc, DeclarationName Name, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9085
void setLocStart(SourceLocation Loc)
Sets the starting location of the clause.
Definition: OpenMPClause.h:72
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
void ClearSwitchCaseIDs()
Definition: ASTReader.cpp:9659
unsigned NumUniqueDeclarations
Number of unique base declarations.
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:774
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:68
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:8712
An AtomicType record.
Definition: ASTBitCodes.h:1152
static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, ASTConsumer *Consumer)
Under non-PCH compilation the consumer receives the objc methods before receiving the implementation...
Definition: ASTReader.cpp:8034
The placeholder type for dependent types.
Definition: ASTBitCodes.h:864
All of the names in this module are visible.
Definition: Module.h:277
unsigned getNumParams() const
Definition: TypeLoc.h:1437
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2057
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:633
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map...
Definition: Module.h:269
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
Decl * GetExternalDecl(uint32_t ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:7523
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:3789
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, const RecordData &Record, unsigned &Idx)
Read a UnresolvedSet structure.
Definition: ASTReader.cpp:9291
struct CXXLitOpName CXXLiteralOperatorName
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:126
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:69
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4438
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
BuiltinTemplateDecl * getTypePackElementDecl() const
CanQualType UnknownAnyTy
Definition: ASTContext.h:1043
The &#39;unsigned _Fract&#39; type.
Definition: ASTBitCodes.h:972
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:375
NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:9440
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
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:6017
Record code for the table of offsets into the Objective-C method pool.
Definition: ASTBitCodes.h:473
Defines the clang::FileSystemOptions interface.
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2346
ContinuousRangeMap< unsigned, int, 2 > SLocRemap
Definition: ASTUnit.cpp:2353
A DependentSizedArrayType record.
Definition: ASTBitCodes.h:1131
CanQualType UnsignedLongTy
Definition: ASTContext.h:1024
Record code for the remapping information used to relate loaded modules to the various offsets and ID...
Definition: ASTBitCodes.h:568
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
Definition: TemplateBase.h:694
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:134
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:2080
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:519
void ReadTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument array.
Definition: ASTReader.cpp:9281
CanQualType DependentTy
Definition: ASTContext.h:1043
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1957
void * HeaderFileInfoTable
The on-disk hash table that contains information about each of the header files.
Definition: Module.h:358
CanQualType WCharTy
Definition: ASTContext.h:1017
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:150
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:9743
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:503
Offsets into the input-files block where input files reside.
Definition: ASTBitCodes.h:323
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
Definition: ASTReader.cpp:161
CanQualType ObjCBuiltinClassTy
Definition: ASTContext.h:1046
void setUDMapperRefs(ArrayRef< Expr *> DMDs)
Set the user-defined mappers that are in the trailing objects of the class.
unsigned getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.h:706
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:1737
PreprocessorRecordTypes
Record types used within a preprocessor block.
Definition: ASTBitCodes.h:679
static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags)
Definition: ASTReader.cpp:486
CanQualType BoundMemberTy
Definition: ASTContext.h:1043
SourceLocation getEnd() const
Definition: ASTBitCodes.h:214
The block containing the submodule structure.
Definition: ASTBitCodes.h:266
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:947
void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx, TypeLoc TL)
Raad the type locations for the given TInfo.
Definition: ASTReader.cpp:7169
Wrapper for source info for record types.
Definition: TypeLoc.h:718
std::string BaseDirectory
The base directory of the module.
Definition: Module.h:128
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1914
unsigned CalculateHash()
Definition: ODRHash.cpp:204
The template argument is a type.
Definition: TemplateBase.h:59
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
PragmaMSStructKind
Definition: PragmaKinds.h:23
Wraps an ObjCPointerType with source location information.
Definition: TypeLoc.h:1305
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:238
Holds information about the various types of exception specification.
Definition: Type.h:3773
ContinuousRangeMap< uint32_t, int, 2 > TypeRemap
Remapping table for type IDs in this module.
Definition: Module.h:458
Selector DecodeSelector(serialization::SelectorID Idx)
Definition: ASTReader.cpp:8990
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:90
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
Definition: ASTReader.h:1661
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
Definition: Module.h:330
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:76
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:45
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
Definition: ASTReader.cpp:9019
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:8061
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:3778
Keeps track of options that affect how file operations are performed.
CanQualType Char8Ty
Definition: ASTContext.h:1020
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:111
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2280
static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID)
ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the specified cursor.
Definition: ASTReader.cpp:1618
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
Definition: ASTReader.cpp:7188
A template argument list.
Definition: DeclTemplate.h:214
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:240
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1657
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
ExternCContextDecl * getExternCContextDecl() const
IdentifierInfo * DecodeIdentifierInfo(serialization::IdentifierID ID)
Definition: ASTReader.cpp:8798
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:3781
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:662
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
Definition: ASTReader.h:182
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:234
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:2255
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:1007
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:495
The C++ &#39;char16_t&#39; type.
Definition: ASTBitCodes.h:876
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:7498
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2682
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:246
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:7462
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:9015
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:7825
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.h:216
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl *> &Decls) override
Read the set of unused file-scope declarations known to the external Sema source. ...
Definition: ASTReader.cpp:8606
An TemplateTypeParmType record.
Definition: ASTBitCodes.h:1119
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:75
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:929
SmallVector< uint64_t, 8 > PragmaDiagMappings
Diagnostic IDs and their mappings that the user changed.
Definition: Module.h:463
Record code for the filesystem options table.
Definition: ASTBitCodes.h:351
static OMPMapClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars original expressions, NumUniqueDeclarations declar...
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:1652
const char * IdentifierTableData
Actual data for the on-disk hash table of identifiers.
Definition: Module.h:284
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1444
There is no such object (it&#39;s outside its lifetime).
Definition: APValue.h:82
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:412
CanQualType Char16Ty
Definition: ASTContext.h:1021
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:152
static DiagnosticMapping deserialize(unsigned Bits)
Deserialize a mapping.
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
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:981
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1136
ASTImporterLookupTable & LT
const DeclOffset * DeclOffsets
Offset of each declaration within the bitstream, indexed by the declaration ID (-1).
Definition: Module.h:412
Location information for a TemplateArgument.
Definition: TemplateBase.h:392
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
Definition: ASTReader.h:154
Declaration of a class template.
Record code for the offsets of each type.
Definition: ASTBitCodes.h:402
A DependentAddressSpaceType record.
Definition: ASTBitCodes.h:1173
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:2936
The block containing the definitions of all of the types and decls used within the AST file...
Definition: ASTBitCodes.h:260
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:1254
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:60
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
virtual void ReadModuleName(StringRef ModuleName)
Definition: ASTReader.h:138
TypedefDecl * getObjCClassDecl() const
Retrieve the typedef declaration corresponding to the predefined Objective-C &#39;Class&#39; type...
static OMPFromClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:251
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:8363
void resolveLinkAsDependencies(Module *Mod)
Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...
Definition: ModuleMap.cpp:58
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:780
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1681
Defines the clang::TargetInfo interface.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:689
void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion=OMPD_unknown)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:122
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition: ASTReader.h:393
TypeLocReader(ModuleFile &F, ASTReader &Reader, const ASTReader::RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:6867
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:273
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition: MacroInfo.h:325
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1914
The (signed) &#39;int&#39; type.
Definition: ASTBitCodes.h:843
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:3751
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1611
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
std::pair< ObjCMethodList, ObjCMethodList > GlobalMethods
Definition: Sema.h:1200
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:91
Specifies a required feature.
Definition: ASTBitCodes.h:748
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:7687
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:350
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:24
SourceRange getSourceRange() const override LLVM_READONLY
Retrieves the source range for the friend declaration.
Definition: DeclFriend.h:148
unsigned getNumTypeArgs() const
Definition: TypeLoc.h:951
CanQualType IntTy
Definition: ASTContext.h:1023
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:396
Record for offsets of DECL_UPDATES records for declarations that were modified after being deserializ...
Definition: ASTBitCodes.h:536
unsigned ModuleMapFileHomeIsCwd
Set the &#39;home directory&#39; of a module map file to the current working directory (or the home directory...
a
Definition: emmintrin.h:320
static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool IsSystem, bool Complain)
Definition: ASTReader.cpp:493
result[0]
Definition: emmintrin.h:120
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:5030
llvm::BitstreamCursor PreprocessorDetailCursor
The cursor to the start of the (optional) detailed preprocessing record block.
Definition: Module.h:323
The C++ &#39;wchar_t&#39; type.
Definition: ASTBitCodes.h:837
The ObjC &#39;Class&#39; type.
Definition: ASTBitCodes.h:885
void setProtocolLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:969
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1162
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...
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false) const
C++11 deduced auto type.
unsigned IndexHeaderMapHeader
Whether this is a header inside a framework that is currently being built.
Definition: HeaderSearch.h:84
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:7679
unsigned IsValid
Whether this file has been looked up as a header.
Definition: HeaderSearch.h:87
static bool isWhitelistedDecl(const Decl *D, const DeclContext *Parent)
Definition: ODRHash.cpp:438
Record code for weak undeclared identifiers.
Definition: ASTBitCodes.h:522
The block containing information about the preprocessor.
Definition: ASTBitCodes.h:256
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:8051
QualType getDefaultArgument() const
Retrieve the default argument, if any.
void setLocation(SourceLocation L)
Definition: Token.h:134
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:647
Wrapper for source info for builtin types.
Definition: TypeLoc.h:546
#define true
Definition: stdbool.h:16
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1140
A set of overloaded template declarations.
Definition: TemplateName.h:203
Wrapper for template type parameters.
Definition: TypeLoc.h:734
Record code for the headers search options table.
Definition: ASTBitCodes.h:354
Module * Other
The module that this module conflicts with.
Definition: Module.h:368
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:164
This represents a decl that may have a name.
Definition: Decl.h:248
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
Definition: ASTContext.h:1766
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
Definition: ASTContext.h:1744
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:303
The block of input files, which were used as inputs to create this AST file.
Definition: ASTBitCodes.h:280
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:298
const uint32_t * SelectorOffsets
Offsets into the selector lookup table&#39;s data array where each selector resides.
Definition: Module.h:380
CanQualType BoolTy
Definition: ASTContext.h:1015
void UpdateSema()
Update the state of Sema after loading some additional modules.
Definition: ASTReader.cpp:8234
unsigned LocalNumTypes
The number of types in this AST file.
Definition: Module.h:447
Represents a C++ namespace alias.
Definition: DeclCXX.h:3156
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1635
Kind
The basic Objective-C runtimes that we know about.
Definition: ObjCRuntime.h:30
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:1269
static TypeIdx fromTypeID(TypeID ID)
Definition: ASTBitCodes.h:104
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:7808
InputFileRecordTypes
Record types that occur within the input-files block inside the control block.
Definition: ASTBitCodes.h:383
void FinishedDeserializing() override
Notify ASTReader that we finished the deserialization of a decl or type.
CanQualType DoubleTy
Definition: ASTContext.h:1026
A function-like macro definition.
Definition: ASTBitCodes.h:690
~ASTReader() override
The Objective-C &#39;Protocol&#39; type.
Definition: ASTBitCodes.h:1239
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:274
Wrapper for source info for pointers.
Definition: TypeLoc.h:1237
SourceLocation getBegin() const
const FileEntry * File
The file entry for the module file.
Definition: Module.h:163
The fast qualifier mask.
Definition: Type.h:183
unsigned NumComponents
Total number of expression components.
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:29
void setObjCOrBuiltinID(unsigned ID)
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:481
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1250
void ReadModuleName(StringRef ModuleName) override
Definition: ASTReader.cpp:150
The &#39;_Sat unsigned short _Fract&#39; type.
Definition: ASTBitCodes.h:1005
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:82
This class handles loading and caching of source files into memory.
static OMPToClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3805
PredefinedDeclIDs
Predefined declaration IDs.
Definition: ASTBitCodes.h:1222
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.
Record code for an update to the TU&#39;s lexically contained declarations.
Definition: ASTBitCodes.h:514
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3498
The &#39;_Sat _Fract&#39; type.
Definition: ASTBitCodes.h:999
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1978
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:220
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:43
bool isDeletedAsWritten() const
Definition: Decl.h:2167
SourceLocation getLocation() const
Definition: DeclBase.h:429
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:435
bool loadGlobalIndex()
Attempts to load the global index.
Definition: ASTReader.cpp:4004
void startToken()
Reset all flags to cleared.
Definition: Token.h:171
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
Definition: ASTReader.cpp:8922
Objective-C "Class" redefinition type.
Definition: ASTBitCodes.h:1204
A PackExpansionType record.
Definition: ASTBitCodes.h:1137
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
Definition: ASTReader.cpp:8638
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
A single template declaration.
Definition: TemplateName.h:200
CanQualType OCLClkEventTy
Definition: ASTContext.h:1051
The pseudo-object placeholder type.
Definition: ASTBitCodes.h:909
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:174
virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain)
Receives the diagnostic options.
Definition: ASTReader.h:164
void setUnderlyingTInfo(TypeSourceInfo *TI) const
Definition: TypeLoc.h:1880
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:250
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:629
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
Definition: ASTReader.cpp:9647
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:124
A DependentTemplateSpecializationType record.
Definition: ASTBitCodes.h:1128
CanQualType UnsignedIntTy
Definition: ASTContext.h:1024
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:8837
Record code for the array of tentative definitions.
Definition: ASTBitCodes.h:467
The &#39;__float128&#39; type.
Definition: ASTBitCodes.h:933
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.