<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66216>66216</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[WebAssembly] Incorrect code generated after enabling tail-call
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
slavek-kucera
</td>
</tr>
</table>
<pre>
I've recently encountered a problem while compiling for the WebAssembly target after enabling a tail-call optimization (`-mtail-call`).
I believe I've managed to reproduce the issue with the following code:
```
struct X {
char a[124];
int b;
};
const X global = {{}, 5};
int __attribute__((noinline)) g(X x, X) {
volatile int i = 0;
return x.b;
}
int f(X x) {
return g(x, global);
}
```
Commenting out the volatile variable `i` in the `g` function changes the return value of the `f` function.
My understanding is that the __stack_pointer adjustment at the end of `f` leave the prepared arguments below the stack pointer address where they are overwritten by the store in the `g` function.
https://godbolt.org/z/dvMG9xde9
The code seems to be generated this way since release 15 (https://godbolt.org/z/x4TY57861)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElMFu4zgPx59GuRANbMV24oMP7QT50MPcBvi6p4CWGVtTWQok2mnm6ReS0zbtYrGAIUOm-OfPFEkMQfeWqBHlkyj3K5x4cL4JBmd6fXidFHlcta67Ns9CbmcCT4osmyuQVW6yTJ46QDh71xoa4TJoQ6DceNZG2x5OzgMPBP-n9jEEGltzBUbfEwOemDyQxTadRGDU5kGhMeDOrEf9B1k7C0LuRJU9jB9mUWVC1muR7UX2uKzP0JLRNBPcMEe02FMH7MDT2btuUpRAdAgTwUXzkLYnZ4y7xPjKdSQ2j_eqMdDypG1gPymGFxDbp-ULAIAa0AOK8imXhSj3YnNn05ah_fgitp9W5WyIUr1xLRoQm31Sjc9eyB9Q3h9e1ih2PCKz1-3EdDzGxMidddoabUnIWsgaeiF3L_AWNV7i_gvr7AxyvKCopVPU7AuwJ568hbf1V-pvFKf3GN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