Skip to content

Commit 8e0b830

Browse files
committed
Code review adjustments. Add test case.
1 parent d681097 commit 8e0b830

File tree

2 files changed

+77
-31
lines changed

2 files changed

+77
-31
lines changed

llvm/test/Bindings/llvm-c/debug_info_new_format.ll

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@
33

44
; CHECK: ; ModuleID = 'debuginfo.c'
55
; CHECK-NEXT: source_filename = "debuginfo.c"
6-
7-
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !31 {
6+
7+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !39 {
88
; CHECK-NEXT: entry:
9-
; CHECK-NEXT: #dbg_declare(i64 0, !38, !DIExpression(), !45)
10-
; CHECK-NEXT: #dbg_declare(i64 0, !39, !DIExpression(), !45)
11-
; CHECK-NEXT: #dbg_declare(i64 0, !40, !DIExpression(), !45)
12-
; CHECK-NEXT: #dbg_label(!46, !45)
9+
; CHECK-NEXT: #dbg_declare(i64 0, !44, !DIExpression(), !51)
10+
; CHECK-NEXT: #dbg_declare(i64 0, !45, !DIExpression(), !51)
11+
; CHECK-NEXT: #dbg_declare(i64 0, !46, !DIExpression(), !51)
12+
; CHECK-NEXT: #dbg_label(!52, !51)
1313
; CHECK-NEXT: br label %vars
14-
; CHECK-NEXT: #dbg_label(!47, !45)
14+
; CHECK-NEXT: #dbg_label(!53, !51)
1515
; CHECK-NEXT: br label %vars
16-
; CHECK: vars:
16+
; CHECK: vars: ; preds = %entry, %entry
1717
; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
1818
; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
19-
; CHECK-NEXT: #dbg_value(i64 0, !41, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !48)
20-
; CHECK-NEXT: #dbg_value(i64 1, !43, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !48)
19+
; CHECK-NEXT: #dbg_value(i64 0, !47, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !54)
20+
; CHECK-NEXT: #dbg_value(i64 1, !49, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !54)
2121
; CHECK-NEXT: %a = add i64 %p1, %p2
2222
; CHECK-NEXT: ret i64 0
2323
; CHECK-NEXT: }
24-
24+
2525
; CHECK: !llvm.dbg.cu = !{!0}
2626
; CHECK-NEXT: !FooType = !{!28}
2727
; CHECK-NEXT: !EnumTest = !{!3}
28-
28+
; CHECK-NEXT: !SubrangeType = !{!33}
29+
; CHECK-NEXT: !SetType1 = !{!34}
30+
; CHECK-NEXT: !SetType2 = !{!35}
31+
; CHECK-NEXT: !DynType = !{!36}
32+
2933
; 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: "/")
3034
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
3135
; CHECK-NEXT: !2 = !{!3}
@@ -56,22 +60,28 @@
5660
; CHECK-NEXT: !27 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
5761
; CHECK-NEXT: !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 192, dwarfAddressSpace: 0)
5862
; 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")
59-
; CHECK-NEXT: !30 = !{!6, !6, !6}
60-
; 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)
61-
; CHECK-NEXT: !32 = !DISubroutineType(types: !33)
62-
; CHECK-NEXT: !33 = !{!6, !6, !34}
63-
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !35)
64-
; CHECK-NEXT: !35 = !{!36}
65-
; CHECK-NEXT: !36 = !DISubrange(count: 10, lowerBound: 0)
66-
; CHECK-NEXT: !37 = !{!38, !39, !40, !41, !43, !44}
67-
; CHECK-NEXT: !38 = !DILocalVariable(name: "a", arg: 1, scope: !31, file: !1, line: 42, type: !6)
68-
; CHECK-NEXT: !39 = !DILocalVariable(name: "b", arg: 2, scope: !31, file: !1, line: 42, type: !6)
69-
; CHECK-NEXT: !40 = !DILocalVariable(name: "c", arg: 3, scope: !31, file: !1, line: 42, type: !34)
70-
; CHECK-NEXT: !41 = !DILocalVariable(name: "d", scope: !42, file: !1, line: 43, type: !6)
71-
; CHECK-NEXT: !42 = distinct !DILexicalBlock(scope: !31, file: !1, line: 42)
72-
; CHECK-NEXT: !43 = !DILocalVariable(name: "e", scope: !42, file: !1, line: 44, type: !6)
73-
; CHECK-NEXT: !44 = !DILabel(scope: !31, name: "label3", file: !1, line: 42)
74-
; CHECK-NEXT: !45 = !DILocation(line: 42, scope: !31)
75-
; CHECK-NEXT: !46 = !DILabel(scope: !31, name: "label1", file: !1, line: 42)
76-
; CHECK-NEXT: !47 = !DILabel(scope: !31, name: "label2", file: !1, line: 42)
77-
; CHECK-NEXT: !48 = !DILocation(line: 43, scope: !31)
63+
; CHECK-NEXT: !30 = !{!31}
64+
; 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")
65+
; CHECK-NEXT: !32 = !{!6, !6, !6}
66+
; CHECK-NEXT: !33 = !DISubrangeType(name: "foo", scope: !1, file: !1, line: 42, size: 64, baseType: !6, lowerBound: i64 0, upperBound: i64 1)
67+
; CHECK-NEXT: !34 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
68+
; CHECK-NEXT: !35 = !DIDerivedType(tag: DW_TAG_set_type, name: "subrangeset", scope: !1, file: !1, line: 42, baseType: !33, size: 64)
69+
; 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())
70+
; CHECK-NEXT: !37 = !{!38}
71+
; CHECK-NEXT: !38 = !DISubrange(count: 10, lowerBound: 0)
72+
; 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)
73+
; CHECK-NEXT: !40 = !DISubroutineType(types: !41)
74+
; CHECK-NEXT: !41 = !{!6, !6, !42}
75+
; CHECK-NEXT: !42 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !37)
76+
; CHECK-NEXT: !43 = !{!44, !45, !46, !47, !49, !50}
77+
; CHECK-NEXT: !44 = !DILocalVariable(name: "a", arg: 1, scope: !39, file: !1, line: 42, type: !6)
78+
; CHECK-NEXT: !45 = !DILocalVariable(name: "b", arg: 2, scope: !39, file: !1, line: 42, type: !6)
79+
; CHECK-NEXT: !46 = !DILocalVariable(name: "c", arg: 3, scope: !39, file: !1, line: 42, type: !42)
80+
; CHECK-NEXT: !47 = !DILocalVariable(name: "d", scope: !48, file: !1, line: 43, type: !6)
81+
; CHECK-NEXT: !48 = distinct !DILexicalBlock(scope: !39, file: !1, line: 42)
82+
; CHECK-NEXT: !49 = !DILocalVariable(name: "e", scope: !48, file: !1, line: 44, type: !6)
83+
; CHECK-NEXT: !50 = !DILabel(scope: !39, name: "label3", file: !1, line: 42)
84+
; CHECK-NEXT: !51 = !DILocation(line: 42, scope: !39)
85+
; CHECK-NEXT: !52 = !DILabel(scope: !39, name: "label1", file: !1, line: 42)
86+
; CHECK-NEXT: !53 = !DILabel(scope: !39, name: "label2", file: !1, line: 42)
87+
; CHECK-NEXT: !54 = !DILocation(line: 43, scope: !39)

llvm/tools/llvm-c-test/debuginfo.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,42 @@ int llvm_test_dibuilder(void) {
215215
LLVMAddNamedMetadataOperand(
216216
M, "EnumTest", LLVMMetadataAsValue(LLVMGetModuleContext(M), EnumTest));
217217

218+
LLVMMetadataRef lo = LLVMValueAsMetadata(FooVal1);
219+
LLVMMetadataRef hi = LLVMValueAsMetadata(FooVal2);
220+
LLVMMetadataRef SubrangeMetadataTy = LLVMDIBuilderCreateSubrangeType(
221+
DIB, File, "foo", 3, 42, File, 64, 0, 0, Int64Ty, lo, hi, NULL, NULL);
222+
LLVMAddNamedMetadataOperand(
223+
M, "SubrangeType",
224+
LLVMMetadataAsValue(LLVMGetModuleContext(M), SubrangeMetadataTy));
225+
226+
LLVMMetadataRef SetMetadataTy1 = LLVMDIBuilderCreateSetType(
227+
DIB, File, "enumset", 7, File, 42, 64, 0, EnumTest);
228+
LLVMMetadataRef SetMetadataTy2 = LLVMDIBuilderCreateSetType(
229+
DIB, File, "subrangeset", 11, File, 42, 64, 0, SubrangeMetadataTy);
230+
LLVMAddNamedMetadataOperand(
231+
M, "SetType1",
232+
LLVMMetadataAsValue(LLVMGetModuleContext(M), SetMetadataTy1));
233+
LLVMAddNamedMetadataOperand(
234+
M, "SetType2",
235+
LLVMMetadataAsValue(LLVMGetModuleContext(M), SetMetadataTy2));
236+
237+
LLVMMetadataRef DynSubscripts[] = {
238+
LLVMDIBuilderGetOrCreateSubrange(DIB, 0, 10),
239+
};
240+
LLVMMetadataRef LocExpression = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
241+
LLVMMetadataRef DynamicArrayMetadataTy = LLVMDIBuilderCreateDynamicArrayType(
242+
DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1,
243+
LocExpression, NULL, NULL, NULL, NULL);
244+
LLVMAddNamedMetadataOperand(
245+
M, "DynType",
246+
LLVMMetadataAsValue(LLVMGetModuleContext(M), DynamicArrayMetadataTy));
247+
248+
LLVMMetadataRef StructElts[] = {Int64Ty, Int64Ty, Int64Ty};
249+
LLVMMetadataRef StructDestTy = LLVMDIBuilderCreateStructType(
250+
DIB, NameSpace, "ThisStruct", 9, File, 0, 192, 0, 0, NULL, StructElts, 3,
251+
LLVMDWARFSourceLanguageC, NULL, "ThisStruct", 9);
252+
LLVMReplaceArrays(DIB, &StructDbgTy, &StructDestTy, 1);
253+
218254
// Using the new debug format, debug records get attached to instructions.
219255
// Insert a `br` and `ret` now to absorb the debug records which are
220256
// currently "trailing", meaning that they're associated with a block

0 commit comments

Comments
 (0)