<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111855>111855</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Invalid wasm module produced when combining -fPIC with -O1
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bjorn3
</td>
</tr>
</table>
<pre>
# Reproduction
```shell
cat > foo.c <<EOF
struct table {
int (*f1)(char, int);
int (*f2)(void);
} functable;
int g(char, int);
void h() {
struct table t;
t.f1 = g;
__atomic_store(&functable.f1, &t.f1, 5);
__atomic_store(&functable.f2, &t.f2, 5);
}
void i(char buf, int j) {
h();
functable.f1(buf, j);
}
EOF
wasi-sdk-24.0-x86_64-linux/bin/clang -fPIC -O1 foo.c -c -o foo.wasm
wabt-1.0.31/bin/wasm-validate foo.wasm
```
# Result
```
foo.wasm:00000db: error: type mismatch at end of function, expected [] but got [i32]
```
# Version
```
wasi-sdk-24.0-x86_64-linux/bin/clang -v
clang version 18.1.2-wasi-sdk (https://github.com/llvm/llvm-project 26a1d6601d727a96f4301d0d8647b5a42760ae0c)
Target: wasm32-unknown-wasi
Thread model: posix
```
26a1d6601d727a96f4301d0d8647b5a42760ae0c (LLVM 18.1.2)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF2PmzgU_TXm5QpkX_P5wEOaNFKlrrparfo6MtiApw6OsEmm_35lYDJJd7rdRpGx75fPOdyLcE73o1I1yT6Q7BCJ2Q92qptnO408aqz8XhPk8Jc6T1bOrdd2JPRA6G5bc7r-3aCMWW2t8ED4R-isTVogfE_4_uOX4-p0fppbD140RgEpPqxWAD16IFgS3HWMYEWwbAcxEdwHTzDw90JxDb1YLe9jSHGAbh7b5ZY367KG7P7n5dc1FIRhuaS6R_mA3t9h8knHgPAD9HfGpyfh7Um3T87bSS3V8husJPDcA8Hcb9vsgeYvkvEtGf-VTIrDHQ-9sYVm7jbG8PwDsY3rHfhHoOWW-_zuNbe3exVOx05-izFNaPxS5k95Ghs9zi8Ej40eCR5bI8Ye4u7PT3uIv7CtS-IWYrvsr8KdXos1PmYJTTi7ZQdvfBFGS-HVD_G3Xnxo0KV53Wz8u227Hm91-I6Gn2wI34GaJjuFjf9-VnDS7iR8O4DwoEYJtlslCgOBe1AvZ9V6JWGdI2hmD7314ag5kuzwC4xf1eR-Nlu_q-1lm8PldFkLAysTlmD8WiVM0OD92RG-I3gkeOy1H-Ymae2J4NGYy-sjPk_2WbUeMBdM5jllssBCVHmXcsoklWWeFk0mUixyKhRtQ4ssAP4WU698UDCIyzGex2-jvY4LiC1kmJSQcLJSmRB4tk6__IdU_xdDoPf589c_NtoEq0jWXFa8EpGqWYFlVnDkWTTUVS5lkwtKFSrelTQXSuVlIyrOC9m1LNI1UkwZZZRljGdpwnhFKcvyhqIsyq4hKVUnoU0S5Ers1EfauVnVjLEyyyIjGmXc8oFFHNUVFi_B0BXRVC8aN3PvSEqNdt69lfHaG1V_GpeGX0QMSs1Gwfo1VhKugxqhtadGj_o2V1fthzBc0TyZ-vfeMsHjAs8RPG74LzX-EwAA__9NDb57">