aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp422
1 files changed, 216 insertions, 206 deletions
diff --git a/contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp b/contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp
index 4d439691ef83..1f68f6bc3e38 100644
--- a/contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp
+++ b/contrib/llvm-project/clang/lib/Serialization/ASTReader.cpp
@@ -390,8 +390,10 @@ static bool checkTargetOptions(const TargetOptions &TargetOpts,
// We can tolerate different CPUs in many cases, notably when one CPU
// supports a strict superset of another. When allowing compatible
// differences skip this check.
- if (!AllowCompatibleDifferences)
+ if (!AllowCompatibleDifferences) {
CHECK_TARGET_OPT(CPU, "target CPU");
+ CHECK_TARGET_OPT(TuneCPU, "tune CPU");
+ }
#undef CHECK_TARGET_OPT
@@ -1244,12 +1246,6 @@ void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
Diag(DiagID) << Arg1 << Arg2 << Arg3;
}
-void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
- unsigned Select) const {
- if (!Diags.isDiagnosticInFlight())
- Diag(DiagID) << Arg1 << Arg2 << Select;
-}
-
void ASTReader::Error(llvm::Error &&Err) const {
Error(toString(std::move(Err)));
}
@@ -1503,7 +1499,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
// we will also try to fail gracefully by setting up the SLocEntry.
unsigned InputID = Record[4];
InputFile IF = getInputFile(*F, InputID);
- const FileEntry *File = IF.getFile();
+ Optional<FileEntryRef> File = IF.getFile();
bool OverriddenBuffer = IF.isOverridden();
// Note that we only check if a File was returned. If it was out-of-date
@@ -1519,9 +1515,8 @@ bool ASTReader::ReadSLocEntry(int ID) {
}
SrcMgr::CharacteristicKind
FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
- // FIXME: The FileID should be created from the FileEntryRef.
- FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter,
- ID, BaseOffset + Record[0]);
+ FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID,
+ BaseOffset + Record[0]);
SrcMgr::FileInfo &FileInfo =
const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
FileInfo.NumCreatedFIDs = Record[5];
@@ -1536,15 +1531,15 @@ bool ASTReader::ReadSLocEntry(int ID) {
NumFileDecls));
}
- const SrcMgr::ContentCache *ContentCache
- = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
- if (OverriddenBuffer && !ContentCache->BufferOverridden &&
- ContentCache->ContentsEntry == ContentCache->OrigEntry &&
- !ContentCache->getRawBuffer()) {
+ const SrcMgr::ContentCache &ContentCache =
+ SourceMgr.getOrCreateContentCache(*File, isSystem(FileCharacter));
+ if (OverriddenBuffer && !ContentCache.BufferOverridden &&
+ ContentCache.ContentsEntry == ContentCache.OrigEntry &&
+ !ContentCache.getBufferIfLoaded()) {
auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
if (!Buffer)
return true;
- SourceMgr.overrideFileContents(File, std::move(Buffer));
+ SourceMgr.overrideFileContents(*File, std::move(Buffer));
}
break;
@@ -1919,7 +1914,8 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
// FIXME: This is not always the right filename-as-written, but we're not
// going to use this information to rebuild the module, so it doesn't make
// a lot of difference.
- Module::Header H = {std::string(key.Filename), *FileMgr.getFile(Filename)};
+ Module::Header H = {std::string(key.Filename),
+ *FileMgr.getOptionalFileRef(Filename)};
ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
}
@@ -2214,6 +2210,29 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II,
PP.setLoadedMacroDirective(II, Earliest, Latest);
}
+bool ASTReader::shouldDisableValidationForFile(
+ const serialization::ModuleFile &M) const {
+ if (DisableValidationKind == DisableValidationForModuleKind::None)
+ return false;
+
+ // If a PCH is loaded and validation is disabled for PCH then disable
+ // validation for the PCH and the modules it loads.
+ ModuleKind K = CurrentDeserializingModuleKind.getValueOr(M.Kind);
+
+ switch (K) {
+ case MK_MainFile:
+ case MK_Preamble:
+ case MK_PCH:
+ return bool(DisableValidationKind & DisableValidationForModuleKind::PCH);
+ case MK_ImplicitModule:
+ case MK_ExplicitModule:
+ case MK_PrebuiltModule:
+ return bool(DisableValidationKind & DisableValidationForModuleKind::Module);
+ }
+
+ return false;
+}
+
ASTReader::InputFileInfo
ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
// Go find this input file.
@@ -2300,27 +2319,25 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
StringRef Filename = FI.Filename;
uint64_t StoredContentHash = FI.ContentHash;
- const FileEntry *File = nullptr;
- if (auto FE = FileMgr.getFile(Filename, /*OpenFile=*/false))
- File = *FE;
+ OptionalFileEntryRefDegradesToFileEntryPtr File =
+ expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false));
// If we didn't find the file, resolve it relative to the
// original directory from which this AST file was created.
- if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
+ if (!File && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
F.OriginalDir != F.BaseDirectory) {
std::string Resolved = resolveFileRelativeToOriginalDir(
std::string(Filename), F.OriginalDir, F.BaseDirectory);
if (!Resolved.empty())
- if (auto FE = FileMgr.getFile(Resolved))
- File = *FE;
+ File = expectedToOptional(FileMgr.getFileRef(Resolved));
}
// For an overridden file, create a virtual file with the stored
// size/timestamp.
- if ((Overridden || Transient) && File == nullptr)
- File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime);
+ if ((Overridden || Transient) && !File)
+ File = FileMgr.getVirtualFileRef(Filename, StoredSize, StoredTime);
- if (File == nullptr) {
+ if (!File) {
if (Complain) {
std::string ErrorStr = "could not find file '";
ErrorStr += Filename;
@@ -2362,7 +2379,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
auto HasInputFileChanged = [&]() {
if (StoredSize != File->getSize())
return ModificationType::Size;
- if (!DisableValidation && StoredTime &&
+ if (!shouldDisableValidationForFile(F) && StoredTime &&
StoredTime != File->getModificationTime()) {
// In case the modification time changes but not the content,
// accept the cached file as legit.
@@ -2393,7 +2410,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
auto FileChange = HasInputFileChanged();
// For an overridden file, there is nothing to validate.
if (!Overridden && FileChange != ModificationType::None) {
- if (Complain) {
+ if (Complain && !Diags.isDiagnosticInFlight()) {
// Build a list of the PCH imports that got us here (in reverse).
SmallVector<ModuleFile *, 4> ImportStack(1, &F);
while (!ImportStack.back()->ImportedBy.empty())
@@ -2401,20 +2418,12 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
// The top-level PCH is stale.
StringRef TopLevelPCHName(ImportStack.back()->FileName);
- unsigned DiagnosticKind =
- moduleKindForDiagnostic(ImportStack.back()->Kind);
- if (DiagnosticKind == 0)
- Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName,
- (unsigned)FileChange);
- else if (DiagnosticKind == 1)
- Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName,
- (unsigned)FileChange);
- else
- Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName,
- (unsigned)FileChange);
+ Diag(diag::err_fe_ast_file_modified)
+ << Filename << moduleKindForDiagnostic(ImportStack.back()->Kind)
+ << TopLevelPCHName << FileChange;
// Print the import stack.
- if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
+ if (ImportStack.size() > 1) {
Diag(diag::note_pch_required_by)
<< Filename << ImportStack[0]->FileName;
for (unsigned I = 1; I < ImportStack.size(); ++I)
@@ -2422,8 +2431,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
<< ImportStack[I-1]->FileName << ImportStack[I]->FileName;
}
- if (!Diags.isDiagnosticInFlight())
- Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
+ Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
}
IsOutOfDate = true;
@@ -2431,7 +2439,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
// FIXME: If the file is overridden and we've already opened it,
// issue an error (or split it into a separate FileEntry).
- InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate);
+ InputFile IF = InputFile(*File, Overridden || Transient, IsOutOfDate);
// Note that we've loaded this input file.
F.InputFilesLoaded[ID-1] = IF;
@@ -2587,6 +2595,8 @@ ASTReader::ReadControlBlock(ModuleFile &F,
return Success;
};
+ bool DisableValidation = shouldDisableValidationForFile(F);
+
// Read all of the records and blocks in the control block.
RecordData Record;
unsigned NumInputs = 0;
@@ -2739,7 +2749,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
return VersionMismatch;
}
- bool hasErrors = Record[7];
+ bool hasErrors = Record[6];
if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) {
Diag(diag::err_pch_with_compiler_errors);
return HadErrors;
@@ -2757,8 +2767,6 @@ ASTReader::ReadControlBlock(ModuleFile &F,
F.HasTimestamps = Record[5];
- F.PCHHasObjectFile = Record[6];
-
const std::string &CurBranch = getClangFullRepositoryVersion();
StringRef ASTBranch = Blob;
if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
@@ -2887,7 +2895,8 @@ ASTReader::ReadControlBlock(ModuleFile &F,
// If we're implicitly loading a module, the base directory can't
// change between the build and use.
// Don't emit module relocation error if we have -fno-validate-pch
- if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+ if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
+ DisableValidationForModuleKind::Module) &&
F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
auto BuildDir = PP.getFileManager().getDirectory(Blob);
if (!BuildDir || *BuildDir != M->Directory) {
@@ -3599,11 +3608,12 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
case OPENCL_EXTENSIONS:
for (unsigned I = 0, E = Record.size(); I != E; ) {
auto Name = ReadString(Record, I);
- auto &Opt = OpenCLExtensions.OptMap[Name];
- Opt.Supported = Record[I++] != 0;
- Opt.Enabled = Record[I++] != 0;
- Opt.Avail = Record[I++];
- Opt.Core = Record[I++];
+ auto &OptInfo = OpenCLExtensions.OptMap[Name];
+ OptInfo.Supported = Record[I++] != 0;
+ OptInfo.Enabled = Record[I++] != 0;
+ OptInfo.Avail = Record[I++];
+ OptInfo.Core = Record[I++];
+ OptInfo.Opt = Record[I++];
}
break;
@@ -3714,7 +3724,9 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
}
case LATE_PARSED_TEMPLATE:
- LateParsedTemplates.append(Record.begin(), Record.end());
+ LateParsedTemplates.emplace_back(
+ std::piecewise_construct, std::forward_as_tuple(&F),
+ std::forward_as_tuple(Record.begin(), Record.end()));
break;
case OPTIMIZE_PRAGMA_OPTIONS:
@@ -3756,25 +3768,25 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
ForceCUDAHostDeviceDepth = Record[0];
break;
- case PACK_PRAGMA_OPTIONS: {
+ case ALIGN_PACK_PRAGMA_OPTIONS: {
if (Record.size() < 3) {
Error("invalid pragma pack record");
return Failure;
}
- PragmaPackCurrentValue = Record[0];
- PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]);
+ PragmaAlignPackCurrentValue = ReadAlignPackInfo(Record[0]);
+ PragmaAlignPackCurrentLocation = ReadSourceLocation(F, Record[1]);
unsigned NumStackEntries = Record[2];
unsigned Idx = 3;
// Reset the stack when importing a new module.
- PragmaPackStack.clear();
+ PragmaAlignPackStack.clear();
for (unsigned I = 0; I < NumStackEntries; ++I) {
- PragmaPackStackEntry Entry;
- Entry.Value = Record[Idx++];
+ PragmaAlignPackStackEntry Entry;
+ Entry.Value = ReadAlignPackInfo(Record[Idx++]);
Entry.Location = ReadSourceLocation(F, Record[Idx++]);
Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
- PragmaPackStrings.push_back(ReadString(Record, Idx));
- Entry.SlotLabel = PragmaPackStrings.back();
- PragmaPackStack.push_back(Entry);
+ PragmaAlignPackStrings.push_back(ReadString(Record, Idx));
+ Entry.SlotLabel = PragmaAlignPackStrings.back();
+ PragmaAlignPackStack.push_back(Entry);
}
break;
}
@@ -3784,7 +3796,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
Error("invalid pragma pack record");
return Failure;
}
- FpPragmaCurrentValue = Record[0];
+ FpPragmaCurrentValue = FPOptionsOverride::getFromOpaqueInt(Record[0]);
FpPragmaCurrentLocation = ReadSourceLocation(F, Record[1]);
unsigned NumStackEntries = Record[2];
unsigned Idx = 3;
@@ -3792,7 +3804,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
FpPragmaStack.clear();
for (unsigned I = 0; I < NumStackEntries; ++I) {
FpPragmaStackEntry Entry;
- Entry.Value = Record[Idx++];
+ Entry.Value = FPOptionsOverride::getFromOpaqueInt(Record[Idx++]);
Entry.Location = ReadSourceLocation(F, Record[Idx++]);
Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
FpPragmaStrings.push_back(ReadString(Record, Idx));
@@ -3917,9 +3929,11 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
auto &Map = PP.getHeaderSearchInfo().getModuleMap();
const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
// Don't emit module relocation error if we have -fno-validate-pch
- if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
+ if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
+ DisableValidationForModuleKind::Module) &&
+ !ModMap) {
if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
- if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
+ if (auto ASTFE = M ? M->getASTFile() : None) {
// This module was defined by an imported (explicit) module.
Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName
<< ASTFE->getName();
@@ -3940,7 +3954,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
return OutOfDate;
}
- assert(M->Name == F.ModuleName && "found module with different name");
+ assert(M && M->Name == F.ModuleName && "found module with different name");
// Check the primary module map file.
auto StoredModMap = FileMgr.getFile(F.ModuleMapPath);
@@ -4203,6 +4217,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
SmallVectorImpl<ImportedSubmodule> *Imported) {
llvm::SaveAndRestore<SourceLocation>
SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
+ llvm::SaveAndRestore<Optional<ModuleKind>> SetCurModuleKindRAII(
+ CurrentDeserializingModuleKind, Type);
// Defer any pending actions until we get to the end of reading the AST file.
Deserializing AnASTFile(this);
@@ -4510,9 +4526,9 @@ ASTReader::ReadASTCore(StringRef FileName,
return Missing;
// Otherwise, return an error.
- Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type)
- << FileName << !ErrorStr.empty()
- << ErrorStr;
+ Diag(diag::err_ast_file_not_found)
+ << moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty()
+ << ErrorStr;
return Failure;
case ModuleManager::OutOfDate:
@@ -4522,9 +4538,9 @@ ASTReader::ReadASTCore(StringRef FileName,
return OutOfDate;
// Otherwise, return an error.
- Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type)
- << FileName << !ErrorStr.empty()
- << ErrorStr;
+ Diag(diag::err_ast_file_out_of_date)
+ << moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty()
+ << ErrorStr;
return Failure;
}
@@ -4545,7 +4561,7 @@ ASTReader::ReadASTCore(StringRef FileName,
// Sniff for the signature.
if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
- Diag(diag::err_module_file_invalid)
+ Diag(diag::err_ast_file_invalid)
<< moduleKindForDiagnostic(Type) << FileName << std::move(Err);
return Failure;
}
@@ -4637,6 +4653,7 @@ ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
PP.getHeaderSearchInfo().getHeaderSearchOpts();
bool AllowCompatibleConfigurationMismatch =
F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule;
+ bool DisableValidation = shouldDisableValidationForFile(F);
ASTReadResult Result = readUnhashedControlBlockImpl(
&F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch,
@@ -4981,10 +4998,10 @@ void ASTReader::InitializeContext() {
/*ImportLoc=*/Import.ImportLoc);
if (Import.ImportLoc.isValid())
PP.makeModuleVisible(Imported, Import.ImportLoc);
- // FIXME: should we tell Sema to make the module visible too?
+ // This updates visibility for Preprocessor only. For Sema, which can be
+ // nullptr here, we do the same later, in UpdateSema().
}
}
- ImportedModules.clear();
}
void ASTReader::finalizeForWriting() {
@@ -5528,7 +5545,8 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
if (!ParentModule) {
if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
// Don't emit module relocation error if we have -fno-validate-pch
- if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+ if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
+ DisableValidationForModuleKind::Module) &&
CurFile != F.File) {
Error(diag::err_module_file_conflict,
CurrentModule->getTopLevelModuleName(), CurFile->getName(),
@@ -5579,7 +5597,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
case SUBMODULE_UMBRELLA_HEADER: {
std::string Filename = std::string(Blob);
ResolveImportedPath(F, Filename);
- if (auto Umbrella = PP.getFileManager().getFile(Filename)) {
+ if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
if (!CurrentModule->getUmbrellaHeader())
ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob);
else if (CurrentModule->getUmbrellaHeader().Entry != *Umbrella) {
@@ -5612,7 +5630,8 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
case SUBMODULE_UMBRELLA_DIR: {
std::string Dirname = std::string(Blob);
ResolveImportedPath(F, Dirname);
- if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
+ if (auto Umbrella =
+ PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
if (!CurrentModule->getUmbrellaDir())
ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob);
else if (CurrentModule->getUmbrellaDir().Entry != *Umbrella) {
@@ -5773,6 +5792,7 @@ bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain,
TargetOptions TargetOpts;
TargetOpts.Triple = ReadString(Record, Idx);
TargetOpts.CPU = ReadString(Record, Idx);
+ TargetOpts.TuneCPU = ReadString(Record, Idx);
TargetOpts.ABI = ReadString(Record, Idx);
for (unsigned N = Record[Idx++]; N; --N) {
TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx));
@@ -5841,6 +5861,7 @@ bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record,
HSOpts.DisableModuleHash = Record[Idx++];
HSOpts.ImplicitModuleMaps = Record[Idx++];
HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++];
+ HSOpts.EnablePrebuiltImplicitModules = Record[Idx++];
HSOpts.UseBuiltinIncludes = Record[Idx++];
HSOpts.UseStandardSystemIncludes = Record[Idx++];
HSOpts.UseStandardCXXIncludes = Record[Idx++];
@@ -6468,8 +6489,8 @@ void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
TL.setBuiltinLoc(readSourceLocation());
if (TL.needsExtraLocalData()) {
TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Reader.readInt()));
- TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Reader.readInt()));
- TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Reader.readInt()));
+ TL.setWrittenSignSpec(static_cast<TypeSpecifierSign>(Reader.readInt()));
+ TL.setWrittenWidthSpec(static_cast<TypeSpecifierWidth>(Reader.readInt()));
TL.setModeAttr(Reader.readInt());
}
}
@@ -7036,6 +7057,11 @@ QualType ASTReader::GetType(TypeID ID) {
T = Context.SingletonId; \
break;
#include "clang/Basic/AArch64SVEACLETypes.def"
+#define PPC_VECTOR_TYPE(Name, Id, Size) \
+ case PREDEF_TYPE_##Id##_ID: \
+ T = Context.Id##Ty; \
+ break;
+#include "clang/Basic/PPCTypes.def"
}
assert(!T.isNull() && "Unknown predefined type");
@@ -7092,15 +7118,15 @@ ASTRecordReader::readTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
NestedNameSpecifierLoc QualifierLoc =
readNestedNameSpecifierLoc();
SourceLocation TemplateNameLoc = readSourceLocation();
- return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
- SourceLocation());
+ return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+ TemplateNameLoc, SourceLocation());
}
case TemplateArgument::TemplateExpansion: {
NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc();
SourceLocation TemplateNameLoc = readSourceLocation();
SourceLocation EllipsisLoc = readSourceLocation();
- return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
- EllipsisLoc);
+ return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+ TemplateNameLoc, EllipsisLoc);
}
case TemplateArgument::Null:
case TemplateArgument::Integral:
@@ -7836,12 +7862,13 @@ void ASTReader::InitializeSema(Sema &S) {
// FIXME: What happens if these are changed by a module import?
if (!FPPragmaOptions.empty()) {
assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
- FPOptionsOverride NewOverrides(FPPragmaOptions[0]);
+ FPOptionsOverride NewOverrides =
+ FPOptionsOverride::getFromOpaqueInt(FPPragmaOptions[0]);
SemaObj->CurFPFeatures =
NewOverrides.applyOverrides(SemaObj->getLangOpts());
}
- SemaObj->OpenCLFeatures.copy(OpenCLExtensions);
+ SemaObj->OpenCLFeatures = OpenCLExtensions;
SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap;
SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap;
@@ -7880,32 +7907,37 @@ void ASTReader::UpdateSema() {
}
SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
- if (PragmaPackCurrentValue) {
+ if (PragmaAlignPackCurrentValue) {
// The bottom of the stack might have a default value. It must be adjusted
// to the current value to ensure that the packing state is preserved after
// popping entries that were included/imported from a PCH/module.
bool DropFirst = false;
- if (!PragmaPackStack.empty() &&
- PragmaPackStack.front().Location.isInvalid()) {
- assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue &&
+ if (!PragmaAlignPackStack.empty() &&
+ PragmaAlignPackStack.front().Location.isInvalid()) {
+ assert(PragmaAlignPackStack.front().Value ==
+ SemaObj->AlignPackStack.DefaultValue &&
"Expected a default alignment value");
- SemaObj->PackStack.Stack.emplace_back(
- PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue,
- SemaObj->PackStack.CurrentPragmaLocation,
- PragmaPackStack.front().PushLocation);
+ SemaObj->AlignPackStack.Stack.emplace_back(
+ PragmaAlignPackStack.front().SlotLabel,
+ SemaObj->AlignPackStack.CurrentValue,
+ SemaObj->AlignPackStack.CurrentPragmaLocation,
+ PragmaAlignPackStack.front().PushLocation);
DropFirst = true;
}
- for (const auto &Entry :
- llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0))
- SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value,
- Entry.Location, Entry.PushLocation);
- if (PragmaPackCurrentLocation.isInvalid()) {
- assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue &&
- "Expected a default alignment value");
+ for (const auto &Entry : llvm::makeArrayRef(PragmaAlignPackStack)
+ .drop_front(DropFirst ? 1 : 0)) {
+ SemaObj->AlignPackStack.Stack.emplace_back(
+ Entry.SlotLabel, Entry.Value, Entry.Location, Entry.PushLocation);
+ }
+ if (PragmaAlignPackCurrentLocation.isInvalid()) {
+ assert(*PragmaAlignPackCurrentValue ==
+ SemaObj->AlignPackStack.DefaultValue &&
+ "Expected a default align and pack value");
// Keep the current values.
} else {
- SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue;
- SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation;
+ SemaObj->AlignPackStack.CurrentValue = *PragmaAlignPackCurrentValue;
+ SemaObj->AlignPackStack.CurrentPragmaLocation =
+ PragmaAlignPackCurrentLocation;
}
}
if (FpPragmaCurrentValue) {
@@ -7936,6 +7968,15 @@ void ASTReader::UpdateSema() {
SemaObj->FpPragmaStack.CurrentPragmaLocation = FpPragmaCurrentLocation;
}
}
+
+ // For non-modular AST files, restore visiblity of modules.
+ for (auto &Import : ImportedModules) {
+ if (Import.ImportLoc.isInvalid())
+ continue;
+ if (Module *Imported = getSubmodule(Import.ID)) {
+ SemaObj->makeModuleVisible(Imported, Import.ImportLoc);
+ }
+ }
}
IdentifierInfo *ASTReader::get(StringRef Name) {
@@ -8370,25 +8411,28 @@ void ASTReader::ReadPendingInstantiations(
void ASTReader::ReadLateParsedTemplates(
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
&LPTMap) {
- for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
- /* In loop */) {
- FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++]));
+ for (auto &LPT : LateParsedTemplates) {
+ ModuleFile *FMod = LPT.first;
+ RecordDataImpl &LateParsed = LPT.second;
+ for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+ FunctionDecl *FD =
+ cast<FunctionDecl>(GetLocalDecl(*FMod, LateParsed[Idx++]));
- auto LT = std::make_unique<LateParsedTemplate>();
- LT->D = GetDecl(LateParsedTemplates[Idx++]);
+ auto LT = std::make_unique<LateParsedTemplate>();
+ LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
- ModuleFile *F = getOwningModuleFile(LT->D);
- assert(F && "No module");
+ ModuleFile *F = getOwningModuleFile(LT->D);
+ assert(F && "No module");
- unsigned TokN = LateParsedTemplates[Idx++];
- LT->Toks.reserve(TokN);
- for (unsigned T = 0; T < TokN; ++T)
- LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+ unsigned TokN = LateParsed[Idx++];
+ LT->Toks.reserve(TokN);
+ for (unsigned T = 0; T < TokN; ++T)
+ LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
- LPTMap.insert(std::make_pair(FD, std::move(LT)));
+ LPTMap.insert(std::make_pair(FD, std::move(LT)));
+ }
}
-
- LateParsedTemplates.clear();
}
void ASTReader::LoadSelector(Selector Sel) {
@@ -8582,11 +8626,6 @@ Module *ASTReader::getModule(unsigned ID) {
return getSubmodule(ID);
}
-bool ASTReader::DeclIsFromPCHWithObjectFile(const Decl *D) {
- ModuleFile *MF = getOwningModuleFile(D);
- return MF && MF->PCHHasObjectFile;
-}
-
ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) {
if (ID & 1) {
// It's a module, look it up by submodule ID.
@@ -8939,65 +8978,6 @@ ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record,
return SourceRange(beg, end);
}
-static FixedPointSemantics
-ReadFixedPointSemantics(const SmallVectorImpl<uint64_t> &Record,
- unsigned &Idx) {
- unsigned Width = Record[Idx++];
- unsigned Scale = Record[Idx++];
- uint64_t Tmp = Record[Idx++];
- bool IsSigned = Tmp & 0x1;
- bool IsSaturated = Tmp & 0x2;
- bool HasUnsignedPadding = Tmp & 0x4;
- return FixedPointSemantics(Width, Scale, IsSigned, IsSaturated,
- HasUnsignedPadding);
-}
-
-static const llvm::fltSemantics &
-readAPFloatSemantics(ASTRecordReader &reader) {
- return llvm::APFloatBase::EnumToSemantics(
- static_cast<llvm::APFloatBase::Semantics>(reader.readInt()));
-}
-
-APValue ASTRecordReader::readAPValue() {
- unsigned Kind = readInt();
- switch ((APValue::ValueKind) Kind) {
- case APValue::None:
- return APValue();
- case APValue::Indeterminate:
- return APValue::IndeterminateValue();
- case APValue::Int:
- return APValue(readAPSInt());
- case APValue::Float: {
- const llvm::fltSemantics &FloatSema = readAPFloatSemantics(*this);
- return APValue(readAPFloat(FloatSema));
- }
- case APValue::FixedPoint: {
- FixedPointSemantics FPSema = ReadFixedPointSemantics(Record, Idx);
- return APValue(APFixedPoint(readAPInt(), FPSema));
- }
- case APValue::ComplexInt: {
- llvm::APSInt First = readAPSInt();
- return APValue(std::move(First), readAPSInt());
- }
- case APValue::ComplexFloat: {
- const llvm::fltSemantics &FloatSema1 = readAPFloatSemantics(*this);
- llvm::APFloat First = readAPFloat(FloatSema1);
- const llvm::fltSemantics &FloatSema2 = readAPFloatSemantics(*this);
- return APValue(std::move(First), readAPFloat(FloatSema2));
- }
- case APValue::LValue:
- case APValue::Vector:
- case APValue::Array:
- case APValue::Struct:
- case APValue::Union:
- case APValue::MemberPointer:
- case APValue::AddrLabelDiff:
- // TODO : Handle all these APValue::ValueKind.
- return APValue();
- }
- llvm_unreachable("Invalid APValue::ValueKind");
-}
-
/// Read a floating-point value
llvm::APFloat ASTRecordReader::readAPFloat(const llvm::fltSemantics &Sem) {
return llvm::APFloat(Sem, readAPInt());
@@ -9172,7 +9152,7 @@ void ASTReader::visitTopLevelModuleMaps(
InputFileInfo IFI = readInputFileInfo(MF, I + 1);
if (IFI.TopLevelModuleMap)
// FIXME: This unnecessarily re-reads the InputFileInfo.
- if (auto *FE = getInputFile(MF, I + 1).getFile())
+ if (auto FE = getInputFile(MF, I + 1).getFile())
Visitor(FE);
}
}
@@ -11653,12 +11633,13 @@ ASTReader::ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
ASTContext *Context,
const PCHContainerReader &PCHContainerRdr,
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
- StringRef isysroot, bool DisableValidation,
+ StringRef isysroot,
+ DisableValidationForModuleKind DisableValidationKind,
bool AllowASTWithCompilerErrors,
bool AllowConfigurationMismatch, bool ValidateSystemInputs,
bool ValidateASTInputFilesContent, bool UseGlobalIndex,
std::unique_ptr<llvm::Timer> ReadTimer)
- : Listener(DisableValidation
+ : Listener(bool(DisableValidationKind &DisableValidationForModuleKind::PCH)
? cast<ASTReaderListener>(new SimpleASTReaderListener(PP))
: cast<ASTReaderListener>(new PCHValidator(PP, *this))),
SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
@@ -11666,7 +11647,7 @@ ASTReader::ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
ContextObj(Context), ModuleMgr(PP.getFileManager(), ModuleCache,
PCHContainerRdr, PP.getHeaderSearchInfo()),
DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot),
- DisableValidation(DisableValidation),
+ DisableValidationKind(DisableValidationKind),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
AllowConfigurationMismatch(AllowConfigurationMismatch),
ValidateSystemInputs(ValidateSystemInputs),
@@ -11717,9 +11698,9 @@ class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
public:
OMPClauseReader(ASTRecordReader &Record)
: Record(Record), Context(Record.getContext()) {}
-
-#define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *C);
-#include "llvm/Frontend/OpenMP/OMPKinds.def"
+#define GEN_CLANG_CLAUSE_CLASS
+#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *C);
+#include "llvm/Frontend/OpenMP/OMP.inc"
OMPClause *readClause();
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
@@ -12523,10 +12504,10 @@ void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) {
SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components;
Components.reserve(TotalComponents);
for (unsigned i = 0; i < TotalComponents; ++i) {
- Expr *AssociatedExpr = Record.readExpr();
+ Expr *AssociatedExprPr = Record.readExpr();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExprPr, AssociatedDecl,
+ /*IsNonContiguous=*/false);
}
C->setComponents(Components, ListSizes);
}
@@ -12600,8 +12581,14 @@ void OMPClauseReader::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
void OMPClauseReader::VisitOMPToClause(OMPToClause *C) {
C->setLParenLoc(Record.readSourceLocation());
+ for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
+ C->setMotionModifier(
+ I, static_cast<OpenMPMotionModifierKind>(Record.readInt()));
+ C->setMotionModifierLoc(I, Record.readSourceLocation());
+ }
C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc());
C->setMapperIdInfo(Record.readDeclarationNameInfo());
+ C->setColonLoc(Record.readSourceLocation());
auto NumVars = C->varlist_size();
auto UniqueDecls = C->getUniqueDeclarationsNum();
auto TotalLists = C->getTotalComponentListNum();
@@ -12640,18 +12627,24 @@ void OMPClauseReader::VisitOMPToClause(OMPToClause *C) {
SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components;
Components.reserve(TotalComponents);
for (unsigned i = 0; i < TotalComponents; ++i) {
- Expr *AssociatedExpr = Record.readSubExpr();
+ Expr *AssociatedExprPr = Record.readSubExpr();
+ bool IsNonContiguous = Record.readBool();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExprPr, AssociatedDecl, IsNonContiguous);
}
C->setComponents(Components, ListSizes);
}
void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) {
C->setLParenLoc(Record.readSourceLocation());
+ for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
+ C->setMotionModifier(
+ I, static_cast<OpenMPMotionModifierKind>(Record.readInt()));
+ C->setMotionModifierLoc(I, Record.readSourceLocation());
+ }
C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc());
C->setMapperIdInfo(Record.readDeclarationNameInfo());
+ C->setColonLoc(Record.readSourceLocation());
auto NumVars = C->varlist_size();
auto UniqueDecls = C->getUniqueDeclarationsNum();
auto TotalLists = C->getTotalComponentListNum();
@@ -12690,10 +12683,10 @@ void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) {
SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components;
Components.reserve(TotalComponents);
for (unsigned i = 0; i < TotalComponents; ++i) {
- Expr *AssociatedExpr = Record.readSubExpr();
+ Expr *AssociatedExprPr = Record.readSubExpr();
+ bool IsNonContiguous = Record.readBool();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExprPr, AssociatedDecl, IsNonContiguous);
}
C->setComponents(Components, ListSizes);
}
@@ -12740,10 +12733,10 @@ void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components;
Components.reserve(TotalComponents);
for (unsigned i = 0; i < TotalComponents; ++i) {
- Expr *AssociatedExpr = Record.readSubExpr();
+ auto *AssociatedExprPr = Record.readSubExpr();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExprPr, AssociatedDecl,
+ /*IsNonContiguous=*/false);
}
C->setComponents(Components, ListSizes);
}
@@ -12784,8 +12777,8 @@ void OMPClauseReader::VisitOMPUseDeviceAddrClause(OMPUseDeviceAddrClause *C) {
for (unsigned i = 0; i < TotalComponents; ++i) {
Expr *AssociatedExpr = Record.readSubExpr();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExpr, AssociatedDecl,
+ /*IsNonContiguous*/ false);
}
C->setComponents(Components, ListSizes);
}
@@ -12827,8 +12820,8 @@ void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
for (unsigned i = 0; i < TotalComponents; ++i) {
Expr *AssociatedExpr = Record.readSubExpr();
auto *AssociatedDecl = Record.readDeclAs<ValueDecl>();
- Components.push_back(OMPClauseMappableExprCommon::MappableComponent(
- AssociatedExpr, AssociatedDecl));
+ Components.emplace_back(AssociatedExpr, AssociatedDecl,
+ /*IsNonContiguous=*/false);
}
C->setComponents(Components, ListSizes);
}
@@ -12919,3 +12912,20 @@ OMPTraitInfo *ASTRecordReader::readOMPTraitInfo() {
}
return &TI;
}
+
+void ASTRecordReader::readOMPChildren(OMPChildren *Data) {
+ if (!Data)
+ return;
+ if (Reader->ReadingKind == ASTReader::Read_Stmt) {
+ // Skip NumClauses, NumChildren and HasAssociatedStmt fields.
+ skipInts(3);
+ }
+ SmallVector<OMPClause *, 4> Clauses(Data->getNumClauses());
+ for (unsigned I = 0, E = Data->getNumClauses(); I < E; ++I)
+ Clauses[I] = readOMPClause();
+ Data->setClauses(Clauses);
+ if (Data->hasAssociatedStmt())
+ Data->setAssociatedStmt(readStmt());
+ for (unsigned I = 0, E = Data->getNumChildren(); I < E; ++I)
+ Data->getChildren()[I] = readStmt();
+}