<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 18, 2020 at 1:19 PM Stefan Kanthak via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><<a href="https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention#return-values" rel="noreferrer" target="_blank">https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention#return-values</a>><br>
<br>
| To return a user-defined type by value in RAX, it must have a length<br>
| of 1, 2, 4, 8, 16, 32, or 64 bits. [...] Otherwise, the caller must<br>
| allocate memory for the return value and pass a pointer to it as the<br>
| first argument. The remaining arguments are then shifted one argument<br>
| to the right. The same pointer must be returned by the callee in RAX.<br></blockquote><div>Is there a particular reason for starting a new thread?</div><div><br></div><div>Statements have been made in <a href="https://lists.llvm.org/pipermail/cfe-dev/2020-September/066811.html">https://lists.llvm.org/pipermail/cfe-dev/2020-September/066811.html</a> to clarify the relationship between __[u]int128_t and the MS ABI.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
--- incompatible.c ---<br>
__attribute__((ms_abi))<br>
__uint128_t buggy(__uint128_t a, __uint128_t b, __uint128_t c) {<br>
    return a + b * c;<br>
}<br>
--- EOF ---<br>
<br>
clang -mno-sse -o- -O3 -S -target amd64-pc-windows incompatible.c<br>
<br>
buggy:                                  # @buggy<br>
# %bb.0:<br>
        movq    (%rdx), %r9             # OUCH: before it was destroyed,<br>
                                        #       r9 held the address of c<br></blockquote><div>It might help to provide the source code for a caller of this function and the associated assembly of the caller to demonstrate such a mismatch.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
        movq    (%r8), %rax<br>
        movq    8(%rdx), %r10<br>
        imulq   %rax, %r10<br>
        mulq    %r9                     # OUCH: the source says b * c,<br>
                                        #       NOT a * <something><br>
        imulq   8(%r8), %r9             # OUCH: idem<br>
        addq    %r10, %rdx<br>
        addq    %r9, %rdx<br>
        addq    (%rcx), %rax            # OUCH: rcx holds the address of<br>
                                        #       the return value!<br>
                                        # OUCH: rax does NOT point to the<br>
                                        #       return value!<br>
        adcq    8(%rcx), %rdx           # OUCH: rcx holds the address of<br>
                                        #       the return value!<br>
        retq<br>
<br>
<br>
Stefan<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>