diff options
| author | Chad Rosier <mcrosier@apple.com> | 2013-04-09 19:34:59 +0000 |
|---|---|---|
| committer | Chad Rosier <mcrosier@apple.com> | 2013-04-09 19:34:59 +0000 |
| commit | d4727e3798981af3d1308418464a10a398290851 (patch) | |
| tree | c44579a1404a7719cc6ca855cd283dcd5914bdaf | |
| parent | e0828ec6027e43724a7c5c76a3409344198dac71 (diff) | |
| download | external_llvm-d4727e3798981af3d1308418464a10a398290851.zip external_llvm-d4727e3798981af3d1308418464a10a398290851.tar.gz external_llvm-d4727e3798981af3d1308418464a10a398290851.tar.bz2 | |
[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
| -rw-r--r-- | include/llvm/MC/MCParser/MCAsmParser.h | 7 | ||||
| -rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 5 | ||||
| -rw-r--r-- | lib/Target/X86/AsmParser/X86AsmParser.cpp | 10 |
3 files changed, 17 insertions, 5 deletions
diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index d7e3902..601f8f7 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -151,6 +151,13 @@ public: virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; bool parseExpression(const MCExpr *&Res); + /// parsePrimaryExpr - Parse a primary expression. + /// + /// @param Res - The value of the expression. The result is undefined + /// on error. + /// @result - False on success. + virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) = 0; + /// parseParenExpression - Parse an arbitrary expression, assuming that an /// initial '(' has already been consumed. /// diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 14577f7..c50177c 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -221,6 +221,7 @@ public: bool parseExpression(const MCExpr *&Res); virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc); + virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc); virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc); virtual bool parseAbsoluteExpression(int64_t &Res); @@ -869,6 +870,10 @@ bool AsmParser::parseExpression(const MCExpr *&Res) { return parseExpression(Res, EndLoc); } +bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { + return ParsePrimaryExpr(Res, EndLoc); +} + const MCExpr * AsmParser::ApplyModifierToExpr(const MCExpr *E, MCSymbolRefExpr::VariantKind Variant) { 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 @@ X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg, 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 @@ X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg, 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 @@ X86Operand *X86AsmParser::ParseIntelMemOperand(unsigned SegReg, 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 @@ X86Operand *X86AsmParser::ParseIntelOffsetOfOperator(SMLoc Start) { 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 @@ X86Operand *X86AsmParser::ParseIntelOperator(SMLoc Start, unsigned OpKind) { SMLoc End; const MCExpr *Val; - if (getParser().parseExpression(Val, End)) + if (getParser().parsePrimaryExpr(Val, End)) return 0; unsigned Length = 0, Size = 0, Type = 0; |
