mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-10 02:56:52 +00:00
make uninit_mask a unit test
This commit is contained in:
parent
6b7f6b98c7
commit
edbbb10477
@ -2,6 +2,8 @@
|
||||
|
||||
mod init_mask;
|
||||
mod provenance_map;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
@ -150,7 +150,7 @@ impl InitMask {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get(&self, i: Size) -> bool {
|
||||
pub fn get(&self, i: Size) -> bool {
|
||||
let (block, bit) = Self::bit_index(i);
|
||||
(self.blocks[block] & (1 << bit)) != 0
|
||||
}
|
||||
|
19
compiler/rustc_middle/src/mir/interpret/allocation/tests.rs
Normal file
19
compiler/rustc_middle/src/mir/interpret/allocation/tests.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn uninit_mask() {
|
||||
let mut mask = InitMask::new(Size::from_bytes(500), false);
|
||||
assert!(!mask.get(Size::from_bytes(499)));
|
||||
mask.set_range(alloc_range(Size::from_bytes(499), Size::from_bytes(1)), true);
|
||||
assert!(mask.get(Size::from_bytes(499)));
|
||||
mask.set_range((100..256).into(), true);
|
||||
for i in 0..100 {
|
||||
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
|
||||
}
|
||||
for i in 100..256 {
|
||||
assert!(mask.get(Size::from_bytes(i)), "{i} should be set");
|
||||
}
|
||||
for i in 256..499 {
|
||||
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// run-pass
|
||||
// ignore-cross-compile
|
||||
// ignore-stage1
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate rustc_middle;
|
||||
extern crate rustc_target;
|
||||
|
||||
use rustc_middle::mir::interpret::InitMask;
|
||||
use rustc_target::abi::Size;
|
||||
|
||||
fn main() {
|
||||
let mut mask = InitMask::new(Size::from_bytes(500), false);
|
||||
assert!(!mask.get(Size::from_bytes(499)));
|
||||
mask.set(Size::from_bytes(499), true);
|
||||
assert!(mask.get(Size::from_bytes(499)));
|
||||
mask.set_range_inbounds(Size::from_bytes(100), Size::from_bytes(256), true);
|
||||
for i in 0..100 {
|
||||
assert!(!mask.get(Size::from_bytes(i)));
|
||||
}
|
||||
for i in 100..256 {
|
||||
assert!(mask.get(Size::from_bytes(i)));
|
||||
}
|
||||
for i in 256..499 {
|
||||
assert!(!mask.get(Size::from_bytes(i)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user