aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/X86/AsmParser/X86AsmParser.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2012-10-25 17:37:43 +0000
committerChad Rosier <mcrosier@apple.com>2012-10-25 17:37:43 +0000
commit5e6b37fa3d5f555b0aba7b2594f28b359a22ea31 (patch)
tree5799fd7eee11cf5124beb09b263c38b60a464ea1 /lib/Target/X86/AsmParser/X86AsmParser.cpp
parenta8a0a155de16830b8fcab539ba2ec21de3145532 (diff)
[ms-inline asm] Add error handling to the ParseIntelDotOperator() function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/AsmParser/X86AsmParser.cpp')
-rw-r--r--lib/Target/X86/AsmParser/X86AsmParser.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 708951126f..7df8be7607 100644
--- a/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -60,7 +60,8 @@ private:
X86Operand *ParseIntelBracExpression(unsigned SegReg, unsigned Size);
X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
- const MCExpr *ParseIntelDotOperator(const MCExpr *Disp);
+ bool ParseIntelDotOperator(const MCExpr *Disp, const MCExpr **NewDisp,
+ SmallString<64> &Err);
bool ParseDirectiveWord(unsigned Size, SMLoc L);
bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
@@ -744,8 +745,15 @@ X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg,
Parser.Lex();
End = Tok.getLoc();
- if (Tok.getString().startswith("."))
- Disp = ParseIntelDotOperator(Disp);
+ if (Tok.getString().startswith(".")) {
+ SmallString<64> Err;
+ const MCExpr *NewDisp;
+ if (ParseIntelDotOperator(Disp, &NewDisp, Err))
+ return ErrorOperand(Tok.getLoc(), Err);
+
+ Parser.Lex(); // Eat the field.
+ Disp = NewDisp;
+ }
End = Tok.getLoc();
@@ -809,30 +817,41 @@ X86Operand *X86AsmParser::ParseIntelMemOperand(unsigned SegReg, SMLoc Start) {
}
/// Parse the '.' operator.
-const MCExpr *X86AsmParser::ParseIntelDotOperator(const MCExpr *Disp) {
+bool X86AsmParser::ParseIntelDotOperator(const MCExpr *Disp,
+ const MCExpr **NewDisp,
+ SmallString<64> &Err) {
AsmToken Tok = *&Parser.getTok();
+ uint64_t OrigDispVal, DotDispVal;
+
+ // FIXME: Handle non-constant expressions.
+ if (const MCConstantExpr *OrigDisp = dyn_cast<MCConstantExpr>(Disp)) {
+ OrigDispVal = OrigDisp->getValue();
+ } else {
+ Err = "Non-constant offsets are not supported!";
+ return true;
+ }
// Drop the '.'.
StringRef DotDispStr = Tok.getString().drop_front(1);
- Lex(); // Eat .field.
-
// .Imm gets lexed as a real.
if (Tok.is(AsmToken::Real)) {
APInt DotDisp;
DotDispStr.getAsInteger(10, DotDisp);
- uint64_t DotDispVal = DotDisp.getZExtValue();
-
- // Special case zero dot displacement.
- if (!DotDispVal) return Disp;
+ DotDispVal = DotDisp.getZExtValue();
+ } else {
+ Err = "Unexpected token type!";
+ return true;
+ }
- // FIXME: Handle non-constant expressions.
- if (const MCConstantExpr *OrigDisp = dyn_cast<MCConstantExpr>(Disp)) {
- uint64_t OrigDispVal = OrigDisp->getValue();
- return MCConstantExpr::Create(OrigDispVal + DotDispVal, getContext());
- }
+ // Special case zero dot displacement.
+ if (!DotDispVal) {
+ *NewDisp = Disp;
+ return false;
}
- return Disp;
+
+ *NewDisp = MCConstantExpr::Create(OrigDispVal + DotDispVal, getContext());
+ return false;
}
/// Parse the 'offset' operator. This operator is used to specify the