diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 37f8b945d785e..d67178c153e88 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -144,30 +144,8 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts, static void optimizeCWD(CowCompilerInvocation &BuildInvocation, StringRef CWD) { BuildInvocation.getMutFileSystemOpts().WorkingDir.clear(); - if (BuildInvocation.getCodeGenOpts().DwarfVersion) { - // It is necessary to explicitly set the DebugCompilationDir - // to a common directory (e.g. root) if IgnoreCWD is true. - // When IgnoreCWD is true, the module's content should not - // depend on the current working directory. However, if dwarf - // information is needed (when CGOpts.DwarfVersion is - // non-zero), then CGOpts.DebugCompilationDir must be - // populated, because otherwise the current working directory - // will be automatically embedded in the dwarf information in - // the pcm, contradicting the assumption that it is safe to - // ignore the CWD. Thus in such cases, - // CGOpts.DebugCompilationDir is explicitly set to a common - // directory. - // FIXME: It is still excessive to create a copy of - // CodeGenOpts for each module. Since we do not modify the - // CodeGenOpts otherwise per module, the following code - // ends up generating identical CodeGenOpts for each module - // with DebugCompilationDir pointing to the root directory. - // We can optimize this away by creating a _single_ copy of - // CodeGenOpts whose DebugCompilationDir points to the root - // directory and reuse it across modules. - BuildInvocation.getMutCodeGenOpts().DebugCompilationDir = - llvm::sys::path::root_path(CWD); - } + BuildInvocation.getMutCodeGenOpts().DebugCompilationDir.clear(); + BuildInvocation.getMutCodeGenOpts().CoverageCompilationDir.clear(); } static std::vector splitString(std::string S, char Separator) { diff --git a/clang/test/ClangScanDeps/modules-debug-dir.c b/clang/test/ClangScanDeps/modules-debug-dir.c index c4fb4982ed791..e2a0e1b7a5b01 100644 --- a/clang/test/ClangScanDeps/modules-debug-dir.c +++ b/clang/test/ClangScanDeps/modules-debug-dir.c @@ -1,5 +1,3 @@ -// REQUIRES: shell - // RUN: rm -rf %t // RUN: split-file %s %t // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json @@ -7,6 +5,12 @@ // RUN: experimental-full -optimize-args=all > %t/result.json // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s +// RUN: %deps-to-rsp %t/result.json --module-name=mod > %t/mod.rsp +// RUN: %clang @%t/mod.rsp -o %t/mod.pcm +// RUN: llvm-dwarfdump --debug-info %t/mod.pcm | FileCheck %s --check-prefix=DWARF +// DWARF: DW_TAG_compile_unit +// DWARF-NOT: DW_AT_comp_dir + //--- cdb.json.in [{ "directory": "DIR", @@ -28,5 +32,5 @@ module mod { // directory when current working directory optimization is in effect. // CHECK: "modules": [ // CHECK: "command-line": [ -// CHECK: "-fdebug-compilation-dir={{\/|.*:(\\)?}}", +// CHECK-NOT: -fdebug-compilation-dir // CHECK: "translation-units": [