MIRParser: Check that instructions only reference DILocation metadata
authorMatthias Braun <matze@braunis.de>
Mon, 1 Oct 2018 17:50:52 +0000 (17:50 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 1 Oct 2018 17:50:52 +0000 (17:50 +0000)
llvm-svn: 343505

llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/test/CodeGen/MIR/X86/invalid-debug-location.mir [new file with mode: 0644]

index 5c6a41a..da758da 100644 (file)
@@ -779,6 +779,8 @@ bool MIParser::parse(MachineInstr *&MI) {
     MDNode *Node = nullptr;
     if (parseMDNode(Node))
       return true;
+    if (!isa<DILocation>(Node))
+      return error("referenced metadata is not a DILocation");
     DebugLocation = DebugLoc(Node);
   }
 
diff --git a/llvm/test/CodeGen/MIR/X86/invalid-debug-location.mir b/llvm/test/CodeGen/MIR/X86/invalid-debug-location.mir
new file mode 100644 (file)
index 0000000..60f718e
--- /dev/null
@@ -0,0 +1,15 @@
+# RUN: not llc -o - %s -run-pass=none 2>&1 | FileCheck %s
+--- |
+  target triple="x86_64--"
+  define void @func() {
+    unreachable
+  }
+  !0 = !{}
+...
+---
+name: func
+body: |
+  bb.0:
+    ; CHECK: [[@LINE+1]]:27: referenced metadata is not a DILocation
+    NOOP debug-location !0
+...