[Mlir-commits] [mlir] f4085c5 - [mlir] Fix two AttributeParser aborts
Jacques Pienaar
llvmlistbot at llvm.org
Mon Apr 18 09:30:41 PDT 2022
Author: Jacques Pienaar
Date: 2022-04-18T09:30:35-07:00
New Revision: f4085c57ddfc1490560213e4611e434d25f84675
URL: https://github.com/llvm/llvm-project/commit/f4085c57ddfc1490560213e4611e434d25f84675
DIFF: https://github.com/llvm/llvm-project/commit/f4085c57ddfc1490560213e4611e434d25f84675.diff
LOG: [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
Added:
Modified:
mlir/lib/Parser/AttributeParser.cpp
mlir/test/IR/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp
index 15d8b17fbdf3c..562b4fe7e5113 100644
--- a/mlir/lib/Parser/AttributeParser.cpp
+++ b/mlir/lib/Parser/AttributeParser.cpp
@@ -169,8 +169,10 @@ Attribute Parser::parseAttribute(Type type) {
const char *curPointer = getToken().getLoc().getPointer();
consumeToken(Token::colon);
if (!consumeIf(Token::colon)) {
- state.lex.resetPointer(curPointer);
- consumeToken();
+ if (getToken().isNot(Token::eof, Token::error)) {
+ state.lex.resetPointer(curPointer);
+ consumeToken();
+ }
break;
}
// Parse the reference itself.
@@ -271,6 +273,10 @@ ParseResult Parser::parseAttributeDict(NamedAttrList &attributes) {
nameId = builder.getStringAttr(getTokenSpelling());
else
return emitError("expected attribute name");
+
+ if (nameId->size() == 0)
+ return emitError("expected valid attribute name");
+
if (!seenKeys.insert(*nameId).second)
return emitError("duplicate key '")
<< nameId->getValue() << "' in dictionary attribute";
diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index da3278b09b23b..7c60f12fe6ffb 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -1643,3 +1643,14 @@ func @invalid_region_dominance_with_dominance_free_regions() {
// -----
func @foo() {} // expected-error {{expected non-empty function body}}
+
+// -----
+
+// expected-error at +1 {{expected valid attribute name}}
+"t"(){""}
+
+// -----
+
+// expected-error at +2 {{expected ']'}}
+"f"() { b = [@m:
+
More information about the Mlir-commits
mailing list