Skip to content

Commit 1419b5d

Browse files
[CAS] Fix working-directory canonicalization when using clang cc1depscan
This is a followup to bb91b1c to fix the removal of working-directory when clang cc1depscan is used. Since the scanner will removes the working-directory, clang-driver needs to make sure the output is correct if that is a relative path to the `-working-directory` option. rdar://136203252
1 parent 01ad97d commit 1419b5d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5104,7 +5104,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job,
51045104
// file here.
51055105
if (Output.isFilename()) {
51065106
CmdArgs.push_back("-o");
5107-
CmdArgs.push_back(Output.getFilename());
5107+
// Fix up the output file if it is a relative path to
5108+
// `-working-directory`.
5109+
SmallString<128> OutPath(
5110+
Args.getLastArgValue(options::OPT_working_directory));
5111+
StringRef Out = Output.getFilename();
5112+
if (llvm::sys::path::is_relative(Out) && !OutPath.empty()) {
5113+
llvm::sys::path::append(OutPath, Output.getFilename());
5114+
Out = OutPath.str();
5115+
}
5116+
CmdArgs.push_back(Args.MakeArgString(Out));
51085117
}
51095118
// FIXME: Clean up this code and factor out the common logic (see the end of
51105119
// the function)

clang/test/CAS/path-independent-cas-outputs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
// RUN: 2>&1 | FileCheck %s --check-prefix=CACHE-HIT
2020
// RUN: diff %t/a/t1_working_dir.o %t/b/t2_working_dir.o
2121

22+
/// Check using a different working directory should cache hit as long as the compilation-dirs are setup correctly and inputs are the same.
23+
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \
24+
// RUN: %clang -target x86_64-apple-macos11 -c %s -working-directory %t/b -o t3_working_dir.o -DNEW_FLAG -Rcompile-job-cache -fdebug-compilation-dir=%t -fcoverage-compilation-dir=%t \
25+
// RUN: 2>&1 | FileCheck %s --check-prefix=CACHE-HIT
26+
2227
// Check that output path is correctly detected with - (stdout)
2328

2429
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \

0 commit comments

Comments
 (0)