[PATCH] D60515: Add a valid token check before parsing a ds directive
Brandon Jones via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 08:23:19 PDT 2019
BrandonTJones created this revision.
BrandonTJones added reviewers: andreadb, grosbach.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
Repository:
rL LLVM
https://reviews.llvm.org/D60515
Files:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/AsmParser/directive_ds.s
Index: llvm/test/MC/AsmParser/directive_ds.s
===================================================================
--- llvm/test/MC/AsmParser/directive_ds.s
+++ llvm/test/MC/AsmParser/directive_ds.s
@@ -56,3 +56,7 @@
# CHECK-ERROR: error: unexpected token in '.ds' directive
TEST9:
.ds 1 2
+
+# CHECK-ERROR: error: directive only accepts integer values
+TEST10:
+ .ds 5.0
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -4676,15 +4676,20 @@
/// ::= .ds.{b, d, l, p, s, w, x} expression
bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) {
SMLoc NumValuesLoc = Lexer.getLoc();
- int64_t NumValues;
- if (checkForValidSection() || parseAbsoluteExpression(NumValues))
- return true;
-
- if (NumValues < 0) {
+ if (Lexer.getKind() == AsmToken::Plus)
+ Lexer.Lex();
+ else if (Lexer.getKind() == AsmToken::Minus) {
Warning(NumValuesLoc, "'" + Twine(IDVal) + "' directive with negative repeat count has no effect");
return false;
}
+ if (Lexer.getKind() != AsmToken::Integer)
+ return Error(NumValuesLoc, "directive only accepts integer values");
+
+ int64_t NumValues;
+ if (checkForValidSection() || parseAbsoluteExpression(NumValues))
+ return true;
+
if (parseToken(AsmToken::EndOfStatement,
"unexpected token in '" + Twine(IDVal) + "' directive"))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60515.194523.patch
Type: text/x-patch
Size: 1498 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190410/ae1e60a3/attachment.bin>
More information about the llvm-commits
mailing list