Skip to content

Commit c958639

Browse files
Awanish PandeySouraVX
authored andcommitted
[DWARF5][DebugInfo]: Added support for DebugInfo generation for auto return type for C++ member functions.
Summary: This patch will provide support for auto return type for the C++ member functions. Before this return type of the member function is deduced and stored in the DIE. This patch includes llvm side implementation of this feature. Patch by: Awanish Pandey <[email protected]> Reviewers: dblaikie, aprantl, shafik, alok, SouraVX, jini.susan.george Reviewed by: dblaikie Differential Revision: https://reviews.llvm.org/D70524
1 parent 52aaf4a commit c958639

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,14 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
11651165
DIE *DeclDie = nullptr;
11661166
StringRef DeclLinkageName;
11671167
if (auto *SPDecl = SP->getDeclaration()) {
1168+
DITypeRefArray DeclArgs, DefinationArgs;
1169+
DeclArgs = SPDecl->getType()->getTypeArray();
1170+
DefinationArgs = SP->getType()->getTypeArray();
1171+
1172+
if (DeclArgs.size() && DefinationArgs.size())
1173+
if (DeclArgs[0] != DefinationArgs[0])
1174+
addType(SPDie, DefinationArgs[0]);
1175+
11681176
DeclDie = getDIE(SPDecl);
11691177
assert(DeclDie && "This DIE should've already been constructed when the "
11701178
"definition DIE was created in "
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
2+
3+
; CHECK: .debug_info contents:
4+
5+
; CHECK: DW_TAG_subprogram
6+
; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1] (indexed {{.*}} string = "_ZN7myClass7findMaxEv")
7+
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} "auto")
8+
; CHECK-NEXT: DW_AT_declaration [DW_FORM_flag_present] (true)
9+
10+
; CHECK: DW_TAG_subprogram
11+
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} "double")
12+
; CHECK: DW_AT_specification [DW_FORM_ref4] (cu + {{.*}} "_ZN7myClass7findMaxEv")
13+
14+
; C++ source to regenerate:
15+
; struct myClass {
16+
; auto findMax();
17+
; };
18+
;
19+
; auto myClass::findMax() {
20+
; return 0.0;
21+
; }
22+
23+
; $ clang++ -O0 -g -gdwarf-5 debug-info-template-align.cpp -c
24+
25+
; ModuleID = '/dir/test.cpp'
26+
source_filename = "/dir/test.cpp"
27+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
28+
target triple = "x86_64-unknown-linux-gnu"
29+
30+
%struct.myClass = type { i8 }
31+
; Function Attrs: noinline nounwind optnone uwtable
32+
define dso_local double @_ZN7myClass7findMaxEv(%struct.myClass* %this) #0 align 2 !dbg !7 {
33+
entry:
34+
%this.addr = alloca %struct.myClass*, align 8
35+
store %struct.myClass* %this, %struct.myClass** %this.addr, align 8
36+
call void @llvm.dbg.declare(metadata %struct.myClass** %this.addr, metadata !17, metadata !DIExpression()), !dbg !19
37+
%this1 = load %struct.myClass*, %struct.myClass** %this.addr, align 8
38+
ret double 0.000000e+00, !dbg !20
39+
}
40+
; Function Attrs: nounwind readnone speculatable willreturn
41+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
42+
43+
attributes #0 = { noinline nounwind optnone uwtable }
44+
attributes #1 = { nounwind readnone speculatable willreturn }
45+
46+
!llvm.dbg.cu = !{!0}
47+
!llvm.module.flags = !{!3, !4, !5}
48+
!llvm.ident = !{!6}
49+
50+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
51+
!1 = !DIFile(filename: "/dir/test.cpp", directory: "/dir/", checksumkind: CSK_MD5, checksum: "4bed8955bd441e3129c12f557ed53962")
52+
!2 = !{}
53+
!3 = !{i32 7, !"Dwarf Version", i32 5}
54+
!4 = !{i32 2, !"Debug Info Version", i32 3}
55+
!5 = !{i32 1, !"wchar_size", i32 4}
56+
!6 = !{!"clang version 10.0.0"}
57+
!7 = distinct !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 20, type: !9, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13, retainedNodes: !2)
58+
!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "myClass", file: !1, line: 16, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS7myClass")
59+
!9 = !DISubroutineType(types: !10)
60+
!10 = !{!11, !12}
61+
!11 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
62+
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
63+
!13 = !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 17, type: !14, scopeLine: 17, flags: DIFlagPrototyped, spFlags: 0)
64+
!14 = !DISubroutineType(types: !15)
65+
!15 = !{!16, !12}
66+
!16 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto")
67+
!17 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !18, flags: DIFlagArtificial | DIFlagObjectPointer)
68+
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
69+
!19 = !DILocation(line: 0, scope: !7)
70+
!20 = !DILocation(line: 21, column: 3, scope: !7)

0 commit comments

Comments
 (0)