OSDN Git Service

[IRVerifier] Avoid crashing on an invalid compile unit.
authorDavide Italiano <davide@freebsd.org>
Wed, 6 Apr 2016 03:07:58 +0000 (03:07 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 6 Apr 2016 03:07:58 +0000 (03:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265514 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Verifier.cpp
test/Verifier/dbg-invalid-compileunit.ll [new file with mode: 0644]

index 5770d6c..fe3d6eb 100644 (file)
@@ -4376,13 +4376,14 @@ void Verifier::verifyTypeRefs() {
   // Visit all the compile units again to map the type references.
   SmallDenseMap<const MDString *, const DIType *, 32> TypeRefs;
   for (auto *CU : CUs->operands())
-    if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
-      for (DIType *Op : Ts)
-        if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
-          if (auto *S = T->getRawIdentifier()) {
-            UnresolvedTypeRefs.erase(S);
-            TypeRefs.insert(std::make_pair(S, T));
-          }
+    if (isa<DICompileUnit>(CU))
+      if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
+        for (DIType *Op : Ts)
+          if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
+            if (auto *S = T->getRawIdentifier()) {
+              UnresolvedTypeRefs.erase(S);
+              TypeRefs.insert(std::make_pair(S, T));
+            }
 
   // Verify debug info intrinsic bit piece expressions.  This needs a second
   // pass through the intructions, since we haven't built TypeRefs yet when
diff --git a/test/Verifier/dbg-invalid-compileunit.ll b/test/Verifier/dbg-invalid-compileunit.ll
new file mode 100644 (file)
index 0000000..8f8a3d9
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
+; CHECK:      assembly parsed, but does not verify
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!1}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = !DIFile(filename: "davide.f", directory: "")