Author: Richard Howell Date: 2022-05-12T07:31:19-07:00 New Revision: ee51e9795a31e1280e30179215c27e09927230e2
URL: https://github.com/llvm/llvm-project/commit/ee51e9795a31e1280e30179215c27e09927230e2 DIFF: https://github.com/llvm/llvm-project/commit/ee51e9795a31e1280e30179215c27e09927230e2.diff LOG: [clang] serialize ORIGINAL_PCH_DIR relative to BaseDirectory This diff changes the serialization of the `ORIGINAL_PCH_DIR` entry in module files to be serialized relative to the module's `BaseDirectory`. This will allow for the module to be relocatable across machines. The path is restored relative to the module's BaseDirectory on deserialization. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D124946 Added: clang/test/Modules/relative-original-dir.m Modified: clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 93ecf222a5b3..85e5b3ecfdd7 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2898,6 +2898,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, case ORIGINAL_PCH_DIR: F.OriginalDir = std::string(Blob); + ResolveImportedPath(F, F.OriginalDir); break; case MODULE_NAME: diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 4eeedc07fb1d..6d9273ed9a53 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1470,8 +1470,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); SmallString<128> OutputPath(OutputFile); - - SM.getFileManager().makeAbsolutePath(OutputPath); + PreparePathForOutput(OutputPath); StringRef origDir = llvm::sys::path::parent_path(OutputPath); RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; diff --git a/clang/test/Modules/relative-original-dir.m b/clang/test/Modules/relative-original-dir.m new file mode 100644 index 000000000000..3ed49142bc30 --- /dev/null +++ b/clang/test/Modules/relative-original-dir.m @@ -0,0 +1,7 @@ +// 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: <ORIGINAL_PCH_DIR abbrevid=7/> blob data = 'outdir' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits