[PATCH] D124946: [clang] serialize ORIGINAL_PCH_DIR relative to BaseDirectory

Richard Howell via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 10:29:01 PDT 2022


rmaz created this revision.
Herald added a project: All.
rmaz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124946

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/relative-original-dir.m


Index: clang/test/Modules/relative-original-dir.m
===================================================================
--- /dev/null
+++ clang/test/Modules/relative-original-dir.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t/normal-module-map
+// 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'
Index: clang/lib/Serialization/ASTWriter.cpp
===================================================================
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1461,8 +1461,7 @@
     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};
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2898,6 +2898,7 @@
 
     case ORIGINAL_PCH_DIR:
       F.OriginalDir = std::string(Blob);
+      ResolveImportedPath(F, F.OriginalDir);
       break;
 
     case MODULE_NAME:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124946.427064.patch
Type: text/x-patch
Size: 1533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220504/751111a5/attachment.bin>


More information about the cfe-commits mailing list