| Issue |
234637
|
| Summary |
[MLIR][Transform][fuzzer-found] transform.foreach aborts when its body contains a non-transform operatio
|
| Labels |
|
| Assignees |
|
| Reporter |
Kiritobl
|
#### Version
git commit hash: 059577967e64f14231b35bcd57f2b88c29909afc
LLVM/MLIR 24.0.0git, optimized build with assertions.
#### Bug Description
The following `transform.foreach` body contains an ordinary `arith.constant` operation. Parsing the module with `mlir-opt` aborts while verifying the enclosing named sequence, before a diagnostic can reject the invalid body.
#### Crash Chain & Root Cause
**Crash chain:**
```text
`transform.named_sequence` verification
→ `getConsumedBlockArguments()`
→ `ForeachOp::getEffects()`
→ `cast<TransformOpInterface>(&op)` on `arith.constant`
→ incompatible-type assertion
```
`ForeachOp::getEffects()` iterates over operations in its body and assumes that every non-terminator implements `TransformOpInterface`. It uses an unconditional `cast` on each operation. Because the enclosing named-sequence verifier queries memory effects before the `foreach` body has been fully rejected, the `arith.constant` reaches this cast and aborts. The effect calculation should handle a non-transform child without asserting, allowing the verifier to emit a 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 verification, before any pass runs. Expected behavior is a diagnostic for the non-transform child operation.
#### Reproducer (`reproducer.mlir`)
```mlir
module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
"transform.foreach"(%arg0)({
^bb0(%arg1: !transform.any_op):
%c0 = "arith.constant"() <{value = 0 : i32}> : () -> i32
"transform.yield"() : () -> ()
}) : (!transform.any_op) -> ()
transform.yield
}
}
```
#### Stack Dump
```text
mlir-opt: llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = mlir::transform::TransformOpInterface; From = mlir::Operation]: 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 0x00005642d7f23669 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1f9b669)
#1 0x00005642d7f1fe6c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f97e6c)
#2 0x00005642d7f1ffd6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fe080f9a520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fe080fee9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007fe080fee9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007fe080fee9bc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007fe080f9a476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007fe080f807f3 abort ./stdlib/abort.c:81:7
#9 0x00007fe080f8071b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007fe080f91e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005642dde73e4e mlir::transform::ForeachOp::getEffects(llvm::SmallVectorImpl<mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>&) (mlir-opt+0x7eebe4e)
#12 0x00005642dde170f3 mlir::detail::MemoryEffectOpInterfaceInterfaceTraits::Model<mlir::transform::ForeachOp>::getEffects(mlir::detail::MemoryEffectOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::SmallVectorImpl<mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>&) (mlir-opt+0x7e8f0f3)
#13 0x00005642ddf000eb mlir::transform::getConsumedBlockArguments(mlir::Block&, llvm::SmallDenseSet<unsigned int, 4u, llvm::DenseMapInfo<unsigned int, void>>&) (mlir-opt+0x7f780eb)
#14 0x00005642dde9c1c0 verifyFunctionLikeConsumeAnnotations(mlir::FunctionOpInterface, bool, bool) TransformOps.cpp:0:0
#15 0x00005642ddea51b8 verifyNamedSequenceOp(mlir::transform::NamedSequenceOp, bool) (.constprop.0) TransformOps.cpp:0:0
#16 0x00005642ddea59f6 mlir::transform::NamedSequenceOp::verify() (mlir-opt+0x7f1d9f6)
#17 0x00005642dde2fb77 mlir::RegisteredOperationName::Model<mlir::transform::NamedSequenceOp>::verifyInvariants(mlir::Operation*) (mlir-opt+0x7ea7b77)
#18 0x00005642e08bea28 (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) Verifier.cpp:0:0
#19 0x00005642e08c0cfe (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#20 0x00005642e08c25ff mlir::verify(mlir::Operation*, bool) (mlir-opt+0xa93a5ff)
#21 0x00005642dde133b0 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) TransformDialect.cpp:0:0
#22 0x00005642dde13375 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) TransformDialect.cpp:0:0
#23 0x00005642dde13a15 mlir::transform::TransformDialect::verifyOperationAttribute(mlir::Operation*, mlir::NamedAttribute) (mlir-opt+0x7e8ba15)
#24 0x00005642e08be65a (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) Verifier.cpp:0:0
#25 0x00005642e08c0cfe (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#26 0x00005642e08c143d (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#27 0x00005642e08c25ff mlir::verify(mlir::Operation*, bool) (mlir-opt+0xa93a5ff)
#28 0x00005642e01d1c32 mlir::parseAsmSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::AsmParserState*, mlir::AsmParserCodeCompleteContext*) (mlir-opt+0xa249c32)
#29 0x00005642d7feaa71 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#30 0x00005642d7fec3de 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
#31 0x00005642d7fec621 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
#32 0x00005642e08dcacd 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)
#33 0x00005642d7fe73da 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
#34 0x00005642d7fecbf8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064bf8)
#35 0x00005642d7fece54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064e54)
#36 0x00005642d7ebdd47 main (mlir-opt+0x1f35d47)
#37 0x00007fe080f81d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#38 0x00007fe080f81e40 call_init ./csu/../csu/libc-start.c:128:20
#39 0x00007fe080f81e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#40 0x00005642d7f02f05 _start (mlir-opt+0x1f7af05)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs