Issue 234636
Summary [MLIR][Transform][fuzzer-found] apply_conversion_patterns verifier dereferences an empty type-converter region
Labels
Assignees
Reporter Kiritobl
    #### Version

git commit hash:  059577967e64f14231b35bcd57f2b88c29909afc

LLVM/MLIR 24.0.0git, optimized build with assertions.

#### Bug Description

The following `transform.apply_conversion_patterns` has a nonempty pattern region and an empty second region. `mlir-opt` aborts while verifying the operation, before a diagnostic can reject the empty type-converter region.

#### Crash Chain & Root Cause

**Crash chain:**

```text
`transform.apply_conversion_patterns` verification
  → `ApplyConversionPatternsOp::verify()` sees two regions
  → `typeConverterRegion.front()` on an empty region
  → `ilist_iterator::operator*()` sentinel assertion
```

The verifier checks that the operation has one or two regions, then accesses the first block of the optional second region without checking whether that region contains a block. A generic-form operation can supply an empty region. The verifier should check `typeConverterRegion.empty()` before calling `front()` and report the malformed region.

#### 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 empty second region.

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

```mlir
module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
    %0 = "transform.structured.match"(%arg0) <{ops = ["func.func"]}> : (!transform.any_op) -> !transform.any_op
    "transform.apply_conversion_patterns"(%0) <{legal_ops = ["func.func", "func.return"]}> ({
      "transform.apply_conversion_patterns.transform.test_conversion_patterns"() : () -> ()
    }, {}) : (!transform.any_op) -> ()
    transform.yield
  }
}
```

#### Stack Dump

```text
mlir-opt: llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:168: llvm::ilist_iterator<OptionsT, IsReverse, IsConst>::reference llvm::ilist_iterator<OptionsT, IsReverse, IsConst>::operator*() const [with OptionsT = llvm::ilist_detail::node_options<mlir::Block, true, false, void, false, void>; bool IsReverse = false; bool IsConst = false; llvm::ilist_iterator<OptionsT, IsReverse, IsConst>::reference = mlir::Block&]: Assertion `!NodePtr->isKnownSentinel()' 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 0x000055b9533db669 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1f9b669)
 #1 0x000055b9533d7e6c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f97e6c)
 #2 0x000055b9533d7fd6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007fc96cb87520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fc96cbdb9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007fc96cbdb9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007fc96cbdb9bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007fc96cb87476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007fc96cb6d7f3 abort ./stdlib/abort.c:81:7
 #9 0x00007fc96cb6d71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007fc96cb7ee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000055b9592e940a (mlir-opt+0x7ea940a)
#12 0x000055b95935211b mlir::transform::ApplyConversionPatternsOp::verify() (mlir-opt+0x7f1211b)
#13 0x000055b9592e6acb mlir::RegisteredOperationName::Model<mlir::transform::ApplyConversionPatternsOp>::verifyInvariants(mlir::Operation*) (mlir-opt+0x7ea6acb)
#14 0x000055b95bd76a28 (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) Verifier.cpp:0:0
#15 0x000055b95bd78cfe (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#16 0x000055b95bd7943d (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#17 0x000055b95bd7943d (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#18 0x000055b95bd7a5ff mlir::verify(mlir::Operation*, bool) (mlir-opt+0xa93a5ff)
#19 0x000055b95b689c32 mlir::parseAsmSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::AsmParserState*, mlir::AsmParserCodeCompleteContext*) (mlir-opt+0xa249c32)
#20 0x000055b9534a2a71 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055b9534a43de 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 0x000055b9534a4621 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 0x000055b95bd94acd 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 0x000055b95349f3da 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 0x000055b9534a4bf8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064bf8)
#26 0x000055b9534a4e54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2064e54)
#27 0x000055b953375d47 main (mlir-opt+0x1f35d47)
#28 0x00007fc96cb6ed90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#29 0x00007fc96cb6ee40 call_init ./csu/../csu/libc-start.c:128:20
#30 0x00007fc96cb6ee40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#31 0x000055b9533baf05 _start (mlir-opt+0x1f7af05)
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to