Skip to content

Commit ace58d6

Browse files
committed
Update to better reflect the different parameter types that can be
given to CreateDynamicArray. Plus additional tests to check.
1 parent d303eee commit ace58d6

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,10 @@ LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
750750
* \param Ty Element type.
751751
* \param Subscripts Subscripts.
752752
* \param NumSubscripts Number of subscripts.
753-
* \param DataLocation DataLocation.
754-
* \param Associated Associated.
755-
* \param Allocated Allocated.
756-
* \param Rank Rank.
753+
* \param DataLocation DataLocation. (DIVariable, DIExpression or NULL)
754+
* \param Associated Associated. (DIVariable, DIExpression or NULL)
755+
* \param Allocated Allocated. (DIVariable, DIExpression or NULL)
756+
* \param Rank Rank. (DIVariable, DIExpression or NULL)
757757
* \param BitStride BitStride.
758758
*/
759759
LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(

llvm/lib/IR/DebugInfo.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,17 @@ LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
13431343
unwrap(Stride), unwrap(Bias)));
13441344
}
13451345

1346+
/// MD may be nullptr, a DIExpression or DIVariable.
1347+
PointerUnion<DIExpression *, DIVariable *> unwrapExprVar(LLVMMetadataRef MD) {
1348+
if (!MD)
1349+
return nullptr;
1350+
MDNode *MDN = unwrapDI<MDNode>(MD);
1351+
if (auto *E = dyn_cast<DIExpression>(MDN))
1352+
return E;
1353+
assert(isa<DIVariable>(MDN) && "Expected DIExpression or DIVariable");
1354+
return cast<DIVariable>(MDN);
1355+
}
1356+
13461357
LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
13471358
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
13481359
size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
@@ -1355,9 +1366,8 @@ LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
13551366
return wrap(unwrap(Builder)->createArrayType(
13561367
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
13571368
Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
1358-
unwrapDI<DIExpression>(DataLocation), unwrapDI<DIExpression>(Associated),
1359-
unwrapDI<DIExpression>(Allocated), unwrapDI<DIExpression>(Rank),
1360-
unwrap(BitStride)));
1369+
unwrapExprVar(DataLocation), unwrapExprVar(Associated),
1370+
unwrapExprVar(Allocated), unwrapExprVar(Rank), unwrap(BitStride)));
13611371
}
13621372

13631373
void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T,

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
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 !46 {
7+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !44 {
88
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: #dbg_declare(i64 0, !49, !DIExpression(), !58)
10+
; CHECK-NEXT: #dbg_declare(i64 0, !50, !DIExpression(), !58)
911
; 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)
1212
; CHECK-NEXT: #dbg_label(!59, !58)
1313
; CHECK-NEXT: br label %vars
1414
; CHECK-NEXT: #dbg_label(!60, !58)
@@ -17,8 +17,8 @@
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, !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)
20+
; CHECK-NEXT: #dbg_value(i64 0, !42, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !61)
21+
; CHECK-NEXT: #dbg_value(i64 1, !52, !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: }
@@ -31,7 +31,7 @@
3131
; CHECK-NEXT: !SetType1 = !{!37}
3232
; CHECK-NEXT: !SetType2 = !{!38}
3333
; CHECK-NEXT: !DynType = !{!39}
34-
; CHECK-NEXT: !ClassType = !{!42}
34+
; CHECK-NEXT: !ClassType = !{!54}
3535

3636
; 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: "/")
3737
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
@@ -72,26 +72,26 @@
7272
; 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)
7373
; CHECK-NEXT: !37 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
7474
; 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())
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: !42, rank: !DIExpression())
7676
; CHECK-NEXT: !40 = !{!41}
7777
; 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)
78+
; CHECK-NEXT: !42 = !DILocalVariable(name: "d", scope: !43, file: !1, line: 43, type: !6)
79+
; CHECK-NEXT: !43 = distinct !DILexicalBlock(scope: !44, file: !1, line: 42)
80+
; 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)
81+
; CHECK-NEXT: !45 = !DISubroutineType(types: !46)
82+
; CHECK-NEXT: !46 = !{!6, !6, !47}
83+
; CHECK-NEXT: !47 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !40)
84+
; CHECK-NEXT: !48 = !{!49, !50, !51, !42, !52, !53}
85+
; CHECK-NEXT: !49 = !DILocalVariable(name: "a", arg: 1, scope: !44, file: !1, line: 42, type: !6)
86+
; CHECK-NEXT: !50 = !DILocalVariable(name: "b", arg: 2, scope: !44, file: !1, line: 42, type: !6)
87+
; CHECK-NEXT: !51 = !DILocalVariable(name: "c", arg: 3, scope: !44, file: !1, line: 42, type: !47)
88+
; CHECK-NEXT: !52 = !DILocalVariable(name: "e", scope: !43, file: !1, line: 44, type: !6)
89+
; CHECK-NEXT: !53 = !DILabel(scope: !44, name: "label3", file: !1, line: 42)
90+
; CHECK-NEXT: !54 = !DICompositeType(tag: DW_TAG_class_type, name: "Class", scope: !4, file: !1, size: 192, flags: DIFlagFwdDecl, elements: !55, identifier: "FooClass")
91+
; CHECK-NEXT: !55 = !{!56}
92+
; CHECK-NEXT: !56 = !{!6, !6, !57}
93+
; CHECK-NEXT: !57 = !DIBasicType(name: "Int32", size: 32)
94+
; CHECK-NEXT: !58 = !DILocation(line: 42, scope: !44)
95+
; CHECK-NEXT: !59 = !DILabel(scope: !44, name: "label1", file: !1, line: 42)
96+
; CHECK-NEXT: !60 = !DILabel(scope: !44, name: "label2", file: !1, line: 42)
97+
; CHECK-NEXT: !61 = !DILocation(line: 43, scope: !44)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,11 @@ int llvm_test_dibuilder(void) {
261261
LLVMMetadataRef DynSubscripts[] = {
262262
LLVMDIBuilderGetOrCreateSubrange(DIB, 0, 10),
263263
};
264-
LLVMMetadataRef L = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
264+
LLVMMetadataRef Loc = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
265+
LLVMMetadataRef Rank = LLVMDIBuilderCreateExpression(DIB, NULL, 0);
265266
LLVMMetadataRef DynamicArrayMetadataTy = LLVMDIBuilderCreateDynamicArrayType(
266-
DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1, L,
267-
NULL, NULL, NULL, NULL);
267+
DIB, File, "foo", 3, 42, File, 64 * 10, 0, Int64Ty, DynSubscripts, 1, Loc,
268+
FooVar1, NULL, Rank, NULL);
268269
LLVMAddNamedMetadataOperand(
269270
M, "DynType",
270271
LLVMMetadataAsValue(LLVMGetModuleContext(M), DynamicArrayMetadataTy));

0 commit comments

Comments
 (0)