diff options
author | Heejin Ahn <aheejin@gmail.com> | 2018-05-05 20:53:23 +0000 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2018-05-05 20:53:23 +0000 |
commit | c86da6bcfe16e9334e492c6fa774e028e3f1123a (patch) | |
tree | 2c96fb14e788bb1af1cbe42b0d4918d564a1bd13 /llvm/lib/CodeGen/MIRParser/MIParser.cpp | |
parent | 862eebb6d6dcab31b2bcac6717d928bfc3ed5caa (diff) | |
download | llvm-c86da6bcfe16e9334e492c6fa774e028e3f1123a.zip llvm-c86da6bcfe16e9334e492c6fa774e028e3f1123a.tar.gz llvm-c86da6bcfe16e9334e492c6fa774e028e3f1123a.tar.bz2 |
[MIRPraser] Improve error checking for typed immediate operands
Summary:
This improves error checks for typed immediate operands introduced in
D45948 (rL331586), and removes a code block copied by mistake.
Reviewers: rtereshin
Subscribers: dschuff, sbc100, jgravelle-google, llvm-commits
Differential Revision: https://reviews.llvm.org/D46491
llvm-svn: 331600
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MIParser.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 3cc42582..acb4ab6 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -1303,11 +1303,11 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { } bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { - if (Token.range().front() == 's' || Token.range().front() == 'p') - if (!llvm::all_of(Token.range().drop_front(), isdigit)) + if (Token.range().front() == 's' || Token.range().front() == 'p') { + StringRef SizeStr = Token.range().drop_front(); + if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit)) return error("Expected integers after 's'/'p' type character"); - if (!llvm::all_of(Token.range().drop_front(), isdigit)) - return error("Expected integers after 's'/'p' type character"); + } if (Token.range().front() == 's') { Ty = LLT::scalar(APSInt(Token.range().drop_front()).getZExtValue()); @@ -1339,7 +1339,8 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { if (Token.range().front() != 's') return error(Loc, "expected '<N x sM>' for vector type"); - if (!llvm::all_of(Token.range().drop_front(), isdigit)) + StringRef SizeStr = Token.range().drop_front(); + if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit)) return error("Expected integers after 's' type character"); uint64_t ScalarSize = APSInt(Token.range().drop_front()).getZExtValue(); lex(); @@ -1354,7 +1355,13 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) { assert(Token.is(MIToken::Identifier)); - if (!llvm::all_of(Token.range().drop_front(), isdigit)) + StringRef TypeStr = Token.range(); + if (TypeStr.front() != 'i' && TypeStr.front() != 's' && + TypeStr.front() != 'p') + return error( + "A typed immediate operand should start with one of 'i', 's', or 'p'"); + StringRef SizeStr = Token.range().drop_front(); + if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit)) return error("Expected integers after 'i'/'s'/'p' type character"); auto Loc = Token.location(); |