diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6018,9 +6018,6 @@ HelpText<"Disable validation of precompiled headers">, MarshallingInfoFlag, "DisableValidationForModuleKind::None">, Normalizer<"makeFlagToValueNormalizer(DisableValidationForModuleKind::All)">; -def fpcm_output_path_independent : Flag<["-"], "fpcm-output-path-independent">, - HelpText<"Output a PCM/PCH file that does not write out information about its output path">, - MarshallingInfoFlag>; def fallow_pcm_with_errors : Flag<["-"], "fallow-pcm-with-compiler-errors">, HelpText<"Accept a PCM file that was created with compiler errors">, MarshallingInfoFlag>; diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -344,15 +344,6 @@ /// When using -emit-module, treat the modulemap as a system module. unsigned IsSystemModule : 1; - /// Output a PCM/PCH file that does not write out information about its output - /// path. - /// - /// FIXME: This only controls whether \p ORIGINAL_PCH_DIR record is written - /// out or not. Consider either removing that record entirely if it's no - /// longer relevant or switching the default to not write it unless an option - /// is set to true. - unsigned OutputPathIndependentPCM : 1; - /// Output (and read) PCM files regardless of compiler errors. unsigned AllowPCMWithCompilerErrors : 1; @@ -525,8 +516,8 @@ ASTDumpLookups(false), BuildingImplicitModule(false), BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false), IncludeTimestamps(true), UseTemporary(true), - OutputPathIndependentPCM(false), AllowPCMWithCompilerErrors(false), - ModulesShareFileManager(true), TimeTraceGranularity(500) {} + AllowPCMWithCompilerErrors(false), ModulesShareFileManager(true), + TimeTraceGranularity(500) {} /// getInputKindForExtension - Return the appropriate input kind for a file /// extension. For example, "c" would return Language::C. diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -343,9 +343,6 @@ /// name. ORIGINAL_FILE, - /// The directory that the PCH was originally created in. - ORIGINAL_PCH_DIR, - /// Record code for file ID of the file or buffer that was used to /// generate the AST file. ORIGINAL_FILE_ID, diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -455,7 +455,7 @@ void WriteBlockInfoBlock(); void WriteControlBlock(Preprocessor &PP, ASTContext &Context, - StringRef isysroot, StringRef OutputFile); + StringRef isysroot); /// Write out the signature and diagnostic options, and return the signature. ASTFileSignature writeUnhashedControlBlock(Preprocessor &PP, @@ -533,7 +533,7 @@ void WriteDecl(ASTContext &Context, Decl *D); ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot, - StringRef OutputFile, Module *WritingModule); + Module *WritingModule); public: /// Create a new precompiled header writer that outputs to @@ -573,8 +573,7 @@ ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors = false, - bool ShouldCacheASTInMemory = false, - bool OutputPathIndependent = false); + bool ShouldCacheASTInMemory = false); /// Emit a token. void AddToken(const Token &Tok, RecordDataImpl &Record); @@ -765,7 +764,6 @@ ASTWriter Writer; bool AllowASTWithErrors; bool ShouldCacheASTInMemory; - bool OutputPathIndependent; protected: ASTWriter &getWriter() { return Writer; } @@ -778,8 +776,7 @@ std::shared_ptr Buffer, ArrayRef> Extensions, bool AllowASTWithErrors = false, bool IncludeTimestamps = true, - bool ShouldCacheASTInMemory = false, - bool OutputPathIndependent = false); + bool ShouldCacheASTInMemory = false); ~PCHGenerator() override; void InitializeSema(Sema &S) override { SemaPtr = &S; } diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -148,10 +148,6 @@ /// build this AST file. FileID OriginalSourceFileID; - /// The directory that the PCH was originally created in. Used to - /// allow resolving headers even after headers+PCH was moved to a new path. - std::string OriginalDir; - std::string ModuleMapPath; /// Whether this precompiled header is a relocatable PCH file. diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -140,8 +140,7 @@ CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, FrontendOpts.ModuleFileExtensions, CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, - FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH, - FrontendOpts.OutputPathIndependentPCM)); + FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI, std::string(InFile), OutputFile, std::move(OS), Buffer)); @@ -204,9 +203,7 @@ /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule, /*ShouldCacheASTInMemory=*/ - +CI.getFrontendOpts().BuildingImplicitModule, - /*OutputPathIndependent=*/ - +CI.getFrontendOpts().OutputPathIndependentPCM)); + +CI.getFrontendOpts().BuildingImplicitModule)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI, std::string(InFile), OutputFile, std::move(OS), Buffer)); return std::make_unique(std::move(Consumers)); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1395,41 +1395,6 @@ } } -/// If a header file is not found at the path that we expect it to be -/// and the PCH file was moved from its original location, try to resolve the -/// file by assuming that header+PCH were moved together and the header is in -/// the same place relative to the PCH. -static std::string -resolveFileRelativeToOriginalDir(const std::string &Filename, - const std::string &OriginalDir, - const std::string &CurrDir) { - assert(OriginalDir != CurrDir && - "No point trying to resolve the file if the PCH dir didn't change"); - - using namespace llvm::sys; - - SmallString<128> filePath(Filename); - fs::make_absolute(filePath); - assert(path::is_absolute(OriginalDir)); - SmallString<128> currPCHPath(CurrDir); - - path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), - fileDirE = path::end(path::parent_path(filePath)); - path::const_iterator origDirI = path::begin(OriginalDir), - origDirE = path::end(OriginalDir); - // Skip the common path components from filePath and OriginalDir. - while (fileDirI != fileDirE && origDirI != origDirE && - *fileDirI == *origDirI) { - ++fileDirI; - ++origDirI; - } - for (; origDirI != origDirE; ++origDirI) - path::append(currPCHPath, ".."); - path::append(currPCHPath, fileDirI, fileDirE); - path::append(currPCHPath, path::filename(Filename)); - return std::string(currPCHPath.str()); -} - bool ASTReader::ReadSLocEntry(int ID) { if (ID == 0) return false; @@ -2332,16 +2297,6 @@ 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 && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && - F.OriginalDir != F.BaseDirectory) { - std::string Resolved = resolveFileRelativeToOriginalDir( - std::string(Filename), F.OriginalDir, F.BaseDirectory); - if (!Resolved.empty()) - File = expectedToOptional(FileMgr.getFileRef(Resolved)); - } - // For an overridden file, create a virtual file with the stored // size/timestamp. if ((Overridden || Transient) && !File) @@ -2896,11 +2851,6 @@ F.OriginalSourceFileID = FileID::get(Record[0]); break; - case ORIGINAL_PCH_DIR: - F.OriginalDir = std::string(Blob); - ResolveImportedPath(F, F.OriginalDir); - break; - case MODULE_NAME: F.ModuleName = std::string(Blob); Diag(diag::remark_module_import) @@ -8704,8 +8654,9 @@ ModuleFile &MF = ModuleMgr.getPrimaryModule(); StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); StringRef FileName = llvm::sys::path::filename(MF.FileName); - return ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, - MF.Signature); + return ASTSourceDescriptor(ModuleName, + llvm::sys::path::parent_path(MF.FileName), + FileName, MF.Signature); } return None; } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -786,7 +786,6 @@ RECORD(MODULE_MAP_FILE); RECORD(IMPORTS); RECORD(ORIGINAL_FILE); - RECORD(ORIGINAL_PCH_DIR); RECORD(ORIGINAL_FILE_ID); RECORD(INPUT_FILE_OFFSETS); @@ -1187,7 +1186,7 @@ /// Write the control block. void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, - StringRef isysroot, StringRef OutputFile) { + StringRef isysroot) { using namespace llvm; Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); @@ -1470,21 +1469,6 @@ Record.push_back(SM.getMainFileID().getOpaqueValue()); Stream.EmitRecord(ORIGINAL_FILE_ID, Record); - // Original PCH directory - if (!OutputFile.empty() && OutputFile != "-") { - auto Abbrev = std::make_shared(); - Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name - unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); - - SmallString<128> OutputPath(OutputFile); - PreparePathForOutput(OutputPath); - StringRef origDir = llvm::sys::path::parent_path(OutputPath); - - RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; - Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); - } - std::set AffectingModuleMaps; if (WritingModule) { AffectingModuleMaps = @@ -4483,8 +4467,7 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors, - bool ShouldCacheASTInMemory, - bool OutputPathIndependent) { + bool ShouldCacheASTInMemory) { WritingAST = true; ASTHasCompilerErrors = hasErrors; @@ -4500,9 +4483,7 @@ Context = &SemaRef.Context; PP = &SemaRef.PP; this->WritingModule = WritingModule; - ASTFileSignature Signature = WriteASTCore( - SemaRef, isysroot, OutputPathIndependent ? StringRef() : OutputFile, - WritingModule); + ASTFileSignature Signature = WriteASTCore(SemaRef, isysroot, WritingModule); Context = nullptr; PP = nullptr; this->WritingModule = nullptr; @@ -4528,7 +4509,6 @@ } ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, - StringRef OutputFile, Module *WritingModule) { using namespace llvm; @@ -4682,7 +4662,7 @@ } // Write the control block - WriteControlBlock(PP, Context, isysroot, OutputFile); + WriteControlBlock(PP, Context, isysroot); // Write the remaining AST contents. Stream.FlushToWord(); diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -25,14 +25,13 @@ StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer, ArrayRef> Extensions, bool AllowASTWithErrors, bool IncludeTimestamps, - bool ShouldCacheASTInMemory, bool OutputPathIndependent) + bool ShouldCacheASTInMemory) : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()), SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data), Writer(Stream, this->Buffer->Data, ModuleCache, Extensions, IncludeTimestamps), AllowASTWithErrors(AllowASTWithErrors), - ShouldCacheASTInMemory(ShouldCacheASTInMemory), - OutputPathIndependent(OutputPathIndependent) { + ShouldCacheASTInMemory(ShouldCacheASTInMemory) { this->Buffer->IsComplete = false; } @@ -71,7 +70,7 @@ // For serialization we are lenient if the errors were // only warn-as-error kind. PP.getDiagnostics().hasUncompilableErrorOccurred(), - ShouldCacheASTInMemory, OutputPathIndependent); + ShouldCacheASTInMemory); Buffer->IsComplete = true; } diff --git a/clang/test/Modules/relative-original-dir.m b/clang/test/Modules/relative-original-dir.m deleted file mode 100644 --- a/clang/test/Modules/relative-original-dir.m +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: rm -rf %t/normal-module-map -// RUN: mkdir -p %t -// RUN: cp -r %S/Inputs/normal-module-map %t -// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-name=libA -emit-module %t/normal-module-map/module.map -o %t/normal-module-map/outdir/mod.pcm -// RUN: llvm-bcanalyzer --dump --disable-histogram %t/normal-module-map/outdir/mod.pcm | FileCheck %s - -// CHECK: blob data = 'outdir' diff --git a/clang/test/PCH/pch-output-path-independent.c b/clang/test/PCH/pch-output-path-independent.c --- a/clang/test/PCH/pch-output-path-independent.c +++ b/clang/test/PCH/pch-output-path-independent.c @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t/a %t/b -// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent -// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent +// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch +// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch // RUN: diff %t/a/t1.pch %t/b/t2.pch