[llvm] ced1250 - MIRParser: Fix asserting with invalid flags on machine operands

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 18:46:30 PDT 2022


Author: Matt Arsenault
Date: 2022-04-05T21:46:26-04:00
New Revision: ced1250b0f458c3dfeecb8157dd4838d87c8288d

URL: https://github.com/llvm/llvm-project/commit/ced1250b0f458c3dfeecb8157dd4838d87c8288d
DIFF: https://github.com/llvm/llvm-project/commit/ced1250b0f458c3dfeecb8157dd4838d87c8288d.diff

LOG: MIRParser: Fix asserting with invalid flags on machine operands

Constructing an operand with kills on defs and deads on uses asserts
in the constructor, so diagnose these.

Added: 
    llvm/test/CodeGen/MIR/AMDGPU/dead-flag-on-use-operand-parse-error.mir
    llvm/test/CodeGen/MIR/AMDGPU/killed-flag-on-def-parse-error.mir

Modified: 
    llvm/lib/CodeGen/MIRParser/MIParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index d3835d21570c5..52ba26098600a 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -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
index 0000000000000..ae4093f849720
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AMDGPU/dead-flag-on-use-operand-parse-error.mir
@@ -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
index 0000000000000..2b082cd53fe44
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AMDGPU/killed-flag-on-def-parse-error.mir
@@ -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
+
+...


        


More information about the llvm-commits mailing list