Fix Invalid Instruction format in fuzzgen (#4738)
* cranelift: Add assert to prevent wrong InstFormat being used for the wrong opcode * cranelift: Use correct instruction format when inserting opcodes in fuzzgen (fixes #4733) * cranelift: Use debug assert on InstFormat assert
This commit is contained in:
@@ -902,6 +902,9 @@ fn gen_format_constructor(format: &InstructionFormat, fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "data.sign_extend_immediates(ctrl_typevar);");
|
||||
}
|
||||
|
||||
// Assert that this opcode belongs to this format
|
||||
fmtln!(fmt, "debug_assert_eq!(opcode.format(), InstructionFormat::from(&data), \"Wrong InstructionFormat for Opcode: {}\", opcode);");
|
||||
|
||||
fmt.line("self.build(data, ctrl_typevar)");
|
||||
});
|
||||
fmtln!(fmt, "}");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//! function. Many of its methods are generated from the meta language instruction definitions.
|
||||
|
||||
use crate::ir;
|
||||
use crate::ir::instructions::InstructionFormat;
|
||||
use crate::ir::types;
|
||||
use crate::ir::{DataFlowGraph, InstructionData};
|
||||
use crate::ir::{Inst, Opcode, Type, Value};
|
||||
@@ -217,7 +218,7 @@ mod tests {
|
||||
use crate::cursor::{Cursor, FuncCursor};
|
||||
use crate::ir::condcodes::*;
|
||||
use crate::ir::types::*;
|
||||
use crate::ir::{Function, InstBuilder, ValueDef};
|
||||
use crate::ir::{Function, InstBuilder, Opcode, TrapCode, ValueDef};
|
||||
|
||||
#[test]
|
||||
fn types() {
|
||||
@@ -262,4 +263,17 @@ mod tests {
|
||||
assert!(iadd != iconst);
|
||||
assert_eq!(pos.func.dfg.value_def(v0), ValueDef::Result(iconst, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn panics_when_inserting_wrong_opcode() {
|
||||
let mut func = Function::new();
|
||||
let block0 = func.dfg.make_block();
|
||||
let mut pos = FuncCursor::new(&mut func);
|
||||
pos.insert_block(block0);
|
||||
|
||||
// We are trying to create a Opcode::Return with the InstData::Trap, which is obviously wrong
|
||||
pos.ins()
|
||||
.Trap(Opcode::Return, I32, TrapCode::BadConversionToInteger);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user