diff --git a/compiler/noirc_evaluator/src/ssa/opt/die.rs b/compiler/noirc_evaluator/src/ssa/opt/die.rs index 095413d7b9a..7356998ceb8 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/die.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/die.rs @@ -191,6 +191,7 @@ impl Context { self.used_values.insert(value_id); } Value::Array { array, .. } => { + self.used_values.insert(value_id); for elem in array { self.mark_used_instruction_results(dfg, *elem); } @@ -198,6 +199,9 @@ impl Context { Value::Param { .. } => { self.used_values.insert(value_id); } + Value::NumericConstant { .. } => { + self.used_values.insert(value_id); + } _ => { // Does not comprise of any instruction results } diff --git a/test_programs/execution_success/brillig_constant_reference_regression/Nargo.toml b/test_programs/execution_success/brillig_constant_reference_regression/Nargo.toml new file mode 100644 index 00000000000..2df127c83e8 --- /dev/null +++ b/test_programs/execution_success/brillig_constant_reference_regression/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "brillig_constant_reference_regression" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/brillig_constant_reference_regression/Prover.toml b/test_programs/execution_success/brillig_constant_reference_regression/Prover.toml new file mode 100644 index 00000000000..8fbe88fbb98 --- /dev/null +++ b/test_programs/execution_success/brillig_constant_reference_regression/Prover.toml @@ -0,0 +1 @@ +sorted_index = ["1", "0"] diff --git a/test_programs/execution_success/brillig_constant_reference_regression/src/main.nr b/test_programs/execution_success/brillig_constant_reference_regression/src/main.nr new file mode 100644 index 00000000000..c975d20a3b6 --- /dev/null +++ b/test_programs/execution_success/brillig_constant_reference_regression/src/main.nr @@ -0,0 +1,16 @@ +unconstrained fn main(sorted_index: [u32; 2]) { + let original = [ + 55, + 11 + ]; + + let mut sorted = original; // Stores the constant "original" into the sorted reference + + for i in 0..2 { + let index = sorted_index[i]; + let value = original[index]; + sorted[i] = value; // On first iteration, we should not mutate the original constant array, RC should be > 1 + } + + assert_eq(sorted[1], 55); +}