Skip to content

Commit cc9c8b9

Browse files
committed
Tighten up DIFile verifier for checksums
Differential Revision: https://reviews.llvm.org/D41965 llvm-svn: 322314
1 parent 08abcac commit cc9c8b9

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "llvm/ADT/SmallPtrSet.h"
5656
#include "llvm/ADT/SmallSet.h"
5757
#include "llvm/ADT/SmallVector.h"
58+
#include "llvm/ADT/StringExtras.h"
5859
#include "llvm/ADT/StringMap.h"
5960
#include "llvm/ADT/StringRef.h"
6061
#include "llvm/ADT/Twine.h"
@@ -967,8 +968,23 @@ void Verifier::visitDISubroutineType(const DISubroutineType &N) {
967968

968969
void Verifier::visitDIFile(const DIFile &N) {
969970
AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N);
970-
AssertDI((N.getChecksumKind() != DIFile::CSK_None ||
971-
N.getChecksum().empty()), "invalid checksum kind", &N);
971+
AssertDI(N.getChecksumKind() <= DIFile::CSK_Last, "invalid checksum kind",
972+
&N);
973+
size_t Size;
974+
switch (N.getChecksumKind()) {
975+
case DIFile::CSK_None:
976+
Size = 0;
977+
break;
978+
case DIFile::CSK_MD5:
979+
Size = 32;
980+
break;
981+
case DIFile::CSK_SHA1:
982+
Size = 40;
983+
break;
984+
}
985+
AssertDI(N.getChecksum().size() == Size, "invalid checksum length", &N);
986+
AssertDI(N.getChecksum().find_if_not(llvm::isHexDigit) == StringRef::npos,
987+
"invalid checksum", &N);
972988
}
973989

974990
void Verifier::visitDICompileUnit(const DICompileUnit &N) {

llvm/test/MC/AArch64/coff-debug.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-ma
2121
!llvm.ident = !{!6}
2222

2323
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
24-
!1 = !DIFile(filename: "a.c", directory: "/", checksumkind: CSK_MD5, checksum: "")
24+
!1 = !DIFile(filename: "a.c", directory: "/", checksumkind: CSK_MD5, checksum: "12345678901234567890123456789012")
2525
!2 = !{}
2626
!3 = !{i32 2, !"CodeView", i32 1}
2727
!4 = !{i32 2, !"Debug Info Version", i32 3}
@@ -102,9 +102,9 @@ attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-ma
102102
; CHECK: Subsection [
103103
; CHECK: SubSectionType: FileChecksums (0xF4)
104104
; CHECK: FileChecksum {
105-
; CHECK: ChecksumSize: 0x0
105+
; CHECK: ChecksumSize: 0x10
106106
; CHECK: ChecksumKind: MD5 (0x1)
107-
; CHECK: ChecksumBytes: ()
107+
; CHECK: ChecksumBytes: (12 34 56 78 90 12 34 56 78 90 12 34 56 78 90 12)
108108
; CHECK: }
109109
; CHECK: ]
110110
; CHECK: Subsection [

llvm/test/Verifier/DIFile.ll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llvm-as -disable-output < %s 2>&1 | FileCheck %s
2+
3+
; The lengths for None and MD5 are wrong; SHA1 has a non-hex digit.
4+
; CHECK: invalid checksum length
5+
; CHECK: invalid checksum{{$}}
6+
; CHECK: invalid checksum length
7+
; CHECK: warning: ignoring invalid debug info in <stdin>
8+
9+
@t1 = global i32 1, align 4, !dbg !0
10+
@t2 = global i32 0, align 4, !dbg !6
11+
12+
!llvm.dbg.cu = !{!2}
13+
!llvm.module.flags = !{!11, !12, !13}
14+
!llvm.ident = !{!14}
15+
16+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
17+
!1 = distinct !DIGlobalVariable(name: "t1", scope: !2, file: !10, line: 1, type: !9, isLocal: false, isDefinition: true)
18+
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 322159)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
19+
!3 = !DIFile(filename: "t.c", directory: "/scratch", checksumkind: CSK_None, checksum: "00")
20+
!4 = !{}
21+
!5 = !{!0, !6}
22+
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
23+
!7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)
24+
!8 = !DIFile(filename: "./t2.h", directory: "/scratch", checksumkind: CSK_MD5, checksum: "2222")
25+
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
26+
!10 = !DIFile(filename: "./t1.h", directory: "/scratch", checksumkind: CSK_SHA1, checksum: "123456789012345678901234567890123456789.")
27+
!11 = !{i32 2, !"Dwarf Version", i32 4}
28+
!12 = !{i32 2, !"Debug Info Version", i32 3}
29+
!13 = !{i32 1, !"wchar_size", i32 4}
30+
!14 = !{!"clang version 7.0.0 (trunk 322159)"}

0 commit comments

Comments
 (0)