Skip to content

Commit cbbd067

Browse files
Fix calculation of mask for constant values
This fixes an error when a constant is being loaded into a flag. The constants associated with a flag value have their size set to zero. That causes the mask for the constant value to be all zeros. Due to that, getting the value of a zero sized constant will always return 0 even if it should be 1. This commit special cases the size of zero to create a mask of 1 which will correctly mask off the lowest byte and return that as the constant.
1 parent 98f9bae commit cbbd067

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

rust/src/low_level_il/operation.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,12 +1754,14 @@ where
17541754
}
17551755
}
17561756

1757-
let mut mask = -1i64 as u64;
1758-
1759-
if self.op.size < mem::size_of::<u64>() {
1760-
mask <<= self.op.size * 8;
1761-
mask = !mask;
1762-
}
1757+
let mask: u64 = if self.op.size == 0 {
1758+
1
1759+
} else if self.op.size < mem::size_of::<u64>() {
1760+
let m = -1i64 << (self.op.size * 8);
1761+
!m as u64
1762+
} else {
1763+
(-1i64) as u64
1764+
};
17631765

17641766
self.op.operands[0] & mask
17651767
}

0 commit comments

Comments
 (0)