[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 03:09:51 PDT 2018
aheejin created this revision.
aheejin added a reviewer: rtereshin.
Herald added subscribers: llvm-commits, jgravelle-google, sbc100, dschuff.
This improves error checks for typed immediate operands introduced in
https://reviews.llvm.org/D45948 (https://reviews.llvm.org/rL331586), and removes a code block copied by mistake.
Repository:
rL LLVM
https://reviews.llvm.org/D46491
Files:
lib/CodeGen/MIRParser/MIParser.cpp
test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
Index: test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir
===================================================================
--- /dev/null
+++ 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: test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
===================================================================
--- /dev/null
+++ 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
+...
Index: lib/CodeGen/MIRParser/MIParser.cpp
===================================================================
--- lib/CodeGen/MIRParser/MIParser.cpp
+++ 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46491.145358.patch
Type: text/x-patch
Size: 3500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180505/65d89fc8/attachment.bin>
More information about the llvm-commits
mailing list