Author: Richard Howell
Date: 2023-04-05T07:19:48-07:00
New Revision: 8ee5029b225ba1ff415e0a0a6a68dc4e3efee4d1

URL: 
https://github.com/llvm/llvm-project/commit/8ee5029b225ba1ff415e0a0a6a68dc4e3efee4d1
DIFF: 
https://github.com/llvm/llvm-project/commit/8ee5029b225ba1ff415e0a0a6a68dc4e3efee4d1.diff

LOG: [clang] don't serialize MODULE_DIRECTORY with ModuleFileHomeIsCwd

Fix a bug in the MODULE_DIRECTORY serialization logic
that would cause MODULE_DIRECTORY to be serialized when
`-fmodule-file-home-is-cwd` is specified.

This matches the original logic added in:
https://github.com/apple/llvm-project/commit/f7b41371d9ede1aecf0930e5bd4a463519264633

Reviewed By: keith

Differential Revision: https://reviews.llvm.org/D147561

Added: 
    

Modified: 
    clang/lib/Serialization/ASTWriter.cpp
    clang/test/Modules/module-file-home-is-cwd.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 177a3c3a34d73..245304254811a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1288,11 +1288,11 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, 
ASTContext &Context,
     // If the home of the module is the current working directory, then we
     // want to pick up the cwd of the build process loading the module, not
     // our cwd, when we load this module.
-    if (!(PP.getHeaderSearchInfo()
+    if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
+        (!PP.getHeaderSearchInfo()
               .getHeaderSearchOpts()
               .ModuleMapFileHomeIsCwd ||
-          PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) 
||
-        WritingModule->Directory->getName() != StringRef(".")) {
+         WritingModule->Directory->getName() != StringRef("."))) {
       // Module directory.
       auto Abbrev = std::make_shared<BitCodeAbbrev>();
       Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));

diff  --git a/clang/test/Modules/module-file-home-is-cwd.m 
b/clang/test/Modules/module-file-home-is-cwd.m
index 706b815e6d0c2..a3875d578bb60 100644
--- a/clang/test/Modules/module-file-home-is-cwd.m
+++ b/clang/test/Modules/module-file-home-is-cwd.m
@@ -5,11 +5,12 @@
 // RUN:     -fmodules-embed-all-files %S/Inputs/normal-module-map/module.map \
 // RUN:     -o %t/mod.pcm
 // RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s 
--check-prefix=INPUT
 
-// CHECK: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
-// CHECK: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
-// CHECK: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 // CHECK-NOT: MODULE_DIRECTORY
+// INPUT: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
+// INPUT: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
+// INPUT: <INPUT_FILE {{.*}}/> blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 
 @import libA;
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to