[codegen] Check for downcasting in bitcast instruction
Bitcasting to a smaller size is invalid. closes #854
This commit is contained in:
committed by
Benjamin Bouvier
parent
5426e42a27
commit
863ac809d9
@@ -696,6 +696,13 @@ impl<'a> Verifier<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
Unary {
|
||||
opcode: Opcode::Bitcast,
|
||||
arg,
|
||||
} => {
|
||||
self.verify_bitcast(inst, arg, errors)?;
|
||||
}
|
||||
|
||||
// Exhaustive list so we can't forget to add new formats
|
||||
Unary { .. }
|
||||
| UnaryImm { .. }
|
||||
@@ -981,6 +988,28 @@ impl<'a> Verifier<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_bitcast(
|
||||
&self,
|
||||
inst: Inst,
|
||||
arg: Value,
|
||||
errors: &mut VerifierErrors,
|
||||
) -> VerifierStepResult<()> {
|
||||
let typ = self.func.dfg.ctrl_typevar(inst);
|
||||
let value_type = self.func.dfg.value_type(arg);
|
||||
|
||||
if typ.lane_bits() < value_type.lane_bits() {
|
||||
fatal!(
|
||||
errors,
|
||||
inst,
|
||||
"The bitcast argument {} doesn't fit in a type of {} bits",
|
||||
arg,
|
||||
typ.lane_bits()
|
||||
)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn domtree_integrity(
|
||||
&self,
|
||||
domtree: &DominatorTree,
|
||||
|
||||
Reference in New Issue
Block a user