summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2018-01-11 22:03:43 +0000
committerPaul Robinson <paul.robinson@sony.com>2018-01-11 22:03:43 +0000
commitcc9c8b95bdb05c36168e50832ead45a895b0b045 (patch)
tree6ab168be838cd54a77a228e48f88e0bfb7e89d47
parent08abcac9dc0fada5af47e7001732ddd9e4de7f9c (diff)
downloadbcm5719-llvm-cc9c8b95bdb05c36168e50832ead45a895b0b045.tar.gz
bcm5719-llvm-cc9c8b95bdb05c36168e50832ead45a895b0b045.zip
Tighten up DIFile verifier for checksums
Differential Revision: https://reviews.llvm.org/D41965 llvm-svn: 322314
-rw-r--r--llvm/lib/IR/Verifier.cpp20
-rw-r--r--llvm/test/MC/AArch64/coff-debug.ll6
-rw-r--r--llvm/test/Verifier/DIFile.ll30
3 files changed, 51 insertions, 5 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 89af3db34c0..b83201f982f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -55,6 +55,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
@@ -967,8 +968,23 @@ void Verifier::visitDISubroutineType(const DISubroutineType &N) {
void Verifier::visitDIFile(const DIFile &N) {
AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N);
- AssertDI((N.getChecksumKind() != DIFile::CSK_None ||
- N.getChecksum().empty()), "invalid checksum kind", &N);
+ AssertDI(N.getChecksumKind() <= DIFile::CSK_Last, "invalid checksum kind",
+ &N);
+ size_t Size;
+ switch (N.getChecksumKind()) {
+ case DIFile::CSK_None:
+ Size = 0;
+ break;
+ case DIFile::CSK_MD5:
+ Size = 32;
+ break;
+ case DIFile::CSK_SHA1:
+ Size = 40;
+ break;
+ }
+ AssertDI(N.getChecksum().size() == Size, "invalid checksum length", &N);
+ AssertDI(N.getChecksum().find_if_not(llvm::isHexDigit) == StringRef::npos,
+ "invalid checksum", &N);
}
void Verifier::visitDICompileUnit(const DICompileUnit &N) {
diff --git a/llvm/test/MC/AArch64/coff-debug.ll b/llvm/test/MC/AArch64/coff-debug.ll
index 6c814e8fd37..ec2fcc4f55f 100644
--- a/llvm/test/MC/AArch64/coff-debug.ll
+++ b/llvm/test/MC/AArch64/coff-debug.ll
@@ -21,7 +21,7 @@ attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-ma
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
-!1 = !DIFile(filename: "a.c", directory: "/", checksumkind: CSK_MD5, checksum: "")
+!1 = !DIFile(filename: "a.c", directory: "/", checksumkind: CSK_MD5, checksum: "12345678901234567890123456789012")
!2 = !{}
!3 = !{i32 2, !"CodeView", i32 1}
!4 = !{i32 2, !"Debug Info Version", i32 3}
@@ -102,9 +102,9 @@ attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-ma
; CHECK: Subsection [
; CHECK: SubSectionType: FileChecksums (0xF4)
; CHECK: FileChecksum {
-; CHECK: ChecksumSize: 0x0
+; CHECK: ChecksumSize: 0x10
; CHECK: ChecksumKind: MD5 (0x1)
-; CHECK: ChecksumBytes: ()
+; CHECK: ChecksumBytes: (12 34 56 78 90 12 34 56 78 90 12 34 56 78 90 12)
; CHECK: }
; CHECK: ]
; CHECK: Subsection [
diff --git a/llvm/test/Verifier/DIFile.ll b/llvm/test/Verifier/DIFile.ll
new file mode 100644
index 00000000000..652be7f83db
--- /dev/null
+++ b/llvm/test/Verifier/DIFile.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-as -disable-output < %s 2>&1 | FileCheck %s
+
+; The lengths for None and MD5 are wrong; SHA1 has a non-hex digit.
+; CHECK: invalid checksum length
+; CHECK: invalid checksum{{$}}
+; CHECK: invalid checksum length
+; CHECK: warning: ignoring invalid debug info in <stdin>
+
+@t1 = global i32 1, align 4, !dbg !0
+@t2 = global i32 0, align 4, !dbg !6
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "t1", scope: !2, file: !10, line: 1, type: !9, isLocal: false, isDefinition: true)
+!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)
+!3 = !DIFile(filename: "t.c", directory: "/scratch", checksumkind: CSK_None, checksum: "00")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)
+!8 = !DIFile(filename: "./t2.h", directory: "/scratch", checksumkind: CSK_MD5, checksum: "2222")
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !DIFile(filename: "./t1.h", directory: "/scratch", checksumkind: CSK_SHA1, checksum: "123456789012345678901234567890123456789.")
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{i32 1, !"wchar_size", i32 4}
+!14 = !{!"clang version 7.0.0 (trunk 322159)"}
OpenPOWER on IntegriCloud