From 828b9355354023816d67c671f002ba0752bb7e64 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 18 Jan 2024 17:24:01 +0100 Subject: [PATCH 1/2] testsuite: Fix missing handling of little endian. Some failures occur in the testsuite because we did not account for the little-endian case. gcc/testsuite/ChangeLog: * rust/compile/issue-1446.rs: Add swap_bytes function. * rust/compile/iterators1.rs: Remove unused {to, from}_le functions. --- gcc/testsuite/rust/compile/issue-1446.rs | 10 +++++++++- gcc/testsuite/rust/compile/iterators1.rs | 18 ------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/gcc/testsuite/rust/compile/issue-1446.rs b/gcc/testsuite/rust/compile/issue-1446.rs index 8bfa42b9dace..969ad380ee69 100644 --- a/gcc/testsuite/rust/compile/issue-1446.rs +++ b/gcc/testsuite/rust/compile/issue-1446.rs @@ -1,3 +1,11 @@ +// fake function +pub fn swap_bytes(this: u32) -> u32 { + (((this) & 0xff000000) >> 24) + | (((this) & 0x00ff0000) >> 8) + | (((this) & 0x0000ff00) << 8) + | (((this) & 0x000000ff) << 24) +} + pub fn to_le(this: u32) -> u32 { #[cfg(target_endian = "little")] { @@ -5,6 +13,6 @@ pub fn to_le(this: u32) -> u32 { } #[cfg(not(target_endian = "little"))] { - this.swap_bytes() + swap_bytes(this) } } diff --git a/gcc/testsuite/rust/compile/iterators1.rs b/gcc/testsuite/rust/compile/iterators1.rs index 35fea5a04938..1141758b14a7 100644 --- a/gcc/testsuite/rust/compile/iterators1.rs +++ b/gcc/testsuite/rust/compile/iterators1.rs @@ -232,24 +232,6 @@ macro_rules! impl_uint { } } - pub fn to_le(self) -> Self { - #[cfg(target_endian = "little")] - { - self - } - } - - pub const fn from_le_bytes(bytes: [u8; mem::size_of::()]) -> Self { - Self::from_le(Self::from_ne_bytes(bytes)) - } - - pub const fn from_le(x: Self) -> Self { - #[cfg(target_endian = "little")] - { - x - } - } - pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { unsafe { mem::transmute(bytes) } } From 65ef110d7a43da1e829f20b9805f8de3de69e824 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 23 Jan 2024 17:19:31 +0100 Subject: [PATCH 2/2] gccrs: Fix scan-gimple testcases on LE platforms. gcc/testsuite/ChangeLog: * rust/compile/macros/builtin/eager1.rs: Switch to scan-assembler directive as the GIMPLE dump does not contain strings on LE. * rust/compile/macros/builtin/recurse2.rs: Likewise. --- .../rust/compile/macros/builtin/eager1.rs | 2 +- .../rust/compile/macros/builtin/recurse2.rs | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/rust/compile/macros/builtin/eager1.rs b/gcc/testsuite/rust/compile/macros/builtin/eager1.rs index 65a80fda62ef..7c6f6f95d61c 100644 --- a/gcc/testsuite/rust/compile/macros/builtin/eager1.rs +++ b/gcc/testsuite/rust/compile/macros/builtin/eager1.rs @@ -15,7 +15,7 @@ macro_rules! b { } fn main() { - // { dg-final { scan-tree-dump-times {"test1canary"} 1 gimple } } + // { dg-final { scan-assembler {"test1canary"} } } let _ = concat!(a!(), 1, b!()); // should not error concat!(a!(), true, b!(),); diff --git a/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs b/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs index 2e73ab54fb60..73e6ab4aa6cd 100644 --- a/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs +++ b/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs @@ -15,7 +15,29 @@ macro_rules! a { }; } +extern "C" { + fn printf(fmt: *const i8, ...); +} + +fn print_ptr(s: &str) { + unsafe { + printf("%p\n\0" as *const str as *const i8, s as *const str); + } +} + +fn print_str(s: &str) { + unsafe { + printf( + "%s\n\0" as *const str as *const i8, + s as *const str as *const i8, + ); + } +} + +// { dg-final { scan-assembler {"abheyho"} } } +static S: &str = concat!("a", 'b', a!(), a!(b c d e f a!()), '\0'); + fn main() { - // { dg-final { scan-tree-dump-times {"abheyho"} 1 gimple } } - let _ = concat!("a", 'b', a!(), a!(b c d e f a!()), '\0'); + print_ptr(S); + print_str(S); }