[AMDGPU] return Fail instead of SolfFail from addOperand()
authorStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Mon, 4 Nov 2019 20:41:31 +0000 (12:41 -0800)
committerStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Tue, 5 Nov 2019 18:25:27 +0000 (10:25 -0800)
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

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
llvm/test/MC/Disassembler/AMDGPU/decode-err.txt [new file with mode: 0644]

index ec2e2c4..4ae9815 100644 (file)
@@ -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 (file)
index 0000000..b90ce05
--- /dev/null
@@ -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