Fix branch_destination/analyze_branch for BranchInt/BranchFloat.

This commit is contained in:
Dan Gohman
2017-11-08 10:27:55 -08:00
parent 889b06fd16
commit e213c2654f
3 changed files with 58 additions and 21 deletions

View File

@@ -335,6 +335,16 @@ impl InstructionData {
ref args,
..
} => BranchInfo::SingleDest(destination, args.as_slice(pool)),
InstructionData::BranchInt {
destination,
ref args,
..
} |
InstructionData::BranchFloat {
destination,
ref args,
..
} |
InstructionData::Branch {
destination,
ref args,
@@ -346,7 +356,10 @@ impl InstructionData {
..
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)[2..]),
InstructionData::BranchTable { table, .. } => BranchInfo::Table(table),
_ => BranchInfo::NotABranch,
_ => {
debug_assert!(!self.opcode().is_branch());
BranchInfo::NotABranch
}
}
}
@@ -358,8 +371,14 @@ impl InstructionData {
match *self {
InstructionData::Jump { destination, .. } |
InstructionData::Branch { destination, .. } |
InstructionData::BranchInt { destination, .. } |
InstructionData::BranchFloat { destination, .. } |
InstructionData::BranchIcmp { destination, .. } => Some(destination),
_ => None,
InstructionData::BranchTable { .. } => None,
_ => {
debug_assert!(!self.opcode().is_branch());
None
}
}
}
@@ -371,8 +390,14 @@ impl InstructionData {
match *self {
InstructionData::Jump { ref mut destination, .. } |
InstructionData::Branch { ref mut destination, .. } |
InstructionData::BranchInt { ref mut destination, .. } |
InstructionData::BranchFloat { ref mut destination, .. } |
InstructionData::BranchIcmp { ref mut destination, .. } => Some(destination),
_ => None,
InstructionData::BranchTable { .. } => None,
_ => {
debug_assert!(!self.opcode().is_branch());
None
}
}
}
@@ -387,7 +412,10 @@ impl InstructionData {
InstructionData::IndirectCall { sig_ref, ref args, .. } => {
CallInfo::Indirect(sig_ref, &args.as_slice(pool)[1..])
}
_ => CallInfo::NotACall,
_ => {
debug_assert!(!self.opcode().is_call());
CallInfo::NotACall
}
}
}
}

View File

@@ -1102,6 +1102,7 @@ mod tests {
use super::{Verifier, Error};
use ir::Function;
use ir::instructions::{InstructionData, Opcode};
use entity::EntityList;
use settings;
macro_rules! assert_err_with_msg {
@@ -1131,10 +1132,18 @@ mod tests {
let ebb0 = func.dfg.make_ebb();
func.layout.append_ebb(ebb0);
let nullary_with_bad_opcode = func.dfg.make_inst(InstructionData::UnaryImm {
opcode: Opcode::Jump,
opcode: Opcode::F32const,
imm: 0.into(),
});
func.layout.append_inst(nullary_with_bad_opcode, ebb0);
func.layout.append_inst(
func.dfg.make_inst(InstructionData::Jump {
opcode: Opcode::Jump,
destination: ebb0,
args: EntityList::default(),
}),
ebb0,
);
let flags = &settings::Flags::new(&settings::builder());
let verifier = Verifier::new(&func, flags.into());
assert_err_with_msg!(verifier.run(), "instruction format");