]> granicus.if.org Git - llvm/commitdiff
[Verifier] Diagnose invalid DIType references instead of crashing.
authorDavide Italiano <davide@freebsd.org>
Fri, 25 Aug 2017 22:08:15 +0000 (22:08 +0000)
committerDavide Italiano <davide@freebsd.org>
Fri, 25 Aug 2017 22:08:15 +0000 (22:08 +0000)
Fixes PR34325.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311805 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Verifier.cpp
test/Verifier/pr34325.ll [new file with mode: 0644]

index 0cd6dbb0664a99522fb0ea6877c2134244226e34..e28644a081cdac717e233993e3a1a04ce40c3902 100644 (file)
@@ -1154,6 +1154,7 @@ void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) {
 
   AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
   AssertDI(!N.getName().empty(), "missing global variable name", &N);
+  AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
   AssertDI(N.getType(), "missing global variable type", &N);
   if (auto *Member = N.getRawStaticDataMemberDeclaration()) {
     AssertDI(isa<DIDerivedType>(Member),
diff --git a/test/Verifier/pr34325.ll b/test/Verifier/pr34325.ll
new file mode 100644 (file)
index 0000000..5b21f67
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: not opt -verify %s 2>&1 | FileCheck %s
+
+; CHECK: invalid type ref
+
+@bar = global i64 0, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!8}
+
+!0 = !DIGlobalVariableExpression(var: !1)
+!1 = !DIGlobalVariable(name: "c", scope: null, isLocal: false, isDefinition: true, type: !6)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, retainedTypes: !4, globals: !7)
+!3 = !DIFile(filename: "a", directory: "")
+!4 = !{!5}
+!5 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !6, file: !3, identifier: "patatino")
+!6 = distinct !DISubprogram(name: "b", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !2)
+!7 = !{!0}
+!8 = !{i32 2, !"Debug Info Version", i32 3}