From 26053818a32a75b451c800109b15dfd2a415d446 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 25 Aug 2017 22:08:15 +0000 Subject: [PATCH] [Verifier] Diagnose invalid DIType references instead of crashing. Fixes PR34325. llvm-svn: 311805 --- llvm/lib/IR/Verifier.cpp | 1 + llvm/test/Verifier/pr34325.ll | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 llvm/test/Verifier/pr34325.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 0cd6dbb0664a..e28644a081cd 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -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(Member), diff --git a/llvm/test/Verifier/pr34325.ll b/llvm/test/Verifier/pr34325.ll new file mode 100644 index 000000000000..5b21f67fa5dd --- /dev/null +++ b/llvm/test/Verifier/pr34325.ll @@ -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}