https://gcc.gnu.org/g:4cd0f0c6d31dbfbbf5086685b96d9be0ac412a85

commit r16-2837-g4cd0f0c6d31dbfbbf5086685b96d9be0ac412a85
Author: Vishruth-Thimmaiah <vishruththimma...@gmail.com>
Date:   Wed May 28 23:03:27 2025 +0530

    gccrs: fix: ICE when parsing unterminated raw byte strings
    
    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 <vishruththimma...@gmail.com>

Diff:
---
 gcc/rust/lex/rust-lex.cc                                      | 10 +++++-----
 gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs |  6 ++++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 8a5668f38589..76ff15c21bc1 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 000000000000..91a3c9a2ff8e
--- /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"#
+}
+

Reply via email to