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

    <tr>
        <th>Summary</th>
        <td>
            LTO breaks the multi-value (i.e., `experimental-mv`) ABI for WebAssembly in Clang and generates incompatible function signatures
        </td>
    </tr>

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

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

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

<pre>
    I’ve been using the [multi-value ABI for WebAssembly](https://github.com/WebAssembly/multi-value/blob/61975c83a286b96517659eded062f4e11dbac4c7/proposals/multi-value/Overview.md) in Clang (i.e., `-mmultivalue -Xclang -target-abi -Xclang experimental-mv`) and it’s been working relatively well. I decided to enable LTO (thin) in the pipeline and everything exploded—the signatures of all of the functions using multi-value returns are changed in the final WebAssembly binary (lowering the multi-value returns to pointer parameters). The linker seems to be the culprit, because all of the signatures in the LLVM bitcode produced for the individual object files are correct (I’ve painstakingly inspected all of them to confirm this). Also, the same problem persists with full LTO.

Given that this is a proprietary project that involves a somewhat complex pipeline, it’s difficult to extract a reasonable sample of the code to reproduce this issue, but I can try to create an example from scratch if necessary.

I think the following Emscripten issues are related to this issue too:
- emscripten-core/emscripten#10831
- emscripten-core/emscripten#15638
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU1v4zYQ_TX0ZWBDoj4sHXxINusiQIq9LNpeR-TI4oYiBZKS439fkLITBxsUvVgANXp88-bNM3qvTobowKpHVj1tcA6DdYdf1mAY0IzoFjJ-01l5OTyz75w1GWvbhaAjMjB7ZU4QBgJWPY6zDmq7oJ4JHh6fobcO_qbuwXsaO31h1RPjzRDC5FnxwPiR8eNJhWHudsKOjB_va_nxDo3xY6dtx_ixztt9JZoCeVN3bV3l-7pqSZLMat6XlOeyQ1GKPePHydnJetT-N6wfC7lF0Xk3SsZbU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