Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/primval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva
U64(_) => 6,
_ => unreachable!(),
};
let mask = (1 << mask_bits) - 1;
let r = match right {
I8(i) => (i & ((1 << mask_bits) - 1)) as u32,
I16(i) => (i & ((1 << mask_bits) - 1)) as u32,
I32(i) => (i & ((1 << mask_bits) - 1)) as u32,
I64(i) => (i & ((1 << mask_bits) - 1)) as u32,
U8(i) => (i & ((1 << mask_bits) - 1)) as u32,
U16(i) => (i & ((1 << mask_bits) - 1)) as u32,
U32(i) => (i & ((1 << mask_bits) - 1)) as u32,
U64(i) => (i & ((1 << mask_bits) - 1)) as u32,
I8(i) => i as u8 & mask,
I16(i) => i as u8 & mask,
I32(i) => i as u8 & mask,
I64(i) => i as u8 & mask,
U8(i) => i as u8 & mask,
U16(i) => i as u8 & mask,
U32(i) => i as u8 & mask,
U64(i) => i as u8 & mask,
_ => panic!("bad MIR: bitshift rhs is not integral"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solson Do you have things set up so you can use bug! and span_bug! from librustc? I think those would be preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be possible. I filed #32.

};
let r = r as u32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, is it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, & mask can be done just once, afterwards.

macro_rules! shift {
($v:ident, $l:ident, $r:ident) => ({
match bin_op {
Expand Down