Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlir/lib/AsmParser/AttributeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ DenseElementsAttr TensorLiteralParser::getStringAttr(SMLoc loc, ShapedType type,
stringRefValues.reserve(storage.size());

for (auto val : storage) {
if (!val.second.is(Token::string)) {
p.emitError(loc) << "expected string token, got "
<< val.second.getSpelling();
return nullptr;
}
stringValues.push_back(val.second.getStringValue());
stringRefValues.emplace_back(stringValues.back());
}
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/IR/invalid-builtin-attributes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,13 @@ func.func @print_error_on_correct_line() {
sparse <> : i32
return
}

// -----

// Prevent assertions when parsing a dense attribute expected to be a string
// but encountering a different type.
func.func @expect_to_parse_literal() {
// expected-error@below {{expected string token, got 23}}
%0 = arith.constant dense<[23]> : tensor<1x!unknown<>>
return
}