Skip to content

Commit 8680c4c

Browse files
demoitemgithub-actions[bot]
authored andcommitted
Automerge: Add checksum option for create file (#162592)
Add create file with checksum to the C interface
2 parents fdc28e7 + 7bbb4a5 commit 8680c4c

File tree

4 files changed

+111
-54
lines changed

4 files changed

+111
-54
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ enum {
203203
};
204204
typedef unsigned LLVMMetadataKind;
205205

206+
/**
207+
* The kind of checksum to emit.
208+
*/
209+
typedef enum { CSK_MD5, CSK_SHA1, CSK_SHA256 } LLVMChecksumKind;
210+
206211
/**
207212
* An LLVM DWARF type encoding.
208213
*/
@@ -326,6 +331,25 @@ LLVM_C_ABI LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder,
326331
const char *Directory,
327332
size_t DirectoryLen);
328333

334+
/**
335+
* Create a file descriptor to hold debugging information for a file.
336+
* \param Builder The \c DIBuilder.
337+
* \param Filename File name.
338+
* \param FilenameLen The length of the C string passed to \c Filename.
339+
* \param Directory Directory.
340+
* \param DirectoryLen The length of the C string passed to \c Directory.
341+
* \param ChecksumKind The kind of checksum. eg MD5, SHA256
342+
* \param Checksum The checksum.
343+
* \param ChecksumLen The length of the checksum.
344+
* \param Souce The embedded source.
345+
* \param SourceLen The length of the source.
346+
*/
347+
LLVM_C_ABI LLVMMetadataRef LLVMDIBuilderCreateFileWithChecksum(
348+
LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen,
349+
const char *Directory, size_t DirectoryLen, LLVMChecksumKind ChecksumKind,
350+
const char *Checksum, size_t ChecksumLen, const char *Source,
351+
size_t SourceLen);
352+
329353
/**
330354
* Creates a new descriptor for a module with the specified parent scope.
331355
* \param Builder The \c DIBuilder.

llvm/lib/IR/DebugInfo.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,35 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
10951095
StringRef(Directory, DirectoryLen)));
10961096
}
10971097

1098+
static llvm::DIFile::ChecksumKind
1099+
map_from_llvmChecksumKind(LLVMChecksumKind CSKind) {
1100+
switch (CSKind) {
1101+
case LLVMChecksumKind::CSK_MD5:
1102+
return llvm::DIFile::CSK_MD5;
1103+
case LLVMChecksumKind::CSK_SHA1:
1104+
return llvm::DIFile::CSK_SHA1;
1105+
case LLVMChecksumKind::CSK_SHA256:
1106+
return llvm::DIFile::CSK_SHA256;
1107+
}
1108+
llvm_unreachable("Unhandled Checksum Kind");
1109+
}
1110+
1111+
LLVMMetadataRef LLVMDIBuilderCreateFileWithChecksum(
1112+
LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen,
1113+
const char *Directory, size_t DirectoryLen, LLVMChecksumKind ChecksumKind,
1114+
const char *Checksum, size_t ChecksumLen, const char *Source,
1115+
size_t SourceLen) {
1116+
StringRef ChkSum = StringRef(Checksum, ChecksumLen);
1117+
auto CSK = map_from_llvmChecksumKind(ChecksumKind);
1118+
llvm::DIFile::ChecksumInfo<StringRef> CSInfo(CSK, ChkSum);
1119+
std::optional<StringRef> Src;
1120+
if (SourceLen > 0)
1121+
Src = StringRef(Source, SourceLen);
1122+
return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1123+
StringRef(Directory, DirectoryLen),
1124+
CSInfo, Src));
1125+
}
1126+
10981127
LLVMMetadataRef
10991128
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
11001129
const char *Name, size_t NameLen,

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

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
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 !44 {
6+
7+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !45 {
88
; CHECK-NEXT: entry:
9-
; CHECK-NEXT: #dbg_declare(i64 0, !49, !DIExpression(), !58)
10-
; CHECK-NEXT: #dbg_declare(i64 0, !50, !DIExpression(), !58)
11-
; CHECK-NEXT: #dbg_declare(i64 0, !51, !DIExpression(), !58)
12-
; CHECK-NEXT: #dbg_label(!59, !58)
9+
; CHECK-NEXT: #dbg_declare(i64 0, !50, !DIExpression(), !59)
10+
; CHECK-NEXT: #dbg_declare(i64 0, !51, !DIExpression(), !59)
11+
; CHECK-NEXT: #dbg_declare(i64 0, !52, !DIExpression(), !59)
12+
; CHECK-NEXT: #dbg_label(!60, !59)
1313
; CHECK-NEXT: br label %vars
14-
; CHECK-NEXT: #dbg_label(!60, !58)
14+
; CHECK-NEXT: #dbg_label(!61, !59)
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, !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)
20+
; CHECK-NEXT: #dbg_value(i64 0, !43, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !62)
21+
; CHECK-NEXT: #dbg_value(i64 1, !53, !DIExpression(DW_OP_constu, 1, DW_OP_stack_value), !62)
2222
; CHECK-NEXT: %a = add i64 %p1, %p2
2323
; CHECK-NEXT: ret i64 0
2424
; CHECK-NEXT: }
2525

2626
; CHECK: !llvm.dbg.cu = !{!0}
27-
; CHECK-NEXT: !FooType = !{!33}
27+
; CHECK-NEXT: !FooType = !{!34}
2828
; CHECK-NEXT: !EnumTest = !{!3}
2929
; CHECK-NEXT: !LargeEnumTest = !{!11}
30-
; CHECK-NEXT: !SubrangeType = !{!36}
31-
; CHECK-NEXT: !SetType1 = !{!37}
32-
; CHECK-NEXT: !SetType2 = !{!38}
33-
; CHECK-NEXT: !DynType = !{!39}
34-
; CHECK-NEXT: !ClassType = !{!54}
30+
; CHECK-NEXT: !SubrangeType = !{!37}
31+
; CHECK-NEXT: !SetType1 = !{!38}
32+
; CHECK-NEXT: !SetType2 = !{!39}
33+
; CHECK-NEXT: !DynType = !{!40}
34+
; CHECK-NEXT: !ClassType = !{!55}
3535

36-
; 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: "/")
36+
; 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: !29, splitDebugInlining: false, sysroot: "/")
3737
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
3838
; CHECK-NEXT: !2 = !{!3, !11}
3939
; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "EnumTest", scope: !4, file: !1, baseType: !6, size: 64, elements: !7)
@@ -57,41 +57,42 @@
5757
; CHECK-NEXT: !21 = !DIGlobalVariableExpression(var: !22, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
5858
; CHECK-NEXT: !22 = distinct !DIGlobalVariable(name: "global", scope: !5, file: !1, line: 1, type: !23, isLocal: true, isDefinition: true)
5959
; CHECK-NEXT: !23 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !6)
60-
; CHECK-NEXT: !24 = !{!25, !27}
61-
; CHECK-NEXT: !25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !26, file: !1, line: 42)
60+
; CHECK-NEXT: !24 = !{!25, !28}
61+
; CHECK-NEXT: !25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !26, file: !27, line: 42)
6262
; CHECK-NEXT: !26 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
63-
; CHECK-NEXT: !27 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !25, file: !1, line: 42)
64-
; CHECK-NEXT: !28 = !{!29}
65-
; CHECK-NEXT: !29 = !DIMacroFile(file: !1, nodes: !30)
66-
; CHECK-NEXT: !30 = !{!31, !32}
67-
; CHECK-NEXT: !31 = !DIMacro(type: DW_MACINFO_define, name: "SIMPLE_DEFINE")
68-
; CHECK-NEXT: !32 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
69-
; CHECK-NEXT: !33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 192, dwarfAddressSpace: 0)
70-
; 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")
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: !42, rank: !DIExpression())
76-
; CHECK-NEXT: !40 = !{!41}
77-
; CHECK-NEXT: !41 = !DISubrange(count: 10, lowerBound: 0)
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)
63+
; CHECK-NEXT: !27 = !DIFile(filename: "debuginfo.c", directory: ".", checksumkind: CSK_MD5, checksum: "1234", source: "source")
64+
; CHECK-NEXT: !28 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !25, file: !1, line: 42)
65+
; CHECK-NEXT: !29 = !{!30}
66+
; CHECK-NEXT: !30 = !DIMacroFile(file: !1, nodes: !31)
67+
; CHECK-NEXT: !31 = !{!32, !33}
68+
; CHECK-NEXT: !32 = !DIMacro(type: DW_MACINFO_define, name: "SIMPLE_DEFINE")
69+
; CHECK-NEXT: !33 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
70+
; CHECK-NEXT: !34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !35, size: 192, dwarfAddressSpace: 0)
71+
; CHECK-NEXT: !35 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !4, file: !1, size: 192, elements: !36, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
72+
; CHECK-NEXT: !36 = !{!6, !6, !6}
73+
; CHECK-NEXT: !37 = !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)
74+
; CHECK-NEXT: !38 = !DIDerivedType(tag: DW_TAG_set_type, name: "enumset", scope: !1, file: !1, line: 42, baseType: !3, size: 64)
75+
; CHECK-NEXT: !39 = !DIDerivedType(tag: DW_TAG_set_type, name: "subrangeset", scope: !1, file: !1, line: 42, baseType: !37, size: 64)
76+
; CHECK-NEXT: !40 = !DICompositeType(tag: DW_TAG_array_type, name: "foo", scope: !1, file: !1, line: 42, baseType: !6, size: 640, elements: !41, dataLocation: !DIExpression(), associated: !43, rank: !DIExpression())
77+
; CHECK-NEXT: !41 = !{!42}
78+
; CHECK-NEXT: !42 = !DISubrange(count: 10, lowerBound: 0)
79+
; CHECK-NEXT: !43 = !DILocalVariable(name: "d", scope: !44, file: !1, line: 43, type: !6)
80+
; CHECK-NEXT: !44 = distinct !DILexicalBlock(scope: !45, file: !1, line: 42)
81+
; CHECK-NEXT: !45 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !46, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !49)
82+
; CHECK-NEXT: !46 = !DISubroutineType(types: !47)
83+
; CHECK-NEXT: !47 = !{!6, !6, !48}
84+
; CHECK-NEXT: !48 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !41)
85+
; CHECK-NEXT: !49 = !{!50, !51, !52, !43, !53, !54}
86+
; CHECK-NEXT: !50 = !DILocalVariable(name: "a", arg: 1, scope: !45, file: !1, line: 42, type: !6)
87+
; CHECK-NEXT: !51 = !DILocalVariable(name: "b", arg: 2, scope: !45, file: !1, line: 42, type: !6)
88+
; CHECK-NEXT: !52 = !DILocalVariable(name: "c", arg: 3, scope: !45, file: !1, line: 42, type: !48)
89+
; CHECK-NEXT: !53 = !DILocalVariable(name: "e", scope: !44, file: !1, line: 44, type: !6)
90+
; CHECK-NEXT: !54 = !DILabel(scope: !45, name: "label3", file: !1, line: 42)
91+
; CHECK-NEXT: !55 = !DICompositeType(tag: DW_TAG_class_type, name: "Class", scope: !4, file: !1, size: 192, flags: DIFlagFwdDecl, elements: !56, identifier: "FooClass")
92+
; CHECK-NEXT: !56 = !{!57}
93+
; CHECK-NEXT: !57 = !{!6, !6, !58}
94+
; CHECK-NEXT: !58 = !DIBasicType(name: "Int32", size: 32)
95+
; CHECK-NEXT: !59 = !DILocation(line: 42, scope: !45)
96+
; CHECK-NEXT: !60 = !DILabel(scope: !45, name: "label1", file: !1, line: 42)
97+
; CHECK-NEXT: !61 = !DILabel(scope: !45, name: "label2", file: !1, line: 42)
98+
; CHECK-NEXT: !62 = !DILocation(line: 43, scope: !45)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ int llvm_test_dibuilder(void) {
4343
LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename,
4444
strlen(Filename), ".", 1);
4545

46+
LLVMMetadataRef FileCS = LLVMDIBuilderCreateFileWithChecksum(
47+
DIB, Filename, strlen(Filename), ".", 1, CSK_MD5, "1234", 4, "source", 6);
48+
4649
LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(
4750
DIB, LLVMDWARFSourceLanguageC, File, "llvm-c-test", 11, 0, NULL, 0, 0,
4851
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0, "/", 1, "", 0);
@@ -61,7 +64,7 @@ int llvm_test_dibuilder(void) {
6164
"/test/include/llvm-c-test-import.h", 34,
6265
"", 0);
6366
LLVMMetadataRef ImportedModule = LLVMDIBuilderCreateImportedModuleFromModule(
64-
DIB, Module, OtherModule, File, 42, NULL, 0);
67+
DIB, Module, OtherModule, FileCS, 42, NULL, 0);
6568
LLVMDIBuilderCreateImportedModuleFromAlias(DIB, Module, ImportedModule, File,
6669
42, NULL, 0);
6770

0 commit comments

Comments
 (0)