Verify that the parsed predicate attribute of a cmpi operation is a string.

PiperOrigin-RevId: 229419703
This commit is contained in:
River Riddle 2019-01-15 12:33:09 -08:00 committed by jpienaar
parent 0e58de70e7
commit f8341cfe06
2 changed files with 16 additions and 5 deletions

View File

@ -536,9 +536,9 @@ void CmpIOp::build(Builder *build, OperationState *result,
bool CmpIOp::parse(OpAsmParser *parser, OperationState *result) {
SmallVector<OpAsmParser::OperandType, 2> ops;
SmallVector<NamedAttribute, 4> attrs;
StringAttr predicateName;
Attribute predicateNameAttr;
Type type;
if (parser->parseAttribute(predicateName, getPredicateAttrName().data(),
if (parser->parseAttribute(predicateNameAttr, getPredicateAttrName().data(),
attrs) ||
parser->parseComma() || parser->parseOperandList(ops, 2) ||
parser->parseOptionalAttributeDict(attrs) ||
@ -546,12 +546,17 @@ bool CmpIOp::parse(OpAsmParser *parser, OperationState *result) {
parser->resolveOperands(ops, type, result->operands))
return true;
if (!predicateNameAttr.isa<StringAttr>())
return parser->emitError(parser->getNameLoc(),
"expected string comparison predicate attribute");
// Rewrite string attribute to an enum value.
auto predicate = getPredicateByName(predicateName.getValue());
StringRef predicateName = predicateNameAttr.cast<StringAttr>().getValue();
auto predicate = getPredicateByName(predicateName);
if (predicate == CmpIPredicate::NumPredicates)
return parser->emitError(parser->getNameLoc(),
"unknown comparison predicate \"" +
Twine(predicateName.getValue()) + "\"");
"unknown comparison predicate \"" + predicateName +
"\"");
auto builder = parser->getBuilder();
Type i1Type = getCheckedI1SameShape(&builder, type);

View File

@ -506,3 +506,9 @@ func @dma_wait_no_tag_memref(%tag : f32, %c0 : index) {
// expected-error@+1 {{expected tag to be of memref type}}
dma_wait %tag[%c0], %arg0 : f32
}
// -----
func @invalid_cmp_attr(%idx : i32) {
// expected-error@+1 {{expected string comparison predicate attribute}}
%cmp = cmpi i1, %idx, %idx : i32