Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
405 changes: 5 additions & 400 deletions compiler/noirc_evaluator/src/ssa/opt/die.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/opt/preprocess_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Ssa {
// Try to reduce the number of blocks.
function.simplify_function();
// Remove leftover instructions.
function.dead_instruction_elimination(true, false, false);
function.dead_instruction_elimination(false, false);

// Put it back into the SSA, so the next functions can pick it up.
self.functions.insert(id, function);
Expand Down
22 changes: 22 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,12 +868,34 @@ impl<'a> FunctionContext<'a> {
match lvalue {
LValue::Ident => unreachable!("Cannot assign to a variable without a reference"),
LValue::Index { old_array: mut array, index, array_lvalue, location } => {
let array_type = &self.builder.type_of_value(array);

// Checks for index Out-of-bounds
match array_type {
Type::Array(_, len) => {
let len =
self.builder.numeric_constant(*len as u128, NumericType::length_type());
self.codegen_access_check(index, len);
}
_ => unreachable!("must have array or slice but got {array_type}"),
}

array = self.assign_lvalue_index(new_value, array, index, location);
self.assign_new_value(*array_lvalue, array.into());
}
LValue::SliceIndex { old_slice: slice, index, slice_lvalue, location } => {
let mut slice_values = slice.into_value_list(self);

let array_type = &self.builder.type_of_value(slice_values[1]);

// Checks for index Out-of-bounds
match array_type {
Type::Slice(_) => {
self.codegen_access_check(index, slice_values[0]);
}
_ => unreachable!("must have array or slice but got {array_type}"),
}

slice_values[1] =
self.assign_lvalue_index(new_value, slice_values[1], index, location);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "array_oob_regression_7952"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = [[]]
b = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main(a: [[u32; 0]; 1], b: bool) -> pub [u32; 0] {
if (b) {
a[0]
} else {
a[0]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[array_oob_regression_7952] Circuit output: Vec([])
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "array_oob_regression_7965"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = 1
b = [[0, 1, 0, "\\\t"], [0, 1, 1, "mp"], [0, 0, 0, "\t/"], [0, 0, 0, "ab"]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global G_A: [[bool; 0]; 2] = [[], []];

fn main(a: bool, b: [(u1, bool, u1, str<2>); 4]) -> pub [bool; 0] {
if (a) {
G_A[((((b[0].0 as u8) + (b[0].0 as u8)) as u32) % 2)]
} else {
G_A[((((b[0].0 as u8) + (b[0].0 as u8)) as u32) % 2)]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[array_oob_regression_7965] Circuit output: Vec([])
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "array_oob_regression_7975"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b = [[0]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main(b: [[i1; 1]; 1]) -> pub [[i1; 1]; 1] {
if (b[0][0] == b[0][0]) {
b
} else {
b
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[array_oob_regression_7975] Circuit output: Vec([Vec([Field(0)])])

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading