Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect codegen for int128 parameters with x64-systemv calling conv #59011

Open
T0b1-iOS opened this issue Nov 16, 2022 · 6 comments
Open

Incorrect codegen for int128 parameters with x64-systemv calling conv #59011

T0b1-iOS opened this issue Nov 16, 2022 · 6 comments

Comments

@T0b1-iOS
Copy link

Description

When compiling C/C++ code that takes an __int128 as its sixth argument, llvm splits it into two 64bit ints that get passed in a register and on the stack. According to the SysV ABI __int128 should be treated like a struct of two 64bit ints and therefore be passed completely in memory in that case.

Reproduction

https://godbolt.org/z/o8MMMYdY6

Input C++:

using uint128_t = unsigned __int128;

unsigned long long tmpfn(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint128_t t) {
    return (t >> 64) & 0xFFFFFFFFFFFFFFFF;
}

unsigned long long tmpfn2(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint128_t t) {
    return t & 0xFFFFFFFFFFFFFFFF;
}

Output from clang 15:

tmpfn:
        mov     rax, qword ptr [rsp + 8]
        ret
tmpfn2:
        mov     rax, r9
        ret

Output from gcc 12:

tmpfn:
        mov     rax, QWORD PTR [rsp+16]
        ret
tmpfn2:
        mov     rax, QWORD PTR [rsp+8]
        ret
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 16, 2022

@llvm/issue-subscribers-clang-codegen

@tgross35
Copy link

There is a WIP patch that should fix this: https://reviews.llvm.org/D86310

@nikic
Copy link
Contributor

nikic commented Aug 11, 2023

I don't think that patch will fix this issue. This is not an alignment problem.

@tgross35
Copy link

Not the current patch, but I think resolving this is part of the wanted fix

Also, this is related to #41784

@RalfJung
Copy link
Contributor

RalfJung commented Sep 13, 2023

Looks like https://reviews.llvm.org/D158169 is the patch to fix this?

And it landed. So is this fixed?

@tgross35
Copy link

Unfortunately not yet - that fixes only the register passing component which means clang and GCC are now compatible, but the alignment produced by LLVM is still incorrect, so rust still isn't compatible. The fix for that is in https://reviews.llvm.org/D86310, which I think is just waiting for a review.

So not yet but close :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants