Skip to content

Commit f4085c5

Browse files
committed
[mlir] Fix two AttributeParser aborts
Reproducers that resulted in triggering the following asserts mlir::NamedAttribute::NamedAttribute(mlir::StringAttr, mlir::Attribute) mlir/lib/IR/Attributes.cpp:29:3 consumeToken mlir/lib/Parser/Parser.h:126 Differential Revision: https://reviews.llvm.org/D122240
1 parent a6efcf1 commit f4085c5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mlir/lib/Parser/AttributeParser.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ Attribute Parser::parseAttribute(Type type) {
169169
const char *curPointer = getToken().getLoc().getPointer();
170170
consumeToken(Token::colon);
171171
if (!consumeIf(Token::colon)) {
172-
state.lex.resetPointer(curPointer);
173-
consumeToken();
172+
if (getToken().isNot(Token::eof, Token::error)) {
173+
state.lex.resetPointer(curPointer);
174+
consumeToken();
175+
}
174176
break;
175177
}
176178
// Parse the reference itself.
@@ -271,6 +273,10 @@ ParseResult Parser::parseAttributeDict(NamedAttrList &attributes) {
271273
nameId = builder.getStringAttr(getTokenSpelling());
272274
else
273275
return emitError("expected attribute name");
276+
277+
if (nameId->size() == 0)
278+
return emitError("expected valid attribute name");
279+
274280
if (!seenKeys.insert(*nameId).second)
275281
return emitError("duplicate key '")
276282
<< nameId->getValue() << "' in dictionary attribute";

mlir/test/IR/invalid.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,3 +1643,14 @@ func @invalid_region_dominance_with_dominance_free_regions() {
16431643
// -----
16441644
16451645
func @foo() {} // expected-error {{expected non-empty function body}}
1646+
1647+
// -----
1648+
1649+
// expected-error@+1 {{expected valid attribute name}}
1650+
"t"(){""}
1651+
1652+
// -----
1653+
1654+
// expected-error@+2 {{expected ']'}}
1655+
"f"() { b = [@m:
1656+

0 commit comments

Comments
 (0)