From: Adrian Prantl Date: Wed, 23 Aug 2017 21:52:24 +0000 (+0000) Subject: Add a Verifier check for DILocation's scopes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2224c91e599dfd2d5a9bfd10520d5c3a1a0a817;p=llvm Add a Verifier check for DILocation's scopes. Found via https://bugs.llvm.org/show_bug.cgi?id=33997. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311608 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index c4ae3bb0a4b..7697b3d59b5 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -839,6 +839,8 @@ void Verifier::visitDILocation(const DILocation &N) { "location requires a valid scope", &N, N.getRawScope()); if (auto *IA = N.getRawInlinedAt()) AssertDI(isa(IA), "inlined-at should be a location", &N, IA); + if (auto *SP = dyn_cast(N.getRawScope())) + AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N); } void Verifier::visitGenericDINode(const GenericDINode &N) { @@ -1067,6 +1069,8 @@ void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { AssertDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N); AssertDI(N.getRawScope() && isa(N.getRawScope()), "invalid local scope", &N, N.getRawScope()); + if (auto *SP = dyn_cast(N.getRawScope())) + AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N); } void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { diff --git a/test/Verifier/DILocation-parents.ll b/test/Verifier/DILocation-parents.ll new file mode 100644 index 00000000000..810d0f64c58 --- /dev/null +++ b/test/Verifier/DILocation-parents.ll @@ -0,0 +1,34 @@ +; RUN: not llvm-as %s -o - 2>&1 | FileCheck %s +source_filename = "t.c" +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.12.0" + +define void @f() !dbg !4 { +entry: +; CHECK: scope points into the type hierarchy +; CHECK: DILocation + ret void, !dbg !7 +} + +define void @g() !dbg !8 { +entry: +; CHECK: scope points into the type hierarchy +; CHECK: DILexicalBlockFile + ret void, !dbg !9 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug) +!1 = !DIFile(filename: "t.c", directory: "/tmp") +!2 = !{i32 2, !"Dwarf Version", i32 4} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !5, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, unit: !0) +!5 = !DISubroutineType(types: !{}) +!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !5, isDefinition: false, scopeLine: 2) +!7 = !DILocation(line: 2, scope: !6) +!8 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 2, type: !5, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, unit: !0) +!9 = !DILocation(line: 2, scope: !10, inlinedAt: !11) +!10 = !DILexicalBlockFile(scope: !6, file: !2, discriminator: 0) +!11 = !DILocation(line: 2, scope: !8)