[PATCH] D46491: [MIRPraser] Improve error checking for typed immediate operands
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 5 13:58:14 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331600: [MIRPraser] Improve error checking for typed immediate operands (authored by aheejin, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D46491
Files:
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
Index: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
@@ -1303,11 +1303,11 @@
}
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 @@
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::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();
Index: llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
===================================================================
--- llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
+++ llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
@@ -0,0 +1,13 @@
+# RUN: not llc -mtriple=wasm32-unknown-unknown -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a typed immediate operand does not start with 'i', 's', or 'p'
+---
+name: test_typed_immediate_operand_invalid1
+liveins:
+ - { reg: '$arguments' }
+body: |
+ bb.0:
+ liveins: $arguments
+ ; CHECK: [[@LINE+1]]:24: A typed immediate operand should start with one of 'i', 's', or 'p'
+ %0:i32 = CONST_I32 abc 0, implicit-def dead $arguments
+ RETURN_VOID implicit-def dead $arguments
+...
Index: llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
===================================================================
--- llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
+++ llvm/trunk/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
@@ -0,0 +1,13 @@
+# RUN: not llc -mtriple=wasm32-unknown-unknown -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a typed immediate operand is only a single 'i'/'s'/'p' character
+---
+name: test_typed_immediate_operand_invalid0
+liveins:
+ - { reg: '$arguments' }
+body: |
+ bb.0:
+ liveins: $arguments
+ ; CHECK: [[@LINE+1]]:24: Expected integers after 'i'/'s'/'p' type character
+ %0:i32 = CONST_I32 i 0, implicit-def dead $arguments
+ RETURN_VOID implicit-def dead $arguments
+...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46491.145381.patch
Type: text/x-patch
Size: 3711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180505/017e38c7/attachment.bin>
More information about the llvm-commits
mailing list