[IRVerifier] Don't crash on invalid DIFile inside DISubprogram.
authorDavide Italiano <davide@freebsd.org>
Wed, 6 Apr 2016 18:46:39 +0000 (18:46 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 6 Apr 2016 18:46:39 +0000 (18:46 +0000)
r265515, this time with the correct fix. file inside DISubprogram is not
mandatory.

llvm-svn: 265586

llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/dbg-difile-crash.ll [new file with mode: 0644]

index fad4aac..212e2bf 100644 (file)
@@ -988,6 +988,8 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) {
 void Verifier::visitDISubprogram(const DISubprogram &N) {
   Assert(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N);
   Assert(isScopeRef(N, N.getRawScope()), "invalid scope", &N, N.getRawScope());
+  if (auto *F = N.getRawFile())
+    Assert(isa<DIFile>(F), "invalid file", &N, F);
   if (auto *T = N.getRawType())
     Assert(isa<DISubroutineType>(T), "invalid subroutine type", &N, T);
   Assert(isTypeRef(N, N.getRawContainingType()), "invalid containing type", &N,
diff --git a/llvm/test/Verifier/dbg-difile-crash.ll b/llvm/test/Verifier/dbg-difile-crash.ll
new file mode 100644 (file)
index 0000000..75ec889
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
+; CHECK:      assembly parsed, but does not verify
+; CHECK-NEXT: invalid file
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!llvm.dbg.cu = !{!1}
+!1 = distinct !DICompileUnit(file: !2, language: DW_LANG_C99, subprograms: !{!3})
+!2 = !DIFile(filename: "file.c", directory: "/path/to/dir")
+!3 = distinct !DISubprogram(name: "blah", file: !1)