MIR Parser: report an error when a basic block isn't found.
authorAlex Lorenz <arphaman@gmail.com>
Fri, 19 Jun 2015 20:12:03 +0000 (20:12 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 19 Jun 2015 20:12:03 +0000 (20:12 +0000)
This commit reports an error when the MIR parser can't find
a basic block with the machine basic block's name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240174 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MIRParser/MIRParser.cpp
test/CodeGen/MIR/machine-basic-block-unknown-name.mir [new file with mode: 0644]

index 20d7f815655f77200a7b6eb461e5db2f117a0d70..1fef3f6dcb3465a0b76844baf8ce3c4688340dc1 100644 (file)
@@ -212,7 +212,9 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
     if (!YamlMBB.Name.empty()) {
       BB = dyn_cast_or_null<BasicBlock>(
           F.getValueSymbolTable().lookup(YamlMBB.Name));
-      // TODO: Report an error if a basic block isn't found.
+      if (!BB)
+        return error(Twine("basic block '") + YamlMBB.Name +
+                     "' is not defined in the function '" + MF.getName() + "'");
     }
     auto *MBB = MF.CreateMachineBasicBlock(BB);
     MF.insert(MF.end(), MBB);
diff --git a/test/CodeGen/MIR/machine-basic-block-unknown-name.mir b/test/CodeGen/MIR/machine-basic-block-unknown-name.mir
new file mode 100644 (file)
index 0000000..4c363c6
--- /dev/null
@@ -0,0 +1,18 @@
+# RUN: not llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that an error is reported whenever the MIR parser can't find
+# a basic block with the machine basis block's name.
+
+--- |
+
+  define i32 @foo() {
+  entry:
+    ret i32 0
+  }
+
+...
+---
+name:            foo
+body:
+  # CHECK: basic block 'entrie' is not defined in the function 'foo'
+  - name:         entrie
+...