<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58665>58665</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
opt crash with "-wasm-cfg-sort"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
merlinsun
</td>
</tr>
</table>
<pre>
Hi, this case is a little strange.
I use `emcc` to generate `.ll` file from an empty file via:
```console
$ /emsdk/upstream/emscripten/emcc -S -emit-llvm -O3 -mllvm -disable-llvm-optzns empty.c -o empty.ll
```
The generated file is:
```console
$ cat empty.ll
; ModuleID = 'empty.c'
source_filename = "empty.c"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-emscripten"
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 16.0.0 (https://github.com/llvm/llvm-project 277c382760bf9575cfa2eac73d5ad1db91466d3f)"}
```
Then, I use `opt` via:
```console
$ /emsdk/upstream/bin/opt -wasm-cfg-sort empty.ll -o empty.opt.ll
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /emsdk/upstream/bin/opt -wasm-cfg-sort empty.ll -o empty.opt.ll
#0 0x000055ad8e2da503 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/emsdk/upstream/bin/opt+0x22cf503)
#1 0x000055ad8e2d7e5e llvm::sys::RunSignalHandlers() (/emsdk/upstream/bin/opt+0x22cce5e)
#2 0x000055ad8e2dac4f SignalHandler(int) Signals.cpp:0:0
#3 0x00007fc98715c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000055ad8d5d5db0 llvm::MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(llvm::LLVMTargetMachine const*) (/emsdk/upstream/bin/opt+0x15cadb0)
#5 0x000055ad8d5d6858 llvm::Pass* llvm::callDefaultCtor<llvm::MachineModuleInfoWrapperPass>() (/emsdk/upstream/bin/opt+0x15cb858)
#6 0x000055ad8daa8117 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) (/emsdk/upstream/bin/opt+0x1a9d117)
#7 0x000055ad8daa7df8 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) (/emsdk/upstream/bin/opt+0x1a9cdf8)
#8 0x000055ad8ccd02e1 main (/emsdk/upstream/bin/opt+0xcc52e1)
#9 0x00007fc987143d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#10 0x00007fc987143e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#11 0x000055ad8cc30caa _start (/emsdk/upstream/bin/opt+0xc25caa)
Segmentation fault (core dumped)
```
Version:
```console
$ /emsdk/upstream/emscripten/emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.24 (68a9f990429e0bcfb63b1cde68bad792554350a5)
clang version 16.0.0 (https://github.com/llvm/llvm-project 277c382760bf9575cfa2eac73d5ad1db91466d3f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
```
OS: Ubuntu 22.04.1 LTS
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFV91znDYQ_2u4Fw2MEN8P92DHTpMZu_H0nOTxRkiCUy0Eg4Q_8td3BRgf16S120xrHyCk_fjtane1lC1_2nr4wsNnH6RH3iF7kAYxagSCJ0VKWqsEMranuhbBRPkRDbDupVg0jMED2RbVQoue2nE6UMrNVhI4q75tENVINJ19mqbuJfWis0kU0E0_1mrTKjHPkhh55L1oDL-D59CBfkGbaYr1srNCjy-MIX-HfNFI6yt13yD_U4T8ZhpyaWipxLjgt539ps0EIwCudh4C1DWQ6fX2IBaT-ARbmlegZtSeCo7O0XXLByU-XiAvgotkMwoYTTSmHXom9k6Np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