[llvm] r321930 - [X86] When parsing rounding mode operands, provide a proper end location so we don't crash when trying to print an error message using it.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 22:41:07 PST 2018


Author: ctopper
Date: Fri Jan  5 22:41:07 2018
New Revision: 321930

URL: http://llvm.org/viewvc/llvm-project?rev=321930&view=rev
Log:
[X86] When parsing rounding mode operands, provide a proper end location so we don't crash when trying to print an error message using it.

Modified:
    llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
    llvm/trunk/test/MC/X86/avx512-err.s

Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=321930&r1=321929&r2=321930&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Fri Jan  5 22:41:07 2018
@@ -825,7 +825,7 @@ private:
   bool ParseIntelDotOperator(IntelExprStateMachine &SM, SMLoc &End);
   unsigned IdentifyIntelInlineAsmOperator(StringRef Name);
   unsigned ParseIntelInlineAsmOperator(unsigned OpKind);
-  std::unique_ptr<X86Operand> ParseRoundingModeOp(SMLoc Start, SMLoc End);
+  std::unique_ptr<X86Operand> ParseRoundingModeOp(SMLoc Start);
   bool ParseIntelNamedOperator(StringRef Name, IntelExprStateMachine &SM);
   void RewriteIntelExpression(IntelExprStateMachine &SM, SMLoc Start,
                               SMLoc End);
@@ -1595,7 +1595,7 @@ bool X86AsmParser::ParseIntelInlineAsmId
 
 //ParseRoundingModeOp - Parse AVX-512 rounding mode operand
 std::unique_ptr<X86Operand>
-X86AsmParser::ParseRoundingModeOp(SMLoc Start, SMLoc End) {
+X86AsmParser::ParseRoundingModeOp(SMLoc Start) {
   MCAsmParser &Parser = getParser();
   const AsmToken &Tok = Parser.getTok();
   // Eat "{" and mark the current place.
@@ -1616,6 +1616,7 @@ X86AsmParser::ParseRoundingModeOp(SMLoc
     Parser.Lex();  // Eat the sae
     if (!getLexer().is(AsmToken::RCurly))
       return ErrorOperand(Tok.getLoc(), "Expected } at this point");
+    SMLoc End = Tok.getEndLoc();
     Parser.Lex();  // Eat "}"
     const MCExpr *RndModeOp =
       MCConstantExpr::create(rndMode, Parser.getContext());
@@ -1794,7 +1795,7 @@ std::unique_ptr<X86Operand> X86AsmParser
   // Rounding mode operand.
   if (getSTI().getFeatureBits()[X86::FeatureAVX512] &&
       getLexer().is(AsmToken::LCurly))
-    return ParseRoundingModeOp(Start, End);
+    return ParseRoundingModeOp(Start);
 
   // Register operand.
   unsigned RegNo = 0;
@@ -1895,9 +1896,9 @@ std::unique_ptr<X86Operand> X86AsmParser
     return X86Operand::CreateImm(Val, Start, End);
   }
   case AsmToken::LCurly:{
-    SMLoc Start = Parser.getTok().getLoc(), End;
+    SMLoc Start = Parser.getTok().getLoc();
     if (getSTI().getFeatureBits()[X86::FeatureAVX512])
-      return ParseRoundingModeOp(Start, End);
+      return ParseRoundingModeOp(Start);
     return ErrorOperand(Start, "Unexpected '{' in expression");
   }
   }

Modified: llvm/trunk/test/MC/X86/avx512-err.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/avx512-err.s?rev=321930&r1=321929&r2=321930&view=diff
==============================================================================
--- llvm/trunk/test/MC/X86/avx512-err.s (original)
+++ llvm/trunk/test/MC/X86/avx512-err.s Fri Jan  5 22:41:07 2018
@@ -8,3 +8,6 @@ vfmsub213ps %zmm8, %zmm8, %zmm8{%k2} {rn
 
 // ERR: Expected an op-mask register at this point
 vfmsub213ps %zmm8, %zmm8, %zmm8 {rn-sae}
+
+// ERR: invalid operand for instruction
+cvtsd2sil  {rn-sae}, %xmm1, %eax




More information about the llvm-commits mailing list