[llvm] r332850 - [LLVM-C] Add DIBuilder Bindings For ObjC Classes

Robert Widmann via llvm-commits llvm-commits at lists.llvm.org
Mon May 21 09:27:35 PDT 2018


Author: codafi
Date: Mon May 21 09:27:35 2018
New Revision: 332850

URL: http://llvm.org/viewvc/llvm-project?rev=332850&view=rev
Log:
[LLVM-C] Add DIBuilder Bindings For ObjC Classes

Summary: Add LLVMDIBuilderCreateObjCIVar, LLVMDIBuilderCreateObjCProperty, and LLVMDIBuilderCreateInheritance to allow declaring metadata for Objective-C class hierarchies and their associated properties and instance variables.

Reviewers: whitequark, deadalnix

Reviewed By: whitequark

Subscribers: harlanhaskins, llvm-commits

Differential Revision: https://reviews.llvm.org/D47123

Modified:
    llvm/trunk/include/llvm-c/DebugInfo.h
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/test/Bindings/llvm-c/debug_info.ll
    llvm/trunk/tools/llvm-c-test/debuginfo.c

Modified: llvm/trunk/include/llvm-c/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/DebugInfo.h?rev=332850&r1=332849&r2=332850&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/DebugInfo.h (original)
+++ llvm/trunk/include/llvm-c/DebugInfo.h Mon May 21 09:27:35 2018
@@ -632,6 +632,50 @@ LLVMDIBuilderCreateMemberPointerType(LLV
                                      uint64_t SizeInBits,
                                      uint32_t AlignInBits,
                                      LLVMDIFlags Flags);
+/**
+ * Create debugging information entry for Objective-C instance variable.
+ * \param Builder      The DIBuilder.
+ * \param Name         Member name.
+ * \param NameLen      The length of the C string passed to \c Name.
+ * \param File         File where this member is defined.
+ * \param LineNo       Line number.
+ * \param SizeInBits   Member size.
+ * \param AlignInBits  Member alignment.
+ * \param OffsetInBits Member offset.
+ * \param Flags        Flags to encode member attribute, e.g. private
+ * \param Ty           Parent type.
+ * \param PropertyNode Property associated with this ivar.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
+                            const char *Name, size_t NameLen,
+                            LLVMMetadataRef File, unsigned LineNo,
+                            uint64_t SizeInBits, uint32_t AlignInBits,
+                            uint64_t OffsetInBits, LLVMDIFlags Flags,
+                            LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode);
+
+/**
+ * Create debugging information entry for Objective-C property.
+ * \param Builder            The DIBuilder.
+ * \param Name               Property name.
+ * \param NameLen            The length of the C string passed to \c Name.
+ * \param File               File where this property is defined.
+ * \param LineNo             Line number.
+ * \param GetterName         Name of the Objective C property getter selector.
+ * \param GetterNameLen      The length of the C string passed to \c GetterName.
+ * \param SetterName         Name of the Objective C property setter selector.
+ * \param SetterNameLen      The length of the C string passed to \c SetterName.
+ * \param PropertyAttributes Objective C property attributes.
+ * \param Ty                 Type.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
+                                const char *Name, size_t NameLen,
+                                LLVMMetadataRef File, unsigned LineNo,
+                                const char *GetterName, size_t GetterNameLen,
+                                const char *SetterName, size_t SetterNameLen,
+                                unsigned PropertyAttributes,
+                                LLVMMetadataRef Ty);
 
 /**
  * Create a new DIType* with the "object pointer"
@@ -681,7 +725,7 @@ LLVMDIBuilderCreateNullPtrType(LLVMDIBui
  * \param File       File where this type is defined.
  * \param LineNo     Line number.
  * \param Scope      The surrounding context for the typedef.
-*/
+ */
 LLVMMetadataRef
 LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
                            const char *Name, size_t NameLen,
@@ -689,6 +733,22 @@ LLVMDIBuilderCreateTypedef(LLVMDIBuilder
                            LLVMMetadataRef Scope);
 
 /**
+ * Create debugging information entry to establish inheritance relationship
+ * between two types.
+ * \param Builder       The DIBuilder.
+ * \param Ty            Original type.
+ * \param BaseTy        Base type. Ty is inherits from base.
+ * \param BaseOffset    Base offset.
+ * \param VBPtrOffset  Virtual base pointer offset.
+ * \param Flags         Flags to describe inheritance attribute, e.g. private
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
+                               LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
+                               uint64_t BaseOffset, uint32_t VBPtrOffset,
+                               LLVMDIFlags Flags);
+
+/**
  * Create a permanent forward-declared type.
  * \param Builder             The DIBuilder.
  * \param Tag                 A unique tag for this type.

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=332850&r1=332849&r2=332850&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Mon May 21 09:27:35 2018
@@ -1013,6 +1013,34 @@ LLVMDIBuilderCreateStaticMemberType(
 }
 
 LLVMMetadataRef
+LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
+                            const char *Name, size_t NameLen,
+                            LLVMMetadataRef File, unsigned LineNo,
+                            uint64_t SizeInBits, uint32_t AlignInBits,
+                            uint64_t OffsetInBits, LLVMDIFlags Flags,
+                            LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
+  return wrap(unwrap(Builder)->createObjCIVar(
+                  {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+                  SizeInBits, AlignInBits, OffsetInBits,
+                  map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
+                  unwrapDI<MDNode>(PropertyNode)));
+}
+
+LLVMMetadataRef
+LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
+                                const char *Name, size_t NameLen,
+                                LLVMMetadataRef File, unsigned LineNo,
+                                const char *GetterName, size_t GetterNameLen,
+                                const char *SetterName, size_t SetterNameLen,
+                                unsigned PropertyAttributes,
+                                LLVMMetadataRef Ty) {
+  return wrap(unwrap(Builder)->createObjCProperty(
+                  {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+                  {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
+                  PropertyAttributes, unwrapDI<DIType>(Ty)));
+}
+
+LLVMMetadataRef
 LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
                                      LLVMMetadataRef Type) {
   return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
@@ -1030,6 +1058,16 @@ LLVMDIBuilderCreateTypedef(LLVMDIBuilder
 }
 
 LLVMMetadataRef
+LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
+                               LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
+                               uint64_t BaseOffset, uint32_t VBPtrOffset,
+                               LLVMDIFlags Flags) {
+  return wrap(unwrap(Builder)->createInheritance(
+                  unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
+                  BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
+}
+
+LLVMMetadataRef
 LLVMDIBuilderCreateForwardDecl(
     LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
     size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,

Modified: llvm/trunk/test/Bindings/llvm-c/debug_info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/debug_info.ll?rev=332850&r1=332849&r2=332850&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/debug_info.ll (original)
+++ llvm/trunk/test/Bindings/llvm-c/debug_info.ll Mon May 21 09:27:35 2018
@@ -3,49 +3,57 @@
 ; CHECK: ; ModuleID = 'debuginfo.c'
 ; CHECK-NEXT: source_filename = "debuginfo.c"
 
-; CHECK:      define i64 @foo(i64, i64, <10 x i64>) !dbg !17 {
+; CHECK:      define i64 @foo(i64, i64, <10 x i64>) !dbg !20 {
 ; CHECK-NEXT: entry:
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !29
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !29
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !26, metadata !DIExpression()), !dbg !29
-; CHECK:      vars:
-; CHECK-NEXT:   call void @llvm.dbg.value(metadata i64 0, metadata !27, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !30
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !27, metadata !DIExpression()), !dbg !32
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !28, metadata !DIExpression()), !dbg !32
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !29, metadata !DIExpression()), !dbg !32
+; CHECK:      vars:                                             ; No predecessors!
+; CHECK-NEXT:   call void @llvm.dbg.value(metadata i64 0, metadata !30, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !33
 ; CHECK-NEXT: }
 
-; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
-; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+; CHECK:      ; Function Attrs: nounwind readnone speculatable
+; CHECK-NEXT: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
 
-; CHECK: !llvm.dbg.cu = !{!0}
-; CHECK: !FooType = !{!13}
+; CHECK:      ; Function Attrs: nounwind readnone speculatable
+; CHECK-NEXT: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
 
-; CHECK:      !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !9, splitDebugInlining: false)
+; CHECK:      attributes #0 = { nounwind readnone speculatable }
+
+; CHECK:      !llvm.dbg.cu = !{!0}
+; CHECK-NEXT: !FooType = !{!16}
+
+; CHECK:      !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !12, splitDebugInlining: false)
 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
 ; CHECK-NEXT: !2 = !{}
-; CHECK-NEXT: !3 = !{!4}
+; CHECK-NEXT: !3 = !{!4, !8}
 ; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
-; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
+; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "globalClass", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
 ; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
-; CHECK-NEXT: !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !8)
-; CHECK-NEXT: !8 = !DIBasicType(name: "Int64", size: 64)
-; CHECK-NEXT: !9 = !{!10, !12}
-; CHECK-NEXT: !10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !11, file: !1, line: 42)
-; CHECK-NEXT: !11 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
-; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42)
-; CHECK-NEXT: !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 192, dwarfAddressSpace: 0)
-; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !15, file: !1, size: 192, elements: !16, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
-; CHECK-NEXT: !15 = !DINamespace(name: "NameSpace", scope: !6)
-; CHECK-NEXT: !16 = !{!8, !8, !8}
-; CHECK-NEXT: !17 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !18, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !23)
-; CHECK-NEXT: !18 = !DISubroutineType(types: !19)
-; CHECK-NEXT: !19 = !{!8, !8, !20}
-; CHECK-NEXT: !20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 640, flags: DIFlagVector, elements: !21)
-; CHECK-NEXT: !21 = !{!22}
-; CHECK-NEXT: !22 = !DISubrange(count: 10)
-; CHECK-NEXT: !23 = !{!24, !25, !26, !27}
-; CHECK-NEXT: !24 = !DILocalVariable(name: "a", arg: 1, scope: !17, file: !1, line: 42, type: !8)
-; CHECK-NEXT: !25 = !DILocalVariable(name: "b", arg: 2, scope: !17, file: !1, line: 42, type: !8)
-; CHECK-NEXT: !26 = !DILocalVariable(name: "c", arg: 3, scope: !17, file: !1, line: 42, type: !20)
-; CHECK-NEXT: !27 = !DILocalVariable(name: "d", scope: !28, file: !1, line: 43, type: !8)
-; CHECK-NEXT: !28 = distinct !DILexicalBlock(scope: !17, file: !1, line: 42)
-; CHECK-NEXT: !29 = !DILocation(line: 42, scope: !17)
-; CHECK-NEXT: !30 = !DILocation(line: 43, scope: !17)
+; CHECK-NEXT: !7 = !DICompositeType(tag: DW_TAG_structure_type, name: "TestClass", scope: !1, file: !1, line: 42, size: 64, flags: DIFlagObjcClassComplete, elements: !2)
+; CHECK-NEXT: !8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
+; CHECK-NEXT: !9 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !10, isLocal: true, isDefinition: true)
+; CHECK-NEXT: !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !11)
+; CHECK-NEXT: !11 = !DIBasicType(name: "Int64", size: 64)
+; CHECK-NEXT: !12 = !{!13, !15}
+; CHECK-NEXT: !13 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !14, file: !1, line: 42)
+; CHECK-NEXT: !14 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
+; CHECK-NEXT: !15 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !13, file: !1, line: 42)
+; CHECK-NEXT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 192, dwarfAddressSpace: 0)
+; CHECK-NEXT: !17 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !18, file: !1, size: 192, elements: !19, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
+; CHECK-NEXT: !18 = !DINamespace(name: "NameSpace", scope: !6)
+; CHECK-NEXT: !19 = !{!11, !11, !11}
+; CHECK-NEXT: !20 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !21, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !26)
+; CHECK-NEXT: !21 = !DISubroutineType(types: !22)
+; CHECK-NEXT: !22 = !{!11, !11, !23}
+; CHECK-NEXT: !23 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 640, flags: DIFlagVector, elements: !24)
+; CHECK-NEXT: !24 = !{!25}
+; CHECK-NEXT: !25 = !DISubrange(count: 10)
+; CHECK-NEXT: !26 = !{!27, !28, !29, !30}
+; CHECK-NEXT: !27 = !DILocalVariable(name: "a", arg: 1, scope: !20, file: !1, line: 42, type: !11)
+; CHECK-NEXT: !28 = !DILocalVariable(name: "b", arg: 2, scope: !20, file: !1, line: 42, type: !11)
+; CHECK-NEXT: !29 = !DILocalVariable(name: "c", arg: 3, scope: !20, file: !1, line: 42, type: !23)
+; CHECK-NEXT: !30 = !DILocalVariable(name: "d", scope: !31, file: !1, line: 43, type: !11)
+; CHECK-NEXT: !31 = distinct !DILexicalBlock(scope: !20, file: !1, line: 42)
+; CHECK-NEXT: !32 = !DILocation(line: 42, scope: !20)
+; CHECK-NEXT: !33 = !DILocation(line: 43, scope: !20)

Modified: llvm/trunk/tools/llvm-c-test/debuginfo.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/debuginfo.c?rev=332850&r1=332849&r2=332850&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/debuginfo.c (original)
+++ llvm/trunk/tools/llvm-c-test/debuginfo.c Mon May 21 09:27:35 2018
@@ -17,6 +17,17 @@
 #include <stdio.h>
 #include <string.h>
 
+static LLVMMetadataRef
+declare_objc_class(LLVMDIBuilderRef DIB, LLVMMetadataRef File) {
+  LLVMMetadataRef Decl = LLVMDIBuilderCreateStructType(DIB, File, "TestClass", 9, File, 42, 64, 0, LLVMDIFlagObjcClassComplete, NULL, NULL, 0, 0, NULL, NULL, 0);
+  LLVMMetadataRef SuperDecl = LLVMDIBuilderCreateStructType(DIB, File, "TestSuperClass", 14, File, 42, 64, 0, LLVMDIFlagObjcClassComplete, NULL, NULL, 0, 0, NULL, NULL, 0);
+  LLVMDIBuilderCreateInheritance(DIB, Decl, SuperDecl, 0, 0, 0);
+  LLVMMetadataRef TestProperty =
+      LLVMDIBuilderCreateObjCProperty(DIB, "test", 4, File, 42, "getTest", 7, "setTest", 7, 0x20 /*copy*/ | 0x40 /*nonatomic*/, SuperDecl);
+  LLVMDIBuilderCreateObjCIVar(DIB, "_test", 5, File, 42, 64, 0, 64, LLVMDIFlagPublic, SuperDecl, TestProperty);
+  return Decl;
+}
+
 int llvm_test_dibuilder(void) {
   const char *Filename = "debuginfo.c";
   LLVMModuleRef M = LLVMModuleCreateWithName(Filename);
@@ -48,6 +59,14 @@ int llvm_test_dibuilder(void) {
   LLVMDIBuilderCreateImportedModuleFromAlias(DIB, Module, ImportedModule,
                                              File, 42);
 
+  LLVMMetadataRef ClassTy = declare_objc_class(DIB, File);
+  LLVMMetadataRef GlobalClassValueExpr =
+    LLVMDIBuilderCreateConstantValueExpression(DIB, 0);
+  LLVMDIBuilderCreateGlobalVariableExpression(DIB, Module, "globalClass", 11,
+                                              "", 0, File, 1, ClassTy,
+                                              true, GlobalClassValueExpr,
+                                              NULL, 0);
+
   LLVMMetadataRef Int64Ty =
     LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
   LLVMMetadataRef Int64TypeDef =




More information about the llvm-commits mailing list