-
Notifications
You must be signed in to change notification settings - Fork 48
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
Proposal: Remove i128
/u128
from the improper_ctypes
lint
#255
Comments
To help increase awareness of these changes, I was also considering writing a short blog post or blurb in the release notes before 1.77. Not sure which is a better option here, if anything. |
i128
/`u128
from the improper_ctypes
linti128
/u128
from the improper_ctypes
lint
Verifying: does this mean u128/i128 are now compatible with LLVM/clang and GCC on Linux targets, and with MSVC on Windows -windows-msvc targets, and with MinGW on Windows -windows-gnu targets? A mention in the release notes would be a good idea. And since this has been an issue for so long, I personally think it'd also be wonderful to have a dedicated blog post highlighting the new compatibility and the people who worked so hard to bring about that compatibility. Nominating this for lang team discussion. |
To the best of my knowledge, the compatibility matrix for x86 Linux looks like this:
The ABI bug comes from LLVM incorrectly splitting an I don't know of any other architecture incompatibilities but also have no way of verifying that, though LLVM appears to do the right thing for other ABIs I could find. Can't seem to link to that comment directly, but if you search "It probably makes sense to have reasoning" on https://reviews.llvm.org/D86310, my sources list should pop up. As far as I know, MSVC does not support 128-bit integers, so LLVM just assumes its windows targets use the same size/alignment as Linux. Have to imagine if they ever add support they would make it match, but I'll ping some Windows people on Zulip to confirm. |
Given that Finally, I haven't analyzed this, but what's the status of |
Even easier, we just fire this lint only if an Jokes aside, a backend-dependent lint sounds feasible. My only question is the extent we want to go to warn about this bug, since it only shows up in very specific circumstances, and C-C compatibility is wonky anyways (if you have LLVM < 18 then you probably also have Clang < 18 and would suffer from this same issue there).
I just tested locally with A quick check says it reported alignment of 8 at some point https://rust.godbolt.org/z/GMK4sqcK7, but I guess cg-gcc on godbolt hasn't been updated since August. |
On the topic of platform-specifc invalid_ctypes, we need to figure out what to do for @joshtriplett did any discussion happen here yet? |
We discussed this in today's @rust-lang/lang design meeting. We came to a consensus among those present (@pnkfelix, @tmandry, @nikomatsakis, and myself) that it is OK to enable this conditional on having a fixed LLVM. Without setting a fully general policy here, we think it's OK to have the availability of this feature depend on your LLVM version. We'd like to see some mechanism by which people get an error if they try to use this with a non-fixed LLVM. We didn't try to settle the question of the exact form the error should take. We do want to make sure it's hard to end up in this situation. Some additional non-consensus speculation that some folks were supportive of: To a first approximation a hard error might be OK, but we may need to weaken that to a very very visible overridable error (not suppressed by cap-lints) that allows people to compile code on a Rust using old LLVM as long as they never touch the actual function that uses 128-bit types. Pinging @scottmcm to ensure you have the opportunity to raise any objections you might have to this. |
What's the current status of this? Has there been progress on the idea of permitting this conditional on Rust being built with a sufficiently new LLVM? |
I haven't done anything with it yet, but will pick it up at some point if nobody beats me to it |
It's probably worth pointing out that while the MSVC ABI does not officially support 128-bit integers, Clang targeting rustc#[no_mangle]
pub extern "C" fn extend(num: i16) -> i128 {
num as i128
} Notice return type is
extend:
mov rax, rcx
movsx rcx, dx
mov qword ptr [rax], rcx
sar rcx, 63
mov qword ptr [rax + 8], rcx
ret clang__int128 extend(short num) {
return num;
} Notice return type is
Return in extend: # @extend
movsx rax, cx
movq xmm0, rax
sar rax, 63
movq xmm1, rax
punpcklqdq xmm0, xmm1 # xmm0 = xmm0[0],xmm1[0]
ret So we still are not ABI compatible with Clang on |
@wesleywiser do you happen to know if there is a reason clang elected to use xmm? Assuming this wasn't a decision based on performance / register pressure, it seems like an odd choice to break from sysv. cplusplus/papers#1793 seems to be progressing so I wonder if we will get actual guidance from Microsoft in the near future. |
For a while, Rust's 128-bit integer types have been incompatible with those from C. The original issue is here rust-lang/rust#54341, with some more concise background information at the MCP here rust-lang/compiler-team#683
The current Beta of 1.77 will have rust-lang/rust#116672, which manually sets the alignment of
i128
to make it ABI-compliant with any version of LLVM (clang
does something similar now). 1.78 will have LLVM18 as the vendored version which fixes the source of this error.Proposal: now that we are ABI-compliant, do not raise
improper_ctypes
on our 128-bit integers. I did some testing with abi-cafe and a more isolated https://github.com/tgross35/quick-abi-check during the time https://reviews.llvm.org/D86310 was being worked on, and verified everything lines up. (It would be great to have some fork of abi-cafe in tree, but that is a separate discussion.)@joshtriplett mentioned that changing this lint needs a lang FCP https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/LLVM.20alignment.20of.20i128/near/398422037.
cc @maurer
Reference change from when I was testing rust-lang/rust@c742908
Edit: blog at https://blog.rust-lang.org/2024/03/30/i128-layout-update.html has more background information.
The text was updated successfully, but these errors were encountered: