Author: Richard Howell Date: 2022-05-12T07:29:37-07:00 New Revision: f11056943e56a32d81bb36d11fb5ce8d2b2ce79b
URL: https://github.com/llvm/llvm-project/commit/f11056943e56a32d81bb36d11fb5ce8d2b2ce79b DIFF: https://github.com/llvm/llvm-project/commit/f11056943e56a32d81bb36d11fb5ce8d2b2ce79b.diff LOG: [clang] serialize SUBMODULE_TOPHEADER relative to BaseDirectory This diff changes the serialization of the `SUBMODULE_TOPHEADER` entry in module files to be serialized relative to the module's `BaseDirectory`. This matches the behavior of the `SUBMODULE_HEADER` entry and 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/D124938 Added: clang/test/Modules/relative-submodule-topheader.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 c9601f0a164c9..93ecf222a5b30 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5637,9 +5637,12 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F, // them here. break; - case SUBMODULE_TOPHEADER: - CurrentModule->addTopHeaderFilename(Blob); + case SUBMODULE_TOPHEADER: { + std::string HeaderName(Blob); + ResolveImportedPath(F, HeaderName); + CurrentModule->addTopHeaderFilename(HeaderName); break; + } case SUBMODULE_UMBRELLA_DIR: { // See comments in SUBMODULE_UMBRELLA_HEADER diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e42f41f8fbc2d..4eeedc07fb1d4 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2857,8 +2857,11 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { { auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; - for (auto *H : TopHeaders) - Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); + for (auto *H : TopHeaders) { + SmallString<128> HeaderName(H->getName()); + PreparePathForOutput(HeaderName); + Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, HeaderName); + } } // Emit the imports. diff --git a/clang/test/Modules/relative-submodule-topheader.m b/clang/test/Modules/relative-submodule-topheader.m new file mode 100644 index 0000000000000..c7c2f13076866 --- /dev/null +++ b/clang/test/Modules/relative-submodule-topheader.m @@ -0,0 +1,10 @@ +// RUN: cd %S +// RUN: %clang_cc1 -fmodules -fno-implicit-modules -x objective-c++ -fmodule-name=std -emit-module Inputs/submodules/module.map -o %t/mod.pcm +// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s + +// CHECK: <SUBMODULE_HEADER abbrevid=6/> blob data = 'vector.h' +// CHECK: <SUBMODULE_TOPHEADER abbrevid=7/> blob data = 'vector.h' +// CHECK: <SUBMODULE_HEADER abbrevid=6/> blob data = 'type_traits.h' +// CHECK: <SUBMODULE_TOPHEADER abbrevid=7/> blob data = 'type_traits.h' +// CHECK: <SUBMODULE_HEADER abbrevid=6/> blob data = 'hash_map.h' +// CHECK: <SUBMODULE_TOPHEADER abbrevid=7/> blob data = 'hash_map.h' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits