Skip to content

Commit 73dffda

Browse files
committed
Add LLVM-C DILabel DebugInfo Tests
1 parent 01f2dab commit 73dffda

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
14241424
* \param NameLen Length of variable name.
14251425
* \param File The file to create the label in.
14261426
* \param LineNo Line Number.
1427-
* \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it.
1427+
* \param AlwaysPreserve Preserve the label regardless of optimization.
14281428
*
14291429
* @see llvm::DIBuilder::createLabel()
14301430
*/

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !31 {
88
; CHECK-NEXT: entry:
9-
; CHECK-NEXT: #dbg_declare(i64 0, !38, !DIExpression(), !44)
10-
; CHECK-NEXT: #dbg_declare(i64 0, !39, !DIExpression(), !44)
11-
; CHECK-NEXT: #dbg_declare(i64 0, !40, !DIExpression(), !44)
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)
13+
; CHECK-NEXT: br label %vars
14+
; CHECK-NEXT: #dbg_label(!47, !45)
1215
; CHECK-NEXT: br label %vars
1316
; CHECK: vars:
1417
; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
1518
; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
16-
; CHECK-NEXT: #dbg_value(i64 0, !41, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !45)
17-
; CHECK-NEXT: #dbg_value(i64 1, !43, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !45)
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)
1821
; CHECK-NEXT: %a = add i64 %p1, %p2
1922
; CHECK-NEXT: ret i64 0
2023
; CHECK-NEXT: }
@@ -60,12 +63,15 @@
6063
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !35)
6164
; CHECK-NEXT: !35 = !{!36}
6265
; CHECK-NEXT: !36 = !DISubrange(count: 10, lowerBound: 0)
63-
; CHECK-NEXT: !37 = !{!38, !39, !40, !41, !43}
66+
; CHECK-NEXT: !37 = !{!38, !39, !40, !41, !43, !44}
6467
; CHECK-NEXT: !38 = !DILocalVariable(name: "a", arg: 1, scope: !31, file: !1, line: 42, type: !6)
6568
; CHECK-NEXT: !39 = !DILocalVariable(name: "b", arg: 2, scope: !31, file: !1, line: 42, type: !6)
6669
; CHECK-NEXT: !40 = !DILocalVariable(name: "c", arg: 3, scope: !31, file: !1, line: 42, type: !34)
6770
; CHECK-NEXT: !41 = !DILocalVariable(name: "d", scope: !42, file: !1, line: 43, type: !6)
6871
; CHECK-NEXT: !42 = distinct !DILexicalBlock(scope: !31, file: !1, line: 42)
6972
; CHECK-NEXT: !43 = !DILocalVariable(name: "e", scope: !42, file: !1, line: 44, type: !6)
70-
; CHECK-NEXT: !44 = !DILocation(line: 42, scope: !31)
71-
; CHECK-NEXT: !45 = !DILocation(line: 43, scope: !31)
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)

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ int llvm_test_dibuilder(void) {
163163

164164
LLVMSetSubprogram(FooFunction, FunctionMetadata);
165165

166+
LLVMMetadataRef FooLabel1 = LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
167+
"label1", 6, File, 42, false);
168+
LLVMDIBuilderInsertLabelAtEnd(DIB, FooLabel1, FooParamLocation,
169+
FooEntryBlock);
170+
166171
LLVMMetadataRef FooLexicalBlock =
167172
LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0);
168173

@@ -210,8 +215,6 @@ int llvm_test_dibuilder(void) {
210215
LLVMAddNamedMetadataOperand(
211216
M, "EnumTest", LLVMMetadataAsValue(LLVMGetModuleContext(M), EnumTest));
212217

213-
LLVMDIBuilderFinalize(DIB);
214-
215218
// Using the new debug format, debug records get attached to instructions.
216219
// Insert a `br` and `ret` now to absorb the debug records which are
217220
// currently "trailing", meaning that they're associated with a block
@@ -221,6 +224,20 @@ int llvm_test_dibuilder(void) {
221224
LLVMPositionBuilderAtEnd(Builder, FooEntryBlock);
222225
// Build `br label %vars` in entry.
223226
LLVMBuildBr(Builder, FooVarBlock);
227+
228+
// Build another br for the sake of testing labels.
229+
LLVMMetadataRef FooLabel2 = LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
230+
"label2", 6, File, 42, false);
231+
LLVMDIBuilderInsertLabelBefore(DIB, FooLabel2, FooParamLocation,
232+
LLVMBuildBr(Builder, FooVarBlock));
233+
// label3 will be emitted, but label4 won't be emitted
234+
// because label3 is AlwaysPreserve and label4 is not.
235+
LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
236+
"label3", 6, File, 42, true);
237+
LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
238+
"label4", 6, File, 42, false);
239+
LLVMDIBuilderFinalize(DIB);
240+
224241
// Build `ret i64 0` in vars.
225242
LLVMPositionBuilderAtEnd(Builder, FooVarBlock);
226243
LLVMTypeRef I64 = LLVMInt64TypeInContext(Ctx);

0 commit comments

Comments
 (0)