[ms-inline asm] Use parsePrimaryExpr in lieu of parseExpression if we need to
parse an identifier. Otherwise, parseExpression may parse multiple tokens,
which makes it impossible to properly compute an immediate displacement.
An example of such a case is the source operand (i.e., [Symbol + ImmDisp]) in
the below example:
__asm mov eax, [Symbol + ImmDisp]
The existing test cases exercise this patch.
rdar://13611297
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179115 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 85caa04..11248bd 100644
--- a/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1130,7 +1130,7 @@
if (ParseRegister(TmpReg, Start, End)) {
const MCExpr *Disp;
SMLoc IdentStart = Tok.getLoc();
- if (getParser().parseExpression(Disp, End))
+ if (getParser().parsePrimaryExpr(Disp, End))
return 0;
if (X86Operand *Err = ParseIntelVarWithQualifier(Disp, IdentStart))
@@ -1182,7 +1182,7 @@
SM.onRegister(TmpReg);
UpdateLocLex = false;
break;
- } else if (!getParser().parseExpression(Disp, End)) {
+ } else if (!getParser().parsePrimaryExpr(Disp, End)) {
SM.onDispExpr();
UpdateLocLex = false;
break;
@@ -1324,7 +1324,7 @@
const MCExpr *Disp = 0;
SMLoc IdentStart = Tok.getLoc();
- if (getParser().parseExpression(Disp, End))
+ if (getParser().parsePrimaryExpr(Disp, End))
return 0;
if (!isParsingInlineAsm())
@@ -1401,7 +1401,7 @@
SMLoc End;
const MCExpr *Val;
- if (getParser().parseExpression(Val, End))
+ if (getParser().parsePrimaryExpr(Val, End))
return ErrorOperand(Start, "Unable to parse expression!");
// Don't emit the offset operator.
@@ -1437,7 +1437,7 @@
SMLoc End;
const MCExpr *Val;
- if (getParser().parseExpression(Val, End))
+ if (getParser().parsePrimaryExpr(Val, End))
return 0;
unsigned Length = 0, Size = 0, Type = 0;