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

    <tr>
        <th>Summary</th>
        <td>
            clang: x86 stdcall/thiscall with an empty object parameter yields ABI-incompatible code
        </td>
    </tr>

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

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

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

<pre>
    Reproducer: https://godbolt.org/z/4havqnxxj

Notice on the difference of `ret` size for `T::x`: gcc returns by 12 where clang returns by 8, and each caller computes the stack size for the respective return size. It's easy to see that if you try to mix the code generated between two the stack gets corrupted and the program crashes. Changing thiscall to stdcall yields a similar result, just with `this` added to the parameter size for each.

For the question of which ABI is right I'm no expert but from googling it seems Itanium ABI defines empty object parameters to be treated as `struct{ char; }` so I'd assume that gcc is right in this case.

My real world case involves a 32 bit mingw app which [defaults the member functions to thiscall](https://github.com/llvm/llvm-project/blob/fee8f561bdc9317eee13b8f1866ca0dc778c1dc5/clang/lib/AST/ItaniumCXXABI.cpp#L239). The program immediately crashes as soon as it tries to copy a single `std::string` as `_M_construct()` is compiled by clang where the copy constructor itself is provided by libstdc++ from gcc-built mingw.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVlE2PozgQhn8NuZQagQkkHDgk3RqppZk97PZhbiNjF-AegxnbJGF-_ZZN-mNX2sNKCR_-qqqn3pfWyLX5E2dr5CLQJsUJBu9nRw8J-0K_3sjWaJ8a29Pbb_rvB375Nd1ur0n2lGSn7fqH8UogmAn8gCBV16HFKYx0kFSZRU9XcOo3QmdsGHoJIYrTjR5D1F4IoFWLnRy0K-QMrgMdAULzqf88c0zYI_BJAnIxgOBaowVhxnnx6GJ057n4-RErDFl0MwqvLng_Kk6n8OwTdnB0lFvBG3CItJx7UB2sZgFv4_CobvEUYSRCjxNa7lFCi_6KSBV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