[codegen] Check for downcasting in bitcast instruction

Bitcasting to a smaller size is invalid.

closes #854
This commit is contained in:
Wander Lairson Costa
2019-09-16 18:59:23 -03:00
committed by Benjamin Bouvier
parent 5426e42a27
commit 863ac809d9
2 changed files with 52 additions and 0 deletions

View File

@@ -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,