mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Set clang module directory correctly with fmodule-file-home-is-cwd
When building and importing modules built with `-fmodule-file-home-is-cwd` we should be setting the debug info directory to the current working directory. This matches the behavior in clang: https://reviews.llvm.org/D134911
This commit is contained in:
@@ -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"
|
||||
@@ -404,7 +406,7 @@ public:
|
||||
auto *CS = DS->InlinedCallSite;
|
||||
if (!CS)
|
||||
return nullptr;
|
||||
|
||||
|
||||
auto CachedInlinedAt = InlinedAtCache.find(CS);
|
||||
if (CachedInlinedAt != InlinedAtCache.end())
|
||||
return cast<llvm::MDNode>(CachedInlinedAt->second);
|
||||
@@ -769,6 +771,15 @@ private:
|
||||
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;
|
||||
@@ -1308,7 +1319,7 @@ private:
|
||||
}
|
||||
// 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,
|
||||
@@ -1561,7 +1572,7 @@ private:
|
||||
return createPointerSizedStruct(Scope,
|
||||
MangledName,
|
||||
MainFile, 0, Flags, MangledName);
|
||||
|
||||
|
||||
case TypeKind::BuiltinTuple:
|
||||
llvm_unreachable("BuiltinTupleType should not show up here");
|
||||
|
||||
@@ -1818,7 +1829,7 @@ private:
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) {
|
||||
// Is this an empty type?
|
||||
if (DbgTy.isNull())
|
||||
|
||||
16
test/DebugInfo/module-file-home-is-cwd.swift
Normal file
16
test/DebugInfo/module-file-home-is-cwd.swift
Normal file
@@ -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")
|
||||
Reference in New Issue
Block a user