Skip to content

Commit 75b4ff6

Browse files
committed
Address code review and try fixing the test on windows.
1 parent 7021180 commit 75b4ff6

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts,
129129
Opts.Remarks.clear();
130130
}
131131

132-
static void optimizeCWD(FileSystemOptions &FSOpts, CodeGenOptions &CGOpts,
133-
const std::string &CWD) {
134-
FSOpts.WorkingDir.clear();
135-
if (CGOpts.DwarfVersion) {
132+
static void optimizeCWD(CowCompilerInvocation &BuildInvocation, StringRef CWD) {
133+
BuildInvocation.getMutFileSystemOpts().WorkingDir.clear();
134+
if (BuildInvocation.getCodeGenOpts().DwarfVersion) {
136135
// It is necessary to explicitly set the DebugCompilationDir
137136
// to a common directory (e.g. root) if IgnoreCWD is true.
138137
// When IgnoreCWD is true, the module's content should not
@@ -145,7 +144,16 @@ static void optimizeCWD(FileSystemOptions &FSOpts, CodeGenOptions &CGOpts,
145144
// ignore the CWD. Thus in such cases,
146145
// CGOpts.DebugCompilationDir is explicitly set to a common
147146
// directory.
148-
CGOpts.DebugCompilationDir = llvm::sys::path::root_path(CWD);
147+
// FIXME: It is still excessive to create a copy of
148+
// CodeGenOpts for each module. Since we do not modify the
149+
// CodeGenOpts otherwise per module, the following code
150+
// ends up generating identical CodeGenOpts for each module
151+
// with DebugCompilationDir pointing to the root directory.
152+
// We can optimize this away by creating a _single_ copy of
153+
// CodeGenOpts whose DebugCompilationDir points to the root
154+
// directory and reuse it across modules.
155+
BuildInvocation.getMutCodeGenOpts().DebugCompilationDir =
156+
llvm::sys::path::root_path(CWD);
149157
}
150158
}
151159

@@ -765,8 +773,7 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
765773
MDC.ScanInstance.getVirtualFileSystem()
766774
.getCurrentWorkingDirectory();
767775
if (CWD)
768-
optimizeCWD(BuildInvocation.getMutFileSystemOpts(),
769-
BuildInvocation.getMutCodeGenOpts(), *CWD);
776+
optimizeCWD(BuildInvocation, *CWD);
770777
}
771778
});
772779

clang/test/ClangScanDeps/modules-debug-dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// REQUIRES: shell
2+
13
// RUN: rm -rf %t
24
// RUN: split-file %s %t
35
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
46
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format \
57
// RUN: experimental-full > %t/result.json
6-
// RUN: cat %t/result.json | FileCheck %s
8+
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
79

810
//--- cdb.json.in
911
[{
@@ -26,5 +28,5 @@ module mod {
2628
// directory when current working directory optimization is in effect.
2729
// CHECK: "modules": [
2830
// CHECK: "command-line": [
29-
// CHECK: "-fdebug-compilation-dir={{\/|.*:}}",
31+
// CHECK: "-fdebug-compilation-dir={{\/|.*:(\\)?}}",
3032
// CHECK: "translation-units": [

0 commit comments

Comments
 (0)