[llvm] de56a89 - [AMDGPU] return Fail instead of SolfFail from addOperand()

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 10:37:25 PST 2019


Author: Stanislav Mekhanoshin
Date: 2019-11-05T10:25:27-08:00
New Revision: de56a890725713dffc4ab5bf5fb2f434df27ed4d

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

LOG: [AMDGPU] return Fail instead of SolfFail from addOperand()

addOperand() method of AMDGPU disassembler returns SoftFail
on error. All instances which may lead to that place are
an impossible encdoing, not something which is possible to
encode, but semantically incorrect as described for SoftFail.

Then tablegen generates a check of the following form:

if (Decode...(..) == MCDisassembler::Fail) { return MCDisassembler::Fail; }

Since we can only return Success and SoftFail that is dead
code as detected by the static code analyzer.

Solution: return Fail as it should be.

See https://bugs.llvm.org/show_bug.cgi?id=43886

Differential Revision: https://reviews.llvm.org/D69819

Added: 
    llvm/test/MC/Disassembler/AMDGPU/decode-err.txt

Modified: 
    llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index ec2e2c4e8b71..4ae981581027 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -73,7 +73,7 @@ addOperand(MCInst &Inst, const MCOperand& Opnd) {
   Inst.addOperand(Opnd);
   return Opnd.isValid() ?
     MCDisassembler::Success :
-    MCDisassembler::SoftFail;
+    MCDisassembler::Fail;
 }
 
 static int insertNamedMCOperand(MCInst &MI, const MCOperand &Op,

diff  --git a/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt b/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt
new file mode 100644
index 000000000000..b90ce05a56e0
--- /dev/null
+++ b/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt
@@ -0,0 +1,4 @@
+# RUN: llvm-mc -arch=amdgcn -mcpu=gfx900 -disassemble -show-encoding < %s 2>&1 | FileCheck -check-prefix=GCN %s
+
+# GCN: warning: invalid instruction encoding
+0xdf,0x00,0x00,0x02


        


More information about the llvm-commits mailing list