Skip to content

[IncludeTree] Do not pass compilation directories #11034

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3332,6 +3332,10 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
std::string Remapped = remapDIPath(Path);
StringRef Relative(Remapped);
StringRef CompDir = TheCU->getDirectory();
// If compilation is not empty, return the path as it is.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this can probably go upstream but I can't write a test case for it since it only manifest for a file system that doesn't have current working directory.

if (CompDir.empty())
return Remapped;

if (Relative.consume_front(CompDir))
Relative.consume_front(llvm::sys::path::get_separator());

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Tooling/DependencyScanning/ScanAndUpdateArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void tooling::dependencies::configureInvocationForCaching(
// Clear APINotes options.
CI.getAPINotesOpts().ModuleSearchPaths = {};

// Reset debug/coverage compilation dir as include-tree uses absolute path.
CodeGenOpts.DebugCompilationDir.clear();
CodeGenOpts.CoverageCompilationDir.clear();
// Update output paths, and clear working directory.
auto CWD = FileSystemOpts.WorkingDir;
updateRelativePath(FrontendOpts.OutputFile, CWD);
Expand Down
8 changes: 6 additions & 2 deletions clang/test/ClangScanDeps/include-tree-preserve-pch-path.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// REQUIRES: ondisk_cas

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed -e "s|DIR|%/t|g" %t/cdb_pch.json.template > %t/cdb_pch.json
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
Expand All @@ -10,9 +11,10 @@

// CHECK: "-fmodule-format=obj"
// CHECK: "-dwarf-ext-refs"
// CHECK-NOT: -fdebug-compilation-dir

// RUN: %deps-to-rsp %t/deps_pch.json --tu-index 0 > %t/pch.rsp
// RUN: %clang @%t/pch.rsp
// RUN: %clang @%t/pch.rsp -Rcompile-job-cache

// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas > %t/deps_tu.json
// RUN: FileCheck %s -input-file %t/deps_tu.json -DPREFIX=%/t
Expand All @@ -21,7 +23,9 @@
// RUN: %clang @%t/tu.rsp

// RUN: cat %t/tu.ll | FileCheck %s -check-prefix=LLVMIR -DPREFIX=%/t
// LLVMIR: !DICompileUnit({{.*}}, splitDebugFilename: "prefix.pch"
// LLVMIR: !DIFile(filename: "[[PREFIX]]/tu.c", directory: "")
// LLVMIR: !DICompileUnit({{.*}}, splitDebugFilename: "[[PREFIX]]/prefix.pch"
// LLVMIR: !DIFile(filename: "prefix.h", directory: "")

// Extract include-tree casid
// RUN: cat %t/tu.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/tu.casid
Expand Down