<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/175717>175717</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
wasm-exceptions in clang 21 vs clang 20
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anutosh491
</td>
</tr>
</table>
<pre>
Hey @sbc100 @aheejin
I would like some help from your end. I maintain clang-repl and the clang-repl in the browser through wasm usecase (which allows writing C++ in the browser in a repl format)
Can be tried out here : https://compiler-research.org/xeus-cpp/lab/index.html
The above link is already using `-fwasm-exceptions` & `-mllvm -wasm-enable-sjlj` with the CompilerBuilder as can be seen through the clang cc1 command. This is clang 20.1.8 based.
`
"" -cc1 -triple wasm32-unknown-emscripten ....... -target-feature +exception-handling -target-feature +multivalue -target-feature +reference-types -exception-model=wasm -mllvm -wasm-enable-eh ....... -fcxx-exceptions -fexceptions -exception-model=wasm -iwithsysroot/include/compat -fincremental-extensions -mllvm -wasm-enable-sjlj -o "<<< inputs >>>.o" -x c++ "<<< inputs >>>"
`
And hence you can do exception handling using the same
<img width="1073" height="316" alt="Image" src="https://github.com/user-attachments/assets/85b59f3f-b7c6-4070-b702-b99ba25d6400" />
**But what we notice is as we're migrating to clang 21.1.8, wasm-exceptions doesn't work the same.**
Let me take this out of Jupyter and demonstrate it through a toy project. A standard clang-repl in the browser workflow looks like this
code in cell x -> PTU (partial translation unit as code in a repl can be incomplete -> LLVM IR -> incr_module_x.o where x is cell number -> incr_module_x.wasm which is built as a standlone side module and loaded on top of a main module (from where we can parse and execute code)
So it's one of these steps, where things can go wrong. In our case I suspect the LLVM IR being built is wrong and hence the wasm generated is also wrong.
Taking the minimalistic example of
```
try { throw 1; } catch (...) { 0; }
```
note that we're using only `-fwasm-exceptions`. our compiler builder args look something like
```
CB.SetCompilerArgs({
"-v",
"-xc++",
"-std=c++23",
"-Xclang", "-iwithsysroot/include/compat",
"-fwasm-exceptions"
});
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVl1v47oR_TX0y0CCTNmW_eAHO9mgKbZA0bst-nZBkWOJG4oUyFFk__uCpOLsptm9hpBI_JiPwzNnKELQnUU8su2ZbR9XYqLe-aOwE7nQbw7rVevU7fg3vAHbVKGV66qKb6JH_K4tsOrEqtMzzG4yCox-QQhuQOjRjHDxboCbmzygVSU8wyC0JaEtSCNsV3gcDQirgHr8cUjbNNJ6Nwf0QL13U9fDLMIAU0ApAgLj-7nXsgdhjJsDzF6Tth08MH5m_PzRhrYgIBm_OD8IYvyQQ38QFloE8hoVuImgR4_A6hP0RGNg9YnxJ8afpBtGbdAXHgMKL_vS-Y7xpytOoZDjyPiTES3jT9oqvJY9DSY7-NYjiNa9IhhtX0AHEMajUDeYQgyY7ariElMr8CpxJO1sYLsKGN-lucGY1wGKvMKK1mARvpvvccmsqU9ZPizBnSdtFHoQAWTOKyDaO4B3mEHKNUg3DCKey7dehxhXnuJVuS730IqAqswpsF0V_3LOOIci7i3I69FgOpKaF5N9sW62BQ5Bej0SWijzDwoSvkMqLihoisjy8z3PohdWmQjCJ6uGyZB-FWbCz2Y9XtCjlVjQbcQA7-AVg1NoWP2Y6PIZfNi_R3eR1-sPwENx-fHjV0Z1RD7cgneO0pFLMylcWCIIiou20uOAloQp8EpoQ7b4i9OEwkHEt37ID2g7ThSA1V_yU7qE_RXkwu_fro6T92OrTieroI9gxWJMzFAO7rnB_RQyISNLghhwOfv6QQ8dzFpRz-pHxvm6auoYTI-66ymP1etdHBJm-X4eRIdxJHiZR36upk5TP7WldAPjT1NAXwgiIfuIWGD8SYSA6WW_bbeHS30p2kbuik3VVEXbVLxoD4dW8K3abaoq-olm6y9LyJGr8TlPBHMvCGYE60hLTOUXYEbGG48w6M6LJBvk3ui_jvRn_AE-1CQoh8Ey3hDMzr_cYSqzr-z3KxIMCCReECiWVVQUd4G_T-ONYmFaBQoHZwN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