[mlir][bug] Parsing a string in an integer dense tensor aborts in TensorLiteralParser
Version
git commit hash: 2a96d5737524012839e786699a0b327f22d1cfee
Bug Description
An integer dense tensor attribute containing a string literal aborts in TensorLiteralParser::getIntAttrElements. The input is invalid, but mlir-opt should emit a parser diagnostic instead of terminating with an assertion.
Crash Chain & Root Cause
Location: mlir/lib/AsmParser/AttributeParser.cpp.
Crash flow:
mlir-opt parses `dense<["oops"]> : tensor<1xi1>`
→ `Parser::parseDenseElementsAttr()`
→ `TensorLiteralParser::getAttr()`
→ `TensorLiteralParser::getIntAttrElements()`
→ assertion: unexpected token type
The integer-element parser assumes every tensor element token is an integer or boolean. A string token violates that assumption and reaches an assertion instead of a parse error.
Steps to Reproduce
Run the following command with the provided reproducer MLIR:
mlir-opt reproducer.mlir -o /dev/null
Reproducer (reproducer.mlir)
module { "test.op"() {x = dense<["oops"]> : tensor<1xi1>} : () -> () }
Stack Dump
mlir-opt: AttributeParser.cpp:649: llvm::ParseResult (anonymous namespace)::TensorLiteralParser::getIntAttrElements(llvm::SMLoc, mlir::Type, std::vector<APInt> &): Assertion `token.isAny(Token::integer, Token::kw_true, Token::kw_false) && "unexpected token type"' failed.
Stack dump:
0. Program arguments: mlir-opt reproducer.mlir -o <output>
1. MLIR Parser: custom op parser 'builtin.module'
@llvm/issue-subscribers-mlir
Author: Peixiang Qin (Kiritobl)
git commit hash: 2a96d5737524012839e786699a0b327f22d1cfee
Bug Description
An integer dense tensor attribute containing a string literal aborts in TensorLiteralParser::getIntAttrElements. The input is invalid, but mlir-opt should emit a parser diagnostic instead of terminating with an assertion.
Crash Chain & Root Cause
Location: mlir/lib/AsmParser/AttributeParser.cpp.
Crash flow:
mlir-opt parses `dense<["oops"]> : tensor<1xi1>`
→ `Parser::parseDenseElementsAttr()`
→ `TensorLiteralParser::getAttr()`
→ `TensorLiteralParser::getIntAttrElements()`
→ assertion: unexpected token type
The integer-element parser assumes every tensor element token is an integer or boolean. A string token violates that assumption and reaches an assertion instead of a parse error.
Steps to Reproduce
Run the following command with the provided reproducer MLIR:
mlir-opt reproducer.mlir -o /dev/null
Reproducer (reproducer.mlir)
module { "test.op"() {x = dense<["oops"]> : tensor<1xi1>} : () -> () }
Stack Dump
mlir-opt: AttributeParser.cpp:649: llvm::ParseResult (anonymous namespace)::TensorLiteralParser::getIntAttrElements(llvm::SMLoc, mlir::Type, std::vector<APInt> &): Assertion `token.isAny(Token::integer, Token::kw_true, Token::kw_false) && "unexpected token type"' failed.
Stack dump:
0. Program arguments: mlir-opt reproducer.mlir -o <output>
1. MLIR Parser: custom op parser 'builtin.module'
</details>