Skip to content

Commit 2b68ec1

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
1 parent 5e8e03d commit 2b68ec1

File tree

14 files changed

+51
-114
lines changed

14 files changed

+51
-114
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,7 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
643643
}
644644

645645
StringRef CGDebugInfo::getCurrentDirname() {
646-
if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
647-
return CGM.getCodeGenOpts().DebugCompilationDir;
648-
649-
if (!CWDName.empty())
650-
return CWDName;
651-
llvm::ErrorOr<std::string> CWD =
652-
CGM.getFileSystem()->getCurrentWorkingDirectory();
653-
if (!CWD)
654-
return StringRef();
655-
return CWDName = internString(*CWD);
646+
return CGM.getCodeGenOpts().DebugCompilationDir;
656647
}
657648

658649
void CGDebugInfo::CreateCompileUnit() {
@@ -3246,6 +3237,9 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
32463237
std::string Remapped = remapDIPath(Path);
32473238
StringRef Relative(Remapped);
32483239
StringRef CompDir = TheCU->getDirectory();
3240+
if (CompDir.empty())
3241+
return Remapped;
3242+
32493243
if (Relative.consume_front(CompDir))
32503244
Relative.consume_front(llvm::sys::path::get_separator());
32513245

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class CGDebugInfo {
158158
/// This is a storage for names that are constructed on demand. For
159159
/// example, C++ destructors, C++ operators etc..
160160
llvm::BumpPtrAllocator DebugInfoNames;
161-
StringRef CWDName;
162161

163162
llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
164163
llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,12 +2449,7 @@ CoverageMappingModuleGen::CoverageMappingModuleGen(
24492449
: CGM(CGM), SourceInfo(SourceInfo) {}
24502450

24512451
std::string CoverageMappingModuleGen::getCurrentDirname() {
2452-
if (!CGM.getCodeGenOpts().CoverageCompilationDir.empty())
2453-
return CGM.getCodeGenOpts().CoverageCompilationDir;
2454-
2455-
SmallString<256> CWD;
2456-
llvm::sys::fs::current_path(CWD);
2457-
return CWD.str().str();
2452+
return CGM.getCodeGenOpts().CoverageCompilationDir;
24582453
}
24592454

24602455
std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,18 @@ static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC,
242242
static const char *addDebugCompDirArg(const ArgList &Args,
243243
ArgStringList &CmdArgs,
244244
const llvm::vfs::FileSystem &VFS) {
245+
std::string DebugCompDir;
245246
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
246-
options::OPT_fdebug_compilation_dir_EQ)) {
247-
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
248-
CmdArgs.push_back(Args.MakeArgString(Twine("-fdebug-compilation-dir=") +
249-
A->getValue()));
247+
options::OPT_fdebug_compilation_dir_EQ))
248+
DebugCompDir = A->getValue();
249+
250+
if (DebugCompDir.empty()) {
251+
if (llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory())
252+
DebugCompDir = std::move(*CWD);
250253
else
251-
A->render(Args, CmdArgs);
252-
} else if (llvm::ErrorOr<std::string> CWD =
253-
VFS.getCurrentWorkingDirectory()) {
254-
CmdArgs.push_back(Args.MakeArgString("-fdebug-compilation-dir=" + *CWD));
254+
return nullptr;
255255
}
256+
CmdArgs.push_back(Args.MakeArgString("-fdebug-compilation-dir=" + DebugCompDir));
256257
StringRef Path(CmdArgs.back());
257258
return Path.substr(Path.find('=') + 1).data();
258259
}
@@ -541,17 +542,17 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
541542
CmdArgs.push_back("-fcoverage-mcdc");
542543
}
543544

545+
StringRef CoverageCompDir;
544546
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
545-
options::OPT_fcoverage_compilation_dir_EQ)) {
546-
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
547-
CmdArgs.push_back(Args.MakeArgString(
548-
Twine("-fcoverage-compilation-dir=") + A->getValue()));
549-
else
550-
A->render(Args, CmdArgs);
551-
} else if (llvm::ErrorOr<std::string> CWD =
552-
D.getVFS().getCurrentWorkingDirectory()) {
553-
CmdArgs.push_back(Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD));
554-
}
547+
options::OPT_fcoverage_compilation_dir_EQ))
548+
CoverageCompDir = A->getValue();
549+
if (CoverageCompDir.empty()) {
550+
if (auto CWD = D.getVFS().getCurrentWorkingDirectory())
551+
CmdArgs.push_back(
552+
Args.MakeArgString(Twine("-fcoverage-compilation-dir=") + *CWD));
553+
} else
554+
CmdArgs.push_back(Args.MakeArgString(Twine("-fcoverage-compilation-dir=") +
555+
CoverageCompDir));
555556

556557
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
557558
auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,8 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts,
144144

145145
static void optimizeCWD(CowCompilerInvocation &BuildInvocation, StringRef CWD) {
146146
BuildInvocation.getMutFileSystemOpts().WorkingDir.clear();
147-
if (BuildInvocation.getCodeGenOpts().DwarfVersion) {
148-
// It is necessary to explicitly set the DebugCompilationDir
149-
// to a common directory (e.g. root) if IgnoreCWD is true.
150-
// When IgnoreCWD is true, the module's content should not
151-
// depend on the current working directory. However, if dwarf
152-
// information is needed (when CGOpts.DwarfVersion is
153-
// non-zero), then CGOpts.DebugCompilationDir must be
154-
// populated, because otherwise the current working directory
155-
// will be automatically embedded in the dwarf information in
156-
// the pcm, contradicting the assumption that it is safe to
157-
// ignore the CWD. Thus in such cases,
158-
// CGOpts.DebugCompilationDir is explicitly set to a common
159-
// directory.
160-
// FIXME: It is still excessive to create a copy of
161-
// CodeGenOpts for each module. Since we do not modify the
162-
// CodeGenOpts otherwise per module, the following code
163-
// ends up generating identical CodeGenOpts for each module
164-
// with DebugCompilationDir pointing to the root directory.
165-
// We can optimize this away by creating a _single_ copy of
166-
// CodeGenOpts whose DebugCompilationDir points to the root
167-
// directory and reuse it across modules.
168-
BuildInvocation.getMutCodeGenOpts().DebugCompilationDir =
169-
llvm::sys::path::root_path(CWD);
170-
}
147+
BuildInvocation.getMutCodeGenOpts().DebugCompilationDir.clear();
148+
BuildInvocation.getMutCodeGenOpts().CoverageCompilationDir.clear();
171149
}
172150

173151
static std::vector<std::string> splitString(std::string S, char Separator) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
// REQUIRES: shell
2-
31
// RUN: rm -rf %t
42
// RUN: split-file %s %t
53
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
64
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format \
75
// RUN: experimental-full -optimize-args=all > %t/result.json
86
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
97

8+
// RUN: %deps-to-rsp %t/result.json --module-name=mod > %t/mod.rsp
9+
// RUN: %clang @%t/mod.rsp -o %t/mod.pcm
10+
// RUN: llvm-dwarfdump --debug-info %t/mod.pcm | FileCheck %s --check-prefix=DWARF
11+
// DWARF: DW_TAG_compile_unit
12+
// DWARF-NOT: DW_AT_comp_dir
13+
1014
//--- cdb.json.in
1115
[{
1216
"directory": "DIR",
@@ -28,5 +32,5 @@ module mod {
2832
// directory when current working directory optimization is in effect.
2933
// CHECK: "modules": [
3034
// CHECK: "command-line": [
31-
// CHECK: "-fdebug-compilation-dir={{\/|.*:(\\)?}}",
35+
// CHECK-NOT: -fdebug-compilation-dir
3236
// CHECK: "translation-units": [

clang/test/CodeGen/debug-info-abspath.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22
// RUN: cp %s %t/UNIQUEISH_SENTINEL/debug-info-abspath.c
33

44
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
5+
// RUN: -fdebug-compilation-dir=%t/UNIQUEISH_SENTINEL/debug-info-abspath.c \
56
// RUN: %t/UNIQUEISH_SENTINEL/debug-info-abspath.c -emit-llvm -o - \
67
// RUN: | FileCheck %s
78

89
// RUN: cp %s %t.c
910
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
11+
// RUN: -fdebug-compilation-dir=%t \
1012
// RUN: %t.c -emit-llvm -o - | FileCheck %s --check-prefix=INTREE
1113

12-
// RUN: cd %t/UNIQUEISH_SENTINEL
13-
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
14-
// RUN: debug-info-abspath.c -emit-llvm -o - \
15-
// RUN: | FileCheck %s --check-prefix=CURDIR
16-
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
17-
// RUN: %s -emit-llvm -o - | FileCheck %s --check-prefix=CURDIR
18-
1914
void foo(void) {}
2015

2116
// Since %s is an absolute path, directory should be the common
@@ -28,7 +23,3 @@ void foo(void) {}
2823

2924
// INTREE: = distinct !DISubprogram({{.*}}![[SPFILE:[0-9]+]]
3025
// INTREE: DIFile({{.*}}directory: "{{.+}}CodeGen{{.*}}")
31-
32-
// CURDIR: = distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
33-
// CURDIR: ![[CUFILE]] = !DIFile({{.*}}directory: "{{.+}}UNIQUEISH_SENTINEL")
34-

clang/test/CodeGen/debug-info-compilation-dir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@
77
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-DIR %s
88
// CHECK-DIR: CodeGen
99

10+
/// Test path remapping.
11+
// RUN: %clang_cc1 -fdebug-compilation-dir=%S -main-file-name %s -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-ABS %s
12+
// CHECK-ABS: DIFile(filename: "{{.*}}debug-info-compilation-dir.c", directory: "{{.*}}CodeGen")
13+
14+
// RUN: %clang_cc1 -main-file-name %s -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-NOMAP %s
15+
// CHECK-NOMAP: DIFile(filename: "{{.*}}debug-info-compilation-dir.c", directory: "")
16+

clang/test/CodeGen/debug-prefix-map.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// RUN: rm -rf %t && mkdir -p %t/a/b && cp %s %t/a/b/c.c
1313
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -fdebug-prefix-map=%t/a/b=y -fdebug-prefix-map=%t/a=x %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-X
1414
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -fdebug-prefix-map=%t/a=x -fdebug-prefix-map=%t/a/b=y %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-Y
15+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -main-file-name %t/a/b/c.c -fdebug-compilation-dir=%t/a -fdebug-prefix-map=%t/a=x -fdebug-prefix-map=%t/a/b=y %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-REMAP-Y
1516

1617
#include "Inputs/stdio.h"
1718

@@ -26,9 +27,9 @@ void test_rewrite_includes(void) {
2627
vprintf("string", argp);
2728
}
2829

29-
// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}<stdin>",
3030
// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}",
3131
// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "")
32+
// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}<stdin>",
3233
// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}Inputs{{/|\\\\}}stdio.h",
3334
// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "")
3435
// CHECK-NO-MAIN-FILE-NAME-NOT: !DIFile(filename:
@@ -54,3 +55,5 @@ void test_rewrite_includes(void) {
5455

5556
// CHECK-X: !DIFile(filename: "x{{/|\\\\}}b{{/|\\\\}}c.c", directory: "")
5657
// CHECK-Y: !DIFile(filename: "y{{/|\\\\}}c.c", directory: "")
58+
59+
// CHECK-REMAP-Y: !DIFile(filename: "y{{/|\\\\}}c.c", directory: "x")

clang/test/CodeGenCXX/debug-info-function-context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s \
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s -fdebug-compilation-dir=%S \
22
// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp -o - | FileCheck %s
33

44
struct C {

0 commit comments

Comments
 (0)