From a985bc18bcd7dbfc242082782124b925cdaf7df0 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Jul 2016 12:33:19 -0700 Subject: [PATCH] Don't return any values from inst_results() for VOID instructions. Instructions that don't produce any result values are marked with first_type() = VOID. The inst_results() iterator should not return any values for such instructions. --- src/libcretonne/repr.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/libcretonne/repr.rs b/src/libcretonne/repr.rs index a42b9de20f..ff8d5d4dee 100644 --- a/src/libcretonne/repr.rs +++ b/src/libcretonne/repr.rs @@ -1,6 +1,6 @@ //! Representation of Cretonne IL functions. -use types::{Type, FunctionName, Signature}; +use types::{Type, FunctionName, Signature, VOID}; use entities::{Ebb, NO_EBB, Inst, NO_INST, Value, NO_VALUE, ExpandedValue, StackSlot}; use instructions::*; use std::fmt::{self, Display, Formatter}; @@ -167,7 +167,11 @@ impl Function { pub fn inst_results<'a>(&'a self, inst: Inst) -> Values<'a> { Values { func: self, - cur: Value::new_direct(inst), + cur: if self[inst].first_type() == VOID { + NO_VALUE + } else { + Value::new_direct(inst) + }, } } @@ -538,6 +542,26 @@ mod tests { let ins = &func[inst]; assert_eq!(ins.opcode(), Opcode::Iconst); assert_eq!(ins.first_type(), types::I32); + + // Result iterator. + let mut res = func.inst_results(inst); + assert!(res.next().is_some()); + assert!(res.next().is_none()); + } + + #[test] + fn no_results() { + let mut func = Function::new(); + + let idata = InstructionData::Nullary { + opcode: Opcode::Trap, + ty: types::VOID, + }; + let inst = func.make_inst(idata); + + // Result iterator should be empty. + let mut res = func.inst_results(inst); + assert_eq!(res.next(), None); } #[test]