@@ -1042,8 +1042,8 @@ class X86AsmParser : public MCTargetAsmParser {
1042
1042
}
1043
1043
PrevState = CurrState;
1044
1044
}
1045
- void onRParen () {
1046
- PrevState = State;
1045
+ bool onRParen (StringRef &ErrMsg ) {
1046
+ IntelExprState CurrState = State;
1047
1047
switch (State) {
1048
1048
default :
1049
1049
State = IES_ERROR;
@@ -1054,9 +1054,27 @@ class X86AsmParser : public MCTargetAsmParser {
1054
1054
case IES_RBRAC:
1055
1055
case IES_RPAREN:
1056
1056
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
+ }
1057
1073
IC.pushOperator (IC_RPAREN);
1058
1074
break ;
1059
1075
}
1076
+ PrevState = CurrState;
1077
+ return false ;
1060
1078
}
1061
1079
bool onOffset (const MCExpr *Val, SMLoc OffsetLoc, StringRef ID,
1062
1080
const InlineAsmIdentifierInfo &IDInfo,
@@ -2172,7 +2190,11 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
2172
2190
}
2173
2191
break ;
2174
2192
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 ;
2176
2198
}
2177
2199
if (SM.hadError ())
2178
2200
return Error (Tok.getLoc (), " unknown token in expression" );
0 commit comments