Skip to content

Commit c2a9bba

Browse files
[DebugInfo] Add DW_AT_artificial for compiler generated static member. (#115851)
Consider the case when the compiler generates a static member. Any consumer of the debug info generated for that case, would benefit if that member has the DW_AT_artificial flag.
1 parent 6be567b commit c2a9bba

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,10 @@ DIE *DwarfUnit::getOrCreateStaticMemberDIE(const DIDerivedType *DT) {
17891789
addFlag(StaticMemberDIE, dwarf::DW_AT_external);
17901790
addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
17911791

1792+
// Consider the case when the static member was created by the compiler.
1793+
if (DT->isArtificial())
1794+
addFlag(StaticMemberDIE, dwarf::DW_AT_artificial);
1795+
17921796
// FIXME: We could omit private if the parent is a class_type, and
17931797
// public if the parent is something else.
17941798
addAccess(StaticMemberDIE, DT->getFlags());
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; RUN: llc -O0 -filetype=obj < %s | \
2+
; RUN: llvm-dwarfdump --debug-info - | FileCheck %s
3+
4+
; LLVM IR generated from:
5+
6+
; struct S {
7+
; static int Member; <-- Manually marked as artificial
8+
; };
9+
; int S::Member = 1;
10+
11+
source_filename = "artificial-static-member.cpp"
12+
target triple = "x86_64-pc-linux-gnu"
13+
14+
@_ZN1S6MemberE = dso_local global i32 1, align 4, !dbg !0
15+
16+
!llvm.dbg.cu = !{!2}
17+
!llvm.module.flags = !{!9, !10}
18+
19+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
20+
!1 = distinct !DIGlobalVariable(name: "Member", linkageName: "_ZN1S6MemberE", scope: !2, type: !5, isLocal: false, isDefinition: true, declaration: !6)
21+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, emissionKind: FullDebug, globals: !4)
22+
!3 = !DIFile(filename: "artificial-static-member.cpp", directory: "")
23+
!4 = !{!0}
24+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
25+
!6 = !DIDerivedType(tag: DW_TAG_variable, name: "Member", scope: !7, baseType: !5, flags: DIFlagArtificial | DIFlagStaticMember)
26+
!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", size: 8, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS1S")
27+
!8 = !{!6}
28+
!9 = !{i32 7, !"Dwarf Version", i32 5}
29+
!10 = !{i32 2, !"Debug Info Version", i32 3}
30+
31+
; CHECK: {{.*}}DW_TAG_structure_type
32+
; CHECK-NEXT: DW_AT_calling_convention
33+
; CHECK-NEXT: DW_AT_name ("S")
34+
; CHECK-NEXT: DW_AT_byte_size
35+
36+
; CHECK: {{.*}}DW_TAG_variable
37+
; CHECK-NEXT: DW_AT_name ("Member")
38+
; CHECK-NEXT: DW_AT_type
39+
; CHECK-NEXT: DW_AT_external (true)
40+
; CHECK-NEXT: DW_AT_declaration (true)
41+
; CHECK-NEXT: DW_AT_artificial (true)

0 commit comments

Comments
 (0)