[llvm] r198099 - AsmParser: cleanup diagnostics for .rep/.rept

Saleem Abdulrasool compnerd at compnerd.org
Fri Dec 27 22:39:30 PST 2013


Author: compnerd
Date: Sat Dec 28 00:39:29 2013
New Revision: 198099

URL: http://llvm.org/viewvc/llvm-project?rev=198099&view=rev
Log:
AsmParser: cleanup diagnostics for .rep/.rept

Avoid double diagnostics for invalid expressions for count.  Improve caret
location for negative count.

Added:
    llvm/trunk/test/MC/AsmParser/directive_rept-diagnostics.s
Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=198099&r1=198098&r2=198099&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sat Dec 28 00:39:29 2013
@@ -3958,12 +3958,19 @@ void AsmParser::instantiateMacroLikeBody
 /// parseDirectiveRept
 ///   ::= .rep | .rept count
 bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
+  const MCExpr *CountExpr;
+  SMLoc CountLoc = getTok().getLoc();
+  if (parseExpression(CountExpr))
+    return true;
+
   int64_t Count;
-  if (parseAbsoluteExpression(Count))
-    return TokError("unexpected token in '" + Dir + "' directive");
+  if (!CountExpr->EvaluateAsAbsolute(Count)) {
+    eatToEndOfStatement();
+    return Error(CountLoc, "unexpected token in '" + Dir + "' directive");
+  }
 
   if (Count < 0)
-    return TokError("Count is negative");
+    return Error(CountLoc, "Count is negative");
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '" + Dir + "' directive");

Added: llvm/trunk/test/MC/AsmParser/directive_rept-diagnostics.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_rept-diagnostics.s?rev=198099&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_rept-diagnostics.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_rept-diagnostics.s Sat Dec 28 00:39:29 2013
@@ -0,0 +1,41 @@
+# RUN: not llvm-mc -triple i686-elf -filetype asm -o /dev/null %s 2>&1 \
+# RUN:   | FileCheck %s
+
+	.data
+
+	.global invalid_expression
+	.type invalid_expression, at object
+invalid_expression:
+	.rept *
+
+# CHECK: error: unknown token in expression
+# CHECK: 	.rept *
+# CHECK:              ^
+
+	.global bad_token
+	.type bad_token, at object
+bad_token:
+	.rept bad_token
+
+# CHECK: error: unexpected token in '.rept' directive
+# CHECK: 	.rept bad_token
+# CHECK:              ^
+
+	.global negative
+	.type negative, at object
+negative:
+	.rept -32
+
+# CHECK: error: Count is negative
+# CHECK: 	.rept -32
+# CHECK:              ^
+
+	.global trailer
+	.type trailer, at object
+trailer:
+	.rep 0 trailer
+
+# CHECK: error: unexpected token in '.rep' directive
+# CHECK: 	.rep 0 trailer
+# CHECK:               ^
+





More information about the llvm-commits mailing list