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

    <tr>
        <th>Summary</th>
        <td>
             Clang frontend command failed with exit code 139 when compiling to webassembly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    I am getting `Clang frontend command failed with exit code 139` when compiling code using setjmp/longjmp to webassembly with emscripten 3.1.62. The same code compiles fine with an older (3.1.44) version of emscripten. The code also compiles if all calls to setjmp/longjmp are removed or if optimization level is set to `-O0`

[Crash artifacts (preprocessed source and script)](https://github.com/user-attachments/files/16075525/crash.zip)

Backtrace:
```
0. Program arguments: /home/code/emscripten/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr --sysroot=/home/code/emscripten/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -I/Users/home/code/libcvd -I/home/code/libcvd/build/include -isystem /home/code/toon/include/toon -isystem /home/code/jpeg/include/S -isystem /home/code/libpng/include/png -isystem //home/code/zlib/include/zlib -fwasm-exceptions -Wno-error=enum-constexpr-conversion -fcolor-diagnostics -Oz -DNDEBUG -std=gnu++20 -fvisibility=hidden -MD -c /home/code/libcvd/cvd_src/image_io/jpeg.cxx -o /tmp/jpeg.cxx.o
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/home/code/libcvd/cvd_src/image_io/jpeg.cxx'.
4.      Running pass 'WebAssembly Instruction Selection' on function '@_ZN3CVD4JPEG9ReadPimplC2ERNSt3__213basic_istreamIcNS2_11char_traitsIcEEEE'
 #0 0x000000010616eb48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013eab48)

 #1 0x000000010616c255 llvm::sys::RunSignalHandlers() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e8255)
 #2 0x000000010616df0e llvm::sys::CleanupOnSignal(unsigned long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e9f0e)
 #3 0x00000001060ca181 CrashRecoverySignalHandler(int) (.llvm.957067972329857832) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101346181)
 #4 0x00007ff818abafdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd)
 #5 0x000000031507bb20
 #6 0x000000010738dca7 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102609ca7)
 #7 0x00000001075188d4 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, bool&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027948d4)
 #8 0x0000000107518432 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102794432)
 #9 0x00000001075151fc llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027911fc)
#10 0x000000010751341e llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10278f41e)
#11 0x00000001056d52f8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1009512f8)
#12 0x0000000105c2af05 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea6f05)
#13 0x0000000105c34d94 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100eb0d94)
#14 0x0000000105c2bcd5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea7cd5)
#15 0x0000000106a9e340 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101d1a340)
#16 0x000000010690306c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101b7f06c)
#17 0x0000000107e2dcf9 clang::ParseAST(clang::Sema&, bool, bool) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1030a9cf9)
#18 0x0000000106e741f5 clang::FrontendAction::Execute() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1020f01f5)
#19 0x0000000106dae570 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10202a570)
#20 0x0000000106f70a5a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1021eca5a)
#21 0x0000000104e21480 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10009d480)
#22 0x0000000104e1db2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100099b2a)
#23 0x0000000106bee02e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const::$_0>(long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e6a02e)
#24 0x00000001060c9ed8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101345ed8)
#25 0x0000000106bed8c3 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e698c3)
#26 0x0000000106ba6d79 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e22d79)
#27 0x0000000106ba705f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e2305f)
#28 0x0000000106bcb730 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e47730)
#29 0x0000000104e1cc33 clang_main(int, char**, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100098c33)
#30 0x0000000104e2da2c main (/home/code/emsdk/upstream/bin/clang-19+0x1000a9a2c)
#31 0x000000020c21c366
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 19.0.0git (https:/github.com/llvm/llvm-project c00ada070207979f092be9046a02fcfff8b9f9ce)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/code/emscripten/emsdk/upstream/bin
clang++: note: diagnostic msg:
```
</pre>
<img width="1px" height="1px"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