<div dir="ltr"><div>I'd like to keep the parsing aspects together so that we can move to sharing the error handling string emission handling (i.e. add the directive location strings in one place). I was planning on adding that in an upcoming patch once I figure out a better way to concisely describe tight sequential chain than an or in a conditional. </div><div><br></div><div>That said, you're right those comments signal the transition away from parsing and to should be separated. </div><div><br></div><div>-Nirav</div><div><br></div><div><br></div><div><br></div><div><div><div>-  if (</div><div>+  SMLoc IncbinLoc = getTok().getLoc();</div><div>+  if (check(getTok().isNot(AsmToken::String),</div><div>+            "expected string in '.incbin' directive") ||</div><div>+      parseEscapedString(Filename) ||</div><div>+      parseToken(</div><div>+                 "unexpected token in '.incbin' directive") ||</div><div>+      // Attempt to process the included file.</div><div>+      check(processIncbinFile(Filename), IncbinLoc,</div><div>+            "Could not find incbin file '" + Filename + "'"))</div><div>     return true;</div></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 18, 2016 at 2:37 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Mon, Jul 18, 2016 at 8:31 AM Nirav Dave via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: niravd<br>
Date: Mon Jul 18 10:24:03 2016<br>
New Revision: 275795<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=275795&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=275795&view=rev</a><br>
Log:<br>
[MC] Cleanup Error Handling in AsmParser<br>
<br>
Add parseToken and compatriot functions to stitch error checks in<br>
straight linear code. As part of this fix some erronous handling of<br>
directives where the EndOfStatement token either was not checked or<br>
Lexed on termination.<br>
<br>
Reviewers: rnk, majnemer<br>
<br>
Subscribers: llvm-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D22312" rel="noreferrer" target="_blank">http://reviews.llvm.org/D22312</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
    llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp<br>
    llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp<br>
    llvm/trunk/test/MC/AsmParser/preserve-comments.s<br>
<br>
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=275795&r1=275794&r2=275795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=275795&r1=275794&r2=275795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Jul 18 10:24:03 2016<br>
@@ -428,7 +428,7 @@ void MCAsmStreamer::EmitLinkerOptions(Ar<br>
          ie = Options.end(); it != ie; ++it) {<br>
     OS << ", " << '"' << *it << '"';<br>
   }<br>
-  OS << "\n";<br>
+  EmitEOL();<br>
 }<br>
<br>
 void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {<br>
@@ -614,7 +614,7 @@ void MCAsmStreamer::emitELFSize(MCSymbol<br>
   Symbol->print(OS, MAI);<br>
   OS << ", ";<br>
   Value->print(OS, MAI);<br>
-  OS << '\n';<br>
+  EmitEOL();<br>
 }<br>
<br>
 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,<br>
@@ -1243,10 +1243,10 @@ void MCAsmStreamer::EmitCFIEscape(String<br>
<br>
 void MCAsmStreamer::EmitCFIGnuArgsSize(int64_t Size) {<br>
   MCStreamer::EmitCFIGnuArgsSize(Size);<br>
-<br>
+<br>
   uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };<br>
   unsigned Len = encodeULEB128(Size, Buffer + 1) + 1;<br>
-<br>
+<br>
   PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len));<br>
   EmitEOL();<br>
 }<br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Jul 18 10:24:03 2016<br>
@@ -250,6 +250,29 @@ public:<br>
   void eatToEndOfStatement() override;<br>
<br>
   void checkForValidSection() override;<br>
+<br>
+  bool getTokenLoc(SMLoc &Loc) {<br>
+    Loc = getTok().getLoc();<br>
+    return false;<br>
+  }<br>
+<br>
+  /// parseToken - If current token has the specified kind, eat it and<br>
+  /// return success.  Otherwise, emit the specified error and return failure.<br>
+  bool parseToken(AsmToken::TokenKind T, const Twine &ErrMsg) {<br>
+    if (getTok().getKind() != T)<br>
+      return TokError(ErrMsg);<br>
+    Lex();<br>
+    return false;<br>
+  }<br>
+<br>
+  bool parseIntToken(int64_t &V, const Twine &ErrMsg) {<br>
+    if (getTok().getKind() != AsmToken::Integer)<br>
+      return TokError(ErrMsg);<br>
+    V = getTok().getIntVal();<br>
+    Lex();<br>
+    return false;<br>
+  }<br>
+<br>
   /// }<br>
<br>
 private:<br>
@@ -308,6 +331,18 @@ private:<br>
   }<br>
   static void DiagHandler(const SMDiagnostic &Diag, void *Context);<br>
<br>
+  bool check(bool P, SMLoc Loc, const Twine &Msg) {<br>
+    if (P)<br>
+      return Error(Loc, Msg);<br>
+    return false;<br>
+  }<br>
+<br>
+  bool check(bool P, const Twine &Msg) {<br>
+    if (P)<br>
+      return TokError(Msg);<br>
+    return false;<br>
+  }<br>
+<br>
   /// \brief Enter the specified file. This returns true on failure.<br>
   bool enterIncludeFile(const std::string &Filename);<br>
<br>
@@ -820,10 +855,9 @@ bool AsmParser::parseParenExpr(const MCE<br>
 bool AsmParser::parseBracketExpr(const MCExpr *&Res, SMLoc &EndLoc) {<br>
   if (parseExpression(Res))<br>
     return true;<br>
-  if (Lexer.isNot(AsmToken::RBrac))<br>
-    return TokError("expected ']' in brackets expression");<br>
-  EndLoc = Lexer.getTok().getEndLoc();<br>
-  Lex();<br>
+  EndLoc = getTok().getEndLoc();<br>
+  if (parseToken(AsmToken::RBrac, "expected ']' in brackets expression"))<br>
+    return true;<br>
   return false;<br>
 }<br>
<br>
@@ -888,11 +922,10 @@ bool AsmParser::parsePrimaryExpr(const M<br>
       Lex(); // eat '('.<br>
       StringRef VName;<br>
       parseIdentifier(VName);<br>
-      if (Lexer.isNot(AsmToken::RParen)) {<br>
-          return Error(Lexer.getTok().getLoc(),<br>
-                       "unexpected token in variant, expected ')'");<br>
-      }<br>
-      Lex(); // eat ')'.<br>
+      // eat ')'.<br>
+      if (parseToken(AsmToken::RParen,<br>
+                     "unexpected token in variant, expected ')'"))<br>
+        return true;<br>
       Split = std::make_pair(Identifier, VName);<br>
     }<br>
<br>
@@ -1136,10 +1169,10 @@ bool AsmParser::parseParenExprOfDepth(un<br>
     // We don't Lex() the last RParen.<br>
     // This is the same behavior as parseParenExpression().<br>
     if (ParenDepth - 1 > 0) {<br>
-      if (Lexer.isNot(AsmToken::RParen))<br>
-        return TokError("expected ')' in parentheses expression");<br>
-      EndLoc = Lexer.getTok().getEndLoc();<br>
-      Lex();<br>
+      EndLoc = getTok().getEndLoc();<br>
+      if (parseToken(AsmToken::RParen,<br>
+                     "expected ')' in parentheses expression"))<br>
+        return true;<br>
     }<br>
   }<br>
   return false;<br>
@@ -2238,7 +2271,7 @@ bool AsmParser::parseMacroArguments(cons<br>
         return true;<br>
       }<br>
<br>
-      if (!Lexer.is(AsmToken::Equal)) {<br>
+      if (Lexer.isNot(AsmToken::Equal)) {<br>
         TokError("expected '=' after formal parameter identifier");<br>
         eatToEndOfStatement();<br>
         return true;<br>
@@ -2445,12 +2478,10 @@ bool AsmParser::parseIdentifier(StringRe<br>
 bool AsmParser::parseDirectiveSet(StringRef IDVal, bool allow_redef) {<br>
   StringRef Name;<br>
<br>
-  if (parseIdentifier(Name))<br>
-    return TokError("expected identifier after '" + Twine(IDVal) + "'");<br>
-<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in '" + Twine(IDVal) + "'");<br>
-  Lex();<br>
+  if (check(parseIdentifier(Name),<br>
+            "expected identifier after '" + Twine(IDVal) + "'") ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in '" + Twine(IDVal) + "'"))<br>
+    return true;<br>
<br>
   return parseAssignment(Name, allow_redef, true);<br>
 }<br>
@@ -2510,6 +2541,7 @@ bool AsmParser::parseEscapedString(std::<br>
     }<br>
   }<br>
<br>
+  Lex();<br>
   return false;<br>
 }<br>
<br>
@@ -2520,25 +2552,22 @@ bool AsmParser::parseDirectiveAscii(Stri<br>
     checkForValidSection();<br>
<br>
     for (;;) {<br>
-      if (getLexer().isNot(AsmToken::String))<br>
-        return TokError("expected string in '" + Twine(IDVal) + "' directive");<br>
-<br>
       std::string Data;<br>
-      if (parseEscapedString(Data))<br>
+      if (check(getTok().isNot(AsmToken::String),<br>
+                "expected string in '" + Twine(IDVal) + "' directive") ||<br>
+          parseEscapedString(Data))<br>
         return true;<br>
<br>
       getStreamer().EmitBytes(Data);<br>
       if (ZeroTerminated)<br>
         getStreamer().EmitBytes(StringRef("\0", 1));<br>
<br>
-      Lex();<br>
-<br>
       if (getLexer().is(AsmToken::EndOfStatement))<br>
         break;<br>
<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in '" + Twine(IDVal) + "' directive");<br>
-      Lex();<br>
+      if (parseToken(AsmToken::Comma,<br>
+                     "unexpected token in '" + Twine(IDVal) + "' directive"))<br>
+        return true;<br>
     }<br>
   }<br>
<br>
@@ -2558,18 +2587,13 @@ bool AsmParser::parseDirectiveReloc(SMLo<br>
<br>
   // We can only deal with constant expressions at the moment.<br>
   int64_t OffsetValue;<br>
-  if (!Offset->evaluateAsAbsolute(OffsetValue))<br>
-    return Error(OffsetLoc, "expression is not a constant value");<br>
-<br>
-  if (OffsetValue < 0)<br>
-    return Error(OffsetLoc, "expression is negative");<br>
-<br>
-  if (Lexer.isNot(AsmToken::Comma))<br>
-    return TokError("expected comma");<br>
-  Lex();<br>
+  if (check(!Offset->evaluateAsAbsolute(OffsetValue), OffsetLoc,<br>
+            "expression is not a constant value") ||<br>
+      check(OffsetValue < 0, OffsetLoc, "expression is negative") ||<br>
+      parseToken(AsmToken::Comma, "expected comma") ||<br>
+      check(getTok().isNot(AsmToken::Identifier), "expected relocation name"))<br></blockquote><div><br></div></div></div><div>I find these long if chains substantially harder to read.</div><div><br></div><div>In some of them you even have to add comments have way through the condition. Generally, I suspect that if you need a comment, it shouldn't be in a single condition unless that's a functional necessity. Would you be OK with me refactoring it in that way?</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    return true;<br>
<br>
-  if (Lexer.isNot(AsmToken::Identifier))<br>
-    return TokError("expected relocation name");<br>
   SMLoc NameLoc = Lexer.getTok().getLoc();<br>
   StringRef Name = Lexer.getTok().getIdentifier();<br>
   Lex();<br>
@@ -2585,12 +2609,11 @@ bool AsmParser::parseDirectiveReloc(SMLo<br>
       return Error(ExprLoc, "expression must be relocatable");<br>
   }<br>
<br>
-  if (Lexer.isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in .reloc directive");<br>
-<br>
-  if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc))<br>
-    return Error(NameLoc, "unknown relocation name");<br>
-<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in .reloc directive") ||<br>
+      check(getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc),<br>
+            NameLoc, "unknown relocation name"))<br>
+    return true;<br>
   return false;<br>
 }<br>
<br>
@@ -2620,9 +2643,8 @@ bool AsmParser::parseDirectiveValue(unsi<br>
         break;<br>
<br>
       // FIXME: Improve diagnostic.<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in directive");<br>
-      Lex();<br>
+      if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+        return true;<br>
     }<br>
   }<br>
<br>
@@ -2637,10 +2659,9 @@ bool AsmParser::parseDirectiveOctaValue(<br>
     checkForValidSection();<br>
<br>
     for (;;) {<br>
-      if (Lexer.getKind() == AsmToken::Error)<br>
+      if (getTok().is(AsmToken::Error))<br>
         return true;<br>
-      if (Lexer.getKind() != AsmToken::Integer &&<br>
-          Lexer.getKind() != AsmToken::BigNum)<br>
+      if (getTok().isNot(AsmToken::Integer) && getTok().isNot(AsmToken::BigNum))<br>
         return TokError("unknown token in expression");<br>
<br>
       SMLoc ExprLoc = getLexer().getLoc();<br>
@@ -2670,9 +2691,8 @@ bool AsmParser::parseDirectiveOctaValue(<br>
         break;<br>
<br>
       // FIXME: Improve diagnostic.<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in directive");<br>
-      Lex();<br>
+      if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+        return true;<br>
     }<br>
   }<br>
<br>
@@ -2729,9 +2749,8 @@ bool AsmParser::parseDirectiveRealValue(<br>
       if (Lexer.is(AsmToken::EndOfStatement))<br>
         break;<br>
<br>
-      if (Lexer.isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in directive");<br>
-      Lex();<br>
+      if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+        return true;<br>
     }<br>
   }<br>
<br>
@@ -2756,11 +2775,9 @@ bool AsmParser::parseDirectiveZero() {<br>
       return true;<br>
   }<br>
<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.zero' directive");<br>
-<br>
-  Lex();<br>
-<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.zero' directive"))<br>
+    return true;<br>
   getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);<br>
<br>
   return false;<br>
@@ -2781,27 +2798,18 @@ bool AsmParser::parseDirectiveFill() {<br>
<br>
   SMLoc SizeLoc, ExprLoc;<br>
   if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in '.fill' directive");<br>
-    Lex();<br>
<br>
-    SizeLoc = getLexer().getLoc();<br>
-    if (parseAbsoluteExpression(FillSize))<br>
+    if (parseToken(AsmToken::Comma, "unexpected token in '.fill' directive") ||<br>
+        getTokenLoc(SizeLoc) || parseAbsoluteExpression(FillSize))<br>
       return true;<br>
<br>
     if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in '.fill' directive");<br>
-      Lex();<br>
-<br>
-      ExprLoc = getLexer().getLoc();<br>
-      if (parseAbsoluteExpression(FillExpr))<br>
+      if (parseToken(AsmToken::Comma,<br>
+                     "unexpected token in '.fill' directive") ||<br>
+          getTokenLoc(ExprLoc) || parseAbsoluteExpression(FillExpr) ||<br>
+          parseToken(AsmToken::EndOfStatement,<br>
+                     "unexpected token in '.fill' directive"))<br>
         return true;<br>
-<br>
-      if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-        return TokError("unexpected token in '.fill' directive");<br>
-<br>
-      Lex();<br>
     }<br>
   }<br>
<br>
@@ -2834,18 +2842,15 @@ bool AsmParser::parseDirectiveOrg() {<br>
   // Parse optional fill expression.<br>
   int64_t FillExpr = 0;<br>
   if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in '.org' directive");<br>
-    Lex();<br>
-<br>
-    if (parseAbsoluteExpression(FillExpr))<br>
+    if (parseToken(AsmToken::Comma, "unexpected token in '.org' directive") ||<br>
+        parseAbsoluteExpression(FillExpr))<br>
       return true;<br>
-<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return TokError("unexpected token in '.org' directive");<br>
   }<br>
<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.org' directive"))<br>
+    return true;<br>
+<br>
   getStreamer().emitValueToOffset(Offset, FillExpr);<br>
   return false;<br>
 }<br>
@@ -2865,34 +2870,27 @@ bool AsmParser::parseDirectiveAlign(bool<br>
   int64_t FillExpr = 0;<br>
   int64_t MaxBytesToFill = 0;<br>
   if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in directive");<br>
-    Lex();<br>
+    if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+      return true;<br>
<br>
     // The fill expression can be omitted while specifying a maximum number of<br>
     // alignment bytes, e.g:<br>
     //  .align 3,,4<br>
-    if (getLexer().isNot(AsmToken::Comma)) {<br>
+    if (getTok().isNot(AsmToken::Comma)) {<br>
       HasFillExpr = true;<br>
       if (parseAbsoluteExpression(FillExpr))<br>
         return true;<br>
     }<br>
<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in directive");<br>
-      Lex();<br>
-<br>
-      MaxBytesLoc = getLexer().getLoc();<br>
-      if (parseAbsoluteExpression(MaxBytesToFill))<br>
+    if (getTok().isNot(AsmToken::EndOfStatement)) {<br>
+      if (parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+          getTokenLoc(MaxBytesLoc) || parseAbsoluteExpression(MaxBytesToFill))<br>
         return true;<br>
-<br>
-      if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-        return TokError("unexpected token in directive");<br>
     }<br>
   }<br>
<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))<br>
+    return true;<br>
<br>
   if (!HasFillExpr)<br>
     FillExpr = 0;<br>
@@ -2963,33 +2961,32 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
       return TokError("file number less than one");<br>
   }<br>
<br>
-  if (getLexer().isNot(AsmToken::String))<br>
-    return TokError("unexpected token in '.file' directive");<br>
+  std::string Path = getTok().getString();<br>
<br>
   // Usually the directory and filename together, otherwise just the directory.<br>
   // Allow the strings to have escaped octal character sequence.<br>
-  std::string Path = getTok().getString();<br>
-  if (parseEscapedString(Path))<br>
+  if (check(getTok().isNot(AsmToken::String),<br>
+            "unexpected token in '.file' directive") ||<br>
+      parseEscapedString(Path))<br>
     return true;<br>
-  Lex();<br>
<br>
   StringRef Directory;<br>
   StringRef Filename;<br>
   std::string FilenameData;<br>
   if (getLexer().is(AsmToken::String)) {<br>
-    if (FileNumber == -1)<br>
-      return TokError("explicit path specified, but no file number");<br>
-    if (parseEscapedString(FilenameData))<br>
+    if (check(FileNumber == -1,<br>
+              "explicit path specified, but no file number") ||<br>
+        parseEscapedString(FilenameData))<br>
       return true;<br>
     Filename = FilenameData;<br>
     Directory = Path;<br>
-    Lex();<br>
   } else {<br>
     Filename = Path;<br>
   }<br>
<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.file' directive");<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.file' directive"))<br>
+    return true;<br>
<br>
   if (FileNumber == -1)<br>
     getStreamer().EmitFileDirective(Filename);<br>
@@ -3009,19 +3006,16 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
 /// parseDirectiveLine<br>
 /// ::= .line [number]<br>
 bool AsmParser::parseDirectiveLine() {<br>
+  int64_t LineNumber;<br>
   if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-    if (getLexer().isNot(AsmToken::Integer))<br>
-      return TokError("unexpected token in '.line' directive");<br>
-<br>
-    int64_t LineNumber = getTok().getIntVal();<br>
+    if (parseIntToken(LineNumber, "unexpected token in '.line' directive"))<br>
+      return true;<br>
     (void)LineNumber;<br>
-    Lex();<br>
-<br>
     // FIXME: Do something with the .line.<br>
   }<br>
-<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.line' directive");<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.line' directive"))<br>
+    return true;<br>
<br>
   return false;<br>
 }<br>
@@ -3034,16 +3028,16 @@ bool AsmParser::parseDirectiveLine() {<br>
 /// third number is a column position (zero if not specified).  The remaining<br>
 /// optional items are .loc sub-directives.<br>
 bool AsmParser::parseDirectiveLoc() {<br>
-  if (getLexer().isNot(AsmToken::Integer))<br>
-    return TokError("unexpected token in '.loc' directive");<br>
-  int64_t FileNumber = getTok().getIntVal();<br>
-  if (FileNumber < 1)<br>
-    return TokError("file number less than one in '.loc' directive");<br>
-  if (!getContext().isValidDwarfFileNumber(FileNumber))<br>
-    return TokError("unassigned file number in '.loc' directive");<br>
-  Lex();<br>
+  int64_t FileNumber = 0, LineNumber = 0;<br>
+  SMLoc Loc = getTok().getLoc();<br>
+  if (parseIntToken(FileNumber, "unexpected token in '.loc' directive") ||<br>
+      check(FileNumber < 1, Loc,<br>
+            "file number less than one in '.loc' directive") ||<br>
+      check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,<br>
+            "unassigned file number in '.loc' directive"))<br>
+    return true;<br>
<br>
-  int64_t LineNumber = 0;<br>
+  // optional<br>
   if (getLexer().is(AsmToken::Integer)) {<br>
     LineNumber = getTok().getIntVal();<br>
     if (LineNumber < 0)<br>
@@ -3120,6 +3114,7 @@ bool AsmParser::parseDirectiveLoc() {<br>
         break;<br>
     }<br>
   }<br>
+  Lex();<br>
<br>
   getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,<br>
                                       Isa, Discriminator, StringRef());<br>
@@ -3136,31 +3131,23 @@ bool AsmParser::parseDirectiveStabs() {<br>
 /// parseDirectiveCVFile<br>
 /// ::= .cv_file number filename<br>
 bool AsmParser::parseDirectiveCVFile() {<br>
-  SMLoc FileNumberLoc = getLexer().getLoc();<br>
-  if (getLexer().isNot(AsmToken::Integer))<br>
-    return TokError("expected file number in '.cv_file' directive");<br>
-<br>
-  int64_t FileNumber = getTok().getIntVal();<br>
-  Lex();<br>
-<br>
-  if (FileNumber < 1)<br>
-    return TokError("file number less than one");<br>
-<br>
-  if (getLexer().isNot(AsmToken::String))<br>
-    return TokError("unexpected token in '.cv_file' directive");<br>
-<br>
-  // Usually the directory and filename together, otherwise just the directory.<br>
-  // Allow the strings to have escaped octal character sequence.<br>
+  SMLoc FileNumberLoc = getTok().getLoc();<br>
+  int64_t FileNumber;<br>
   std::string Filename;<br>
-  if (parseEscapedString(Filename))<br>
-    return true;<br>
-  Lex();<br>
-<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.cv_file' directive");<br>
<br>
-  if (getStreamer().EmitCVFileDirective(FileNumber, Filename) == 0)<br>
-    Error(FileNumberLoc, "file number already allocated");<br>
+  if (parseIntToken(FileNumber,<br>
+                    "expected file number in '.cv_file' directive") ||<br>
+      check(FileNumber < 1, FileNumberLoc, "file number less than one") ||<br>
+      check(getTok().isNot(AsmToken::String),<br>
+            "unexpected token in '.cv_file' directive") ||<br>
+      // Usually directory and filename are together, otherwise just<br>
+      // directory. Allow the strings to have escaped octal character sequence.<br>
+      parseEscapedString(Filename) ||<br>
+      parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.cv_file' directive") ||<br>
+      check(getStreamer().EmitCVFileDirective(FileNumber, Filename) == 0,<br>
+            FileNumberLoc, "file number already allocated"))<br>
+    return true;<br>
<br>
   return false;<br>
 }<br>
@@ -3173,20 +3160,19 @@ bool AsmParser::parseDirectiveCVFile() {<br>
 /// third number is a column position (zero if not specified).  The remaining<br>
 /// optional items are .loc sub-directives.<br>
 bool AsmParser::parseDirectiveCVLoc() {<br>
-  if (getLexer().isNot(AsmToken::Integer))<br>
-    return TokError("unexpected token in '.cv_loc' directive");<br>
-<br>
-  int64_t FunctionId = getTok().getIntVal();<br>
-  if (FunctionId < 0)<br>
-    return TokError("function id less than zero in '.cv_loc' directive");<br>
-  Lex();<br>
-<br>
-  int64_t FileNumber = getTok().getIntVal();<br>
-  if (FileNumber < 1)<br>
-    return TokError("file number less than one in '.cv_loc' directive");<br>
-  if (!getContext().isValidCVFileNumber(FileNumber))<br>
-    return TokError("unassigned file number in '.cv_loc' directive");<br>
-  Lex();<br>
+  SMLoc Loc;<br>
+  int64_t FunctionId, FileNumber;<br>
+  if (getTokenLoc(Loc) ||<br>
+      parseIntToken(FunctionId, "unexpected token in '.cv_loc' directive") ||<br>
+      check(FunctionId < 0, Loc,<br>
+            "function id less than zero in '.cv_loc' directive") ||<br>
+      getTokenLoc(Loc) ||<br>
+      parseIntToken(FileNumber, "expected integer in '.cv_loc' directive") ||<br>
+      check(FileNumber < 1, Loc,<br>
+            "file number less than one in '.cv_loc' directive") ||<br>
+      check(!getContext().isValidCVFileNumber(FileNumber), Loc,<br>
+            "unassigned file number in '.cv_loc' directive"))<br>
+    return true;<br>
<br>
   int64_t LineNumber = 0;<br>
   if (getLexer().is(AsmToken::Integer)) {<br>
@@ -3230,6 +3216,7 @@ bool AsmParser::parseDirectiveCVLoc() {<br>
       return Error(Loc, "unknown sub-directive in '.cv_loc' directive");<br>
     }<br>
   }<br>
+  Lex();<br>
<br>
   getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,<br>
                                    ColumnPos, PrologueEnd, IsStmt, StringRef());<br>
@@ -3239,28 +3226,22 @@ bool AsmParser::parseDirectiveCVLoc() {<br>
 /// parseDirectiveCVLinetable<br>
 /// ::= .cv_linetable FunctionId, FnStart, FnEnd<br>
 bool AsmParser::parseDirectiveCVLinetable() {<br>
-  int64_t FunctionId = getTok().getIntVal();<br>
-  if (FunctionId < 0)<br>
-    return TokError("function id less than zero in '.cv_linetable' directive");<br>
-  Lex();<br>
-<br>
-  if (Lexer.isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in '.cv_linetable' directive");<br>
-  Lex();<br>
-<br>
-  SMLoc Loc = getLexer().getLoc();<br>
-  StringRef FnStartName;<br>
-  if (parseIdentifier(FnStartName))<br>
-    return Error(Loc, "expected identifier in directive");<br>
-<br>
-  if (Lexer.isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in '.cv_linetable' directive");<br>
-  Lex();<br>
-<br>
-  Loc = getLexer().getLoc();<br>
-  StringRef FnEndName;<br>
-  if (parseIdentifier(FnEndName))<br>
-    return Error(Loc, "expected identifier in directive");<br>
+  int64_t FunctionId;<br>
+  StringRef FnStartName, FnEndName;<br>
+  SMLoc Loc = getTok().getLoc();<br>
+  if (parseIntToken(FunctionId,<br>
+                    "expected Integer in '.cv_linetable' directive") ||<br>
+      check(FunctionId < 0, Loc,<br>
+            "function id less than zero in '.cv_linetable' directive") ||<br>
+      parseToken(AsmToken::Comma,<br>
+                 "unexpected token in '.cv_linetable' directive") ||<br>
+      getTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,<br>
+                                "expected identifier in directive") ||<br>
+      parseToken(AsmToken::Comma,<br>
+                 "unexpected token in '.cv_linetable' directive") ||<br>
+      getTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,<br>
+                                "expected identifier in directive"))<br>
+    return true;<br>
<br>
   MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);<br>
   MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);<br>
@@ -3273,35 +3254,31 @@ bool AsmParser::parseDirectiveCVLinetabl<br>
 /// ::= .cv_inline_linetable PrimaryFunctionId FileId LineNum FnStart FnEnd<br>
 ///          ("contains" SecondaryFunctionId+)?<br>
 bool AsmParser::parseDirectiveCVInlineLinetable() {<br>
-  int64_t PrimaryFunctionId = getTok().getIntVal();<br>
-  if (PrimaryFunctionId < 0)<br>
-    return TokError(<br>
-        "function id less than zero in '.cv_inline_linetable' directive");<br>
-  Lex();<br>
-<br>
-  int64_t SourceFileId = getTok().getIntVal();<br>
-  if (SourceFileId <= 0)<br>
-    return TokError(<br>
-        "File id less than zero in '.cv_inline_linetable' directive");<br>
-  Lex();<br>
-<br>
-  int64_t SourceLineNum = getTok().getIntVal();<br>
-  if (SourceLineNum < 0)<br>
-    return TokError(<br>
-        "Line number less than zero in '.cv_inline_linetable' directive");<br>
-  Lex();<br>
-<br>
-  SMLoc Loc = getLexer().getLoc();<br>
-  StringRef FnStartName;<br>
-  if (parseIdentifier(FnStartName))<br>
-    return Error(Loc, "expected identifier in directive");<br>
-  MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);<br>
-<br>
-  Loc = getLexer().getLoc();<br>
-  StringRef FnEndName;<br>
-  if (parseIdentifier(FnEndName))<br>
-    return Error(Loc, "expected identifier in directive");<br>
-  MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);<br>
+  int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;<br>
+  StringRef FnStartName, FnEndName;<br>
+  SMLoc Loc = getTok().getLoc();<br>
+  if (parseIntToken(<br>
+          PrimaryFunctionId,<br>
+          "expected PrimaryFunctionId in '.cv_inline_linetable' directive") ||<br>
+      check(PrimaryFunctionId < 0, Loc,<br>
+            "function id less than zero in '.cv_inline_linetable' directive") ||<br>
+      getTokenLoc(Loc) ||<br>
+      parseIntToken(<br>
+          SourceFileId,<br>
+          "expected SourceField in '.cv_inline_linetable' directive") ||<br>
+      check(SourceFileId <= 0, Loc,<br>
+            "File id less than zero in '.cv_inline_linetable' directive") ||<br>
+      getTokenLoc(Loc) ||<br>
+      parseIntToken(<br>
+          SourceLineNum,<br>
+          "expected SourceLineNum in '.cv_inline_linetable' directive") ||<br>
+      check(SourceLineNum < 0, Loc,<br>
+            "Line number less than zero in '.cv_inline_linetable' directive") ||<br>
+      getTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,<br>
+                                "expected identifier in directive") ||<br>
+      getTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,<br>
+                                "expected identifier in directive"))<br>
+    return true;<br>
<br>
   SmallVector<unsigned, 8> SecondaryFunctionIds;<br>
   if (getLexer().is(AsmToken::Identifier)) {<br>
@@ -3321,6 +3298,11 @@ bool AsmParser::parseDirectiveCVInlineLi<br>
     }<br>
   }<br>
<br>
+  if (parseToken(AsmToken::EndOfStatement, "Expected End of Statement"))<br>
+    return true;<br>
+<br>
+  MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);<br>
+  MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);<br>
   getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,<br>
                                                SourceLineNum, FnStartSym,<br>
                                                FnEndSym, SecondaryFunctionIds);<br>
@@ -3348,14 +3330,10 @@ bool AsmParser::parseDirectiveCVDefRange<br>
     Ranges.push_back({GapStartSym, GapEndSym});<br>
   }<br>
<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
   std::string FixedSizePortion;<br>
-  if (parseEscapedString(FixedSizePortion))<br>
+  if (parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      parseEscapedString(FixedSizePortion))<br>
     return true;<br>
-  Lex();<br>
<br>
   getStreamer().EmitCVDefRangeDirective(Ranges, FixedSizePortion);<br>
   return false;<br>
@@ -3414,6 +3392,9 @@ bool AsmParser::parseDirectiveCFIStartPr<br>
     if (parseIdentifier(Simple) || Simple != "simple")<br>
       return TokError("unexpected token in .cfi_startproc directive");<br>
<br>
+  if (parseToken(AsmToken::EndOfStatement, "Expected end of statement"))<br>
+    return true;<br>
+<br>
   getStreamer().EmitCFIStartProc(!Simple.empty());<br>
   return false;<br>
 }<br>
@@ -3443,16 +3424,10 @@ bool AsmParser::parseRegisterOrRegisterN<br>
 /// parseDirectiveCFIDefCfa<br>
 /// ::= .cfi_def_cfa register,  offset<br>
 bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {<br>
-  int64_t Register = 0;<br>
-  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))<br>
-    return true;<br>
-<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
-  int64_t Offset = 0;<br>
-  if (parseAbsoluteExpression(Offset))<br>
+  int64_t Register = 0, Offset = 0;<br>
+  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      parseAbsoluteExpression(Offset))<br>
     return true;<br>
<br>
   getStreamer().EmitCFIDefCfa(Register, Offset);<br>
@@ -3473,16 +3448,10 @@ bool AsmParser::parseDirectiveCFIDefCfaO<br>
 /// parseDirectiveCFIRegister<br>
 /// ::= .cfi_register register, register<br>
 bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {<br>
-  int64_t Register1 = 0;<br>
-  if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc))<br>
-    return true;<br>
-<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
-  int64_t Register2 = 0;<br>
-  if (parseRegisterOrRegisterNumber(Register2, DirectiveLoc))<br>
+  int64_t Register1 = 0, Register2 = 0;<br>
+  if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      parseRegisterOrRegisterNumber(Register2, DirectiveLoc))<br>
     return true;<br>
<br>
   getStreamer().EmitCFIRegister(Register1, Register2);<br>
@@ -3524,14 +3493,9 @@ bool AsmParser::parseDirectiveCFIOffset(<br>
   int64_t Register = 0;<br>
   int64_t Offset = 0;<br>
<br>
-  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))<br>
-    return true;<br>
-<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
-  if (parseAbsoluteExpression(Offset))<br>
+  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      parseAbsoluteExpression(Offset))<br>
     return true;<br>
<br>
   getStreamer().EmitCFIOffset(Register, Offset);<br>
@@ -3541,17 +3505,11 @@ bool AsmParser::parseDirectiveCFIOffset(<br>
 /// parseDirectiveCFIRelOffset<br>
 /// ::= .cfi_rel_offset register, offset<br>
 bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {<br>
-  int64_t Register = 0;<br>
-<br>
-  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))<br>
-    return true;<br>
+  int64_t Register = 0, Offset = 0;<br>
<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
-  int64_t Offset = 0;<br>
-  if (parseAbsoluteExpression(Offset))<br>
+  if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      parseAbsoluteExpression(Offset))<br>
     return true;<br>
<br>
   getStreamer().EmitCFIRelOffset(Register, Offset);<br>
@@ -3591,16 +3549,11 @@ bool AsmParser::parseDirectiveCFIPersona<br>
   if (Encoding == dwarf::DW_EH_PE_omit)<br>
     return false;<br>
<br>
-  if (!isValidEncoding(Encoding))<br>
-    return TokError("unsupported encoding.");<br>
-<br>
-  if (getLexer().isNot(AsmToken::Comma))<br>
-    return TokError("unexpected token in directive");<br>
-  Lex();<br>
-<br>
   StringRef Name;<br>
-  if (parseIdentifier(Name))<br>
-    return TokError("expected identifier in directive");<br>
+  if (check(!isValidEncoding(Encoding), "unsupported encoding.") ||<br>
+      parseToken(AsmToken::Comma, "unexpected token in directive") ||<br>
+      check(parseIdentifier(Name), "expected identifier in directive"))<br>
+    return true;<br>
<br>
   MCSymbol *Sym = getContext().getOrCreateSymbol(Name);<br>
<br>
@@ -3674,9 +3627,9 @@ bool AsmParser::parseDirectiveCFIEscape(<br>
 /// parseDirectiveCFISignalFrame<br>
 /// ::= .cfi_signal_frame<br>
 bool AsmParser::parseDirectiveCFISignalFrame() {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return Error(getLexer().getLoc(),<br>
-                 "unexpected token in '.cfi_signal_frame'");<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.cfi_signal_frame'"))<br>
+    return true;<br>
<br>
   getStreamer().EmitCFISignalFrame();<br>
   return false;<br>
@@ -3698,9 +3651,9 @@ bool AsmParser::parseDirectiveCFIUndefin<br>
 /// ::= .macros_on<br>
 /// ::= .macros_off<br>
 bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return Error(getLexer().getLoc(),<br>
-                 "unexpected token in '" + Directive + "' directive");<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '" + Directive + "' directive"))<br>
+    return true;<br>
<br>
   setMacrosEnabled(Directive == ".macros_on");<br>
   return false;<br>
@@ -3928,8 +3881,9 @@ void AsmParser::checkForBadMacro(SMLoc D<br>
 /// parseDirectiveExitMacro<br>
 /// ::= .exitm<br>
 bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '" + Directive + "' directive");<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '" + Directive + "' directive"))<br>
+    return true;<br>
<br>
   if (!isInsideMacroInstantiation())<br>
     return TokError("unexpected '" + Directive + "' in file, "<br>
@@ -3969,14 +3923,14 @@ bool AsmParser::parseDirectiveEndMacro(S<br>
 /// ::= .purgem<br>
 bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {<br>
   StringRef Name;<br>
-  if (parseIdentifier(Name))<br>
-    return TokError("expected identifier in '.purgem' directive");<br>
-<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.purgem' directive");<br>
-<br>
-  if (!lookupMacro(Name))<br>
-    return Error(DirectiveLoc, "macro '" + Name + "' is not defined");<br>
+  SMLoc Loc;<br>
+  if (getTokenLoc(Loc) || check(parseIdentifier(Name), Loc,<br>
+                                "expected identifier in '.purgem' directive") ||<br>
+      parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.purgem' directive") ||<br>
+      check(!lookupMacro(Name), DirectiveLoc,<br>
+            "macro '" + Name + "' is not defined"))<br>
+    return true;<br>
<br>
   undefineMacro(Name);<br>
   return false;<br>
@@ -3991,16 +3945,13 @@ bool AsmParser::parseDirectiveBundleAlig<br>
   // in the inclusive range 0-30.<br>
   SMLoc ExprLoc = getLexer().getLoc();<br>
   int64_t AlignSizePow2;<br>
-  if (parseAbsoluteExpression(AlignSizePow2))<br>
+  if (parseAbsoluteExpression(AlignSizePow2) ||<br>
+      parseToken(AsmToken::EndOfStatement, "unexpected token after expression "<br>
+                                           "in '.bundle_align_mode' "<br>
+                                           "directive") ||<br>
+      check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,<br>
+            "invalid bundle alignment size (expected between 0 and 30)"))<br>
     return true;<br>
-  else if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token after expression in"<br>
-                    " '.bundle_align_mode' directive");<br>
-  else if (AlignSizePow2 < 0 || AlignSizePow2 > 30)<br>
-    return Error(ExprLoc,<br>
-                 "invalid bundle alignment size (expected between 0 and 30)");<br>
-<br>
-  Lex();<br>
<br>
   // Because of AlignSizePow2's verified range we can safely truncate it to<br>
   // unsigned.<br>
@@ -4020,14 +3971,11 @@ bool AsmParser::parseDirectiveBundleLock<br>
     const char *kInvalidOptionError =<br>
         "invalid option for '.bundle_lock' directive";<br>
<br>
-    if (parseIdentifier(Option))<br>
-      return Error(Loc, kInvalidOptionError);<br>
-<br>
-    if (Option != "align_to_end")<br>
-      return Error(Loc, kInvalidOptionError);<br>
-    else if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return Error(Loc,<br>
-                   "unexpected token after '.bundle_lock' directive option");<br>
+    if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||<br>
+        check(Option != "align_to_end", Loc, kInvalidOptionError) ||<br>
+        check(getTok().isNot(AsmToken::EndOfStatement), Loc,<br>
+              "unexpected token after '.bundle_lock' directive option"))<br>
+      return true;<br>
     AlignToEnd = true;<br>
   }<br>
<br>
@@ -4042,9 +3990,9 @@ bool AsmParser::parseDirectiveBundleLock<br>
 bool AsmParser::parseDirectiveBundleUnlock() {<br>
   checkForValidSection();<br>
<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.bundle_unlock' directive");<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.bundle_unlock' directive"))<br>
+    return true;<br>
<br>
   getStreamer().EmitBundleUnlock();<br>
   return false;<br>
@@ -4062,18 +4010,16 @@ bool AsmParser::parseDirectiveSpace(Stri<br>
<br>
   int64_t FillExpr = 0;<br>
   if (getLexer().isNot(AsmToken::EndOfStatement)) {<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in '" + Twine(IDVal) + "' directive");<br>
-    Lex();<br>
<br>
-    if (parseAbsoluteExpression(FillExpr))<br>
+    if (parseToken(AsmToken::Comma,<br>
+                   "unexpected token in '" + Twine(IDVal) + "' directive") ||<br>
+        parseAbsoluteExpression(FillExpr))<br>
       return true;<br>
-<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return TokError("unexpected token in '" + Twine(IDVal) + "' directive");<br>
   }<br>
<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '" + Twine(IDVal) + "' directive"))<br>
+    return true;<br>
<br>
   // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0.<br>
   getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);<br>
@@ -4099,10 +4045,10 @@ bool AsmParser::parseDirectiveLEB128(boo<br>
     if (getLexer().is(AsmToken::EndOfStatement))<br>
       break;<br>
<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in directive");<br>
-    Lex();<br>
+    if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+      return true;<br>
   }<br>
+  Lex();<br>
<br>
   return false;<br>
 }<br>
@@ -4130,9 +4076,8 @@ bool AsmParser::parseDirectiveSymbolAttr<br>
       if (getLexer().is(AsmToken::EndOfStatement))<br>
         break;<br>
<br>
-      if (getLexer().isNot(AsmToken::Comma))<br>
-        return TokError("unexpected token in directive");<br>
-      Lex();<br>
+      if (parseToken(AsmToken::Comma, "unexpected token in directive"))<br>
+        return true;<br>
     }<br>
   }<br>
<br>
@@ -4221,10 +4166,9 @@ bool AsmParser::parseDirectiveAbort() {<br>
   SMLoc Loc = getLexer().getLoc();<br>
<br>
   StringRef Str = parseStringToEndOfStatement();<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.abort' directive");<br>
-<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.abort' directive"))<br>
+    return true;<br>
<br>
   if (Str.empty())<br>
     Error(Loc, ".abort detected. Assembly stopping.");<br>
@@ -4238,25 +4182,20 @@ bool AsmParser::parseDirectiveAbort() {<br>
 /// parseDirectiveInclude<br>
 ///  ::= .include "filename"<br>
 bool AsmParser::parseDirectiveInclude() {<br>
-  if (getLexer().isNot(AsmToken::String))<br>
-    return TokError("expected string in '.include' directive");<br>
-<br>
   // Allow the strings to have escaped octal character sequence.<br>
   std::string Filename;<br>
-  if (parseEscapedString(Filename))<br>
-    return true;<br>
-  SMLoc IncludeLoc = getLexer().getLoc();<br>
-  Lex();<br>
+  SMLoc IncludeLoc = getTok().getLoc();<br>
<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.include' directive");<br>
-<br>
-  // Attempt to switch the lexer to the included file before consuming the end<br>
-  // of statement to avoid losing it when we switch.<br>
-  if (enterIncludeFile(Filename)) {<br>
-    Error(IncludeLoc, "Could not find include file '" + Filename + "'");<br>
+  if (check(getTok().isNot(AsmToken::String),<br>
+            "expected string in '.include' directive") ||<br>
+      parseEscapedString(Filename) ||<br>
+      check(getTok().isNot(AsmToken::EndOfStatement),<br>
+            "unexpected token in '.include' directive") ||<br>
+      // Attempt to switch the lexer to the included file before consuming the<br>
+      // end of statement to avoid losing it when we switch.<br>
+      check(enterIncludeFile(Filename), IncludeLoc,<br>
+            "Could not find include file '" + Filename + "'"))<br>
     return true;<br>
-  }<br>
<br>
   return false;<br>
 }<br>
@@ -4264,25 +4203,18 @@ bool AsmParser::parseDirectiveInclude()<br>
 /// parseDirectiveIncbin<br>
 ///  ::= .incbin "filename"<br>
 bool AsmParser::parseDirectiveIncbin() {<br>
-  if (getLexer().isNot(AsmToken::String))<br>
-    return TokError("expected string in '.incbin' directive");<br>
-<br>
   // Allow the strings to have escaped octal character sequence.<br>
   std::string Filename;<br>
-  if (parseEscapedString(Filename))<br>
+  SMLoc IncbinLoc = getTok().getLoc();<br>
+  if (check(getTok().isNot(AsmToken::String),<br>
+            "expected string in '.incbin' directive") ||<br>
+      parseEscapedString(Filename) ||<br>
+      parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.incbin' directive") ||<br>
+      // Attempt to process the included file.<br>
+      check(processIncbinFile(Filename), IncbinLoc,<br>
+            "Could not find incbin file '" + Filename + "'"))<br>
     return true;<br>
-  SMLoc IncbinLoc = getLexer().getLoc();<br>
-  Lex();<br>
-<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.incbin' directive");<br>
-<br>
-  // Attempt to process the included file.<br>
-  if (processIncbinFile(Filename)) {<br>
-    Error(IncbinLoc, "Could not find incbin file '" + Filename + "'");<br>
-    return true;<br>
-  }<br>
-<br>
   return false;<br>
 }<br>
<br>
@@ -4295,14 +4227,11 @@ bool AsmParser::parseDirectiveIf(SMLoc D<br>
     eatToEndOfStatement();<br>
   } else {<br>
     int64_t ExprValue;<br>
-    if (parseAbsoluteExpression(ExprValue))<br>
+    if (parseAbsoluteExpression(ExprValue) ||<br>
+        parseToken(AsmToken::EndOfStatement,<br>
+                   "unexpected token in '.if' directive"))<br>
       return true;<br>
<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return TokError("unexpected token in '.if' directive");<br>
-<br>
-    Lex();<br>
-<br>
     switch (DirKind) {<br>
     default:<br>
       llvm_unreachable("unsupported directive");<br>
@@ -4344,10 +4273,9 @@ bool AsmParser::parseDirectiveIfb(SMLoc<br>
   } else {<br>
     StringRef Str = parseStringToEndOfStatement();<br>
<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return TokError("unexpected token in '.ifb' directive");<br>
-<br>
-    Lex();<br>
+    if (parseToken(AsmToken::EndOfStatement,<br>
+                   "unexpected token in '.ifb' directive"))<br>
+      return true;<br>
<br>
     TheCondState.CondMet = ExpectBlank == Str.empty();<br>
     TheCondState.Ignore = !TheCondState.CondMet;<br>
@@ -4368,17 +4296,14 @@ bool AsmParser::parseDirectiveIfc(SMLoc<br>
   } else {<br>
     StringRef Str1 = parseStringToComma();<br>
<br>
-    if (getLexer().isNot(AsmToken::Comma))<br>
-      return TokError("unexpected token in '.ifc' directive");<br>
-<br>
-    Lex();<br>
+    if (parseToken(AsmToken::Comma, "unexpected token in '.ifc' directive"))<br>
+      return true;<br>
<br>
     StringRef Str2 = parseStringToEndOfStatement();<br>
<br>
-    if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-      return TokError("unexpected token in '.ifc' directive");<br>
-<br>
-    Lex();<br>
+    if (parseToken(AsmToken::EndOfStatement,<br>
+                   "unexpected token in '.ifc' directive"))<br>
+      return true;<br>
<br>
     TheCondState.CondMet = ExpectEqual == (Str1.trim() == Str2.trim());<br>
     TheCondState.Ignore = !TheCondState.CondMet;<br>
@@ -4443,10 +4368,9 @@ bool AsmParser::parseDirectiveIfdef(SMLo<br>
   if (TheCondState.Ignore) {<br>
     eatToEndOfStatement();<br>
   } else {<br>
-    if (parseIdentifier(Name))<br>
-      return TokError("expected identifier after '.ifdef'");<br>
-<br>
-    Lex();<br>
+    if (check(parseIdentifier(Name), "expected identifier after '.ifdef'") ||<br>
+        parseToken(AsmToken::EndOfStatement, "unexpected token in '.ifdef'"))<br>
+      return true;<br>
<br>
     MCSymbol *Sym = getContext().lookupSymbol(Name);<br>
<br>
@@ -4494,10 +4418,9 @@ bool AsmParser::parseDirectiveElseIf(SML<br>
 /// parseDirectiveElse<br>
 /// ::= .else<br>
 bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.else' directive");<br>
-<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.else' directive"))<br>
+    return true;<br>
<br>
   if (TheCondState.TheCond != AsmCond::IfCond &&<br>
       TheCondState.TheCond != AsmCond::ElseIfCond)<br>
@@ -4518,10 +4441,9 @@ bool AsmParser::parseDirectiveElse(SMLoc<br>
 /// parseDirectiveEnd<br>
 /// ::= .end<br>
 bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.end' directive");<br>
-<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.end' directive"))<br>
+    return true;<br>
<br>
   while (Lexer.isNot(AsmToken::Eof))<br>
     Lex();<br>
@@ -4588,10 +4510,9 @@ bool AsmParser::parseDirectiveWarning(SM<br>
 /// parseDirectiveEndIf<br>
 /// ::= .endif<br>
 bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {<br>
-  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '.endif' directive");<br>
-<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '.endif' directive"))<br>
+    return true;<br>
<br>
   if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty())<br>
     Error(DirectiveLoc, "Encountered a .endif that doesn't follow a .if or "<br>
@@ -4808,14 +4729,10 @@ bool AsmParser::parseDirectiveRept(SMLoc<br>
     return Error(CountLoc, "unexpected token in '" + Dir + "' directive");<br>
   }<br>
<br>
-  if (Count < 0)<br>
-    return Error(CountLoc, "Count is negative");<br>
-<br>
-  if (Lexer.isNot(AsmToken::EndOfStatement))<br>
-    return TokError("unexpected token in '" + Dir + "' directive");<br>
-<br>
-  // Eat the end of statement.<br>
-  Lex();<br>
+  if (check(Count < 0, CountLoc, "Count is negative") ||<br>
+      parseToken(AsmToken::EndOfStatement,<br>
+                 "unexpected token in '" + Dir + "' directive"))<br>
+    return true;<br>
<br>
   // Lex the rept definition.<br>
   MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);<br>
@@ -4840,22 +4757,14 @@ bool AsmParser::parseDirectiveRept(SMLoc<br>
 /// ::= .irp symbol,values<br>
 bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {<br>
   MCAsmMacroParameter Parameter;<br>
-<br>
-  if (parseIdentifier(Parameter.Name))<br>
-    return TokError("expected identifier in '.irp' directive");<br>
-<br>
-  if (Lexer.isNot(AsmToken::Comma))<br>
-    return TokError("expected comma in '.irp' directive");<br>
-<br>
-  Lex();<br>
-<br>
   MCAsmMacroArguments A;<br>
-  if (parseMacroArguments(nullptr, A))<br>
+  if (check(parseIdentifier(Parameter.Name),<br>
+            "expected identifier in '.irp' directive") ||<br>
+      parseToken(AsmToken::Comma, "expected comma in '.irp' directive") ||<br>
+      parseMacroArguments(nullptr, A) ||<br>
+      parseToken(AsmToken::EndOfStatement, "expected End of Statement"))<br>
     return true;<br>
<br>
-  // Eat the end of statement.<br>
-  Lex();<br>
-<br>
   // Lex the irp definition.<br>
   MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);<br>
   if (!M)<br>
@@ -4882,24 +4791,20 @@ bool AsmParser::parseDirectiveIrp(SMLoc<br>
 /// ::= .irpc symbol,values<br>
 bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {<br>
   MCAsmMacroParameter Parameter;<br>
-<br>
-  if (parseIdentifier(Parameter.Name))<br>
-    return TokError("expected identifier in '.irpc' directive");<br>
-<br>
-  if (Lexer.isNot(AsmToken::Comma))<br>
-    return TokError("expected comma in '.irpc' directive");<br>
-<br>
-  Lex();<br>
-<br>
   MCAsmMacroArguments A;<br>
-  if (parseMacroArguments(nullptr, A))<br>
+<br>
+  if (check(parseIdentifier(Parameter.Name),<br>
+            "expected identifier in '.irpc' directive") ||<br>
+      parseToken(AsmToken::Comma, "expected comma in '.irpc' directive") ||<br>
+      parseMacroArguments(nullptr, A))<br>
     return true;<br>
<br>
   if (A.size() != 1 || A.front().size() != 1)<br>
     return TokError("unexpected token in '.irpc' directive");<br>
<br>
   // Eat the end of statement.<br>
-  Lex();<br>
+  if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))<br>
+    return true;<br>
<br>
   // Lex the irpc definition.<br>
   MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);<br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp Mon Jul 18 10:24:03 2016<br>
@@ -537,7 +537,6 @@ bool DarwinAsmParser::parseDirectiveLink<br>
<br>
     Args.push_back(Data);<br>
<br>
-    Lex();<br>
     if (getLexer().is(AsmToken::EndOfStatement))<br>
       break;<br>
<br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=275795&r1=275794&r2=275795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Mon Jul 18 10:24:03 2016<br>
@@ -212,6 +212,7 @@ bool ELFAsmParser::ParseDirectiveSize(St<br>
<br>
   if (getLexer().isNot(AsmToken::EndOfStatement))<br>
     return TokError("unexpected token in directive");<br>
+  Lex();<br>
<br>
   getStreamer().emitELFSize(Sym, Expr);<br>
   return false;<br>
@@ -478,6 +479,7 @@ bool ELFAsmParser::ParseSectionArguments<br>
 EndStmt:<br>
   if (getLexer().isNot(AsmToken::EndOfStatement))<br>
     return TokError("unexpected token in directive");<br>
+  Lex();<br>
<br>
   unsigned Type = ELF::SHT_PROGBITS;<br>
<br>
@@ -629,6 +631,10 @@ bool ELFAsmParser::ParseDirectiveIdent(S<br>
<br>
   Lex();<br>
<br>
+  if (getLexer().isNot(AsmToken::EndOfStatement))<br>
+    return TokError("unexpected token in '.ident' directive");<br>
+  Lex();<br>
+<br>
   getStreamer().EmitIdent(Data);<br>
   return false;<br>
 }<br>
@@ -727,6 +733,8 @@ bool ELFAsmParser::ParseDirectiveSubsect<br>
   if (getLexer().isNot(AsmToken::EndOfStatement))<br>
     return TokError("unexpected token in directive");<br>
<br>
+  Lex();<br>
+<br>
   getStreamer().SubSection(Subsection);<br>
   return false;<br>
 }<br>
<br>
Modified: llvm/trunk/test/MC/AsmParser/preserve-comments.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/preserve-comments.s?rev=275795&r1=275794&r2=275795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/preserve-comments.s?rev=275795&r1=275794&r2=275795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/AsmParser/preserve-comments.s (original)<br>
+++ llvm/trunk/test/MC/AsmParser/preserve-comments.s Mon Jul 18 10:24:03 2016<br>
@@ -9,3 +9,5 @@ foo:    #Comment here<br>
        ## WHOLE LINE COMMENT<br>
        cmpl    $196, %eax      ## EOL COMMENT<br>
        #endif<br>
+       .ident  "clang version 3.9.0"<br>
+       .section        ".note.GNU-stack","",@progbits<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div>