From bf1fdb852f936ca7c8493c063d6f14ae552fb86f Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Mon, 7 Jan 2019 23:09:09 +0000 Subject: [PATCH] [Verifier] Reject invalid type for DILocalVariable. Reviewers: aprantl Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D56414 llvm-svn: 350578 --- llvm/lib/IR/Verifier.cpp | 2 + llvm/test/DebugInfo/Generic/varargs.ll | 2 +- llvm/test/Verifier/di-subroutine-localvar.ll | 42 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Verifier/di-subroutine-localvar.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 60ff0adb8f41..30e77b92009f 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1241,6 +1241,8 @@ void Verifier::visitDILocalVariable(const DILocalVariable &N) { AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); AssertDI(N.getRawScope() && isa(N.getRawScope()), "local variable requires a valid scope", &N, N.getRawScope()); + if (auto Ty = N.getType()) + AssertDI(!isa(Ty), "invalid type", &N, N.getType()); } void Verifier::visitDILabel(const DILabel &N) { diff --git a/llvm/test/DebugInfo/Generic/varargs.ll b/llvm/test/DebugInfo/Generic/varargs.ll index 96ad9c02ba9c..c8193c05e944 100644 --- a/llvm/test/DebugInfo/Generic/varargs.ll +++ b/llvm/test/DebugInfo/Generic/varargs.ll @@ -95,7 +95,7 @@ attributes #1 = { nounwind readnone } !23 = !DILocalVariable(name: "a", line: 16, scope: !14, file: !15, type: !4) !24 = !DILocation(line: 16, scope: !14) ; Manually modifed to avoid dependence on pointer size -!25 = !DILocalVariable(name: "fptr", line: 18, scope: !14, file: !15, type: !16) +!25 = !DILocalVariable(name: "fptr", line: 18, scope: !14, file: !15, type: !26) !26 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !16) !27 = !DILocation(line: 18, scope: !14) !28 = !DILocation(line: 22, scope: !14) diff --git a/llvm/test/Verifier/di-subroutine-localvar.ll b/llvm/test/Verifier/di-subroutine-localvar.ll new file mode 100644 index 000000000000..477e63362127 --- /dev/null +++ b/llvm/test/Verifier/di-subroutine-localvar.ll @@ -0,0 +1,42 @@ +; RUN: opt %s -verify 2>&1 | FileCheck %s +; CHECK: invalid type +; CHECK: !20 = !DILocalVariable(name: "f", scope: !21, file: !13, line: 970, type: !14) +; CHECK: !14 = !DISubroutineType(types: !15) + + +%timespec.0.1.2.3.0.1.2 = type { i64, i64 } +define internal i64 @init_vdso_clock_gettime(i32, %timespec.0.1.2.3.0.1.2* nonnull) unnamed_addr !dbg !142 { + call void @llvm.dbg.value(metadata i64 (i32, %timespec.0.1.2.3.0.1.2*)* null, metadata !162, metadata !DIExpression()), !dbg !167 + ret i64 -38, !dbg !168 +} +declare void @llvm.dbg.value(metadata, metadata, metadata) #0 +!llvm.module.flags = !{!0} +!llvm.dbg.cu = !{!1} +!0 = !{i32 2, !"Debug Info Version", i32 3} +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "zig 0.3.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !76) +!2 = !DIFile(filename: "test", directory: ".") +!3 = !{!4} +!4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Arch", scope: !5, file: !5, line: 44, baseType: !6, size: 8, align: 8, elements: !7) +!5 = !DIFile(filename: "builtin.zig", directory: "/home/andy/.local/share/zig/stage1/builtin/ugMGxVES9OkDAffv3xhJS3KQVy0Wm1xPM3Bc6x4MBuup5aetdi5pVTrGRG2aDAn0") +!6 = !DIBasicType(name: "u7", size: 8, encoding: DW_ATE_unsigned) +!7 = !{!8} +!8 = !DIEnumerator(name: "armv8_5a", value: 0) +!76 = !{!77} +!77 = !DIGlobalVariableExpression(var: !78, expr: !DIExpression()) +!78 = distinct !DIGlobalVariable(name: "arch", linkageName: "arch", scope: !5, file: !5, line: 437, type: !4, isLocal: true, isDefinition: true) +!81 = !DIFile(filename: "index.zig", directory: "/store/dev/zig/build-llvm8-debug/lib/zig/std/os/linux") +!142 = distinct !DISubprogram(name: "init_vdso_clock_gettime", scope: !81, file: !81, line: 968, type: !143, scopeLine: 968, flags: DIFlagStaticMember, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !153) +!143 = !DISubroutineType(types: !144) +!144 = !{!145} +!145 = !DIBasicType(name: "usize", size: 64, encoding: DW_ATE_unsigned) +!146 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) +!153 = !{!154} +!154 = !DILocalVariable(name: "clk", arg: 1, scope: !142, file: !81, line: 968, type: !146) +!162 = !DILocalVariable(name: "f", scope: !163, file: !81, line: 970, type: !143) +!163 = distinct !DILexicalBlock(scope: !164, file: !81, line: 969, column: 5) +!164 = distinct !DILexicalBlock(scope: !165, file: !81, line: 968, column: 66) +!165 = distinct !DILexicalBlock(scope: !166, file: !81, line: 968, column: 45) +!166 = distinct !DILexicalBlock(scope: !142, file: !81, line: 968, column: 35) +!167 = !DILocation(line: 970, column: 5, scope: !163) +!168 = !DILocation(line: 972, column: 28, scope: !169) +!169 = distinct !DILexicalBlock(scope: !163, file: !81, line: 970, column: 5)