[llvm] Add debuginfo C support for a SetType, Subrangetype, dynamic array type and replace arrays (PR #135607)
peter mckinna via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 19 22:57:51 PDT 2025
https://github.com/demoitem updated https://github.com/llvm/llvm-project/pull/135607
>From 423f6f4893edf6cd90dec15034275e5185eefd69 Mon Sep 17 00:00:00 2001
From: peter mckinna <peter.mckinna at gmail.com>
Date: Mon, 14 Apr 2025 19:31:32 +1000
Subject: [PATCH 1/3] Add support for creating a SetType, a Subrangetype, a
dynamic array type and for replacing arrays to the C inteface
---
llvm/include/llvm-c/DebugInfo.h | 73 ++++++++++++++++++++++++++++++++-
llvm/lib/IR/DebugInfo.cpp | 51 +++++++++++++++++++++++
2 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 11e0b9b4c81e8..0f267d9941b08 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -673,7 +673,6 @@ LLVMMetadataRef LLVMDIBuilderCreateUnionType(
LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
const char *UniqueId, size_t UniqueIdLen);
-
/**
* Create debugging information entry for an array.
* \param Builder The DIBuilder.
@@ -689,6 +688,78 @@ LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size,
LLVMMetadataRef *Subscripts,
unsigned NumSubscripts);
+/**
+ * Create debugging information entry for a set.
+ * @param Builder The DIBuilder.
+ * \param Scope The scope this module is imported into.
+ * \param Name A name that uniquely identifies this set.
+ * \param NameLen The length of the C string passed to \c Name.
+ * \param File File where the set is located.
+ * \param Line Line number of the declaration.
+ * \param SizeInBits Set size.
+ * \param AlignInBits Set alignment.
+ * @param BaseTy The base type of the set.
+ */
+LLVMMetadataRef LLVMDIBuilderCreateSetType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
+ uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef BaseTy);
+
+/**
+ * Create a descriptor for a subrange with dynamic bounds.
+ * \param Builder The DIBuilder.
+ * \param Scope The scope this module is imported into.
+ * \param Name A name that uniquely identifies this set.
+ * \param NameLen The length of the C string passed to \c Name.
+ * \param LineNo Line number.
+ * \param File File where the subrange is located.
+ * \param SizeInBits Member size.
+ * \param AlignInBits Member alignment.
+ * \param Flags Flags.
+ * \param BaseTy The base type of the subrange. eg integer or enumeration
+ * \param LowerBound Lower bound of the subrange.
+ * \param UpperBound Upper bound of the subrange.
+ * \param Stride Stride of the subrange.
+ * \param Bias Bias of the subrange.
+ */
+LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
+ uint64_t SizeInBits, uint32_t AlignInBits,
+ LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
+ LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
+ LLVMMetadataRef Stride, LLVMMetadataRef Bias);
+
+/**
+ * Create debugging information entry for a dynamic array.
+ * \param Builder The DIBuilder.
+ * \param Size Array size.
+ * \param AlignInBits Alignment.
+ * \param Ty Element type.
+ * \param Subscripts Subscripts.
+ * \param NumSubscripts Number of subscripts.
+ * \param DataLocation DataLocation.
+ * \param Associated Associated.
+ * \param Allocated Allocated.
+ * \param Rank Rank.
+ * \param BitStride BitStride.
+ */
+LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
+ uint64_t Size, uint32_t AlignInBits,
+ LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts,
+ LLVMMetadataRef DataLocation, LLVMMetadataRef Associated,
+ LLVMMetadataRef Allocated, LLVMMetadataRef Rank, LLVMMetadataRef BitStride);
+
+/**
+ * Replace arrays.
+ *
+ * @see DIBuilder::replaceArrays()
+ */
+void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T,
+ LLVMMetadataRef *Elements, unsigned NumElements);
+
/**
* Create debugging information entry for a vector type.
* \param Builder The DIBuilder.
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index cefd6fe14a3ac..c2f12f0efa030 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1309,6 +1309,57 @@ return wrap(unwrap(Builder)->createEnumerationType(
LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
}
+LLVMMetadataRef LLVMDIBuilderCreateSetType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
+ uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef BaseTy) {
+ return wrap(unwrap(Builder)->createSetType(
+ unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
+ LineNumber, SizeInBits, AlignInBits, unwrapDI<DIType>(BaseTy)));
+}
+
+LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
+ uint64_t SizeInBits, uint32_t AlignInBits,
+ LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
+ LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
+ LLVMMetadataRef Stride, LLVMMetadataRef Bias
+ ) {
+ return wrap(unwrap(Builder)->createSubrangeType(
+ {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+ unwrapDI<DIScope>(Scope), SizeInBits, AlignInBits,
+ map_from_llvmDIFlags(Flags), unwrapDI<DIType>(BaseTy),
+ unwrap<DIExpression>(LowerBound), unwrap<DIExpression>(UpperBound),
+ unwrap<DIExpression>(Stride), unwrap<DIExpression>(Bias)));
+}
+
+LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
+ uint64_t Size, uint32_t AlignInBits,
+ LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts,
+ LLVMMetadataRef DataLocation, LLVMMetadataRef Associated,
+ LLVMMetadataRef Allocated, LLVMMetadataRef Rank, LLVMMetadataRef BitStride) {
+ auto Subs =
+ unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts});
+ return wrap(unwrap(Builder)->createArrayType(
+ unwrapDI<DIScope>(Scope),
+ {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+ Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
+ unwrap<DIExpression>(DataLocation), unwrap<DIExpression>(Associated),
+ unwrap<DIExpression>(Allocated), unwrap<DIExpression>(Rank),
+ unwrap(BitStride)));
+}
+
+void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T,
+ LLVMMetadataRef *Elements, unsigned NumElements) {
+ auto Arr = unwrap<DICompositeType>(*T);
+ auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
+ NumElements});
+ unwrap(Builder)->replaceArrays(Arr, Elts);
+}
+
LLVMMetadataRef LLVMDIBuilderCreateUnionType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
>From d6810972327e0f0384d508819dc020905d6e36f1 Mon Sep 17 00:00:00 2001
From: peter mckinna <peter.mckinna at gmail.com>
Date: Mon, 14 Apr 2025 19:31:32 +1000
Subject: [PATCH 2/3] Add support for creating a SetType, a Subrangetype, a
dynamic array type and for replacing arrays to the C inteface
---
llvm/include/llvm-c/DebugInfo.h | 25 +++++++++++------------
llvm/lib/IR/DebugInfo.cpp | 35 +++++++++++++++------------------
2 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 0f267d9941b08..f638181ffa947 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -690,15 +690,15 @@ LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size,
/**
* Create debugging information entry for a set.
- * @param Builder The DIBuilder.
- * \param Scope The scope this module is imported into.
+ * \param Builder The DIBuilder.
+ * \param Scope The scope in which the set is defined.
* \param Name A name that uniquely identifies this set.
* \param NameLen The length of the C string passed to \c Name.
* \param File File where the set is located.
* \param Line Line number of the declaration.
* \param SizeInBits Set size.
* \param AlignInBits Set alignment.
- * @param BaseTy The base type of the set.
+ * \param BaseTy The base type of the set.
*/
LLVMMetadataRef LLVMDIBuilderCreateSetType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
@@ -708,8 +708,8 @@ LLVMMetadataRef LLVMDIBuilderCreateSetType(
/**
* Create a descriptor for a subrange with dynamic bounds.
* \param Builder The DIBuilder.
- * \param Scope The scope this module is imported into.
- * \param Name A name that uniquely identifies this set.
+ * \param Scope The scope in which the subrange is defined.
+ * \param Name A name that uniquely identifies this subrange.
* \param NameLen The length of the C string passed to \c Name.
* \param LineNo Line number.
* \param File File where the subrange is located.
@@ -724,9 +724,8 @@ LLVMMetadataRef LLVMDIBuilderCreateSetType(
*/
LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
- size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
- uint64_t SizeInBits, uint32_t AlignInBits,
- LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t SizeInBits,
+ uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
LLVMMetadataRef Stride, LLVMMetadataRef Bias);
@@ -746,11 +745,11 @@ LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
*/
LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
- size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
- uint64_t Size, uint32_t AlignInBits,
- LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts,
- LLVMMetadataRef DataLocation, LLVMMetadataRef Associated,
- LLVMMetadataRef Allocated, LLVMMetadataRef Rank, LLVMMetadataRef BitStride);
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
+ uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts,
+ unsigned NumSubscripts, LLVMMetadataRef DataLocation,
+ LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank,
+ LLVMMetadataRef BitStride);
/**
* Replace arrays.
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index c2f12f0efa030..f14a5bc0dd801 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1320,32 +1320,29 @@ LLVMMetadataRef LLVMDIBuilderCreateSetType(
LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
- size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
- uint64_t SizeInBits, uint32_t AlignInBits,
- LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t SizeInBits,
+ uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
- LLVMMetadataRef Stride, LLVMMetadataRef Bias
- ) {
+ LLVMMetadataRef Stride, LLVMMetadataRef Bias) {
return wrap(unwrap(Builder)->createSubrangeType(
- {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
- unwrapDI<DIScope>(Scope), SizeInBits, AlignInBits,
- map_from_llvmDIFlags(Flags), unwrapDI<DIType>(BaseTy),
- unwrap<DIExpression>(LowerBound), unwrap<DIExpression>(UpperBound),
- unwrap<DIExpression>(Stride), unwrap<DIExpression>(Bias)));
+ {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, unwrapDI<DIScope>(Scope),
+ SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
+ unwrapDI<DIType>(BaseTy), unwrap<DIExpression>(LowerBound),
+ unwrap<DIExpression>(UpperBound), unwrap<DIExpression>(Stride),
+ unwrap<DIExpression>(Bias)));
}
LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
- size_t NameLen, unsigned LineNo, LLVMMetadataRef File,
- uint64_t Size, uint32_t AlignInBits,
- LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts,
- LLVMMetadataRef DataLocation, LLVMMetadataRef Associated,
- LLVMMetadataRef Allocated, LLVMMetadataRef Rank, LLVMMetadataRef BitStride) {
+ size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
+ uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts,
+ unsigned NumSubscripts, LLVMMetadataRef DataLocation,
+ LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank,
+ LLVMMetadataRef BitStride) {
auto Subs =
unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts});
return wrap(unwrap(Builder)->createArrayType(
- unwrapDI<DIScope>(Scope),
- {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+ unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
unwrap<DIExpression>(DataLocation), unwrap<DIExpression>(Associated),
unwrap<DIExpression>(Allocated), unwrap<DIExpression>(Rank),
@@ -1355,8 +1352,8 @@ LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T,
LLVMMetadataRef *Elements, unsigned NumElements) {
auto Arr = unwrap<DICompositeType>(*T);
- auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
- NumElements});
+ auto Elts =
+ unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements});
unwrap(Builder)->replaceArrays(Arr, Elts);
}
>From 8e0b8304d0f01d4dd30eed4b107001cafe4d9ce8 Mon Sep 17 00:00:00 2001
From: peter mckinna <peter.mckinna at gmail.com>
Date: Sun, 20 Apr 2025 15:18:56 +1000
Subject: [PATCH 3/3] Code review adjustments. Add test case.
---
.../Bindings/llvm-c/debug_info_new_format.ll | 72 +++++++++++--------
llvm/tools/llvm-c-test/debuginfo.c | 36 ++++++++++
2 files changed, 77 insertions(+), 31 deletions(-)
diff --git a/llvm/test/Bindings/llvm-c/debug_info_new_format.ll b/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
index a3f4bb2421fa2..a44817e020148 100644
--- a/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
+++ b/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
@@ -3,29 +3,33 @@
; CHECK: ; ModuleID = 'debuginfo.c'
; CHECK-NEXT: source_filename = "debuginfo.c"
-
-; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !31 {
+
+; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !39 {
; CHECK-NEXT: entry:
-; CHECK-NEXT: #dbg_declare(i64 0, !38, !DIExpression(), !45)
-; CHECK-NEXT: #dbg_declare(i64 0, !39, !DIExpression(), !45)
-; CHECK-NEXT: #dbg_declare(i64 0, !40, !DIExpression(), !45)
-; CHECK-NEXT: #dbg_label(!46, !45)
+; CHECK-NEXT: #dbg_declare(i64 0, !44, !DIExpression(), !51)
+; CHECK-NEXT: #dbg_declare(i64 0, !45, !DIExpression(), !51)
+; CHECK-NEXT: #dbg_declare(i64 0, !46, !DIExpression(), !51)
+; CHECK-NEXT: #dbg_label(!52, !51)
; CHECK-NEXT: br label %vars
-; CHECK-NEXT: #dbg_label(!47, !45)
+; CHECK-NEXT: #dbg_label(!53, !51)
; CHECK-NEXT: br label %vars
-; CHECK: vars:
+; CHECK: vars: ; preds = %entry, %entry
; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
-; CHECK-NEXT: #dbg_value(i64 0, !41, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !48)
-; CHECK-NEXT: #dbg_value(i64 1, !43, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !48)
+; CHECK-NEXT: #dbg_value(i64 0, !47, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !54)
+; CHECK-NEXT: #dbg_value(i64 1, !49, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !54)
; CHECK-NEXT: %a = add i64 %p1, %p2
; CHECK-NEXT: ret i64 0
; CHECK-NEXT: }
-
+
; CHECK: !llvm.dbg.cu = !{!0}
; CHECK-NEXT: !FooType = !{!28}
; CHECK-NEXT: !EnumTest = !{!3}
-
+; CHECK-NEXT: !SubrangeType = !{!33}
+; CHECK-NEXT: !SetType1 = !{!34}
+; CHECK-NEXT: !SetType2 = !{!35}
+; CHECK-NEXT: !DynType = !{!36}
+
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !11, imports: !19, macros: !23, splitDebugInlining: false, sysroot: "/")
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
; CHECK-NEXT: !2 = !{!3}
@@ -56,22 +60,28 @@
; CHECK-NEXT: !27 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
; CHECK-NEXT: !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 192, dwarfAddressSpace: 0)
; CHECK-NEXT: !29 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !4, file: !1, size: 192, elements: !30, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
-; CHECK-NEXT: !30 = !{!6, !6, !6}
-; CHECK-NEXT: !31 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !32, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !37)
-; CHECK-NEXT: !32 = !DISubroutineType(types: !33)
-; CHECK-NEXT: !33 = !{!6, !6, !34}
-; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !35)
-; CHECK-NEXT: !35 = !{!36}
-; CHECK-NEXT: !36 = !DISubrange(count: 10, lowerBound: 0)
-; CHECK-NEXT: !37 = !{!38, !39, !40, !41, !43, !44}
-; CHECK-NEXT: !38 = !DILocalVariable(name: "a", arg: 1, scope: !31, file: !1, line: 42, type: !6)
-; CHECK-NEXT: !39 = !DILocalVariable(name: "b", arg: 2, scope: !31, file: !1, line: 42, type: !6)
-; CHECK-NEXT: !40 = !DILocalVariable(name: "c", arg: 3, scope: !31, file: !1, line: 42, type: !34)
-; CHECK-NEXT: !41 = !DILocalVariable(name: "d", scope: !42, file: !1, line: 43, type: !6)
-; CHECK-NEXT: !42 = distinct !DILexicalBlock(scope: !31, file: !1, line: 42)
-; CHECK-NEXT: !43 = !DILocalVariable(name: "e", scope: !42, file: !1, line: 44, type: !6)
-; CHECK-NEXT: !44 = !DILabel(scope: !31, name: "label3", file: !1, line: 42)
-; CHECK-NEXT: !45 = !DILocation(line: 42, scope: !31)
-; CHECK-NEXT: !46 = !DILabel(scope: !31, name: "label1", file: !1, line: 42)
-; CHECK-NEXT: !47 = !DILabel(scope: !31, name: "label2", file: !1, line: 42)
-; CHECK-NEXT: !48 = !DILocation(line: 43, scope: !31)
+; CHECK-NEXT: !30 = !{!31}
+; CHECK-NEXT: !31 = !DICompositeType(tag: DW_TAG_structure_type, name: "ThisStruc", scope: !4, file: !1, size: 192, elements: !32, runtimeLang: DW_LANG_C89, identifier: "ThisStruc")
+; CHECK-NEXT: !32 = !{!6, !6, !6}
+; CHECK-NEXT: !33 = !DISubrangeType(name: "foo", scope: !1, file: !1, line: 42, size: 64, baseType: !6, lowerBound: i64 0, upperBound: i64 1)
+; CHECK-NEXT: !34 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
+; CHECK-NEXT: !35 = !DIDerivedType(tag: DW_TAG_set_type, name: "subrangeset", scope: !1, file: !1, line: 42, baseType: !33, size: 64)
+; CHECK-NEXT: !36 = !DICompositeType(tag: DW_TAG_array_type, name: "foo", scope: !1, file: !1, line: 42, baseType: !6, size: 640, elements: !37, dataLocation: !DIExpression())
+; CHECK-NEXT: !37 = !{!38}
+; CHECK-NEXT: !38 = !DISubrange(count: 10, lowerBound: 0)
+; CHECK-NEXT: !39 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !40, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !43)
+; CHECK-NEXT: !40 = !DISubroutineType(types: !41)
+; CHECK-NEXT: !41 = !{!6, !6, !42}
+; CHECK-NEXT: !42 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !37)
+; CHECK-NEXT: !43 = !{!44, !45, !46, !47, !49, !50}
+; CHECK-NEXT: !44 = !DILocalVariable(name: "a", arg: 1, scope: !39, file: !1, line: 42, type: !6)
+; CHECK-NEXT: !45 = !DILocalVariable(name: "b", arg: 2, scope: !39, file: !1, line: 42, type: !6)
+; CHECK-NEXT: !46 = !DILocalVariable(name: "c", arg: 3, scope: !39, file: !1, line: 42, type: !42)
+; CHECK-NEXT: !47 = !DILocalVariable(name: "d", scope: !48, file: !1, line: 43, type: !6)
+; CHECK-NEXT: !48 = distinct !DILexicalBlock(scope: !39, file: !1, line: 42)
+; CHECK-NEXT: !49 = !DILocalVariable(name: "e", scope: !48, file: !1, line: 44, type: !6)
+; CHECK-NEXT: !50 = !DILabel(scope: !39, name: "label3", file: !1, line: 42)
+; CHECK-NEXT: !51 = !DILocation(line: 42, scope: !39)
+; CHECK-NEXT: !52 = !DILabel(scope: !39, name: "label1", file: !1, line: 42)
+; CHECK-NEXT: !53 = !DILabel(scope: !39, name: "label2", file: !1, line: 42)
+; CHECK-NEXT: !54 = !DILocation(line: 43, scope: !39)
diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c
index baf4ddfcc9a37..10f14bbed120b 100644
--- a/llvm/tools/llvm-c-test/debuginfo.c
+++ b/llvm/tools/llvm-c-test/debuginfo.c
@@ -215,6 +215,42 @@ int llvm_test_dibuilder(void) {
LLVMAddNamedMetadataOperand(
M, "EnumTest", LLVMMetadataAsValue(LLVMGetModuleContext(M), EnumTest));
+ LLVMMetadataRef lo = LLVMValueAsMetadata(FooVal1);
+ LLVMMetadataRef hi = LLVMValueAsMetadata(FooVal2);
+ LLVMMetadataRef SubrangeMetadataTy = LLVMDIBuilderCreateSubrangeType(
+ DIB, File, "foo", 3, 42, File, 64, 0, 0, Int64Ty, lo, hi, NULL, NULL);
+ LLVMAddNamedMetadataOperand(
+ M, "SubrangeType",
+ LLVMMetadataAsValue(LLVMGetModuleContext(M), SubrangeMetadataTy));
+
+ LLVMMetadataRef SetMetadataTy1 = LLVMDIBuilderCreateSetType(
+ DIB, File, "enumset", 7, File, 42, 64, 0, EnumTest);
+ LLVMMetadataRef SetMetadataTy2 = LLVMDIBuilderCreateSetType(
+ DIB, File, "subrangeset", 11, File, 42, 64, 0, SubrangeMetadataTy);
+ LLVMAddNamedMetadataOperand(
+ M, "SetType1",
+ LLVMMetadataAsValue(LLVMGetModuleContext(M), SetMetadataTy1));
+ LLVMAddNamedMetadataOperand(
+ M, "SetType2",
+ LLVMMetadataAsValue(LLVMGetModuleContext(M), SetMetadataTy2));
+
+ LLVMMetadataRef DynSubscripts[] = {
+ LLVMDIBuilderGetOrCreateSubrange(DIB, 0, 10),
+ };
+ LLVMMetadataRef LocExpression = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
+ LLVMMetadataRef DynamicArrayMetadataTy = LLVMDIBuilderCreateDynamicArrayType(
+ DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1,
+ LocExpression, NULL, NULL, NULL, NULL);
+ LLVMAddNamedMetadataOperand(
+ M, "DynType",
+ LLVMMetadataAsValue(LLVMGetModuleContext(M), DynamicArrayMetadataTy));
+
+ LLVMMetadataRef StructElts[] = {Int64Ty, Int64Ty, Int64Ty};
+ LLVMMetadataRef StructDestTy = LLVMDIBuilderCreateStructType(
+ DIB, NameSpace, "ThisStruct", 9, File, 0, 192, 0, 0, NULL, StructElts, 3,
+ LLVMDWARFSourceLanguageC, NULL, "ThisStruct", 9);
+ LLVMReplaceArrays(DIB, &StructDbgTy, &StructDestTy, 1);
+
// Using the new debug format, debug records get attached to instructions.
// Insert a `br` and `ret` now to absorb the debug records which are
// currently "trailing", meaning that they're associated with a block
More information about the llvm-commits
mailing list