-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Fix bool calling convention for aarch64, etc.
#159317
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
Merged
rust-bors
merged 4 commits into
rust-lang:main
from
workingjubilee:aarch64-bool-callconv
Jul 27, 2026
+87
−10
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d199011
tests: Verify aarch64 masks `bool` returns from FFI calls
workingjubilee 444dd28
compiler: Remove the `bool` special-case in ty_utils
workingjubilee 1f59b1e
tests: Include bools in integer arg-extension test
workingjubilee 45a7a3b
compiler: Add zeroext to `bool` for all Rust ABIs
workingjubilee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //@ add-minicore | ||
| //@ assembly-output: emit-asm | ||
| //@ needs-llvm-components: aarch64 | ||
| //@ compile-flags: -Copt-level=3 --target=aarch64-unknown-linux-gnu | ||
|
|
||
| // Previously, Rust used to assume omnipresent zero-extension on bool in FFI returns | ||
| // which resulted in LLVM assuming that a register did not require explicit masking (e.g. `and`) | ||
| // and could be correctly handled via `cmp w0, #0`. | ||
| // `cmp` looks at the full register, but only the 8 bits that contain the bool are specified, | ||
| // and this is particularly glaring in the event of a branch or csel based on this. | ||
| // Thus we are looking for explicit handling like `tst w0, #0x1` or `and w0, #0xFF` | ||
|
|
||
| // NOTE: simplifying this further is risky as `tbnz x0, #0, ...` only examines 1 bit, | ||
| // so LLVM will optimize it all away if there's an immediate jump to another function | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
|
|
||
| #[repr(C)] | ||
| struct Bools { | ||
| a: bool, | ||
| b: bool, | ||
| } | ||
|
|
||
| #[link(name = "rust_test_helpers")] | ||
| unsafe extern "C" { | ||
| safe fn bools_get_first_bool(bools: Bools) -> bool; | ||
| } | ||
|
|
||
| // CHECK-LABEL: broken | ||
| pub fn broken() -> i32 { | ||
| let bools = Bools { a: false, b: true }; | ||
| // CHECK: bl bools_get_first_bool | ||
| // CHECK-NOT: cmp | ||
| // CHECK: tst w0, #0x1 | ||
| // CHECK-NOT: cmp | ||
| if bools_get_first_bool(bools) { 123 } else { 321 } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to address @nikic's review that I shouldn't be diffing so many unrelated tests. Actually doesn't, neat, shrinking the diff considerably. Oddly annoying to puzzle out as, even though we split a single Rust-sig argument into two LLVM-sig arguments, we don't model that (leaving that to
cg_llvm, etc.), and we don't e.g. somehow bundle togetherPassMode::PairandBackendRepr::ScalarPaireven thoughPassMode::Pairbeing attached to anything else is... probably wildly incorrect. Probably will want to restructure these pieces later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, we wind up having to reinvent this thing all over the compiler. Bad!