llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir][bug] Parsing a string in an integer dense tensor aborts in TensorLiteralParser

Open Kiritobl opened this issue 2 months ago • 1 comments

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'

Kiritobl avatar Oct 04 '26 07:10 Kiritobl

@llvm/issue-subscribers-mlir

Author: Peixiang Qin (Kiritobl)

#### 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&lt;["oops"]&gt; : tensor&lt;1xi1&gt;`
  → `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&lt;["oops"]&gt; : tensor&lt;1xi1&gt;} : () -&gt; () }

Stack Dump

mlir-opt: AttributeParser.cpp:649: llvm::ParseResult (anonymous namespace)::TensorLiteralParser::getIntAttrElements(llvm::SMLoc, mlir::Type, std::vector&lt;APInt&gt; &amp;): Assertion `token.isAny(Token::integer, Token::kw_true, Token::kw_false) &amp;&amp; "unexpected token type"' failed.
Stack dump:
0.  Program arguments: mlir-opt reproducer.mlir -o &lt;output&gt;
1.	MLIR Parser: custom op parser 'builtin.module'
</details>