Skip to content

Commit f420b61

Browse files
committed
Fixed unwrap for subrange type failing asserts. Also fixed the replace
arrays test.
1 parent 092e83d commit f420b61

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

llvm/lib/IR/DebugInfo.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,9 +1339,8 @@ LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
13391339
return wrap(unwrap(Builder)->createSubrangeType(
13401340
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo, unwrapDI<DIScope>(Scope),
13411341
SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1342-
unwrapDI<DIType>(BaseTy), unwrap<DIExpression>(LowerBound),
1343-
unwrap<DIExpression>(UpperBound), unwrap<DIExpression>(Stride),
1344-
unwrap<DIExpression>(Bias)));
1342+
unwrapDI<DIType>(BaseTy), unwrap(LowerBound), unwrap(UpperBound),
1343+
unwrap(Stride), unwrap(Bias)));
13451344
}
13461345

13471346
LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
@@ -1356,17 +1355,17 @@ LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
13561355
return wrap(unwrap(Builder)->createArrayType(
13571356
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
13581357
Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
1359-
unwrap<DIExpression>(DataLocation), unwrap<DIExpression>(Associated),
1358+
unwrapDI<DIExpression>(DataLocation), unwrap<DIExpression>(Associated),
13601359
unwrap<DIExpression>(Allocated), unwrap<DIExpression>(Rank),
13611360
unwrap(BitStride)));
13621361
}
13631362

13641363
void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T,
13651364
LLVMMetadataRef *Elements, unsigned NumElements) {
1366-
auto Arr = unwrap<DICompositeType>(*T);
1365+
auto CT = unwrap<DICompositeType>(*T);
13671366
auto Elts =
13681367
unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements});
1369-
unwrap(Builder)->replaceArrays(Arr, Elts);
1368+
unwrap(Builder)->replaceArrays(CT, Elts);
13701369
}
13711370

13721371
LLVMMetadataRef LLVMDIBuilderCreateUnionType(

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
; CHECK: ; ModuleID = 'debuginfo.c'
55
; CHECK-NEXT: source_filename = "debuginfo.c"
66

7-
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !44 {
7+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !46 {
88
; CHECK-NEXT: entry:
9-
; CHECK-NEXT: #dbg_declare(i64 0, !49, !DIExpression(), !56)
10-
; CHECK-NEXT: #dbg_declare(i64 0, !50, !DIExpression(), !56)
11-
; CHECK-NEXT: #dbg_declare(i64 0, !51, !DIExpression(), !56)
12-
; CHECK-NEXT: #dbg_label(!57, !56)
9+
; CHECK-NEXT: #dbg_declare(i64 0, !51, !DIExpression(), !58)
10+
; CHECK-NEXT: #dbg_declare(i64 0, !52, !DIExpression(), !58)
11+
; CHECK-NEXT: #dbg_declare(i64 0, !53, !DIExpression(), !58)
12+
; CHECK-NEXT: #dbg_label(!59, !58)
1313
; CHECK-NEXT: br label %vars
14-
; CHECK-NEXT: #dbg_label(!58, !56)
14+
; CHECK-NEXT: #dbg_label(!60, !58)
1515
; CHECK-NEXT: br label %vars
1616

1717
; CHECK: vars: ; preds = %entry, %entry
1818
; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
1919
; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
20-
; CHECK-NEXT: #dbg_value(i64 0, !52, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !59)
21-
; CHECK-NEXT: #dbg_value(i64 1, !54, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !59)
20+
; CHECK-NEXT: #dbg_value(i64 0, !54, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !61)
21+
; CHECK-NEXT: #dbg_value(i64 1, !56, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !61)
2222
; CHECK-NEXT: %a = add i64 %p1, %p2
2323
; CHECK-NEXT: ret i64 0
2424
; CHECK-NEXT: }
@@ -27,10 +27,11 @@
2727
; CHECK-NEXT: !FooType = !{!33}
2828
; CHECK-NEXT: !EnumTest = !{!3}
2929
; CHECK-NEXT: !LargeEnumTest = !{!11}
30-
; CHECK-NEXT: !SubrangeType = !{!38}
31-
; CHECK-NEXT: !SetType1 = !{!39}
32-
; CHECK-NEXT: !SetType2 = !{!40}
33-
; CHECK-NEXT: !DynType = !{!41}
30+
; CHECK-NEXT: !SubrangeType = !{!36}
31+
; CHECK-NEXT: !SetType1 = !{!37}
32+
; CHECK-NEXT: !SetType2 = !{!38}
33+
; CHECK-NEXT: !DynType = !{!39}
34+
; CHECK-NEXT: !ClassType = !{!42}
3435

3536
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !16, imports: !24, macros: !28, splitDebugInlining: false, sysroot: "/")
3637
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
@@ -67,28 +68,30 @@
6768
; CHECK-NEXT: !32 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
6869
; CHECK-NEXT: !33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 192, dwarfAddressSpace: 0)
6970
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !4, file: !1, size: 192, elements: !35, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
70-
; CHECK-NEXT: !35 = !{!36}
71-
; CHECK-NEXT: !36 = !DICompositeType(tag: DW_TAG_structure_type, name: "ThisStruc", scope: !4, file: !1, size: 192, elements: !37, runtimeLang: DW_LANG_C89, identifier: "ThisStruc")
72-
; CHECK-NEXT: !37 = !{!6, !6, !6}
73-
; CHECK-NEXT: !38 = !DISubrangeType(name: "foo", scope: !1, file: !1, line: 42, size: 64, baseType: !6, lowerBound: i64 0, upperBound: i64 1)
74-
; CHECK-NEXT: !39 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
75-
; CHECK-NEXT: !40 = !DIDerivedType(tag: DW_TAG_set_type, name: "subrangeset", scope: !1, file: !1, line: 42, baseType: !38, size: 64)
76-
; CHECK-NEXT: !41 = !DICompositeType(tag: DW_TAG_array_type, name: "foo", scope: !1, file: !1, line: 42, baseType: !6, size: 640, elements: !42, dataLocation: !DIExpression())
77-
; CHECK-NEXT: !42 = !{!43}
78-
; CHECK-NEXT: !43 = !DISubrange(count: 10, lowerBound: 0)
79-
; CHECK-NEXT: !44 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !45, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !48)
80-
; CHECK-NEXT: !45 = !DISubroutineType(types: !46)
81-
; CHECK-NEXT: !46 = !{!6, !6, !47}
82-
; CHECK-NEXT: !47 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !42)
83-
; CHECK-NEXT: !48 = !{!49, !50, !51, !52, !54, !55}
84-
; CHECK-NEXT: !49 = !DILocalVariable(name: "a", arg: 1, scope: !44, file: !1, line: 42, type: !6)
85-
; CHECK-NEXT: !50 = !DILocalVariable(name: "b", arg: 2, scope: !44, file: !1, line: 42, type: !6)
86-
; CHECK-NEXT: !51 = !DILocalVariable(name: "c", arg: 3, scope: !44, file: !1, line: 42, type: !47)
87-
; CHECK-NEXT: !52 = !DILocalVariable(name: "d", scope: !53, file: !1, line: 43, type: !6)
88-
; CHECK-NEXT: !53 = distinct !DILexicalBlock(scope: !44, file: !1, line: 42)
89-
; CHECK-NEXT: !54 = !DILocalVariable(name: "e", scope: !53, file: !1, line: 44, type: !6)
90-
; CHECK-NEXT: !55 = !DILabel(scope: !44, name: "label3", file: !1, line: 42)
91-
; CHECK-NEXT: !56 = !DILocation(line: 42, scope: !44)
92-
; CHECK-NEXT: !57 = !DILabel(scope: !44, name: "label1", file: !1, line: 42)
93-
; CHECK-NEXT: !58 = !DILabel(scope: !44, name: "label2", file: !1, line: 42)
94-
; CHECK-NEXT: !59 = !DILocation(line: 43, scope: !44)
71+
; CHECK-NEXT: !35 = !{!6, !6, !6}
72+
; CHECK-NEXT: !36 = !DISubrangeType(name: "foo", scope: !1, file: !1, line: 42, size: 64, baseType: !6, lowerBound: i64 0, upperBound: i64 1, stride: i64 8, bias: i64 4)
73+
; CHECK-NEXT: !37 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
74+
; CHECK-NEXT: !38 = !DIDerivedType(tag: DW_TAG_set_type, name: "subrangeset", scope: !1, file: !1, line: 42, baseType: !36, size: 64)
75+
; CHECK-NEXT: !39 = !DICompositeType(tag: DW_TAG_array_type, name: "foo", scope: !1, file: !1, line: 42, baseType: !6, size: 640, elements: !40, dataLocation: !DIExpression(), associated: !DIExpression(), allocated: !DIExpression(), rank: !DIExpression())
76+
; CHECK-NEXT: !40 = !{!41}
77+
; CHECK-NEXT: !41 = !DISubrange(count: 10, lowerBound: 0)
78+
; CHECK-NEXT: !42 = !DICompositeType(tag: DW_TAG_class_type, name: "Class", scope: !4, file: !1, size: 192, flags: DIFlagFwdDecl, elements: !43, identifier: "FooClass")
79+
; CHECK-NEXT: !43 = !{!44}
80+
; CHECK-NEXT: !44 = !{!6, !6, !45}
81+
; CHECK-NEXT: !45 = !DIBasicType(name: "Int32", size: 32)
82+
; CHECK-NEXT: !46 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !47, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !50)
83+
; CHECK-NEXT: !47 = !DISubroutineType(types: !48)
84+
; CHECK-NEXT: !48 = !{!6, !6, !49}
85+
; CHECK-NEXT: !49 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !40)
86+
; CHECK-NEXT: !50 = !{!51, !52, !53, !54, !56, !57}
87+
; CHECK-NEXT: !51 = !DILocalVariable(name: "a", arg: 1, scope: !46, file: !1, line: 42, type: !6)
88+
; CHECK-NEXT: !52 = !DILocalVariable(name: "b", arg: 2, scope: !46, file: !1, line: 42, type: !6)
89+
; CHECK-NEXT: !53 = !DILocalVariable(name: "c", arg: 3, scope: !46, file: !1, line: 42, type: !49)
90+
; CHECK-NEXT: !54 = !DILocalVariable(name: "d", scope: !55, file: !1, line: 43, type: !6)
91+
; CHECK-NEXT: !55 = distinct !DILexicalBlock(scope: !46, file: !1, line: 42)
92+
; CHECK-NEXT: !56 = !DILocalVariable(name: "e", scope: !55, file: !1, line: 44, type: !6)
93+
; CHECK-NEXT: !57 = !DILabel(scope: !46, name: "label3", file: !1, line: 42)
94+
; CHECK-NEXT: !58 = !DILocation(line: 42, scope: !46)
95+
; CHECK-NEXT: !59 = !DILabel(scope: !46, name: "label1", file: !1, line: 42)
96+
; CHECK-NEXT: !60 = !DILabel(scope: !46, name: "label2", file: !1, line: 42)
97+
; CHECK-NEXT: !61 = !DILocation(line: 43, scope: !46)

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,14 @@ int llvm_test_dibuilder(void) {
235235
M, "LargeEnumTest",
236236
LLVMMetadataAsValue(LLVMGetModuleContext(M), LargeEnumTest));
237237

238+
LLVMValueRef FooVal3 = LLVMConstInt(LLVMInt64Type(), 8, false);
239+
LLVMValueRef FooVal4 = LLVMConstInt(LLVMInt64Type(), 4, false);
238240
LLVMMetadataRef lo = LLVMValueAsMetadata(FooVal1);
239241
LLVMMetadataRef hi = LLVMValueAsMetadata(FooVal2);
242+
LLVMMetadataRef strd = LLVMValueAsMetadata(FooVal3);
243+
LLVMMetadataRef bias = LLVMValueAsMetadata(FooVal4);
240244
LLVMMetadataRef SubrangeMetadataTy = LLVMDIBuilderCreateSubrangeType(
241-
DIB, File, "foo", 3, 42, File, 64, 0, 0, Int64Ty, lo, hi, NULL, NULL);
245+
DIB, File, "foo", 3, 42, File, 64, 0, 0, Int64Ty, lo, hi, strd, bias);
242246
LLVMAddNamedMetadataOperand(
243247
M, "SubrangeType",
244248
LLVMMetadataAsValue(LLVMGetModuleContext(M), SubrangeMetadataTy));
@@ -257,19 +261,25 @@ int llvm_test_dibuilder(void) {
257261
LLVMMetadataRef DynSubscripts[] = {
258262
LLVMDIBuilderGetOrCreateSubrange(DIB, 0, 10),
259263
};
260-
LLVMMetadataRef LocExpression = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
264+
LLVMMetadataRef L = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
261265
LLVMMetadataRef DynamicArrayMetadataTy = LLVMDIBuilderCreateDynamicArrayType(
262-
DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1,
263-
LocExpression, NULL, NULL, NULL, NULL);
266+
DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1, L,
267+
L, L, L, NULL);
264268
LLVMAddNamedMetadataOperand(
265269
M, "DynType",
266270
LLVMMetadataAsValue(LLVMGetModuleContext(M), DynamicArrayMetadataTy));
267271

268-
LLVMMetadataRef StructElts[] = {Int64Ty, Int64Ty, Int64Ty};
269-
LLVMMetadataRef StructDestTy = LLVMDIBuilderCreateStructType(
270-
DIB, NameSpace, "ThisStruct", 9, File, 0, 192, 0, 0, NULL, StructElts, 3,
271-
LLVMDWARFSourceLanguageC, NULL, "ThisStruct", 9);
272-
LLVMReplaceArrays(DIB, &StructDbgTy, &StructDestTy, 1);
272+
LLVMMetadataRef StructPTy = LLVMDIBuilderCreateForwardDecl(
273+
DIB, 2 /*DW_TAG_class_type*/, "Class1", 5, NameSpace, File, 0, 0, 192, 0,
274+
"FooClass", 8);
275+
276+
LLVMMetadataRef Int32Ty =
277+
LLVMDIBuilderCreateBasicType(DIB, "Int32", 5, 32, 0, LLVMDIFlagZero);
278+
LLVMMetadataRef StructElts[] = {Int64Ty, Int64Ty, Int32Ty};
279+
LLVMMetadataRef ClassArr = LLVMDIBuilderGetOrCreateArray(DIB, StructElts, 3);
280+
LLVMReplaceArrays(DIB, &StructPTy, &ClassArr, 1);
281+
LLVMAddNamedMetadataOperand(
282+
M, "ClassType", LLVMMetadataAsValue(LLVMGetModuleContext(M), StructPTy));
273283

274284
// Using the new debug format, debug records get attached to instructions.
275285
// Insert a `br` and `ret` now to absorb the debug records which are

0 commit comments

Comments
 (0)