From: Raiki Tamura Date: Thu, 29 Jun 2023 03:06:44 +0000 (+0900) Subject: gccrs: fix lexing byte literal X-Git-Tag: basepoints/gcc-15~2422 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eebe4063c1a839a71fd21cb477c9d9a6cc906195;p=thirdparty%2Fgcc.git gccrs: fix lexing byte literal gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_byte_char):add check for range of codepoint gcc/testsuite/ChangeLog: * rust/compile/bytecharstring.rs:add test for it Signed-off-by: Raiki Tamura --- diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 7f7fc0c80bff..eef022e53aa2 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1736,6 +1736,12 @@ Lexer::parse_byte_char (Location loc) // otherwise, get character from direct input character byte_char = current_char; + if (byte_char.value > 0x7f) + { + rust_error_at (get_current_location (), + "non-ASCII character in %"); + } + skip_input (); current_char = peek_input (); length++; @@ -1758,8 +1764,6 @@ Lexer::parse_byte_char (Location loc) current_column += length; loc += length - 1; - - // TODO: error when byte_char is non ASCII return Token::make_byte_char (loc, byte_char.value); } diff --git a/gcc/testsuite/rust/compile/bytecharstring.rs b/gcc/testsuite/rust/compile/bytecharstring.rs index 9242e2c5a0bc..928dc0cdefbd 100644 --- a/gcc/testsuite/rust/compile/bytecharstring.rs +++ b/gcc/testsuite/rust/compile/bytecharstring.rs @@ -5,4 +5,7 @@ fn main () let _c = '\xef'; // { dg-error "out of range" } let _s = "Foo\xEFBar"; // { dg-error "out of range" } + + let _ = b'あ'; // { dg-error " non-ASCII character" } + let _ = b'🦀'; // { dg-error " non-ASCII character" } }