Update the X86 assembler for .intel_syntax to produce an error for invalid

scale factors in memory addresses. As it does for .att_syntax.

It was producing:
Assertion failed: (((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) && "Invalid scale!"), function CreateMem, file /Volumes/SandBox/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp, line 1133.

rdar://14967214

llvm-svn: 199942
This commit is contained in:
Kevin Enderby 2014-01-23 21:52:41 +00:00
parent 53c98b071e
commit 9d11702f5d
2 changed files with 22 additions and 3 deletions

View File

@ -391,7 +391,7 @@ private:
break; break;
} }
} }
void onInteger(int64_t TmpInt) { bool onInteger(int64_t TmpInt, StringRef &ErrMsg) {
IntelExprState CurrState = State; IntelExprState CurrState = State;
switch (State) { switch (State) {
default: default:
@ -410,6 +410,10 @@ private:
assert (!IndexReg && "IndexReg already set!"); assert (!IndexReg && "IndexReg already set!");
IndexReg = TmpReg; IndexReg = TmpReg;
Scale = TmpInt; Scale = TmpInt;
if(Scale != 1 && Scale != 2 && Scale != 4 && Scale != 8) {
ErrMsg = "scale factor in address must be 1, 2, 4 or 8";
return true;
}
// Get the scale and replace the 'Register * Scale' with '0'. // Get the scale and replace the 'Register * Scale' with '0'.
IC.popOperator(); IC.popOperator();
} else if ((PrevState == IES_PLUS || PrevState == IES_MINUS || } else if ((PrevState == IES_PLUS || PrevState == IES_MINUS ||
@ -426,6 +430,7 @@ private:
break; break;
} }
PrevState = CurrState; PrevState = CurrState;
return false;
} }
void onStar() { void onStar() {
PrevState = State; PrevState = State;
@ -1465,6 +1470,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
return Error(Tok.getLoc(), "Unexpected identifier!"); return Error(Tok.getLoc(), "Unexpected identifier!");
} }
case AsmToken::Integer: { case AsmToken::Integer: {
StringRef ErrMsg;
if (isParsingInlineAsm() && SM.getAddImmPrefix()) if (isParsingInlineAsm() && SM.getAddImmPrefix())
InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix, InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix,
Tok.getLoc())); Tok.getLoc()));
@ -1488,10 +1494,12 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
SM.onIdentifierExpr(Val, Identifier); SM.onIdentifierExpr(Val, Identifier);
End = consumeToken(); End = consumeToken();
} else { } else {
SM.onInteger(IntVal); if (SM.onInteger(IntVal, ErrMsg))
return Error(Loc, ErrMsg);
} }
} else { } else {
SM.onInteger(IntVal); if (SM.onInteger(IntVal, ErrMsg))
return Error(Loc, ErrMsg);
} }
break; break;
} }

View File

@ -0,0 +1,11 @@
// RUN: not llvm-mc -triple x86_64-unknown-unknown %s 2> %t.err
// RUN: FileCheck < %t.err %s
.intel_syntax
// CHECK: error: scale factor in address must be 1, 2, 4 or 8
lea rax, [rdi + rdx*64]
// CHECK: error: scale factor in address must be 1, 2, 4 or 8
lea rax, [rdi + rdx*32]
// CHECK: error: scale factor in address must be 1, 2, 4 or 8
lea rax, [rdi + rdx*16]