Issue 234633
Summary [MLIR][Arith][fuzzer-found] arith.truncf verification casts an unranked tensor to RankedTensorType
Labels
Assignees
Reporter Kiritobl
    Version

git commit hash:  059577967e64f14231b35bcd57f2b88c29909afc

LLVM/MLIR 24.0.0git, optimized build with assertions.

#### Bug Description

The generic `arith.truncf` below takes and returns unranked floating-point tensors. `mlir-opt` aborts while checking generated operation invariants, before the operation can be diagnosed or accepted.

#### Crash Chain & Root Cause

**Crash chain:**

```text
`arith.truncf` invariant verification
  → generated `SameInputOutputTensorDims` predicate
  → `TensorType::getShape()` on `tensor<*xf64>` / `tensor<*xf32>`
  → `cast<RankedTensorType>`
  → incompatible-type assertion
```

`Arith_TruncFOp` declares the `SameInputOutputTensorDims` predicate. Its TableGen _expression_ calls `TensorType::getShape()` for any `TensorType`, but `TensorType` also includes unranked tensors. `getShape()` requires a `RankedTensorType` and asserts for the unranked input or result. The predicate needs to distinguish ranked from unranked tensors and either compare available shapes or emit a verifier diagnostic.

#### Steps to Reproduce

Run the following command with the provided reproducer MLIR:

```bash
mlir-opt reproducer.mlir -o /dev/null
```

The command returns 134 (`SIGABRT`) during invariant verification, before any pass runs.

#### Reproducer (`reproducer.mlir`)

```mlir
module {
  func.func @f(%arg0: tensor<*xf64>) {
    %0 = "arith.truncf"(%arg0) : (tensor<*xf64>) -> tensor<*xf32>
    return
  }
}
```

#### Stack Dump

```text
mlir-opt: llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From&) [with To = mlir::RankedTensorType; From = mlir::TensorType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: mlir-opt reproducer.mlir -o /dev/null
 #0 0x00005617314ca669 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1f9b669)
 #1 0x00005617314c6e6c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f97e6c)
 #2 0x00005617314c6fd6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f851da06520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f851da5a9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f851da5a9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f851da5a9bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f851da06476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f851d9ec7f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f851d9ec71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f851d9fde96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000561739db47a2 (mlir-opt+0xa8857a2)
#12 0x00005617398ce141 mlir::arith::TruncFOp::verifyInvariantsImpl() (mlir-opt+0xa39f141)
#13 0x000056173992ff2b mlir::RegisteredOperationName::Model<mlir::arith::TruncFOp>::verifyInvariants(mlir::Operation*) (mlir-opt+0xa400f2b)
#14 0x0000561739e65a28 (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) Verifier.cpp:0:0
#15 0x0000561739e67cfe (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#16 0x0000561739e6843d (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#17 0x0000561739e6843d (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#18 0x0000561739e695ff mlir::verify(mlir::Operation*, bool) (mlir-opt+0xa93a5ff)
#19 0x0000561739778c32 mlir::parseAsmSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::AsmParserState*, mlir::AsmParserCodeCompleteContext*) (mlir-opt+0xa249c32)
#20 0x0000561731591a71 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x00005617315933de processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#22 0x0000561731593621 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#23 0x0000561739e83acd mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa954acd)
#24 0x000056173158e3da mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#25 0x0000561731593bf8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064bf8)
#26 0x0000561731593e54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064e54)
#27 0x0000561731464d47 main (mlir-opt+0x1f35d47)
#28 0x00007f851d9edd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#29 0x00007f851d9ede40 call_init ./csu/../csu/libc-start.c:128:20
#30 0x00007f851d9ede40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#31 0x00005617314a9f05 _start (mlir-opt+0x1f7af05)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to