Skip to content

Commit 97e1942

Browse files
authored
Merge pull request #765 from rust-lang/fix/shift
Fix shifting a value of a smaller type to a bigger type
2 parents 2426181 + 8deca81 commit 97e1942

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

build_system/src/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,7 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
714714
let path = get_sysroot_dir().join("sysroot_src/library/coretests");
715715
let _ = remove_dir_all(path.join("target"));
716716
// TODO(antoyo): run in release mode when we fix the failures.
717-
// TODO(antoyo): Stop skipping funnel shift tests when those operations are fixed.
718-
run_cargo_command(&[&"test", &"--", &"--skip", &"test_funnel_shift"], Some(&path), env, args)?;
717+
run_cargo_command(&[&"test"], Some(&path), env, args)?;
719718
Ok(())
720719
}
721720

src/int.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
8383
let a_size = a_type.get_size();
8484
let b_size = b_type.get_size();
8585
match a_size.cmp(&b_size) {
86-
std::cmp::Ordering::Less => {
87-
let a = self.context.new_cast(self.location, a, b_type);
88-
a >> b
89-
}
9086
std::cmp::Ordering::Equal => a >> b,
91-
std::cmp::Ordering::Greater => {
87+
_ => {
88+
// NOTE: it is OK to cast even if b has a type bigger than a because b has
89+
// been masked by codegen_ssa before calling Builder::lshr or
90+
// Builder::ashr.
9291
let b = self.context.new_cast(self.location, b, a_type);
9392
a >> b
9493
}
@@ -692,12 +691,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
692691
let a_size = a_type.get_size();
693692
let b_size = b_type.get_size();
694693
match a_size.cmp(&b_size) {
695-
std::cmp::Ordering::Less => {
696-
let a = self.context.new_cast(self.location, a, b_type);
697-
a << b
698-
}
699694
std::cmp::Ordering::Equal => a << b,
700-
std::cmp::Ordering::Greater => {
695+
_ => {
696+
// NOTE: it is OK to cast even if b has a type bigger than a because b has
697+
// been masked by codegen_ssa before calling Builder::shl.
701698
let b = self.context.new_cast(self.location, b, a_type);
702699
a << b
703700
}

0 commit comments

Comments
 (0)