Skip to content

Commit 9112073

Browse files
authored
[RemoveDIs][NFC] Fix rotten green C API test (#92362)
`llvm_test_dibuilder(/*NewDebugInfoMode=*/true)` isn't currently executed in `return llvm_test_dibuilder(false) && llvm_test_dibuilder(true);` because `llvm_test_dibuilder` returns 0 for success. Split the llvm-c-test flag `--test-dibuilder` into two, one for the old and one for the new debug info format. Add another lit test for the new format. Now that the test actually runs, it crashes using the new format with `llvm/lib/IR/LLVMContextImpl.cpp:53:llvm::LLVMContextImpl::~LLVMContextImpl(): Assertion 'TrailingDbgRecords.empty() && "DbgRecords in blocks not cleaned"' failed. Aborted`. Insert terminators into the blocks so that we don't leave the debug records trailing, unattached to any instructions, which fixes that.
1 parent fdaad73 commit 9112073

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-c-test --test-dibuilder | FileCheck %s
1+
; RUN: llvm-c-test --test-dibuilder-old-debuginfo-format | FileCheck %s
22

33
; CHECK: ; ModuleID = 'debuginfo.c'
44
; CHECK-NEXT: source_filename = "debuginfo.c"
@@ -8,8 +8,10 @@
88
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !38, metadata !DIExpression()), !dbg !43
99
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !39, metadata !DIExpression()), !dbg !43
1010
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !40, metadata !DIExpression()), !dbg !43
11-
; CHECK: vars: ; No predecessors!
11+
; CHECK-NEXT: br label %vars
12+
; CHECK: vars:
1213
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !41, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !44
14+
; CHECK-NEXT: ret i64 0
1315
; CHECK-NEXT: }
1416

1517
; CHECK: ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
; RUN: llvm-c-test --test-dibuilder-new-debuginfo-format | FileCheck %s
2+
;; Duplicate of debug_info.ll using debug records instead of intrinsics.
3+
4+
; CHECK: ; ModuleID = 'debuginfo.c'
5+
; CHECK-NEXT: source_filename = "debuginfo.c"
6+
7+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !31 {
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: #dbg_declare(i64 0, !38, !DIExpression(), !43)
10+
; CHECK-NEXT: #dbg_declare(i64 0, !39, !DIExpression(), !43)
11+
; CHECK-NEXT: #dbg_declare(i64 0, !40, !DIExpression(), !43)
12+
; CHECK-NEXT: br label %vars
13+
; CHECK: vars:
14+
; CHECK-NEXT: #dbg_value(i64 0, !41, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !44)
15+
; CHECK-NEXT: ret i64 0
16+
; CHECK-NEXT: }
17+
18+
; CHECK: !llvm.dbg.cu = !{!0}
19+
; CHECK-NEXT: !FooType = !{!28}
20+
; CHECK-NEXT: !EnumTest = !{!3}
21+
22+
; 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: "/")
23+
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
24+
; CHECK-NEXT: !2 = !{!3}
25+
; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "EnumTest", scope: !4, file: !1, baseType: !6, size: 64, elements: !7)
26+
; CHECK-NEXT: !4 = !DINamespace(name: "NameSpace", scope: !5)
27+
; CHECK-NEXT: !5 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
28+
; CHECK-NEXT: !6 = !DIBasicType(name: "Int64", size: 64)
29+
; CHECK-NEXT: !7 = !{!8, !9, !10}
30+
; CHECK-NEXT: !8 = !DIEnumerator(name: "Test_A", value: 0, isUnsigned: true)
31+
; CHECK-NEXT: !9 = !DIEnumerator(name: "Test_B", value: 1, isUnsigned: true)
32+
; CHECK-NEXT: !10 = !DIEnumerator(name: "Test_B", value: 2, isUnsigned: true)
33+
; CHECK-NEXT: !11 = !{!12, !16}
34+
; CHECK-NEXT: !12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
35+
; CHECK-NEXT: !13 = distinct !DIGlobalVariable(name: "globalClass", scope: !5, file: !1, line: 1, type: !14, isLocal: true, isDefinition: true)
36+
; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "TestClass", scope: !1, file: !1, line: 42, size: 64, flags: DIFlagObjcClassComplete, elements: !15)
37+
; CHECK-NEXT: !15 = !{}
38+
; CHECK-NEXT: !16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
39+
; CHECK-NEXT: !17 = distinct !DIGlobalVariable(name: "global", scope: !5, file: !1, line: 1, type: !18, isLocal: true, isDefinition: true)
40+
; CHECK-NEXT: !18 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !6)
41+
; CHECK-NEXT: !19 = !{!20, !22}
42+
; CHECK-NEXT: !20 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !21, file: !1, line: 42)
43+
; CHECK-NEXT: !21 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
44+
; CHECK-NEXT: !22 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !20, file: !1, line: 42)
45+
; CHECK-NEXT: !23 = !{!24}
46+
; CHECK-NEXT: !24 = !DIMacroFile(file: !1, nodes: !25)
47+
; CHECK-NEXT: !25 = !{!26, !27}
48+
; CHECK-NEXT: !26 = !DIMacro(type: DW_MACINFO_define, name: "SIMPLE_DEFINE")
49+
; CHECK-NEXT: !27 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
50+
; CHECK-NEXT: !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 192, dwarfAddressSpace: 0)
51+
; 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")
52+
; CHECK-NEXT: !30 = !{!6, !6, !6}
53+
; 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)
54+
; CHECK-NEXT: !32 = !DISubroutineType(types: !33)
55+
; CHECK-NEXT: !33 = !{!6, !6, !34}
56+
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !35)
57+
; CHECK-NEXT: !35 = !{!36}
58+
; CHECK-NEXT: !36 = !DISubrange(count: 10, lowerBound: 0)
59+
; CHECK-NEXT: !37 = !{!38, !39, !40, !41}
60+
; CHECK-NEXT: !38 = !DILocalVariable(name: "a", arg: 1, scope: !31, file: !1, line: 42, type: !6)
61+
; CHECK-NEXT: !39 = !DILocalVariable(name: "b", arg: 2, scope: !31, file: !1, line: 42, type: !6)
62+
; CHECK-NEXT: !40 = !DILocalVariable(name: "c", arg: 3, scope: !31, file: !1, line: 42, type: !34)
63+
; CHECK-NEXT: !41 = !DILocalVariable(name: "d", scope: !42, file: !1, line: 43, type: !6)
64+
; CHECK-NEXT: !42 = distinct !DILexicalBlock(scope: !31, file: !1, line: 42)
65+
; CHECK-NEXT: !43 = !DILocation(line: 42, scope: !31)
66+
; CHECK-NEXT: !44 = !DILocation(line: 43, scope: !31)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,26 @@ int llvm_test_dibuilder(bool NewDebugInfoFormat) {
215215

216216
LLVMDIBuilderFinalize(DIB);
217217

218+
// Using the new debug format, debug records get attached to instructions.
219+
// Insert a `br` and `ret` now to absorb the debug records which are
220+
// currently "trailing", meaning that they're associated with a block
221+
// but no particular instruction, which is only valid as a transient state.
222+
LLVMContextRef Ctx = LLVMGetModuleContext(M);
223+
LLVMBuilderRef Builder = LLVMCreateBuilderInContext(Ctx);
224+
LLVMPositionBuilderAtEnd(Builder, FooEntryBlock);
225+
// Build `br label %vars` in entry.
226+
LLVMBuildBr(Builder, FooVarBlock);
227+
// Build `ret i64 0` in vars.
228+
LLVMPositionBuilderAtEnd(Builder, FooVarBlock);
229+
LLVMTypeRef I64 = LLVMInt64TypeInContext(Ctx);
230+
LLVMValueRef Zero = LLVMConstInt(I64, 0, false);
231+
LLVMBuildRet(Builder, Zero);
232+
218233
char *MStr = LLVMPrintModuleToString(M);
219234
puts(MStr);
220235
LLVMDisposeMessage(MStr);
221236

237+
LLVMDisposeBuilder(Builder);
222238
LLVMDisposeDIBuilder(DIB);
223239
LLVMDisposeModule(M);
224240

llvm/tools/llvm-c-test/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ int main(int argc, char **argv) {
109109
return llvm_echo();
110110
} else if (argc == 2 && !strcmp(argv[1], "--test-diagnostic-handler")) {
111111
return llvm_test_diagnostic_handler();
112-
} else if (argc == 2 && !strcmp(argv[1], "--test-dibuilder")) {
113-
return llvm_test_dibuilder(false) && llvm_test_dibuilder(true);
112+
} else if (argc == 2 &&
113+
!strcmp(argv[1], "--test-dibuilder-old-debuginfo-format")) {
114+
return llvm_test_dibuilder(false);
115+
} else if (argc == 2 &&
116+
!strcmp(argv[1], "--test-dibuilder-new-debuginfo-format")) {
117+
return llvm_test_dibuilder(true);
114118
} else {
115119
print_usage();
116120
}

0 commit comments

Comments
 (0)