[llvm] [X86] Invalid assembly given inverted meaning (PR #190460)

Takashi Idobe via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 06:37:22 PDT 2026


================

----------------
Takashiidobe wrote:

The codepath that sets the error to `Scale can't be negative` is caught when the last three tokens seen are: reg, multiply, minus. This test case triggers this at `rdx * -`. The parser correctly rejects this with the error. 

The case from the issue is: [reg - const * reg]. The branch that catches the previous case doesn't see the pattern reg, multiply, minus. When the parser sees the minus sign, the previous token is a register (reg -). Reg - is valid cause you could have [rdi - const], so this codepath doesn't have a clean terminator until later, so I decided to pass a bool so that the cases where you do want to terminate (e.g. reg - const *), similarly to other parts of the code.

For this branch I started out without tracking the `-` sign loc. But then the caret will land on the 8 for `[r1 - r2 * 8]` and `[r1 - r2]` will have the caret land on r2, but the messages imply the 8 or r2 are the problem which they aren't. 

The current error message of `[r1 + r2 * - 8]` will land the caret on the `-` which is more informative so I wanted to preserve that behavior for this issue, which requires passing the loc of the previously seen `-` sign.

My main quip when writing this code is having to pass a bool through multiple code paths and the error loc too. If there was enough state preserved to catch `reg - const *` then this would be a way easier patch, but that requires a redesign of this parser. 

https://github.com/llvm/llvm-project/pull/190460


More information about the llvm-commits mailing list