llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[RISCV][MC][xthead] Wrong AsmParser error for `th.ldia`

Open fpetrogalli opened this issue 2 years ago • 2 comments

Maybe I am missing something from the specs [1], but I think that the first assembly instruction in the test llvm/test/MC/RISCV/rv64xtheadmemidx-invalid.s should be reporting an error at column 10 (for 0(a0)) and not column 23 (the first immediate operand, 0):

th.ldia         0(a0), (a1), 0, 0  # CHECK: :[[@LINE]]:23: error: invalid operand for instruction

[1] Quoting https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadmemidx/ldia.adoc

Mnemonic
th.ldia rd, (rs1), imm5, imm2

fpetrogalli avatar Mar 21 '24 09:03 fpetrogalli

@llvm/issue-subscribers-backend-risc-v

Author: Francesco Petrogalli (fpetrogalli)

Maybe I am missing something from the specs [1], but I think that the first assembly instruction in the test `llvm/test/MC/RISCV/rv64xtheadmemidx-invalid.s` should be reporting an error at column 10 (for `0(a0)`) and not column 23 (the first immediate operand, `0`):
th.ldia         0(a0), (a1), 0, 0  # CHECK: :[[@<!-- -->LINE]]:23: error: invalid operand for instruction

[1] Quoting https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadmemidx/ldia.adoc

Mnemonic
th.ldia rd, (rs1), imm5, imm2

llvmbot avatar Mar 21 '24 09:03 llvmbot

The 0, ( and ) are parsed as operands and as a result we hit the following piece of code in MatchInstructionImpl in RISCVGenAsmMatcher.inc since Operands.size() is 9:

// Eliminate obvious mismatches.
  if (Operands.size() > 8) {
    ErrorInfo = 8;
    return Match_InvalidOperand;
  }

As you can see we return 8 for ErrorInfo and hence we set the error on the 8th operand which happens to be the first immediate operand 0.

I'm not saying this is correct. Just explaining what's happening.

svs-quic avatar Mar 22 '24 10:03 svs-quic