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 '' 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-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 +... 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 +...