From f29af09ec12b20d25033805dde98c7331b3f66cc Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 7 Mar 2014 07:27:49 +0000 Subject: [PATCH] Add a bunch of missing changes from r203208 Somehow lost these in a git operation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203210 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTReader.h | 9 +- lib/Serialization/ASTReader.cpp | 229 +++++++++++++----------- test/Modules/dependency-gen.m | 12 +- 3 files changed, 138 insertions(+), 112 deletions(-) diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index f77505d1b0..f171eb93e5 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -545,7 +545,7 @@ private: assert(getKind() == Macro && "Hidden name is not a macro!"); return std::make_pair(Id, MMI); } -}; + }; typedef llvm::SmallDenseMap HiddenMacrosMap; @@ -1024,6 +1024,13 @@ private: /// \brief Reads a statement from the specified cursor. Stmt *ReadStmtFromStream(ModuleFile &F); + /// \brief Reads the stored information about an input file. + void readInputFileInfo(ModuleFile &F, unsigned ID, std::string &Filename, + off_t &StoredSize, time_t &StoredTime, + bool &Overridden); + /// \brief A convenience method to read the filename from an input file. + std::string getInputFileName(ModuleFile &F, unsigned ID); + /// \brief Retrieve the file entry and 'overridden' bit for an input /// file in the given module file. serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 60734db8ab..99ef8f0c9b 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1870,6 +1870,40 @@ void ASTReader::installImportedMacro(IdentifierInfo *II, ModuleMacroInfo *MMI, PP.appendMacroDirective(II, MD); } +void ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID, + std::string &Filename, off_t &StoredSize, + time_t &StoredTime, bool &Overridden) { + // Go find this input file. + BitstreamCursor &Cursor = F.InputFilesCursor; + SavedStreamPosition SavedPosition(Cursor); + Cursor.JumpToBit(F.InputFileOffsets[ID-1]); + + unsigned Code = Cursor.ReadCode(); + RecordData Record; + StringRef Blob; + + unsigned Result = Cursor.readRecord(Code, Record, &Blob); + assert(static_cast(Result) == INPUT_FILE && + "invalid record type for input file"); + (void)Result; + + assert(Record[0] == ID && "Bogus stored ID or offset"); + StoredSize = static_cast(Record[1]); + StoredTime = static_cast(Record[2]); + Overridden = static_cast(Record[3]); + Filename = Blob; + MaybeAddSystemRootToFilename(F, Filename); +} + +std::string ASTReader::getInputFileName(ModuleFile &F, unsigned int ID) { + off_t StoredSize; + time_t StoredTime; + bool Overridden; + std::string Filename; + readInputFileInfo(F, ID, Filename, StoredSize, StoredTime, Overridden); + return Filename; +} + InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { // If this ID is bogus, just return an empty input file. if (ID == 0 || ID > F.InputFilesLoaded.size()) @@ -1887,119 +1921,105 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { SavedStreamPosition SavedPosition(Cursor); Cursor.JumpToBit(F.InputFileOffsets[ID-1]); - unsigned Code = Cursor.ReadCode(); - RecordData Record; - StringRef Blob; - switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { - case INPUT_FILE: { - unsigned StoredID = Record[0]; - assert(ID == StoredID && "Bogus stored ID or offset"); - (void)StoredID; - off_t StoredSize = (off_t)Record[1]; - time_t StoredTime = (time_t)Record[2]; - bool Overridden = (bool)Record[3]; - - // Get the file entry for this input file. - StringRef OrigFilename = Blob; - std::string Filename = OrigFilename; - MaybeAddSystemRootToFilename(F, Filename); - const FileEntry *File - = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) - : FileMgr.getFile(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 == 0 && !F.OriginalDir.empty() && !CurrentDir.empty() && - F.OriginalDir != CurrentDir) { - std::string Resolved = resolveFileRelativeToOriginalDir(Filename, - F.OriginalDir, - CurrentDir); - if (!Resolved.empty()) - File = FileMgr.getFile(Resolved); - } - - // For an overridden file, create a virtual file with the stored - // size/timestamp. - if (Overridden && File == 0) { - File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); + off_t StoredSize; + time_t StoredTime; + bool Overridden; + std::string Filename; + readInputFileInfo(F, ID, Filename, StoredSize, StoredTime, Overridden); + + const FileEntry *File + = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) + : FileMgr.getFile(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 == 0 && !F.OriginalDir.empty() && !CurrentDir.empty() && + F.OriginalDir != CurrentDir) { + std::string Resolved = resolveFileRelativeToOriginalDir(Filename, + F.OriginalDir, + CurrentDir); + if (!Resolved.empty()) + File = FileMgr.getFile(Resolved); + } + + // For an overridden file, create a virtual file with the stored + // size/timestamp. + if (Overridden && File == 0) { + File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); + } + + if (File == 0) { + if (Complain) { + std::string ErrorStr = "could not find file '"; + ErrorStr += Filename; + ErrorStr += "' referenced by AST file"; + Error(ErrorStr.c_str()); } - - if (File == 0) { - if (Complain) { - std::string ErrorStr = "could not find file '"; - ErrorStr += Filename; - ErrorStr += "' referenced by AST file"; - Error(ErrorStr.c_str()); - } - // Record that we didn't find the file. - F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); - return InputFile(); - } - - // Check if there was a request to override the contents of the file - // that was part of the precompiled header. Overridding such a file - // can lead to problems when lexing using the source locations from the - // PCH. - SourceManager &SM = getSourceManager(); - if (!Overridden && SM.isFileOverridden(File)) { - if (Complain) - Error(diag::err_fe_pch_file_overridden, Filename); - // After emitting the diagnostic, recover by disabling the override so - // that the original file will be used. - SM.disableFileContentsOverride(File); - // The FileEntry is a virtual file entry with the size of the contents - // that would override the original contents. Set it to the original's - // size/time. - FileMgr.modifyFileEntry(const_cast(File), - StoredSize, StoredTime); - } - - bool IsOutOfDate = false; - - // For an overridden file, there is nothing to validate. - if (!Overridden && (StoredSize != File->getSize() + // Record that we didn't find the file. + F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); + return InputFile(); + } + + // Check if there was a request to override the contents of the file + // that was part of the precompiled header. Overridding such a file + // can lead to problems when lexing using the source locations from the + // PCH. + SourceManager &SM = getSourceManager(); + if (!Overridden && SM.isFileOverridden(File)) { + if (Complain) + Error(diag::err_fe_pch_file_overridden, Filename); + // After emitting the diagnostic, recover by disabling the override so + // that the original file will be used. + SM.disableFileContentsOverride(File); + // The FileEntry is a virtual file entry with the size of the contents + // that would override the original contents. Set it to the original's + // size/time. + FileMgr.modifyFileEntry(const_cast(File), + StoredSize, StoredTime); + } + + bool IsOutOfDate = false; + + // For an overridden file, there is nothing to validate. + if (!Overridden && (StoredSize != File->getSize() #if !defined(LLVM_ON_WIN32) - // In our regression testing, the Windows file system seems to - // have inconsistent modification times that sometimes - // erroneously trigger this error-handling path. - || StoredTime != File->getModificationTime() + // In our regression testing, the Windows file system seems to + // have inconsistent modification times that sometimes + // erroneously trigger this error-handling path. + || StoredTime != File->getModificationTime() #endif - )) { - if (Complain) { - // Build a list of the PCH imports that got us here (in reverse). - SmallVector ImportStack(1, &F); - while (ImportStack.back()->ImportedBy.size() > 0) - ImportStack.push_back(ImportStack.back()->ImportedBy[0]); - - // The top-level PCH is stale. - StringRef TopLevelPCHName(ImportStack.back()->FileName); - Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); - - // Print the import stack. - if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { + )) { + if (Complain) { + // Build a list of the PCH imports that got us here (in reverse). + SmallVector ImportStack(1, &F); + while (ImportStack.back()->ImportedBy.size() > 0) + ImportStack.push_back(ImportStack.back()->ImportedBy[0]); + + // The top-level PCH is stale. + StringRef TopLevelPCHName(ImportStack.back()->FileName); + Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); + + // Print the import stack. + if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { + Diag(diag::note_pch_required_by) + << Filename << ImportStack[0]->FileName; + for (unsigned I = 1; I < ImportStack.size(); ++I) Diag(diag::note_pch_required_by) - << Filename << ImportStack[0]->FileName; - for (unsigned I = 1; I < ImportStack.size(); ++I) - Diag(diag::note_pch_required_by) - << ImportStack[I-1]->FileName << ImportStack[I]->FileName; - } - - if (!Diags.isDiagnosticInFlight()) - Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; + << ImportStack[I-1]->FileName << ImportStack[I]->FileName; } - IsOutOfDate = true; + if (!Diags.isDiagnosticInFlight()) + Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; } - InputFile IF = InputFile(File, Overridden, IsOutOfDate); - - // Note that we've loaded this input file. - F.InputFilesLoaded[ID-1] = IF; - return IF; - } + IsOutOfDate = true; } - return InputFile(); + InputFile IF = InputFile(File, Overridden, IsOutOfDate); + + // Note that we've loaded this input file. + F.InputFilesLoaded[ID-1] = IF; + return IF; } const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { @@ -2086,14 +2106,11 @@ ASTReader::ReadControlBlock(ModuleFile &F, unsigned N = NumUserInputs; if (ValidateSystemInputs || - (Listener && Listener->needsInputFileVisitation()) || (HSOpts.ModulesValidateOncePerBuildSession && F.Kind == MK_Module)) N = NumInputs; for (unsigned I = 0; I < N; ++I) { InputFile IF = getInputFile(F, I+1, Complain); - if (const FileEntry *F = IF.getFile()) - Listener->visitInputFile(F->getName(), I >= NumUserInputs); if (!IF.getFile() || IF.isOutOfDate()) return OutOfDate; } diff --git a/test/Modules/dependency-gen.m b/test/Modules/dependency-gen.m index 471ce14413..67e590b33e 100644 --- a/test/Modules/dependency-gen.m +++ b/test/Modules/dependency-gen.m @@ -1,20 +1,22 @@ // RUN: rm -rf %t-mcp // RUN: mkdir -p %t-mcp -// RUN: %clang_cc1 -x objective-c -dependency-file %t.d.1 -MT %s.o -I %S/Inputs -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s +// RUN: %clang_cc1 -x objective-c -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -dependency-file %t.d.1 -MT %s.o -I %S/Inputs -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s // RUN: FileCheck %s < %t.d.1 // CHECK: dependency-gen.m // CHECK: Inputs/diamond_top.h // CHECK: Inputs/module.map -// CHECK-NOT: string.h +// CHECK-NOT: usr{{.}}include{{.}}module.map +// CHECK-NOT: stdint.h -// RUN: %clang_cc1 -x objective-c -dependency-file %t.d.2 -MT %s.o -I %S/Inputs -sys-header-deps -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s +// RUN: %clang_cc1 -x objective-c -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -dependency-file %t.d.2 -MT %s.o -I %S/Inputs -sys-header-deps -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s // RUN: FileCheck %s -check-prefix=CHECK-SYS < %t.d.2 // CHECK-SYS: dependency-gen.m // CHECK-SYS: Inputs/diamond_top.h // CHECK-SYS: Inputs/module.map -// CHECK-SYS: string.h +// CHECK-SYS: usr{{.}}include{{.}}module.map +// CHECK-SYS: stdint.h #import "diamond_top.h" -#import "string.h" +#import "stdint.h" // inside sysroot -- 2.40.0