Skip to content

make Complex ABI-compatible on sparc64 and powerpc64 - #161697

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
folkertdev:complex-sparc64-powerpc64
Sep 7, 2026
Merged

make Complex ABI-compatible on sparc64 and powerpc64#161697
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
folkertdev:complex-sparc64-powerpc64

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

tracking issue: #154023

Make the ABI for Complex match C for two slightly more involved targets.

For Sparc64 the implementation matches GCC and Clang 24 and up. In llvm/llvm-project#215015 a bug with how small complex numbers are passed was fixed.

For powerpc64 we match Clang exactly (and Clang is compatible with GCC for this target).

cc @beetrees @Gelbpunkt

@folkertdev folkertdev added the F-complex_numbers `#![feature(complex_numbers)]` label Aug 24, 2026
@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 Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 75 candidates
  • Random selection from 16 candidates

@rust-log-analyzer

This comment has been minimized.

Comment on lines +64 to +68
if is_ret {
let reg = Reg { kind: component.reg_kind(), size: component.size() };
arg.cast_to(CastTarget::pair(reg, reg));
}
return;

@beetrees beetrees Aug 24, 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
if is_ret {
let reg = Reg { kind: component.reg_kind(), size: component.size() };
arg.cast_to(CastTarget::pair(reg, reg));
}
return;
let reg = Reg { kind: component.reg_kind(), size: component.size() };
arg.cast_to(CastTarget::pair(reg, reg));
return;

This seems to be relying on the PassMode::ScalarPair ABI matching the C calling convention for arguments, which (AFAIK) is something we generally avoid for non-Rustic ABIs. Any reason this can't unconditionally use PassMode::Cast?

(PassMode::Cast does currently emit less nice LLVM IR than PassMode::ScalarPair, but that's something that needs to be fixed more generally.)

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It almost works, except for Complex<i16> where I discovered this LLVM bug

Clang never runs into that because it just passes two separate arguments.

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
if is_ret {
let reg = Reg { kind: component.reg_kind(), size: component.size() };
arg.cast_to(CastTarget::pair(reg, reg));
}
return;
if (component == Numeric::Int(Integer::I16)) {
// FIXME: Using `PassMode::Cast` here would hit https://github.com/llvm/llvm-project/issues/218676.
return;
}
let reg = Reg { kind: component.reg_kind(), size: component.size() };
arg.cast_to(CastTarget::pair(reg, reg));
return;

I think this would work then, with the FIXME as a reminder to remove it once the bug is fixed (and/or if/when we stop using LLVM structs as the default option for PassMode::Cast arguments).

@folkertdev
folkertdev force-pushed the complex-sparc64-powerpc64 branch from b5b4c02 to 9e30f0a Compare August 25, 2026 14:12

@Gelbpunkt Gelbpunkt 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.

The powerpc64 changes look correct to me based on my understanding of the ELFv2, ELFv1 and AIX ABIs.

View changes since this review

Comment on lines +68 to +74
//@ revisions: POWERPC64LE POWERPC64 AIX
//@ [POWERPC64LE] compile-flags: --target powerpc64le-unknown-linux-gnu
//@ [POWERPC64LE] needs-llvm-components: powerpc
//@ [POWERPC64] compile-flags: --target powerpc64-unknown-linux-gnu
//@ [POWERPC64] needs-llvm-components: powerpc
//@ [AIX] compile-flags: --target powerpc64-ibm-aix
//@ [AIX] needs-llvm-components: powerpc

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.

I presume you chose these three for testing the three ABIs, so perhaps that could be more clear by calling them ELFV2, ELFV1 and AIX?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

well also endianness, and aix just because it's weird.

@folkertdev
folkertdev force-pushed the complex-sparc64-powerpc64 branch from 9e30f0a to 9e53b26 Compare September 4, 2026 17:05
@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JohnTitor JohnTitor 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.

@rust-bors

rust-bors Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9e53b26 has been approved by JohnTitor

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 7, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 7, 2026
Rollup of 14 pull requests

Successful merges:

 - #162404 (`rust-analyzer` subtree update)
 - #161624 (diagnostics: Point closure trait errors at captured values)
 - #161697 (make `Complex` ABI-compatible on sparc64 and powerpc64)
 - #162182 (delay unexpected successful goal during ambiguity reporting)
 - #162328 (Allow overriding filecheck even if LLVM is built or downloaded)
 - #162367 (Use `reason` for tracked item diagnostics from `cfg_select!`)
 - #162381 (fix bare urls split text)
 - #162388 (std: fix set_permissions_nofollow on espidf and horizon)
 - #162319 (docs(core): correct ARMv8-M Baseline atomic CAS support)
 - #162341 (add regression test for packus_epi16 issue)
 - #162383 (Add a hint for using `nolimit` to the limiting error message)
 - #162384 (remove EnumSizeOpt)
 - #162390 (remove outdated comment in `UnsafeCell::raw_get` source)
 - #162397 (docs: Ask for ABI documentation in the platform support template)
@rust-bors
rust-bors Bot merged commit 4e27adb into rust-lang:main Sep 7, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 7, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 7, 2026
Rollup merge of #161697 - folkertdev:complex-sparc64-powerpc64, r=JohnTitor

make `Complex` ABI-compatible on sparc64 and powerpc64

tracking issue: #154023

Make the ABI for `Complex` match C for two slightly more involved targets.

For Sparc64 the implementation matches GCC and Clang 24 and up. In llvm/llvm-project#215015 a bug with how small complex numbers are passed was fixed.

For powerpc64 we match Clang exactly (and Clang is compatible with GCC for this target).

cc @beetrees @Gelbpunkt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-complex_numbers `#![feature(complex_numbers)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants