Skip to content

Commit 5ec1647

Browse files
asteriteTomAFrench
andauthored
fix(SSA): don't use string literal if byte is "form feed" ('\f') (#8653)
Co-authored-by: Tom French <[email protected]>
1 parent d3cb2b2 commit 5ec1647

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

compiler/noirc_evaluator/src/ssa/ir/printer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,12 @@ fn try_byte_array_to_string(elements: &Vector<ValueId>, dfg: &DataFlowGraph) ->
338338
if element > 0xFF {
339339
return None;
340340
}
341-
let byte = element as u8;
342-
if byte.is_ascii_alphanumeric() || byte.is_ascii_punctuation() || byte.is_ascii_whitespace()
341+
let byte: u8 = element as u8;
342+
const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings
343+
if byte != FORM_FEED
344+
&& (byte.is_ascii_alphanumeric()
345+
|| byte.is_ascii_punctuation()
346+
|| byte.is_ascii_whitespace())
343347
{
344348
string.push(byte as char);
345349
} else {

compiler/noirc_evaluator/src/ssa/parser/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ fn test_make_byte_slice_with_string_literal() {
126126
assert_ssa_roundtrip(src);
127127
}
128128

129+
#[test]
130+
fn test_does_not_use_byte_array_literal_for_form_feed() {
131+
// 12 is '\f', which isn't available in string literals (because in Rust it's the same)
132+
let src = "
133+
acir(inline) fn main f0 {
134+
b0():
135+
v1 = make_array [u8 12] : [u8; 1]
136+
return v1
137+
}
138+
";
139+
assert_ssa_roundtrip(src);
140+
}
141+
129142
#[test]
130143
fn test_block_parameters() {
131144
let src = "

0 commit comments

Comments
 (0)