From 2b2b3f8a0e7aa2f15c626c34cce9eb6abf340692 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 25 Jul 2026 20:56:04 -0400 Subject: [PATCH 1/3] Fix overaligned argument --- src/abi.rs | 13 +++++++--- tests/run/overaligned_byval_arg.rs | 41 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tests/run/overaligned_byval_arg.rs diff --git a/src/abi.rs b/src/abi.rs index 45fc5e3c4f6..2ae60e238ec 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -1,5 +1,5 @@ #[cfg(feature = "master")] -use gccjit::FnAttribute; +use gccjit::{FnAttribute, TypeAttribute}; use gccjit::{ToLValue, ToRValue, Type}; #[cfg(feature = "master")] use rustc_abi::{ArmCall, CanonAbi, InterruptKind, X86Call}; @@ -187,7 +187,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { let ty = cast.gcc_type(cx); apply_attrs(ty, &cast.attrs, argument_tys.len()) } - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: true } => { + PassMode::Indirect { attrs, meta_attrs: None, on_stack: true } => { let x86_interrupt_first_arg = { #[cfg(feature = "master")] { @@ -211,7 +211,14 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { } else { // This is a "byval" argument, so we don't apply the `restrict` attribute on it. on_stack_param_indices.insert(argument_tys.len()); - arg.layout.gcc_type(cx) + let ty = arg.layout.gcc_type(cx); + #[cfg(feature = "master")] + if let Some(align) = attrs.pointee_align { + ty.add_attribute(TypeAttribute::Aligned(align.bytes() as u8)); + } + #[cfg(not(feature = "master"))] + let _ = attrs; + ty } } PassMode::Direct(attrs) => { diff --git a/tests/run/overaligned_byval_arg.rs b/tests/run/overaligned_byval_arg.rs new file mode 100644 index 00000000000..e20ec117329 --- /dev/null +++ b/tests/run/overaligned_byval_arg.rs @@ -0,0 +1,41 @@ +// Compiler: +// +// Run-time: +// status: 0 + +#![feature(no_core)] +#![no_std] +#![no_core] +#![no_main] + +extern crate mini_core; +use mini_core::*; + +#[repr(C)] +struct Big { + a: i64, + b: i64, + c: i64, +} + +#[repr(C, align(64))] +struct Aligned { + x: i32, +} + +#[inline(never)] +#[no_mangle] +extern "C" fn check(_b1: Big, a1: Aligned, _b2: Big, a2: Aligned) -> i32 { + if (&a1 as *const Aligned as usize) % 64 != 0 { + return 1; + } + if (&a2 as *const Aligned as usize) % 64 != 0 { + return 2; + } + 0 +} + +#[no_mangle] +extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 { + check(Big { a: 1, b: 2, c: 3 }, Aligned { x: 42 }, Big { a: 4, b: 5, c: 6 }, Aligned { x: 43 }) +} From 34f4a9c5805a5775d56e590b36b0e8ca8436c028 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 3 Aug 2026 17:36:18 -0400 Subject: [PATCH 2/3] Add -Wno-psabi to silent a warning --- src/gcc_util.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gcc_util.rs b/src/gcc_util.rs index d986dc68e67..56314dca5ef 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -193,6 +193,8 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> { context.add_command_line_option("-fno-strict-aliasing"); // NOTE: Rust relies on LLVM doing wrapping on overflow. context.add_command_line_option("-fwrapv"); + // NOTE: This is needed to hide a warning caused by the alignment fix on byval arguments. + context.add_command_line_option("-Wno-psabi"); if let Some(model) = sess.code_model() { use rustc_target::spec::CodeModel; From db92e5d482fab3149718bf0b903fb90ae00c0518 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 3 Aug 2026 17:38:26 -0400 Subject: [PATCH 3/3] Update gccjit dependency --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/abi.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 060509e51a6..cca0e1e590e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "gccjit" -version = "4.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be5dafc4e649cb4a363e95a5960ef50b0c6f1b8e136ff8eb2e928b40353b5d8b" +checksum = "859af1dd2815fd0f8ca97f5917a595f18c415692b07e58993a6ad34ff13204d5" dependencies = [ "gccjit_sys", ] diff --git a/Cargo.toml b/Cargo.toml index 63a20d46b9d..141949e9189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ default = ["master"] [dependencies] object = { version = "0.37.0", default-features = false, features = ["std", "read"] } tempfile = "3.20" -gccjit = { version = "4.0.0", features = ["dlopen"] } +gccjit = { version = "4.1.0", features = ["dlopen"] } #gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] } # Local copy. diff --git a/src/abi.rs b/src/abi.rs index 2ae60e238ec..445da17dc39 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -214,7 +214,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { let ty = arg.layout.gcc_type(cx); #[cfg(feature = "master")] if let Some(align) = attrs.pointee_align { - ty.add_attribute(TypeAttribute::Aligned(align.bytes() as u8)); + ty.add_attribute(TypeAttribute::Aligned(align.bytes() as u32)); } #[cfg(not(feature = "master"))] let _ = attrs;