From: Vishruth-Thimmaiah <[email protected]>
Fixes an ICE when a raw byte string is not terminated
Fixes Rust-GCC#3731
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::parse_raw_byte_string):
Fix infinite looping when a raw byte string is not terminated.
gcc/testsuite/ChangeLog:
* rust/compile/torture/unended-raw-byte-string.rs:
New test to ensure correct error message for unended raw byte string.
Signed-off-by: Vishruth Thimmaiah <[email protected]>
---
gcc/rust/lex/rust-lex.cc | 10 +++++-----
.../rust/compile/torture/unended-raw-byte-string.rs | 6 ++++++
2 files changed, 11 insertions(+), 5 deletions(-)
create mode 100644
gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 8a5668f3858..76ff15c21bc 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -1897,6 +1897,11 @@ Lexer::parse_raw_byte_string (location_t loc)
break;
}
}
+ else if (current_char.is_eof ())
+ {
+ rust_error_at (string_begin_locus, "unended raw byte string literal");
+ return Token::make (END_OF_FILE, get_current_location ());
+ }
else if (current_char.value > 127)
{
rust_error_at (get_current_location (),
@@ -1904,11 +1909,6 @@ Lexer::parse_raw_byte_string (location_t loc)
current_char.as_string ().c_str ());
current_char = 0;
}
- else if (current_char.is_eof ())
- {
- rust_error_at (string_begin_locus, "unended raw byte string literal");
- return Token::make (END_OF_FILE, get_current_location ());
- }
length++;
current_column++;
diff --git a/gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs
b/gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs
new file mode 100644
index 00000000000..91a3c9a2ff8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs
@@ -0,0 +1,6 @@
+// { dg-excess-errors "...." }
+fn main() {
+ // { dg-error "unended raw byte string literal" "" { target *-*-* } .+1 }
+ let s = br##"123"#
+}
+
--
2.49.0