[llvm] r354978 - [DebugInfo] Apply subprogram attributes on behalf of owner CU

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 27 06:46:59 PST 2019


Author: evgeny777
Date: Wed Feb 27 06:46:59 2019
New Revision: 354978

URL: http://llvm.org/viewvc/llvm-project?rev=354978&view=rev
Log:
[DebugInfo] Apply subprogram attributes on behalf of owner CU

When using full LTO it is possible that template function definition DIE
is bound to one compilation unit and it's declaration to another. We should
add function declaration attributes on behalf of its owner CU otherwise
we may end up with malformed file identifier in function declaration 
DW_AT_decl_file attribute.

Differential revision: https://reviews.llvm.org/D58538

Added:
    llvm/trunk/test/DebugInfo/X86/template_function_decl.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/DIE.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Modified: llvm/trunk/include/llvm/CodeGen/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DIE.h?rev=354978&r1=354977&r2=354978&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DIE.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DIE.h Wed Feb 27 06:46:59 2019
@@ -759,7 +759,7 @@ public:
   ///
   /// \returns the DIEUnit that represents the compile or type unit that owns
   /// this DIE, or NULL if this DIE hasn't been added to a unit DIE.
-  const DIEUnit *getUnit() const;
+  DIEUnit *getUnit() const;
 
   void setOffset(unsigned O) { Offset = O; }
   void setSize(unsigned S) { Size = S; }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=354978&r1=354977&r2=354978&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Wed Feb 27 06:46:59 2019
@@ -211,7 +211,7 @@ const DIE *DIE::getUnitDie() const {
   return nullptr;
 }
 
-const DIEUnit *DIE::getUnit() const {
+DIEUnit *DIE::getUnit() const {
   const DIE *UnitDie = getUnitDie();
   if (UnitDie)
     return UnitDie->Owner.dyn_cast<DIEUnit*>();

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=354978&r1=354977&r2=354978&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Wed Feb 27 06:46:59 2019
@@ -1106,7 +1106,8 @@ DIE *DwarfUnit::getOrCreateSubprogramDIE
   if (SP->isDefinition())
     return &SPDie;
 
-  applySubprogramAttributes(SP, SPDie);
+  static_cast<DwarfUnit *>(SPDie.getUnit())
+      ->applySubprogramAttributes(SP, SPDie);
   return &SPDie;
 }
 

Added: llvm/trunk/test/DebugInfo/X86/template_function_decl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/template_function_decl.ll?rev=354978&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/template_function_decl.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/template_function_decl.ll Wed Feb 27 06:46:59 2019
@@ -0,0 +1,92 @@
+; Checks that DW_AT_decl_file attribute is correctly set for
+; template function declaration. When using full LTO we likely
+; end up having multiple CUs in a single DWARF file, and it is
+; possible that we add template function declaration DIE from
+; CU#1 to structure type DIE from CU#2. In such case we should
+; add source line attributes on behalf of CU#2, not CU#1
+
+; Example source code used to generate this sample (C++)
+; // File inc1.h
+; struct S {
+;   template <typename T> static void tmpfn() {}
+; };
+;
+; // File: inc2.h
+; extern int x;
+; int x;
+;
+; // File: foo.cpp
+; #include "inc1.h"
+; S s;
+;
+; // File: bar.cpp
+; #include "inc1.h"
+; #include "inc2.h"
+; void f3() { S::tmpfn<int>(); }
+
+; RUN: llc -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump %t -o - | FileCheck %s
+
+; CHECK:       DW_AT_linkage_name ("_ZN1S5tmpfnIiEEvv")
+; CHECK-NEXT:  DW_AT_name ("tmpfn<int>")
+; CHECK-NEXT:  DW_AT_decl_file ("{{.*}}inc1.h")
+; CHECK-NEXT:  DW_AT_decl_line (2)
+
+source_filename = "ld-temp.o"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.S = type { i8 }
+
+$_ZN1S5tmpfnIiEEvv = comdat any
+
+ at s = dso_local global %struct.S zeroinitializer, align 1, !dbg !0
+ at x = dso_local global i32 0, align 4, !dbg !8
+
+; Function Attrs: noinline optnone uwtable
+define dso_local void @_Z2f3v() !dbg !21 {
+  call void @_ZN1S5tmpfnIiEEvv(), !dbg !24
+  ret void, !dbg !25
+}
+
+; Function Attrs: noinline nounwind optnone uwtable
+define weak_odr dso_local void @_ZN1S5tmpfnIiEEvv() comdat align 2 !dbg !26 {
+  ret void, !dbg !30
+}
+
+!llvm.dbg.cu = !{!2, !10}
+!llvm.ident = !{!15, !15}
+!llvm.module.flags = !{!16, !17, !18, !19, !20}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 9.0.0 (trunk 354767)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
+!3 = !DIFile(filename: "foo.cpp", directory: "/home/evgeny/work/cpp_lexer/sample2")
+!4 = !{}
+!5 = !{!0}
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !7, line: 1, size: 8, flags: DIFlagTypePassByValue | DIFlagTrivial, elements: !4, identifier: "_ZTS1S")
+!7 = !DIFile(filename: "./inc1.h", directory: "/home/evgeny/work/cpp_lexer/sample2")
+!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
+!9 = distinct !DIGlobalVariable(name: "x", scope: !10, file: !13, line: 2, type: !14, isLocal: false, isDefinition: true)
+!10 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !11, producer: "clang version 9.0.0 (trunk 354767)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !12, nameTableKind: None)
+!11 = !DIFile(filename: "bar.cpp", directory: "/home/evgeny/work/cpp_lexer/sample2")
+!12 = !{!8}
+!13 = !DIFile(filename: "./inc2.h", directory: "/home/evgeny/work/cpp_lexer/sample2")
+!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!15 = !{!"clang version 9.0.0 (trunk 354767)"}
+!16 = !{i32 2, !"Dwarf Version", i32 4}
+!17 = !{i32 2, !"Debug Info Version", i32 3}
+!18 = !{i32 1, !"wchar_size", i32 4}
+!19 = !{i32 1, !"ThinLTO", i32 0}
+!20 = !{i32 1, !"EnableSplitLTOUnit", i32 0}
+!21 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !11, file: !11, line: 3, type: !22, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !10, retainedNodes: !4)
+!22 = !DISubroutineType(types: !23)
+!23 = !{null}
+!24 = !DILocation(line: 3, column: 13, scope: !21)
+!25 = !DILocation(line: 3, column: 30, scope: !21)
+!26 = distinct !DISubprogram(name: "tmpfn<int>", linkageName: "_ZN1S5tmpfnIiEEvv", scope: !6, file: !7, line: 2, type: !22, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !10, templateParams: !28, declaration: !27, retainedNodes: !4)
+!27 = !DISubprogram(name: "tmpfn<int>", linkageName: "_ZN1S5tmpfnIiEEvv", scope: !6, file: !7, line: 2, type: !22, scopeLine: 2, flags: DIFlagPrototyped | DIFlagStaticMember, spFlags: 0, templateParams: !28)
+!28 = !{!29}
+!29 = !DITemplateTypeParameter(name: "T", type: !14)
+!30 = !DILocation(line: 2, column: 46, scope: !26)
+




More information about the llvm-commits mailing list