Skip to content

Set clang module directory correctly with fmodule-file-home-is-cwd #68865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Serialization/ASTReader.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Config/config.h"
Expand Down Expand Up @@ -404,7 +406,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
auto *CS = DS->InlinedCallSite;
if (!CS)
return nullptr;

auto CachedInlinedAt = InlinedAtCache.find(CS);
if (CachedInlinedAt != InlinedAtCache.end())
return cast<llvm::MDNode>(CachedInlinedAt->second);
Expand Down Expand Up @@ -769,6 +771,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
uint64_t Signature =
Desc.getSignature() ? Desc.getSignature().truncatedValue() : ~1ULL;

// Clang modules using fmodule-file-home-is-cwd should have their
// include path set to the working directory.
auto &HSI =
CI.getClangPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts();
if (HSI.ModuleFileHomeIsCwd) {
Desc = ASTSourceDescriptor(Desc.getModuleName(), Opts.DebugCompilationDir,
Desc.getASTFile(), Desc.getSignature());
}

// Handle Clang modules.
if (ClangModule) {
llvm::DIModule *Parent = nullptr;
Expand Down Expand Up @@ -1308,7 +1319,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
}
// FIXME: assert that SizeInBits == OffsetInBits.
SizeInBits = OffsetInBits;

auto FwdDecl = llvm::TempDINode(DBuilder.createReplaceableCompositeType(
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, MainFile, 0,
llvm::dwarf::DW_LANG_Swift, SizeInBits, AlignInBits, Flags,
Expand Down Expand Up @@ -1561,7 +1572,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
return createPointerSizedStruct(Scope,
MangledName,
MainFile, 0, Flags, MangledName);

case TypeKind::BuiltinTuple:
llvm_unreachable("BuiltinTupleType should not show up here");

Expand Down Expand Up @@ -1818,7 +1829,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
return true;
}
#endif

llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) {
// Is this an empty type?
if (DbgTy.isNull())
Expand Down
16 changes: 16 additions & 0 deletions test/DebugInfo/module-file-home-is-cwd.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// First populate the module cache to avoid issues with implicit modules
// and -fmodule-file-home-is-cwd.
// RUN: %target-swift-frontend -module-cache-path %t.mcp -emit-ir %s \
// RUN: -g -I %S/Inputs -o /dev/null

// RUN: %target-swift-frontend -module-cache-path %t.mcp -emit-ir %s \
// RUN: -g -I %S/Inputs -file-compilation-dir /CWD \
// RUN: -Xcc -Xclang -Xcc -fmodule-file-home-is-cwd \
// RUN: -o - | %FileCheck %s

import ClangModule.SubModule

let _ = someFunc(0)

// Ensure compilation directory is set to the debug compilation directory.
// CHECK: !DIFile(filename: "ClangModule", directory: "/CWD")