diff --git a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs index 22daba1de45..806085743d4 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs @@ -302,6 +302,11 @@ impl Loop { pub(super) fn get_const_upper_bound(&self, function: &Function) -> Option { let block = &function.dfg[self.header]; let instructions = block.instructions(); + if instructions.is_empty() { + // If the loop condition is constant time, the loop header will be + // simplified to a simple jump. + return None; + } assert_eq!( instructions.len(), 1, diff --git a/test_programs/execution_success/regression_6734/Nargo.toml b/test_programs/execution_success/regression_6734/Nargo.toml new file mode 100644 index 00000000000..4c757bab454 --- /dev/null +++ b/test_programs/execution_success/regression_6734/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "regression_6734" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/regression_6734/src/main.nr b/test_programs/execution_success/regression_6734/src/main.nr new file mode 100644 index 00000000000..87cac64aaa1 --- /dev/null +++ b/test_programs/execution_success/regression_6734/src/main.nr @@ -0,0 +1,24 @@ +// https://github.com/noir-lang/noir/issues/6734 + +pub fn sub_array_extended( + src: [Field; SRC_LEN], + offset: u32, +) -> [Field; DST_LEN] { + let available_elements_to_copy = SRC_LEN - offset; + let elements_to_copy = if DST_LEN > available_elements_to_copy { + available_elements_to_copy + } else { + DST_LEN + }; + + let mut dst: [Field; DST_LEN] = std::mem::zeroed(); + for i in 0..elements_to_copy { + dst[i] = src[i + offset]; + } + + dst +} + +unconstrained fn main() { + assert_eq(sub_array_extended([], 0), []); +}