Verify that constant values are the correct size
Since we now allow constants of any size, we have to verify that `vconst` (currently the only user of the constant pool) is accessing constants that match its controlling type.
This commit is contained in:
@@ -65,8 +65,9 @@ use crate::ir;
|
||||
use crate::ir::entities::AnyEntity;
|
||||
use crate::ir::instructions::{BranchInfo, CallInfo, InstructionFormat, ResolvedConstraint};
|
||||
use crate::ir::{
|
||||
types, ArgumentLoc, Block, FuncRef, Function, GlobalValue, Inst, InstructionData, JumpTable,
|
||||
Opcode, SigRef, StackSlot, StackSlotKind, Type, Value, ValueDef, ValueList, ValueLoc,
|
||||
types, ArgumentLoc, Block, Constant, FuncRef, Function, GlobalValue, Inst, InstructionData,
|
||||
JumpTable, Opcode, SigRef, StackSlot, StackSlotKind, Type, Value, ValueDef, ValueList,
|
||||
ValueLoc,
|
||||
};
|
||||
use crate::isa::TargetIsa;
|
||||
use crate::iterators::IteratorExtras;
|
||||
@@ -733,16 +734,23 @@ impl<'a> Verifier<'a> {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Unary {
|
||||
opcode: Opcode::Bitcast,
|
||||
arg,
|
||||
} => {
|
||||
self.verify_bitcast(inst, arg, errors)?;
|
||||
}
|
||||
UnaryConst {
|
||||
opcode: Opcode::Vconst,
|
||||
constant_handle,
|
||||
..
|
||||
} => {
|
||||
self.verify_constant_size(inst, constant_handle, errors)?;
|
||||
}
|
||||
|
||||
// Exhaustive list so we can't forget to add new formats
|
||||
Unary { .. }
|
||||
| UnaryConst { .. }
|
||||
| UnaryImm { .. }
|
||||
| UnaryIeee32 { .. }
|
||||
| UnaryIeee64 { .. }
|
||||
@@ -752,7 +760,6 @@ impl<'a> Verifier<'a> {
|
||||
| Ternary { .. }
|
||||
| InsertLane { .. }
|
||||
| ExtractLane { .. }
|
||||
| UnaryConst { .. }
|
||||
| Shuffle { .. }
|
||||
| IntCompare { .. }
|
||||
| IntCompareImm { .. }
|
||||
@@ -1075,6 +1082,27 @@ impl<'a> Verifier<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_constant_size(
|
||||
&self,
|
||||
inst: Inst,
|
||||
constant: Constant,
|
||||
errors: &mut VerifierErrors,
|
||||
) -> VerifierStepResult<()> {
|
||||
let type_size = self.func.dfg.ctrl_typevar(inst).bytes() as usize;
|
||||
let constant_size = self.func.dfg.constants.get(constant).len();
|
||||
if type_size != constant_size {
|
||||
errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"The instruction expects {} to have a size of {} bytes but it has {}",
|
||||
constant, type_size, constant_size
|
||||
),
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn domtree_integrity(
|
||||
&self,
|
||||
domtree: &DominatorTree,
|
||||
|
||||
Reference in New Issue
Block a user