MIRParser: Fix asserting with invalid flags on machine operands
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Mon, 28 Mar 2022 13:36:47 +0000 (09:36 -0400)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Wed, 6 Apr 2022 01:46:26 +0000 (21:46 -0400)
Constructing an operand with kills on defs and deads on uses asserts
in the constructor, so diagnose these.

llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/test/CodeGen/MIR/AMDGPU/dead-flag-on-use-operand-parse-error.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/AMDGPU/killed-flag-on-def-parse-error.mir [new file with mode: 0644]

index d3835d2..52ba260 100644 (file)
@@ -1723,6 +1723,15 @@ bool MIParser::parseRegisterOperand(MachineOperand &Dest,
         RegInfo->Kind == VRegInfo::REGBANK)
       return error("generic virtual registers must have a type");
   }
+
+  if (Flags & RegState::Define) {
+    if (Flags & RegState::Kill)
+      return error("cannot have a killed def operand");
+  } else {
+    if (Flags & RegState::Dead)
+      return error("cannot have a dead use operand");
+  }
+
   Dest = MachineOperand::CreateReg(
       Reg, Flags & RegState::Define, Flags & RegState::Implicit,
       Flags & RegState::Kill, Flags & RegState::Dead, Flags & RegState::Undef,
diff --git a/llvm/test/CodeGen/MIR/AMDGPU/dead-flag-on-use-operand-parse-error.mir b/llvm/test/CodeGen/MIR/AMDGPU/dead-flag-on-use-operand-parse-error.mir
new file mode 100644 (file)
index 0000000..ae4093f
--- /dev/null
@@ -0,0 +1,12 @@
+# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -run-pass=none %s -o /dev/null 2>&1 | FileCheck %s
+---
+name:            foo
+tracksRegLiveness: true
+body:             |
+  bb.0:
+
+    %0:sgpr_32 = S_MOV_B32 0
+    ; CHECK: [[@LINE+1]]:24: cannot have a dead use operand
+    S_ENDPGM 0, dead %0
+
+...
diff --git a/llvm/test/CodeGen/MIR/AMDGPU/killed-flag-on-def-parse-error.mir b/llvm/test/CodeGen/MIR/AMDGPU/killed-flag-on-def-parse-error.mir
new file mode 100644 (file)
index 0000000..2b082cd
--- /dev/null
@@ -0,0 +1,12 @@
+# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -run-pass=none %s -o /dev/null 2>&1 | FileCheck %s
+---
+name:            foo
+tracksRegLiveness: true
+body:             |
+  bb.0:
+
+    ; CHECK: [[@LINE+1]]:23: cannot have a killed def operand
+    killed %0:sgpr_32 = S_MOV_B32 0
+    S_ENDPGM 0
+
+...