]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix: ICE when parsing unterminated raw byte strings
authorVishruth-Thimmaiah <vishruththimmaiah@gmail.com>
Wed, 28 May 2025 17:33:27 +0000 (23:03 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:45 +0000 (16:36 +0200)
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 <vishruththimmaiah@gmail.com>
gcc/rust/lex/rust-lex.cc
gcc/testsuite/rust/compile/torture/unended-raw-byte-string.rs [new file with mode: 0644]

index 8a5668f385894e396c69f4ddb0d5c3f5612dfbf0..76ff15c21bc14591c4ceeaeaee6c810e4214eed4 100644 (file)
@@ -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 (file)
index 0000000..91a3c9a
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-excess-errors "...." }
+fn main() {
+    // { dg-error "unended raw byte string literal" "" { target *-*-* } .+1 }
+    let s = br##"123"#
+}
+