@@ -1042,8 +1042,8 @@ class X86AsmParser : public MCTargetAsmParser {
10421042 }
10431043 PrevState = CurrState;
10441044 }
1045- void onRParen () {
1046- PrevState = State;
1045+ bool onRParen (StringRef &ErrMsg ) {
1046+ IntelExprState CurrState = State;
10471047 switch (State) {
10481048 default :
10491049 State = IES_ERROR;
@@ -1054,9 +1054,27 @@ class X86AsmParser : public MCTargetAsmParser {
10541054 case IES_RBRAC:
10551055 case IES_RPAREN:
10561056 State = IES_RPAREN;
1057+ // In the case of a multiply, onRegister has already set IndexReg
1058+ // directly, with appropriate scale.
1059+ // Otherwise if we just saw a register it has only been stored in
1060+ // TmpReg, so we need to store it into the state machine.
1061+ if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
1062+ // If we already have a BaseReg, then assume this is the IndexReg with
1063+ // no explicit scale.
1064+ if (!BaseReg) {
1065+ BaseReg = TmpReg;
1066+ } else {
1067+ if (IndexReg)
1068+ return regsUseUpError (ErrMsg);
1069+ IndexReg = TmpReg;
1070+ Scale = 0 ;
1071+ }
1072+ }
10571073 IC.pushOperator (IC_RPAREN);
10581074 break ;
10591075 }
1076+ PrevState = CurrState;
1077+ return false ;
10601078 }
10611079 bool onOffset (const MCExpr *Val, SMLoc OffsetLoc, StringRef ID,
10621080 const InlineAsmIdentifierInfo &IDInfo,
@@ -2172,7 +2190,11 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
21722190 }
21732191 break ;
21742192 case AsmToken::LParen: SM.onLParen (); break ;
2175- case AsmToken::RParen: SM.onRParen (); break ;
2193+ case AsmToken::RParen:
2194+ if (SM.onRParen (ErrMsg)) {
2195+ return Error (Tok.getLoc (), ErrMsg);
2196+ }
2197+ break ;
21762198 }
21772199 if (SM.hadError ())
21782200 return Error (Tok.getLoc (), " unknown token in expression" );
0 commit comments