Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initialise strings as u8 array #3682

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/// This function will generate the SSA but does not perform any optimizations on it.
pub(crate) fn generate_ssa(program: Program) -> Result<Ssa, RuntimeError> {
// see which parameter has call_data/return_data attribute
let is_databus = DataBusBuilder::is_databus(&program.main_function_signature);

Check warning on line 43 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (databus)

Check warning on line 43 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (databus)

let is_return_data = matches!(program.return_visibility, Visibility::DataBus);

Expand All @@ -61,7 +61,7 @@
);

// Generate the call_data bus from the relevant parameters. We create it *before* processing the function body
let call_data = function_context.builder.call_data_bus(is_databus);

Check warning on line 64 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (databus)

function_context.codegen_function_body(&main.body)?;

Expand All @@ -88,7 +88,7 @@
call_stack.clear();
call_stack.push_back(return_location);
// replace the returned values with the return data array
if let Some(return_data_bus) = return_data.databus {

Check warning on line 91 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (databus)
return_values.clear();
return_values.push(return_data_bus);
}
Expand Down Expand Up @@ -224,8 +224,9 @@
}

fn codegen_string(&mut self, string: &str) -> Values {
let elements =
vecmap(string.as_bytes(), |byte| self.builder.field_constant(*byte as u128).into());
let elements = vecmap(string.as_bytes(), |byte| {
self.builder.numeric_constant(*byte as u128, Type::unsigned(8)).into()
});
let typ = Self::convert_non_tuple_type(&ast::Type::String(elements.len() as u64));
self.codegen_array(elements, typ)
}
Expand Down Expand Up @@ -447,7 +448,7 @@
/// br loop_entry(v0)
/// loop_entry(i: Field):
/// v2 = lt i v1
/// brif v2, then: loop_body, else: loop_end

Check warning on line 451 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (brif)
/// loop_body():
/// v3 = ... codegen body ...
/// v4 = add 1, i
Expand Down Expand Up @@ -501,7 +502,7 @@
/// For example, the expression `if cond { a } else { b }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: else_block

Check warning on line 505 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (brif)
/// then_block():
/// v1 = ... codegen a ...
/// br end_if(v1)
Expand All @@ -514,7 +515,7 @@
/// As another example, the expression `if cond { a }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: end_block

Check warning on line 518 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (brif)
/// then_block:
/// v1 = ... codegen a ...
/// br end_if()
Expand Down
7 changes: 7 additions & 0 deletions test_programs/execution_success/regression_3635/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_3635"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Empty file.
10 changes: 10 additions & 0 deletions test_programs/execution_success/regression_3635/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test unsafe integer multiplication with overflow: 12^8 = 429 981 696
guipublic marked this conversation as resolved.
Show resolved Hide resolved
// The circuit should handle properly the growth of the bit size
use dep::std;

fn main() {
let x: u8 = 0x61;
let y: u8 = "a".as_bytes()[0];
assert_eq(x, y);
assert_eq(x >> 1, y >> 1);
}
Loading