[llvm] [llvm][DebugInfo][ObjC] Make sure we link backing ivars to their DW_TAG_APPLE_property (PR #165409)

Michael Buch via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 07:53:02 PDT 2025


https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/165409

>From 0d16de6a5c0584ace4a5ea6f1f4ae25df7dfb15c Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 28 Oct 2025 10:09:05 +0000
Subject: [PATCH 1/4] [llvm][DebugInfo][test] Add LLVM tests for Objective-C
 property debug-info

The IR->DWARF pipeline was not properly tested before. This patch adds a
test to generate DWARF for various `DIObjCProperty` constructions.

This caught a couple of bugs:
1. The `DW_AT_APPLE_property_getter` and `DW_AT_APPLE_property_setter`
   properties were emitted the wrong way around.
2. The `DW_TAG_member` ivars were not linking back to the property that
   they back.

These will be fixed in follow-up patches.
---
 llvm/test/DebugInfo/Generic/objc-property.ll | 83 ++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 llvm/test/DebugInfo/Generic/objc-property.ll

diff --git a/llvm/test/DebugInfo/Generic/objc-property.ll b/llvm/test/DebugInfo/Generic/objc-property.ll
new file mode 100644
index 0000000000000..f8ccf141b07c3
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/objc-property.ll
@@ -0,0 +1,83 @@
+; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump --debug-info - | FileCheck %s
+
+; CHECK: DW_TAG_structure_type
+; CHECK:   DW_AT_name ("Foo")
+;
+; CHECK:   DW_TAG_APPLE_property
+; CHECK:     DW_AT_APPLE_property_name ("autoSynthProp")
+; CHECK:     DW_AT_APPLE_property_attribute
+; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
+; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
+;
+; CHECK:   DW_TAG_APPLE_property
+; CHECK:     DW_AT_APPLE_property_name ("synthProp")
+; CHECK:     DW_AT_APPLE_property_attribute
+; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
+; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
+;
+; FIXME: this should have a DW_AT_APPLE_property_getter tag
+; CHECK:   DW_TAG_APPLE_property
+; CHECK:     DW_AT_APPLE_property_name ("customGetterProp")
+; CHECK:     DW_AT_APPLE_property_setter   ("customGetter")
+; CHECK:     DW_AT_APPLE_property_attribute
+; CHECK-SAME: DW_APPLE_PROPERTY_getter, DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
+; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
+;
+; CHECK:   DW_TAG_APPLE_property
+; CHECK:     DW_AT_APPLE_property_name ("customSetterProp")
+; CHECK:     DW_AT_APPLE_property_setter   ("customSetter:")
+; CHECK:     DW_AT_APPLE_property_attribute
+; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
+; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
+;
+; CHECK:   DW_TAG_APPLE_property
+; CHECK:     DW_AT_APPLE_property_name ("customAccessorsProp")
+; CHECK:     DW_AT_APPLE_property_getter   ("customGetter")
+; CHECK:     DW_AT_APPLE_property_setter   ("customSetter:")
+; CHECK:     DW_AT_APPLE_property_attribute
+; CHECK-SAME: DW_APPLE_PROPERTY_getter, DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
+; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
+;
+; FIXME: missing link between DW_TAG_member and the associated DW_TAG_APPLE_property
+; CHECK-NOT: DW_APPLE_property
+; CHECK:   DW_TAG_member
+; CHECK:   DW_TAG_member
+; CHECK:   DW_TAG_member
+; CHECK:   DW_TAG_member
+
+!llvm.module.flags = !{!7, !8}
+!llvm.dbg.cu = !{!13}
+
+!7 = !{i32 7, !"Dwarf Version", i32 5}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !14, producer: "hand written", isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, retainedTypes: !15, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: Apple)
+!14 = !DIFile(filename: "main.m", directory: "/tmp")
+!15 = !{!16}
+!16 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", scope: !14, file: !14, line: 1, size: 128, flags: DIFlagObjcClassComplete, elements: !17, runtimeLang: DW_LANG_ObjC)
+!17 = !{!18, !20, !21, !22, !23, !24, !25, !26, !27, !28, !35, !38, !39, !40, !41, !42, !43}
+!18 = !DIObjCProperty(name: "autoSynthProp", file: !14, line: 5, attributes: 2316, type: !19)
+!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!20 = !DIObjCProperty(name: "synthProp", file: !14, line: 6, attributes: 2316, type: !19)
+!21 = !DIObjCProperty(name: "customGetterProp", file: !14, line: 7, getter: "customGetter", attributes: 2318, type: !19)
+!22 = !DIObjCProperty(name: "customSetterProp", file: !14, line: 8, setter: "customSetter:", attributes: 2444, type: !19)
+!23 = !DIObjCProperty(name: "customAccessorsProp", file: !14, line: 9, setter: "customSetter:", getter: "customGetter", attributes: 2446, type: !19)
+!24 = !DIDerivedType(tag: DW_TAG_member, name: "someBackingIvar", scope: !14, file: !14, line: 2, baseType: !19, size: 32, flags: DIFlagProtected, extraData: !20)
+!25 = !DIDerivedType(tag: DW_TAG_member, name: "_autoSynthProp", scope: !14, file: !14, line: 5, baseType: !19, size: 32, flags: DIFlagPrivate, extraData: !18)
+!26 = !DIDerivedType(tag: DW_TAG_member, name: "_customGetterProp", scope: !14, file: !14, line: 7, baseType: !19, size: 32, flags: DIFlagPrivate, extraData: !21)
+!27 = !DIDerivedType(tag: DW_TAG_member, name: "_customSetterProp", scope: !14, file: !14, line: 8, baseType: !19, size: 32, flags: DIFlagPrivate, extraData: !22)
+!28 = !DISubprogram(name: "-[Foo customGetter]", scope: !16, file: !14, line: 19, type: !29, scopeLine: 19, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!29 = !DISubroutineType(types: !30)
+!30 = !{!19, !31, !32}
+!31 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!32 = !DIDerivedType(tag: DW_TAG_typedef, name: "SEL", file: !14, baseType: !33, flags: DIFlagArtificial)
+!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64)
+!34 = !DICompositeType(tag: DW_TAG_structure_type, name: "objc_selector", file: !14, flags: DIFlagFwdDecl)
+!35 = !DISubprogram(name: "-[Foo customSetter:]", scope: !16, file: !14, line: 23, type: !36, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!36 = !DISubroutineType(types: !37)
+!37 = !{null, !31, !32, !19}
+!38 = !DISubprogram(name: "-[Foo synthProp]", scope: !16, file: !14, line: 17, type: !29, scopeLine: 17, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!39 = !DISubprogram(name: "-[Foo setSynthProp:]", scope: !16, file: !14, line: 17, type: !36, scopeLine: 17, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!40 = !DISubprogram(name: "-[Foo autoSynthProp]", scope: !16, file: !14, line: 5, type: !29, scopeLine: 5, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!41 = !DISubprogram(name: "-[Foo setAutoSynthProp:]", scope: !16, file: !14, line: 5, type: !36, scopeLine: 5, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!42 = !DISubprogram(name: "-[Foo setCustomGetterProp:]", scope: !16, file: !14, line: 7, type: !36, scopeLine: 7, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
+!43 = !DISubprogram(name: "-[Foo customSetterProp]", scope: !16, file: !14, line: 8, type: !29, scopeLine: 8, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)

>From ebac8af6bdfc1149a0389192676ad8ecbeec4bda Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 28 Oct 2025 14:28:22 +0000
Subject: [PATCH 2/4] fixup! fix CHECK-NOT

---
 llvm/test/DebugInfo/Generic/objc-property.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/DebugInfo/Generic/objc-property.ll b/llvm/test/DebugInfo/Generic/objc-property.ll
index f8ccf141b07c3..1eddbe931b558 100644
--- a/llvm/test/DebugInfo/Generic/objc-property.ll
+++ b/llvm/test/DebugInfo/Generic/objc-property.ll
@@ -39,7 +39,7 @@
 ; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
 ; FIXME: missing link between DW_TAG_member and the associated DW_TAG_APPLE_property
-; CHECK-NOT: DW_APPLE_property
+; CHECK-NOT: DW_AT_APPLE_property
 ; CHECK:   DW_TAG_member
 ; CHECK:   DW_TAG_member
 ; CHECK:   DW_TAG_member

>From d62c93f421161b2bcf759d9f7bc63af87479c861 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 28 Oct 2025 14:31:53 +0000
Subject: [PATCH 3/4] fixup! fix CHECK-NOT..again

---
 llvm/test/DebugInfo/Generic/objc-property.ll | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/test/DebugInfo/Generic/objc-property.ll b/llvm/test/DebugInfo/Generic/objc-property.ll
index 1eddbe931b558..64b5c0f99ddbe 100644
--- a/llvm/test/DebugInfo/Generic/objc-property.ll
+++ b/llvm/test/DebugInfo/Generic/objc-property.ll
@@ -39,11 +39,14 @@
 ; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
 ; FIXME: missing link between DW_TAG_member and the associated DW_TAG_APPLE_property
-; CHECK-NOT: DW_AT_APPLE_property
 ; CHECK:   DW_TAG_member
+; CHECK-NOT: DW_AT_APPLE_property
 ; CHECK:   DW_TAG_member
+; CHECK-NOT: DW_AT_APPLE_property
 ; CHECK:   DW_TAG_member
+; CHECK-NOT: DW_AT_APPLE_property
 ; CHECK:   DW_TAG_member
+; CHECK-NOT: DW_AT_APPLE_property
 
 !llvm.module.flags = !{!7, !8}
 !llvm.dbg.cu = !{!13}

>From e361a62726cc30c3e4b4f6fb41c224f0a42396e7 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 28 Oct 2025 14:27:46 +0000
Subject: [PATCH 4/4] [llvm][DebugInfo][ObjC] Make sure we link backing ivars
 to their DW_TAG_APPLE_property

Depends on:
* https://github.com/llvm/llvm-project/pull/165373

When an Objective-C property has a backing ivar, we would previously not add a `DW_AT_APPLE_property` to the ivar's `DW_TAG_member`. This is what was intended based on the [Objective-C DebugInfo docs](https://github.com/llvm/llvm-project/blob/main/llvm/docs/SourceLevelDebugging.rst#proposal) but is not what LLVM currently generates.

LLDB currently doesn't ever try linking the `ObjCPropertyDecl`s to their `ObjCIvarDecl`s, but if we wanted to, this debug-info patch is a pre-requisite.
---
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp    |  2 +-
 llvm/test/DebugInfo/Generic/objc-property.ll | 26 ++++++++++++--------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index e40fb768027b8..7d7588c89fae2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1109,7 +1109,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
           constructMemberDIE(Buffer, DDTy);
         }
       } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {
-        DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
+        DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer, Property);
         StringRef PropertyName = Property->getName();
         addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
         if (Property->getType())
diff --git a/llvm/test/DebugInfo/Generic/objc-property.ll b/llvm/test/DebugInfo/Generic/objc-property.ll
index 64b5c0f99ddbe..0907bb3ce6273 100644
--- a/llvm/test/DebugInfo/Generic/objc-property.ll
+++ b/llvm/test/DebugInfo/Generic/objc-property.ll
@@ -3,34 +3,34 @@
 ; CHECK: DW_TAG_structure_type
 ; CHECK:   DW_AT_name ("Foo")
 ;
-; CHECK:   DW_TAG_APPLE_property
+; CHECK:   0x[[AUTO_SYNTH:[0-9a-f]+]]: DW_TAG_APPLE_property
 ; CHECK:     DW_AT_APPLE_property_name ("autoSynthProp")
 ; CHECK:     DW_AT_APPLE_property_attribute
 ; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
 ; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
-; CHECK:   DW_TAG_APPLE_property
+; CHECK:   0x[[SYNTH:[0-9a-f]+]]: DW_TAG_APPLE_property
 ; CHECK:     DW_AT_APPLE_property_name ("synthProp")
 ; CHECK:     DW_AT_APPLE_property_attribute
 ; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
 ; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
 ; FIXME: this should have a DW_AT_APPLE_property_getter tag
-; CHECK:   DW_TAG_APPLE_property
+; CHECK:   0x[[GET:[0-9a-f]+]]: DW_TAG_APPLE_property
 ; CHECK:     DW_AT_APPLE_property_name ("customGetterProp")
 ; CHECK:     DW_AT_APPLE_property_setter   ("customGetter")
 ; CHECK:     DW_AT_APPLE_property_attribute
 ; CHECK-SAME: DW_APPLE_PROPERTY_getter, DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
 ; CHECK-SAME: DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
-; CHECK:   DW_TAG_APPLE_property
+; CHECK:   0x[[SET:[0-9a-f]+]]: DW_TAG_APPLE_property
 ; CHECK:     DW_AT_APPLE_property_name ("customSetterProp")
 ; CHECK:     DW_AT_APPLE_property_setter   ("customSetter:")
 ; CHECK:     DW_AT_APPLE_property_attribute
 ; CHECK-SAME: DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
 ; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
-; CHECK:   DW_TAG_APPLE_property
+; CHECK:   0x[[ACCESSORS:[0-9a-f]+]]: DW_TAG_APPLE_property
 ; CHECK:     DW_AT_APPLE_property_name ("customAccessorsProp")
 ; CHECK:     DW_AT_APPLE_property_getter   ("customGetter")
 ; CHECK:     DW_AT_APPLE_property_setter   ("customSetter:")
@@ -38,15 +38,21 @@
 ; CHECK-SAME: DW_APPLE_PROPERTY_getter, DW_APPLE_PROPERTY_assign, DW_APPLE_PROPERTY_readwrite,
 ; CHECK-SAME: DW_APPLE_PROPERTY_setter, DW_APPLE_PROPERTY_atomic, DW_APPLE_PROPERTY_unsafe_unretained
 ;
-; FIXME: missing link between DW_TAG_member and the associated DW_TAG_APPLE_property
 ; CHECK:   DW_TAG_member
-; CHECK-NOT: DW_AT_APPLE_property
+; CHECK:     DW_AT_name ("someBackingIvar")
+; CHECK:     DW_AT_APPLE_property (0x[[SYNTH]])
+;
 ; CHECK:   DW_TAG_member
-; CHECK-NOT: DW_AT_APPLE_property
+; CHECK:     DW_AT_name ("_autoSynthProp")
+; CHECK:     DW_AT_APPLE_property (0x[[AUTO_SYNTH]])
+;
 ; CHECK:   DW_TAG_member
-; CHECK-NOT: DW_AT_APPLE_property
+; CHECK:     DW_AT_name ("_customGetterProp")
+; CHECK:     DW_AT_APPLE_property (0x[[GET]])
+;
 ; CHECK:   DW_TAG_member
-; CHECK-NOT: DW_AT_APPLE_property
+; CHECK:     DW_AT_name ("_customSetterProp")
+; CHECK:     DW_AT_APPLE_property (0x[[SET]])
 
 !llvm.module.flags = !{!7, !8}
 !llvm.dbg.cu = !{!13}



More information about the llvm-commits mailing list