From 8ee5029b225ba1ff415e0a0a6a68dc4e3efee4d1 Mon Sep 17 00:00:00 2001 From: Richard Howell Date: Tue, 4 Apr 2023 12:35:45 -0700 Subject: [PATCH] [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 --- clang/lib/Serialization/ASTWriter.cpp | 6 +++--- clang/test/Modules/module-file-home-is-cwd.m | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 177a3c3..2453042 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(); 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 706b815..a3875d5 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: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map' -// CHECK: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h' -// CHECK: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h' // CHECK-NOT: MODULE_DIRECTORY +// INPUT: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map' +// INPUT: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h' +// INPUT: blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h' @import libA; -- 2.7.4