From: Adrian Prantl Date: Thu, 13 Dec 2018 17:53:29 +0000 (+0000) Subject: Reinstate DW_AT_comp_dir support after D55519. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f50c5e1f7bde6f6d4cbb5ff45d369f686e9cac9e;p=clang Reinstate DW_AT_comp_dir support after D55519. The DIFile used by the CU is special and distinct from the main source file. Its directory part specifies what becomes the DW_AT_comp_dir (the compilation directory), even if the source file was specified with an absolute path. To support the .dwo workflow, a valid DW_AT_comp_dir is necessary even if source files were specified with an absolute path. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349065 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index e45b38c10e..f3a07a30eb 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -416,7 +416,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { // Cache the results. auto It = DIFileCache.find(FileName.data()); - if (It != DIFileCache.end()) { // Verify that the information still exists. if (llvm::Metadata *V = It->second) @@ -595,22 +594,27 @@ void CGDebugInfo::CreateCompileUnit() { break; } + uint64_t DwoId = 0; + auto &CGOpts = CGM.getCodeGenOpts(); + // The DIFile used by the CU is distinct from the main source + // file. Its directory part specifies what becomes the + // DW_AT_comp_dir (the compilation directory), even if the source + // file was specified with an absolute path. if (CSKind) CSInfo.emplace(*CSKind, Checksum); + llvm::DIFile *CUFile = DBuilder.createFile( + remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo, + getSource(SM, SM.getMainFileID())); // Create new compile unit. - // FIXME - Eliminate TheCU. - auto &CGOpts = CGM.getCodeGenOpts(); TheCU = DBuilder.createCompileUnit( - LangTag, - createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID())), - CGOpts.EmitVersionIdentMetadata ? Producer : "", + LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "", LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO, CGOpts.DwarfDebugFlags, RuntimeVers, (CGOpts.getSplitDwarfMode() != CodeGenOptions::NoFission) ? "" : CGOpts.SplitDwarfFile, - EmissionKind, 0 /* DWOid */, CGOpts.SplitDwarfInlining, + EmissionKind, DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling, CGM.getTarget().getTriple().isNVPTX() ? llvm::DICompileUnit::DebugNameTableKind::None diff --git a/test/CodeGen/debug-info-abspath.c b/test/CodeGen/debug-info-abspath.c index 1273235793..d360216da2 100644 --- a/test/CodeGen/debug-info-abspath.c +++ b/test/CodeGen/debug-info-abspath.c @@ -8,12 +8,29 @@ // RUN: cp %s %t.c // RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \ // RUN: %t.c -emit-llvm -o - | FileCheck %s --check-prefix=INTREE + +// RUN: cd %t/UNIQUEISH_SENTINEL +// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \ +// RUN: debug-info-abspath.c -emit-obj -o /tmp/t.o +// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \ +// RUN: debug-info-abspath.c -emit-llvm -o - \ +// RUN: | FileCheck %s --check-prefix=CURDIR +// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \ +// RUN: %s -emit-llvm -o - | FileCheck %s --check-prefix=CURDIR + void foo() {} // Since %s is an absolute path, directory should be the common // prefix, but the directory part should be part of the filename. -// CHECK: DIFile(filename: "{{.*}}UNIQUEISH_SENTINEL{{.*}}debug-info-abspath.c" -// CHECK-NOT: directory: "{{.*}}UNIQUEISH_SENTINEL +// CHECK: = distinct !DISubprogram({{.*}}file: ![[SPFILE:[0-9]+]] +// CHECK: ![[SPFILE]] = !DIFile(filename: "{{.*}}UNIQUEISH_SENTINEL +// CHECK-SAME: debug-info-abspath.c" +// CHECK-NOT: directory: "{{.*}}UNIQUEISH_SENTINEL +// INTREE: = distinct !DISubprogram({{.*}}![[SPFILE:[0-9]+]] // INTREE: DIFile({{.*}}directory: "{{.+}}CodeGen{{.*}}") + +// CURDIR: = distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]] +// CURDIR: ![[CUFILE]] = !DIFile({{.*}}directory: "{{.+}}UNIQUEISH_SENTINEL") +