@@ -160,6 +160,7 @@ pub fn simplify_program(mut program: Program) -> SimpleProgram {
160160 for ( name, func) in & program. functions {
161161 let mut array_manager = ArrayManager :: default ( ) ;
162162 let simplified_instructions = simplify_lines (
163+ & program. functions ,
163164 & func. body ,
164165 & mut counters,
165166 & mut new_functions,
@@ -436,6 +437,7 @@ impl ArrayManager {
436437}
437438
438439fn simplify_lines (
440+ functions : & BTreeMap < String , Function > ,
439441 lines : & [ Line ] ,
440442 counters : & mut Counters ,
441443 new_functions : & mut BTreeMap < String , SimpleFunction > ,
@@ -455,6 +457,7 @@ fn simplify_lines(
455457 for ( i, ( pattern, statements) ) in arms. iter ( ) . enumerate ( ) {
456458 assert_eq ! ( * pattern, i, "match patterns should be consecutive, starting from 0" ) ;
457459 simple_arms. push ( simplify_lines (
460+ functions,
458461 statements,
459462 counters,
460463 new_functions,
@@ -606,6 +609,7 @@ fn simplify_lines(
606609
607610 let mut array_manager_then = array_manager. clone ( ) ;
608611 let then_branch_simplified = simplify_lines (
612+ functions,
609613 then_branch,
610614 counters,
611615 new_functions,
@@ -617,6 +621,7 @@ fn simplify_lines(
617621 array_manager_else. valid = array_manager. valid . clone ( ) ; // Crucial: remove the access added in the IF branch
618622
619623 let else_branch_simplified = simplify_lines (
624+ functions,
620625 else_branch,
621626 counters,
622627 new_functions,
@@ -666,6 +671,7 @@ fn simplify_lines(
666671 let mut body_copy = body. clone ( ) ;
667672 replace_vars_for_unroll ( & mut body_copy, iterator, unroll_index, i, & internal_variables) ;
668673 unrolled_lines. extend ( simplify_lines (
674+ functions,
669675 & body_copy,
670676 counters,
671677 new_functions,
@@ -689,6 +695,7 @@ fn simplify_lines(
689695 let valid_aux_vars_in_array_manager_before = array_manager. valid . clone ( ) ;
690696 array_manager. valid . clear ( ) ;
691697 let simplified_body = simplify_lines (
698+ functions,
692699 body,
693700 counters,
694701 new_functions,
@@ -763,6 +770,11 @@ fn simplify_lines(
763770 return_data,
764771 line_number,
765772 } => {
773+ let function = functions. get ( function_name) . expect ( "Function used but not defined: {function_name}" ) ;
774+ if return_data. len ( ) != function. n_returned_vars {
775+ panic ! ( "Expected {} returned vars in call to {function_name}" , function. n_returned_vars) ;
776+ }
777+
766778 let simplified_args = args
767779 . iter ( )
768780 . map ( |arg| simplify_expr ( arg, & mut res, counters, array_manager, const_malloc) )
0 commit comments