MIR Parser: Report an error when parsing machine function with an empty body.
authorAlex Lorenz <arphaman@gmail.com>
Thu, 9 Jul 2015 21:21:33 +0000 (21:21 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 9 Jul 2015 21:21:33 +0000 (21:21 +0000)
This commit adds a new error which is reported when the MIR Parser encounters
a machine function without any machine basic blocks. The machine verifier
expects that the machine functions have at least one MBB, and this error will
prevent machine functions without MBBs from reaching the machine verifier and
crashing with an assertion.

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

lib/CodeGen/MIRParser/MIRParser.cpp
test/CodeGen/MIR/llvmIR.mir
test/CodeGen/MIR/llvmIRMissing.mir
test/CodeGen/MIR/machine-function-missing-body-error.mir [new file with mode: 0644]
test/CodeGen/MIR/machine-function-missing-function.mir
test/CodeGen/MIR/machine-function-missing-name.mir
test/CodeGen/MIR/machine-function.mir
test/CodeGen/MIR/register-info.mir

index e505ab4baeb3aa1736795382d9918fe2dd48c815..e5ba03222357ae7c53482c1a90e05a0c9637ca92 100644 (file)
@@ -275,6 +275,9 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
                    Twine(YamlMBB.ID));
   }
 
+  if (YamlMF.BasicBlocks.empty())
+    return error(Twine("machine function '") + Twine(MF.getName()) +
+                 "' requires at least one machine basic block in its body");
   // Initialize the machine basic blocks after creating them all so that the
   // machine instructions parser can resolve the MBB references.
   unsigned I = 0;
index 4d7fde240c5b23c8af65e6507ec75b5b299fb849..3c084ad7d393ca1683953276cbf95cf6cbb7a225 100644 (file)
@@ -32,4 +32,6 @@
 ...
 ---
 name: foo
+body:
+  - id: 0
 ...
index 83d846ba44c3fcf190cb38174fbea0261f11305e..80cea5a6fdaa67a4a3097bfe1323429262b205c6 100644 (file)
@@ -4,4 +4,6 @@
 ---
 # CHECK: name: foo
 name: foo
+body:
+  - id: 0
 ...
diff --git a/test/CodeGen/MIR/machine-function-missing-body-error.mir b/test/CodeGen/MIR/machine-function-missing-body-error.mir
new file mode 100644 (file)
index 0000000..0dc7477
--- /dev/null
@@ -0,0 +1,15 @@
+# RUN: not llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that the MIR parser reports an error when it encounters a
+# machine function with an empty body.
+
+--- |
+
+  define i32 @foo() {
+    ret i32 0
+  }
+
+...
+---
+# CHECK: machine function 'foo' requires at least one machine basic block in its body
+name:            foo
+...
index eed4142d65976fc4a77596377a28f73a7455c1db..424c34aae8477114ccbb2dc0d83fdbd0cb23de28 100644 (file)
 ...
 ---
 name:            foo
+body:
+  - id: 0
 ...
 ---
 # CHECK: function 'faa' isn't defined in the provided LLVM IR
 name:            faa
+body:
+  - id: 0
 ...
index b16156e54bd1b2d74848fa03ea9aeb34932224a4..a868a65d35f226488bc0761f401add17ff4a21ce 100644 (file)
 ---
 # CHECK: [[@LINE+1]]:1: missing required key 'name'
 nme:             foo
+body:
+  - id: 0
 ...
 ---
 name:            bar
+body:
+  - id: 0
 ...
index 8f053adc22be0f5b62c0b5f87f4fccae55f114fa..afd10ab02c260787263f050e9597a6262a5f7a98 100644 (file)
@@ -27,6 +27,8 @@
 # CHECK-NEXT: hasInlineAsm: false
 # CHECK: ...
 name:            foo
+body:
+  - id: 0
 ...
 ---
 # CHECK: name: bar
@@ -35,6 +37,8 @@ name:            foo
 # CHECK-NEXT: hasInlineAsm: false
 # CHECK: ...
 name:            bar
+body:
+  - id: 0
 ...
 ---
 # CHECK: name: func
@@ -44,6 +48,8 @@ name:            bar
 # CHECK: ...
 name:            func
 alignment:       8
+body:
+  - id: 0
 ...
 ---
 # CHECK: name: func2
@@ -55,4 +61,6 @@ name:            func2
 alignment:       16
 exposesReturnsTwice: true
 hasInlineAsm:    true
+body:
+  - id: 0
 ...
index c01997b46859bc9b10b023faf19537363a603800..9585faa96223c66e41e9bbbe5c0c7f508dae29e9 100644 (file)
@@ -22,6 +22,8 @@
 # CHECK-NEXT: tracksSubRegLiveness: false
 # CHECK: ...
 name:            foo
+body:
+  - id: 0
 ...
 ---
 # CHECK: name: bar
@@ -33,4 +35,6 @@ name: bar
 isSSA: false
 tracksRegLiveness: true
 tracksSubRegLiveness: true
+body:
+  - id: 0
 ...