[llvm] r311608 - Add a Verifier check for DILocation's scopes.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 14:52:24 PDT 2017


Author: adrian
Date: Wed Aug 23 14:52:24 2017
New Revision: 311608

URL: http://llvm.org/viewvc/llvm-project?rev=311608&view=rev
Log:
Add a Verifier check for DILocation's scopes.

Found via https://bugs.llvm.org/show_bug.cgi?id=33997.

Added:
    llvm/trunk/test/Verifier/DILocation-parents.ll
Modified:
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=311608&r1=311607&r2=311608&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Wed Aug 23 14:52:24 2017
@@ -839,6 +839,8 @@ void Verifier::visitDILocation(const DIL
            "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(c
   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) {

Added: llvm/trunk/test/Verifier/DILocation-parents.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/DILocation-parents.ll?rev=311608&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/DILocation-parents.ll (added)
+++ llvm/trunk/test/Verifier/DILocation-parents.ll Wed Aug 23 14:52:24 2017
@@ -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)




More information about the llvm-commits mailing list