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

    <tr>
        <th>Summary</th>
        <td>
            [Bug report] clang-cl fastcall (32bits) abi does not match msvc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I hit an abi incompatibility between msvc and clang regarding fastcall x86-32bits architecture, possibly a clang bug unless something was missed

Assume two functions implemented in two different source files:

x.cpp:
void caller()
{
unsigned long long a = 0x3333333344444444;
int b = 0x11111111, c = 0x22222222;

  fastercall(a, b, c);
}

y.cpp:
__fascall void fastercall(unsigned long long a, int b, int c)
{
unsigned long long v = a;
v += b;
v += c;
std::cout << v << std::endl;
}

Calling method caller() above should result in printing: 0x3333333377777777

And this is the case if both files are compiled with msvc compiler or clang-cl compiler.
But if y.cpp is compiled with clang-cl and x.cpp with msvc then the result is 0x33333333aaaaaaaa

fastcall definition is here: [__fastcall | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/cpp/fastcall?view=msvc-170)

it says the two first DWORDs or smaller size arguments should be passed with ecx edx, the others by stack.
i.e. b and c should go with ecx edx while a go to stack and this is not what clang-cl does:
with msvc edx and ecx have the proper values 0x1…1 and 0x2…2 while it is not the case with clang-cl.

See also Phoebe's issue identification here:
https://godbolt.org/z/v1Ghah68M

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVVvPozYQ_TXkxQoCk4TkgYfky-5qH1at2oc-rnwZgluDkW1y2V_fsbkk2bZSrQTM4Dk-M3PGcCMf1VfSKE9YRxhXRHXCtD3ziiut_INw8DeAjrTuKnCNJEKz7kIsXJiVCmc1c14wrcl9v1sXlCvvCLMCIUH4wUJCP0hvnFNcPwib3PlwIUOnwTniTAu-CUg35kirnAOZZO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