<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119081>119081</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] populateAffineToStdConversionPatterns causes issues in LLVM 19.1.4
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bradenhelmer
      </td>
    </tr>
</table>

<pre>
    My conversion pass here:
```cpp
struct ConvertToLLVMPass
    : public ler::impl::ConvertToLLVMBase<ConvertToLLVMPass> {
  using ConvertToLLVMBase::ConvertToLLVMBase;

  void runOnOperation() override {
 LLVMConversionTarget LLVMTarget(getContext());

    auto &Ctx = getContext();
    Ctx.loadDialect<ControlFlowDialect>();

 LLVMTarget.addLegalOp<ModuleOp>();

    LLVMTypeConverter TC(&getContext());

    RewritePatternSet patterns(&getContext());
 mlir::populateAffineToStdConversionPatterns(patterns);
 mlir::populateSCFToControlFlowConversionPatterns(patterns);
 mlir::arith::populateArithToLLVMConversionPatterns(TC, patterns);
 mlir::populateFinalizeMemRefToLLVMConversionPatterns(TC, patterns);
 mlir::cf::populateControlFlowToLLVMConversionPatterns(TC, patterns);
 mlir::populateFuncToLLVMConversionPatterns(TC, patterns);

    if (failed(applyFullConversion(getOperation(), LLVMTarget,
 std::move(patterns)))) {
      signalPassFailure();
    }
 }
};
```
works completely fine in LLVM 18.1.6. However, when upgrading to 19.1.4, it causes unaligned tcache errors:
```
malloc(): unaligned tcache chunk detected
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
 #0 0x0000630367f59558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./ler-compile+0x30d558)
 #1 0x0000630367f5735e llvm::sys::RunSignalHandlers() (./ler-compile+0x30b35e)
 #2 0x0000630367f59ec8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007d9cf8042520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007d9cf80969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007d9cf80969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007d9cf80969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007d9cf8042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007d9cf80287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007d9cf8089676 __libc_message ./libio/../sysdeps/posix/libc_fatal.c:155:5
#10 0x00007d9cf80a0cfc ./malloc/malloc.c:5668:3
#11 0x00007d9cf80a53dc ./malloc/malloc.c:3195:5
#12 0x00007d9cf84ae98c operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xae98c)
#13 0x00006303680c7005 mlir::populateAffineToStdConversionPatterns(mlir::RewritePatternSet&) (./ler-compile+0x47b005)
#14 0x00006303680bcdcf ConvertToLLVM.cpp:39:5
#15 0x00006303687bc3c2 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./ler-compile+0xb703c2)
#16 0x00006303687bfe9b mlir::PassManager::run(mlir::Operation*) (./ler-compile+0xb73e9b)
#17 0x0000630367d8079d main Main.cpp:90:17
#18 0x00007d9cf8029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#19 0x00007d9cf8029e40 call_init ./csu/../csu/libc-start.c:128:20
#20 0x00007d9cf8029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#21 0x0000630367d64055 _start (./ler-compile+0x118055)
```
I have ensured all necessary dialects are loaded without any issues. I'll also mention that the pass runs correctly every so often, maybe every 5 runs. I also can't attribute it to any specific test case for my program, it seems random and I'm unsure how to proceed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWF1v2zoS_TXMy6ACRX0_-EFxa9wCDRo0w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