summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp27
-rw-r--r--clang/test/Modules/relative-dep-gen.cpp20
2 files changed, 32 insertions, 15 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 0a731f0d942..566c7d7c9f2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1185,17 +1185,26 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
}
if (WritingModule && WritingModule->Directory) {
- // Module directory.
- BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
- unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
- RecordData Record;
- Record.push_back(MODULE_DIRECTORY);
-
SmallString<128> BaseDir(WritingModule->Directory->getName());
cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
- Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
+
+ // 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()
+ .getHeaderSearchOpts()
+ .ModuleMapFileHomeIsCwd ||
+ WritingModule->Directory->getName() != StringRef(".")) {
+ // Module directory.
+ BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
+ unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
+
+ RecordData Record;
+ Record.push_back(MODULE_DIRECTORY);
+ Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
+ }
// Write out all other paths relative to the base directory if possible.
BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
diff --git a/clang/test/Modules/relative-dep-gen.cpp b/clang/test/Modules/relative-dep-gen.cpp
index 1c728a9906f..e58dd6eb359 100644
--- a/clang/test/Modules/relative-dep-gen.cpp
+++ b/clang/test/Modules/relative-dep-gen.cpp
@@ -17,14 +17,22 @@
// RUN: FileCheck --check-prefix=CHECK-BUILD %s < %t/build-cwd.d
// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit-cwd.d
// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-implicit-cwd.d
+//
+// Check that the .d file is still correct after relocating the module.
+// RUN: mkdir %t/Inputs
+// RUN: cp %S/Inputs/relative-dep-gen-1.h %t/Inputs
+// RUN: cp %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-file=%t/mod-cwd.pcm -dependency-file %t/use-explicit-no-map-cwd.d -MT use.o relative-dep-gen.cpp -fsyntax-only -fmodule-map-file-home-is-cwd
+// RUN: cat %t/use-explicit-no-map-cwd.d
+// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit-no-map-cwd.d
#include "Inputs/relative-dep-gen-1.h"
// CHECK-BUILD: mod.pcm:
-// CHECK-BUILD: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
-// CHECK-BUILD: Inputs/relative-dep-gen-1.h
-// CHECK-BUILD: Inputs/relative-dep-gen-2.h
+// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
+// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-1.h
+// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-2.h
// CHECK-USE: use.o:
-// CHECK-USE-DAG: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
-// CHECK-USE-DAG: relative-dep-gen.cpp
-// CHECK-USE-DAG: Inputs{{[/\\]}}relative-dep-gen-1.h
+// CHECK-USE-DAG: {{[ \t]}}relative-dep-gen.cpp
+// CHECK-USE-DAG: {{[ \t]}}Inputs{{[/\\]}}relative-dep-gen-1.h
OpenPOWER on IntegriCloud