[llvm] [X86][AsmParser] Support parentheses around scale and index register in Intel syntax (PR #211003)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 04:47:46 PDT 2026


================
@@ -818,31 +839,40 @@ class X86AsmParser : public MCTargetAsmParser {
         break;
       case IES_PLUS:
       case IES_MINUS:
-      case IES_LPAREN:
       case IES_LBRAC:
         State = IES_REGISTER;
         TmpReg = Reg;
         IC.pushOperand(IC_REGISTER);
+        if (NegativeAdditiveTerm) {
+          ErrMsg = "Scale can't be negative";
+          return true;
+        }
         break;
+      case IES_LPAREN:
       case IES_MULTIPLY:
-        // Index Register - Scale * Register
-        if (PrevState == IES_INTEGER) {
+        // A register already held in TmpReg means we are multiplying two reg
+        if (TmpReg) {
+          ErrMsg = "Register can't be multiplied with register!";
+          return true;
+        }
+        State = IES_REGISTER;
+        TmpReg = Reg;
+        // Recognize this register as a scaled index register. This covers
+        // 'scale * reg' and 'scale * (reg)', including parenthesized or
+        // multi-factor scales where the accumulated value is held in TmpScale.
+        if (TmpScale.has_value() || PrevState == IES_MULTIPLY ||
----------------
e-kud wrote:

Isn't `PrevState == IES_MULTIPLY` covered by `TmpScale.has_value()`? I mean if there was a multiplication, TmpScale would be set already as we are `onRegister`. And `reg * reg` has been already checked. The same for `(PrevState == IES_INTEGER && CurrState == IES_MULTIPLY)`. Am I missing something?

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


More information about the llvm-commits mailing list