From 5e6b37fa3d5f555b0aba7b2594f28b359a22ea31 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 25 Oct 2012 17:37:43 +0000 Subject: [PATCH] [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 --- lib/Target/X86/AsmParser/X86AsmParser.cpp | 53 +++++++++++++++-------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index 708951126f5..7df8be7607a 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(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; - - // FIXME: Handle non-constant expressions. - if (const MCConstantExpr *OrigDisp = dyn_cast(Disp)) { - uint64_t OrigDispVal = OrigDisp->getValue(); - return MCConstantExpr::Create(OrigDispVal + DotDispVal, getContext()); - } + DotDispVal = DotDisp.getZExtValue(); + } else { + Err = "Unexpected token type!"; + return true; } - return Disp; + + // Special case zero dot displacement. + if (!DotDispVal) { + *NewDisp = Disp; + return false; + } + + *NewDisp = MCConstantExpr::Create(OrigDispVal + DotDispVal, getContext()); + return false; } /// Parse the 'offset' operator. This operator is used to specify the