From 209ed071bab1cad917c825c55f3a83feb72cd664 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 20 May 2023 16:54:12 -0400 Subject: [PATCH] align-byval test: add cases for <= align 4 --- tests/codegen/align-byval.rs | 52 ++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/tests/codegen/align-byval.rs b/tests/codegen/align-byval.rs index 10ded42bd66..03641b00c5f 100644 --- a/tests/codegen/align-byval.rs +++ b/tests/codegen/align-byval.rs @@ -29,6 +29,19 @@ impl Copy for i32 {} impl Copy for i64 {} +#[repr(C)] +pub struct NaturalAlign2 { + a: [i16; 16], + b: i16, +} + +#[repr(C)] +#[repr(align(4))] +pub struct ForceAlign4 { + a: [i8; 16], + b: i8, +} + // on i686-windows, this should be passed on stack using `byval` #[repr(C)] pub struct NaturalAlign8 { @@ -37,7 +50,7 @@ pub struct NaturalAlign8 { c: i64 } -// on i686-windows, this should be passed by reference (because the alignment is requested/forced), +// on i686-windows, this is passed by reference (because alignment is >4 and requested/forced), // even though it has the exact same layout as `NaturalAlign8` (!!!) #[repr(C)] #[repr(align(8))] @@ -55,6 +68,36 @@ pub struct ForceAlign16 { } extern "C" { + // m68k: declare void @natural_align_2({{.*}}byval(%NaturalAlign2) align 2{{.*}}) + + // wasm: declare void @natural_align_2({{.*}}byval(%NaturalAlign2) align 2{{.*}}) + + // x86_64-linux: declare void @natural_align_2({{.*}}byval(%NaturalAlign2) align 2{{.*}}) + + // x86_64-windows: declare void @natural_align_2( + // x86_64-windows-NOT: byval + // x86_64-windows-SAME: align 2{{.*}}) + + // i686-linux: declare void @natural_align_2({{.*}}byval(%NaturalAlign2) align 4{{.*}}) + + // i686-windows: declare void @natural_align_2({{.*}}byval(%NaturalAlign2) align 4{{.*}}) + fn natural_align_2(a: NaturalAlign2); + + // m68k: declare void @force_align_4({{.*}}byval(%ForceAlign4) align 4{{.*}}) + + // wasm: declare void @force_align_4({{.*}}byval(%ForceAlign4) align 4{{.*}}) + + // x86_64-linux: declare void @force_align_4({{.*}}byval(%ForceAlign4) align 4{{.*}}) + + // x86_64-windows: declare void @force_align_4( + // x86_64-windows-NOT: byval + // x86_64-windows-SAME: align 4{{.*}}) + + // i686-linux: declare void @force_align_4({{.*}}byval(%ForceAlign4) align 4{{.*}}) + + // i686-windows: declare void @force_align_4({{.*}}byval(%ForceAlign4) align 4{{.*}}) + fn force_align_4(b: ForceAlign4); + // m68k: declare void @natural_align_8({{.*}}byval(%NaturalAlign8) align 4{{.*}}) // wasm: declare void @natural_align_8({{.*}}byval(%NaturalAlign8) align 8{{.*}}) @@ -105,7 +148,12 @@ pub struct ForceAlign16 { fn force_align_16(z: ForceAlign16); } -pub unsafe fn main(x: NaturalAlign8, y: ForceAlign8, z: ForceAlign16) { +pub unsafe fn main( + a: NaturalAlign2, b: ForceAlign4, + x: NaturalAlign8, y: ForceAlign8, z: ForceAlign16 +) { + natural_align_2(a); + force_align_4(b); natural_align_8(x); force_align_8(y); force_align_16(z);