Index: lib/Target/X86/AsmParser/X86AsmParser.cpp =================================================================== --- lib/Target/X86/AsmParser/X86AsmParser.cpp +++ lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -125,8 +125,8 @@ int64_t popOperand() { assert (!PostfixStack.empty() && "Poped an empty stack!"); ICToken Op = PostfixStack.pop_back_val(); - assert ((Op.first == IC_IMM || Op.first == IC_REGISTER) - && "Expected and immediate or register!"); + if (!(Op.first == IC_IMM || Op.first == IC_REGISTER)) + return -1; // Return invalid value of Scale return Op.second; } void pushOperand(InfixCalculatorTok Op, int64_t Val = 0) { @@ -475,6 +475,11 @@ if (CurrState == IES_REGISTER || CurrState == IES_RPAREN || CurrState == IES_INTEGER || CurrState == IES_RBRAC) IC.pushOperator(IC_MINUS); + else if (PrevState == IES_REGISTER && CurrState == IES_MULTIPLY) { + // We have negate operator for Scale: it's illegal + State = IES_ERROR; + break; + } else IC.pushOperator(IC_NEG); if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) { @@ -517,7 +522,14 @@ } PrevState = CurrState; } - void onRegister(unsigned Reg) { + bool checkScale(StringRef &ErrMsg) { + if(Scale != 1 && Scale != 2 && Scale != 4 && Scale != 8) { + ErrMsg = "scale factor in address must be 1, 2, 4 or 8"; + return true; + } + return false; + } + bool onRegister(unsigned Reg, StringRef &ErrMsg) { IntelExprState CurrState = State; switch (State) { default: @@ -537,6 +549,8 @@ IndexReg = Reg; // Get the scale and replace the 'Scale * Register' with '0'. Scale = IC.popOperand(); + if(checkScale(ErrMsg)) + return true; IC.pushOperand(IC_IMM); IC.popOperator(); } else { @@ -545,6 +559,7 @@ break; } PrevState = CurrState; + return false; } void onIdentifierExpr(const MCExpr *SymRef, StringRef SymRefName) { PrevState = State; @@ -586,10 +601,8 @@ assert (!IndexReg && "IndexReg already set!"); IndexReg = TmpReg; Scale = TmpInt; - if(Scale != 1 && Scale != 2 && Scale != 4 && Scale != 8) { - ErrMsg = "scale factor in address must be 1, 2, 4 or 8"; + if(checkScale(ErrMsg)) return true; - } // Get the scale and replace the 'Register * Scale' with '0'. IC.popOperator(); } else { @@ -1386,7 +1399,9 @@ StringRef Identifier = Tok.getString(); UpdateLocLex = false; if (TK != AsmToken::String && !ParseRegister(TmpReg, IdentLoc, End)) { - SM.onRegister(TmpReg); + StringRef ErrMsg; + if (SM.onRegister(TmpReg, ErrMsg)) + return Error(Tok.getLoc(), ErrMsg); } else if (ParseIntelNamedOperator(Identifier, SM)) { UpdateLocLex = true; } else if (!isParsingInlineAsm()) { Index: test/CodeGen/ARM/arguments-nosplit-double.ll =================================================================== --- test/CodeGen/ARM/arguments-nosplit-double.ll +++ test/CodeGen/ARM/arguments-nosplit-double.ll @@ -8,5 +8,6 @@ ret i32 %tmp } +; CHECK-LABEL: f: ; CHECK-NOT: r3 Index: test/CodeGen/ARM/arguments-nosplit-i64.ll =================================================================== --- test/CodeGen/ARM/arguments-nosplit-i64.ll +++ test/CodeGen/ARM/arguments-nosplit-i64.ll @@ -8,5 +8,6 @@ ret i32 %tmp } +; CHECK-LABEL: f: ; CHECK-NOT: r3 Index: test/MC/X86/intel-syntax-invalid-scale.s =================================================================== --- test/MC/X86/intel-syntax-invalid-scale.s +++ test/MC/X86/intel-syntax-invalid-scale.s @@ -9,3 +9,7 @@ lea rax, [rdi + rdx*32] // CHECK: error: scale factor in address must be 1, 2, 4 or 8 lea rax, [rdi + rdx*16] +// CHECK: error: unknown token in expression + lea rax, [rdi + rdx*-8] +// CHECK: error: scale factor in address must be 1, 2, 4 or 8 + lea rax, [rdi + -1*rdx]