Skip to content

Re-enable extension of bool return values on x86_64 - #163917

Open
saethlin wants to merge 2 commits into
rust-lang:mainfrom
saethlin:bool-return-extend
Open

saethlin wants to merge 2 commits into
rust-lang:mainfrom
saethlin:bool-return-extend

Conversation

@saethlin

@saethlin saethlin commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

I think this fixes #163911

Though the test here is a bit hard to figure out, I'm not sure under what conditions expectation goes in the left or the right column. Do I decide that per-target or per-instance? Because x86_64 seems obligated to extend bool returns, so whether it is a "target that extends" or not depends on the type we're dealing with.

I also noticed that because of how the test is written, if codegen starts adding a zeroext on a return type where it is wrong to do so, the test will pass anyway.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2026
@rustbot

rustbot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@BoxyUwU

BoxyUwU commented Oct 7, 2026

Copy link
Copy Markdown
Member

is this worth a stable/beta backport?

@jieyouxu

jieyouxu commented Oct 7, 2026

Copy link
Copy Markdown
Member

is this worth a stable/beta backport?

Nominating just in case.
@rustbot label: +stable-nominated +beta-nominated

@rustbot rustbot added beta-nominated Nominated for backporting to the compiler in the beta channel. stable-nominated Nominated for backporting to the compiler in the stable channel. labels Oct 7, 2026
@jieyouxu jieyouxu added the O-x86_64 Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64) label Oct 7, 2026

@asquared31415 asquared31415 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should fix the issue, the emitted LLVM IR returns to what was emitted in 1.98. A small nit on the conditions to clean it up a bit though.

View changes since this review

Comment thread compiler/rustc_target/src/callconv/x86_64.rs Outdated
@saethlin
saethlin force-pushed the bool-return-extend branch from 39167e7 to 61f40b0 Compare October 7, 2026 22:56
@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

beta backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels are handled by them.

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Oct 8, 2026
@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

stable backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels are handled by them.

@rustbot rustbot added the stable-accepted Accepted for backporting to the compiler in the stable channel. label Oct 8, 2026
@apiraino

apiraino commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

I have approved the backports without this PR being yet properly reviewed and merged (sorryu about that)

r? compiler

@rustbot rustbot assigned JohnTitor and unassigned workingjubilee Oct 8, 2026
@jieyouxu

jieyouxu commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

A random reroll here is likely unhelpful, ABI handling experts are scarce. I'll ask in the private channel. I'll do a review pass as well.

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change itself looks right to me, at least from what I can gather. Some non-blocking nits.
@rustbot author

View changes since this review

Comment thread compiler/rustc_target/src/callconv/x86_64.rs Outdated
Comment thread compiler/rustc_target/src/callconv/x86_64.rs Outdated
Comment on lines 34 to -36
// ZERO/SIGN-EXTENDING TO 32 BITS NON-EXTENDING
// ============================== =======================
// x86_64: void @c_arg_bool(i1 zeroext %_a)

@jieyouxu jieyouxu Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed that because of how the test is written, if codegen starts adding a zeroext on a return type where it is wrong to do so, the test will pass anyway.

Yeah, that seems a bit awkward since it defeats the purpose of the return checks...

For the non-extending return check cases, can we instead match via patterns such as

// x86_64-linux:                                    define {{(dso_local )?}}i1 @c_ret_bool()

That way if the return type gets a zeroext this check should fail. Using this pattern against the uefi one (where it does zeroext) indeed fails to match.

(This is not blocking; I think we can also do this as a follow-up, since this is pre-existing.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: #164016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we have the option to pass FileCheck arguments, you could also use something like --implicit-check-not=zeroext --implicit-check-not=signext.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah. I'm not sure using the implicit flags is much better though, that also seems not very straightforward when looking at the actual diff right?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2026
@jieyouxu jieyouxu added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 9, 2026
@jieyouxu jieyouxu assigned jieyouxu and unassigned JohnTitor Oct 9, 2026
@saethlin
saethlin force-pushed the bool-return-extend branch from 61f40b0 to 3d42c2c Compare October 9, 2026 03:27

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good to me, thanks. I think the test tightening is fine as a follow-up.

Might be worth waiting for another pair of eyes but don't feel too strongly about it. Feel free to r=me otherwise.

View changes since this review

Comment on lines +248 to +249
// Always extend bool returns, x86_64 psABI requires that on the ABI the top 7 bits are zero
// https://github.com/llvm/llvm-project/issues/12579#issuecomment-2718032943

@nikic nikic Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Always extend bool returns, x86_64 psABI requires that on the ABI the top 7 bits are zero
// https://github.com/llvm/llvm-project/issues/12579#issuecomment-2718032943
// The x86_64 psABI requires bools to be zero-extended to 8-bits, with high bits unspecified.
// zeroext i1 has this behavior in the LLVM X86 backend.

I don't think the comment linked here is super relevant, it's talking about a mismatch in how arguments are handled, where Clang/LLVM apply too much extension.

I also think it's worth mentioning here that using zeroext here for partial extension is correct due to special handling in the X86 backend (which is noteworthy because the same wouldn't be true for the AArch64 backend).

I think it would also be good to make the bool case separate and call arg.extend_integer_width(8) for it. The bit width effectively gets ignored right now (as long as it's larger than the bit width we're starting with), but I think it's confusing to have the extend_integer_width_to(32) when it's not actually extending to 32 bits.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The only hitch is that required updating the implementation of extend_integer_width_to.

@RalfJung

RalfJung commented Oct 9, 2026

Copy link
Copy Markdown
Member

r? @nikic

@rustbot rustbot assigned nikic and unassigned jieyouxu Oct 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. beta-nominated Nominated for backporting to the compiler in the beta channel. O-x86_64 Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. stable-accepted Accepted for backporting to the compiler in the stable channel. stable-nominated Nominated for backporting to the compiler in the stable channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Miscompilation with FFI bool return type on x86_64

10 participants