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

@@ -2,45 +2,45 @@ test cat
test verifier
function %iflags(i32) {
ebb0(v0: i32):
ebb200(v0: i32):
v1 = ifcmp_imm v0, 17
brif eq v1, ebb1
brif ugt v1, ebb2
brif eq v1, ebb201
brif ugt v1, ebb202
v2 = iconst.i32 34
v3 = ifcmp v0, v2
v4 = trueif eq v3
brnz v4, ebb2
brnz v4, ebb202
return
ebb1:
ebb201:
return
ebb2:
ebb202:
trap oob
}
; check: $v1 = ifcmp_imm $v0, 17
; check: brif eq $v1, $ebb1
; check: brif ugt $v1, $ebb2
; check: brif eq $v1, $ebb201
; check: brif ugt $v1, $ebb202
; check: $v3 = ifcmp $v0, $v2
; check: $v4 = trueif eq $v3
function %fflags(f32) {
ebb0(v0: f32):
ebb200(v0: f32):
v1 = f32const 0x34.0p0
v2 = ffcmp v0, v1
brff eq v2, ebb1
brff ord v2, ebb2
brff eq v2, ebb201
brff ord v2, ebb202
v3 = trueff gt v2
brnz v3, ebb2
brnz v3, ebb202
return
ebb1:
ebb201:
return
ebb2:
ebb202:
trap oob
}
; check: $v2 = ffcmp $v0, $v1
; check: brff eq $v2, $ebb1
; check: brff ord $v2, $ebb2
; check: brff eq $v2, $ebb201
; check: brff ord $v2, $ebb202
; check: $v3 = trueff gt $v2

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");