From abfb39e2c6942efb6a60fc25bd6fe9fee2c15392 Mon Sep 17 00:00:00 2001 From: Raiki Tamura Date: Thu, 29 Jun 2023 12:06:44 +0900 Subject: 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 --- gcc/rust/lex/rust-lex.cc | 8 ++++++-- gcc/testsuite/rust/compile/bytecharstring.rs | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 28f3863..a921204 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 9242e2c..928dc0c 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" } } -- cgit v1.1