Skip to content

Commit df48b60

Browse files
Merge pull request #68865 from rmaz/breadcrumbcwd
Set clang module directory correctly with fmodule-file-home-is-cwd
2 parents cbf9694 + 76dd1f9 commit df48b60

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "clang/Basic/SourceManager.h"
4949
#include "clang/Basic/TargetInfo.h"
5050
#include "clang/Frontend/CompilerInstance.h"
51+
#include "clang/Lex/HeaderSearchOptions.h"
52+
#include "clang/Lex/Preprocessor.h"
5153
#include "clang/Serialization/ASTReader.h"
5254
#include "llvm/ADT/StringSet.h"
5355
#include "llvm/Config/config.h"
@@ -404,7 +406,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
404406
auto *CS = DS->InlinedCallSite;
405407
if (!CS)
406408
return nullptr;
407-
409+
408410
auto CachedInlinedAt = InlinedAtCache.find(CS);
409411
if (CachedInlinedAt != InlinedAtCache.end())
410412
return cast<llvm::MDNode>(CachedInlinedAt->second);
@@ -769,6 +771,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
769771
uint64_t Signature =
770772
Desc.getSignature() ? Desc.getSignature().truncatedValue() : ~1ULL;
771773

774+
// Clang modules using fmodule-file-home-is-cwd should have their
775+
// include path set to the working directory.
776+
auto &HSI =
777+
CI.getClangPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts();
778+
if (HSI.ModuleFileHomeIsCwd) {
779+
Desc = ASTSourceDescriptor(Desc.getModuleName(), Opts.DebugCompilationDir,
780+
Desc.getASTFile(), Desc.getSignature());
781+
}
782+
772783
// Handle Clang modules.
773784
if (ClangModule) {
774785
llvm::DIModule *Parent = nullptr;
@@ -1308,7 +1319,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13081319
}
13091320
// FIXME: assert that SizeInBits == OffsetInBits.
13101321
SizeInBits = OffsetInBits;
1311-
1322+
13121323
auto FwdDecl = llvm::TempDINode(DBuilder.createReplaceableCompositeType(
13131324
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, MainFile, 0,
13141325
llvm::dwarf::DW_LANG_Swift, SizeInBits, AlignInBits, Flags,
@@ -1561,7 +1572,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15611572
return createPointerSizedStruct(Scope,
15621573
MangledName,
15631574
MainFile, 0, Flags, MangledName);
1564-
1575+
15651576
case TypeKind::BuiltinTuple:
15661577
llvm_unreachable("BuiltinTupleType should not show up here");
15671578

@@ -1818,7 +1829,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
18181829
return true;
18191830
}
18201831
#endif
1821-
1832+
18221833
llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) {
18231834
// Is this an empty type?
18241835
if (DbgTy.isNull())
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// First populate the module cache to avoid issues with implicit modules
2+
// and -fmodule-file-home-is-cwd.
3+
// RUN: %target-swift-frontend -module-cache-path %t.mcp -emit-ir %s \
4+
// RUN: -g -I %S/Inputs -o /dev/null
5+
6+
// RUN: %target-swift-frontend -module-cache-path %t.mcp -emit-ir %s \
7+
// RUN: -g -I %S/Inputs -file-compilation-dir /CWD \
8+
// RUN: -Xcc -Xclang -Xcc -fmodule-file-home-is-cwd \
9+
// RUN: -o - | %FileCheck %s
10+
11+
import ClangModule.SubModule
12+
13+
let _ = someFunc(0)
14+
15+
// Ensure compilation directory is set to the debug compilation directory.
16+
// CHECK: !DIFile(filename: "ClangModule", directory: "/CWD")

0 commit comments

Comments
 (0)