Skip to content

Commit 54d1926

Browse files
committed
Check that are operands are allocated within their Limit
Failure to allocate within the limit results in a `CheckerError::AllocationOutsideLimit`.
1 parent 0a2d1bd commit 54d1926

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/checker.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use alloc::vec::Vec;
104104
use alloc::{format, vec};
105105
use core::default::Default;
106106
use core::hash::Hash;
107+
use core::ops::Range;
107108
use core::result::Result;
108109
use smallvec::{smallvec, SmallVec};
109110

@@ -166,6 +167,12 @@ pub enum CheckerError {
166167
into: Allocation,
167168
from: Allocation,
168169
},
170+
AllocationOutsideLimit {
171+
inst: Inst,
172+
op: Operand,
173+
alloc: Allocation,
174+
range: Range<usize>,
175+
},
169176
}
170177

171178
/// Abstract state for an allocation.
@@ -669,6 +676,18 @@ impl CheckerState {
669676
});
670677
}
671678
}
679+
OperandConstraint::Limit(max) => {
680+
if let Some(preg) = alloc.as_reg() {
681+
if preg.hw_enc() >= max {
682+
return Err(CheckerError::AllocationOutsideLimit {
683+
inst,
684+
op,
685+
alloc,
686+
range: (0..max),
687+
});
688+
}
689+
}
690+
}
672691
}
673692
Ok(())
674693
}

0 commit comments

Comments
 (0)