From 8deca81cf289efdb1a10cec19d46633b5ab5a46f Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 22 Sep 2025 15:52:03 -0400 Subject: [PATCH] Fix shifting a value of a smaller type to a bigger type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François Bernier --- build_system/src/test.rs | 3 +-- src/int.rs | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/build_system/src/test.rs b/build_system/src/test.rs index a892d97356c..1823aa71f40 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -714,8 +714,7 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> { let path = get_sysroot_dir().join("sysroot_src/library/coretests"); let _ = remove_dir_all(path.join("target")); // TODO(antoyo): run in release mode when we fix the failures. - // TODO(antoyo): Stop skipping funnel shift tests when those operations are fixed. - run_cargo_command(&[&"test", &"--", &"--skip", &"test_funnel_shift"], Some(&path), env, args)?; + run_cargo_command(&[&"test"], Some(&path), env, args)?; Ok(()) } diff --git a/src/int.rs b/src/int.rs index 9fb7f6bad68..aa1d3b6b091 100644 --- a/src/int.rs +++ b/src/int.rs @@ -83,12 +83,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { let a_size = a_type.get_size(); let b_size = b_type.get_size(); match a_size.cmp(&b_size) { - std::cmp::Ordering::Less => { - let a = self.context.new_cast(self.location, a, b_type); - a >> b - } std::cmp::Ordering::Equal => a >> b, - std::cmp::Ordering::Greater => { + _ => { + // NOTE: it is OK to cast even if b has a type bigger than a because b has + // been masked by codegen_ssa before calling Builder::lshr or + // Builder::ashr. let b = self.context.new_cast(self.location, b, a_type); a >> b } @@ -692,12 +691,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { let a_size = a_type.get_size(); let b_size = b_type.get_size(); match a_size.cmp(&b_size) { - std::cmp::Ordering::Less => { - let a = self.context.new_cast(self.location, a, b_type); - a << b - } std::cmp::Ordering::Equal => a << b, - std::cmp::Ordering::Greater => { + _ => { + // NOTE: it is OK to cast even if b has a type bigger than a because b has + // been masked by codegen_ssa before calling Builder::shl. let b = self.context.new_cast(self.location, b, a_type); a << b }