[llvm] c2a9bba - [DebugInfo] Add DW_AT_artificial for compiler generated static member. (#115851)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 21:16:15 PST 2024


Author: Carlos Alberto Enciso
Date: 2024-11-15T05:16:12Z
New Revision: c2a9bba4a30349f5411f3b3f9cbe4a6f379816bc

URL: https://github.com/llvm/llvm-project/commit/c2a9bba4a30349f5411f3b3f9cbe4a6f379816bc
DIFF: https://github.com/llvm/llvm-project/commit/c2a9bba4a30349f5411f3b3f9cbe4a6f379816bc.diff

LOG: [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.

Added: 
    llvm/test/DebugInfo/Generic/artificial-static-member.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 316e05ba123921..0a8a1ad38c959f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1789,6 +1789,10 @@ DIE *DwarfUnit::getOrCreateStaticMemberDIE(const DIDerivedType *DT) {
   addFlag(StaticMemberDIE, dwarf::DW_AT_external);
   addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
 
+  // Consider the case when the static member was created by the compiler.
+  if (DT->isArtificial())
+    addFlag(StaticMemberDIE, dwarf::DW_AT_artificial);
+
   // FIXME: We could omit private if the parent is a class_type, and
   // public if the parent is something else.
   addAccess(StaticMemberDIE, DT->getFlags());

diff  --git a/llvm/test/DebugInfo/Generic/artificial-static-member.ll b/llvm/test/DebugInfo/Generic/artificial-static-member.ll
new file mode 100644
index 00000000000000..3263c976e39158
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/artificial-static-member.ll
@@ -0,0 +1,41 @@
+; RUN: llc -O0 -filetype=obj < %s |   \
+; RUN: llvm-dwarfdump --debug-info - | FileCheck %s
+
+; LLVM IR generated from:
+
+; struct S {
+;   static int Member;   <-- Manually marked as artificial
+; };
+; int S::Member = 1;
+
+source_filename = "artificial-static-member.cpp"
+target triple = "x86_64-pc-linux-gnu"
+
+ at _ZN1S6MemberE = dso_local global i32 1, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "Member", linkageName: "_ZN1S6MemberE", scope: !2, type: !5, isLocal: false, isDefinition: true, declaration: !6)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, emissionKind: FullDebug, globals: !4)
+!3 = !DIFile(filename: "artificial-static-member.cpp", directory: "")
+!4 = !{!0}
+!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!6 = !DIDerivedType(tag: DW_TAG_variable, name: "Member", scope: !7, baseType: !5, flags: DIFlagArtificial | DIFlagStaticMember)
+!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", size: 8, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS1S")
+!8 = !{!6}
+!9 = !{i32 7, !"Dwarf Version", i32 5}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+
+; CHECK: {{.*}}DW_TAG_structure_type
+; CHECK-NEXT: DW_AT_calling_convention
+; CHECK-NEXT: DW_AT_name	("S")
+; CHECK-NEXT: DW_AT_byte_size
+
+; CHECK: {{.*}}DW_TAG_variable
+; CHECK-NEXT: DW_AT_name	("Member")
+; CHECK-NEXT: DW_AT_type
+; CHECK-NEXT: DW_AT_external	(true)
+; CHECK-NEXT: DW_AT_declaration	(true)
+; CHECK-NEXT: DW_AT_artificial	(true)


        


More information about the llvm-commits mailing list