]> granicus.if.org Git - llvm/commitdiff
Add a Verifier check for DILocation's scopes.
authorAdrian Prantl <aprantl@apple.com>
Wed, 23 Aug 2017 21:52:24 +0000 (21:52 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 23 Aug 2017 21:52:24 +0000 (21:52 +0000)
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

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

index c4ae3bb0a4b7722caee0f6c33aad822e495baf4f..7697b3d59b5d9c659b7a5ca056d8c04f4fd32461 100644 (file)
@@ -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<DILocation>(IA), "inlined-at should be a location", &N, IA);
+  if (auto *SP = dyn_cast<DISubprogram>(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<DILocalScope>(N.getRawScope()),
            "invalid local scope", &N, N.getRawScope());
+  if (auto *SP = dyn_cast<DISubprogram>(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 (file)
index 0000000..810d0f6
--- /dev/null
@@ -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)