Skip to content

c-variadic: use emit_ptr_va_arg for mips#152576

Open
folkertdev wants to merge 3 commits intorust-lang:mainfrom
folkertdev:mips-va-arg
Open

c-variadic: use emit_ptr_va_arg for mips#152576
folkertdev wants to merge 3 commits intorust-lang:mainfrom
folkertdev:mips-va-arg

Conversation

@folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Feb 13, 2026

tracking issue: #44930

After reading the implementation carefully, I believe it really is just emit_ptr_va_arg.

The LLVM implementation can be found here: https://github.com/llvm/llvm-project/blob/289a3292be0c6a3df86bcdf5be7dd05b79a5570c/llvm/lib/Target/Mips/MipsISelLowering.cpp#L2338.

r? workingjubilee

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Feb 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2026

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

bx,
addr,
target_ty,
PassMode::Direct,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing in the LLVM implementation suggests a double load. byval is not handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and there is no conditional logic based on the size either

Comment on lines +1178 to +1182
match bx.tcx().sess.target.pointer_width {
32 => SlotSize::Bytes4,
64 => SlotSize::Bytes8,
_ => unreachable!(),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on

  unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4;

64 => SlotSize::Bytes8,
_ => unreachable!(),
},
AllowHigherAlign::Yes,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the code allows, and corrects for, a higher alignment

if (Align > getMinStackArgumentAlignment()) {

Comment on lines +1184 to +1187
match bx.tcx().sess.target.endian {
Endian::Big => ForceRightAdjust::Yes,
Endian::Little => ForceRightAdjust::No,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is a whole comment about this

  // In big-endian mode we must adjust the pointer when the load size is smaller
  // than the argument slot size. We must also reduce the known alignment to
  // match. For example in the N64 ABI, we must add 4 bytes to the offset to get
  // the correct half of the slot, and reduce the alignment from 8 (slot
  // alignment) down to 4 (type alignment).

@folkertdev folkertdev added the F-c_variadic `#![feature(c_variadic)]` label Feb 13, 2026
@folkertdev folkertdev changed the title Mips va arg c-variadic: use emit_ptr_va_arg for mips Feb 13, 2026
@folkertdev
Copy link
Contributor Author

Pinging some target maintainers:

@Gelbpunkt @wzssyqa @chenx97 @709924470 @Cyanoxygen @Fearyncess

Mostly this is just a heads-up. You could try to run (with your target) this test to be sure that it all works:

./x test tests/run-make/c-link-to-rust-va-list-fn --target mipsel-unknown-linux-gnu

this likely needs some sort of config in bootstrap.toml, I have

[target.mips64-unknown-linux-gnuabi64]
runner = "qemu-mips64 -L /usr/mips64-linux-gnuabi64"

[target.mipsel-unknown-linux-gnu]
runner = "qemu-mipsel -cpu 24Kf -L /usr/mipsel-linux-gnu"

[target.mips-unknown-linux-gnu]
runner = "qemu-mips -L /usr/mips-linux-gnu"

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-c_variadic `#![feature(c_variadic)]` 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants