diff options
author | Raiki Tamura <tamaron1203@gmail.com> | 2023-07-04 18:21:48 +0900 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:49:31 +0100 |
commit | 43115ccccc8df9fcbe89fae0af0b9f45146530e6 (patch) | |
tree | 05fa3ca8fb7cc385888c91c1e72169444919b50e /gcc/rust/rust-session-manager.cc | |
parent | ba06fbcf5d5d1ed4b4f7cba0f349fc942db776fe (diff) | |
download | gcc-43115ccccc8df9fcbe89fae0af0b9f45146530e6.zip gcc-43115ccccc8df9fcbe89fae0af0b9f45146530e6.tar.gz gcc-43115ccccc8df9fcbe89fae0af0b9f45146530e6.tar.bz2 |
gccrs: add utf-8 validation for input source
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::input_source_is_valid_utf8): New method of `Lexer`.
* lex/rust-lex.h: Likewise.
* rust-session-manager.cc (Session::compile_crate): Add error.
gcc/testsuite/ChangeLog:
* rust/compile/broken_utf8.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 8613c1c..aaf19f3 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -497,6 +497,14 @@ Session::compile_crate (const char *filename) Lexer lex (filename, std::move (file_wrap), linemap, dump_lex_opt); + if (!lex.input_source_is_valid_utf8 ()) + { + rust_error_at (Linemap::unknown_location (), + "cannot read %s; stream did not contain valid UTF-8", + filename); + return; + } + Parser<Lexer> parser (lex); // generate crate from parser |