diff options
author | Marc Poulhiès <dkm@kataplop.net> | 2023-07-12 19:00:10 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:00:26 +0100 |
commit | 8b1e1faa7f2eec13df511fa76d181337efb14f4d (patch) | |
tree | b27afcc750e989da83dcf0a659d2e4cf23eb2b54 /gcc/testsuite/rust/compile | |
parent | 3b0a200eb8c986f17c550b902d5f7ab832b716e2 (diff) | |
download | gcc-8b1e1faa7f2eec13df511fa76d181337efb14f4d.zip gcc-8b1e1faa7f2eec13df511fa76d181337efb14f4d.tar.gz gcc-8b1e1faa7f2eec13df511fa76d181337efb14f4d.tar.bz2 |
gccrs: better handling of incorrect file loading in include_* builtin macros
When the load_file_bytes() fails to open the file, it emits an error but
returns an empty vector (as if the file is empty).
Instead, return a tl::optional nullopt in case of error and an empty
vector in case of an empty file.
fixes #2421
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc
(load_file_bytes): Return a tl::optional.
(MacroBuiltin::include_byte_handler): Adjust and check file was
correctly opened.
(MacroBuiltin::include_str_handler): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/empty_file: New file.
* rust/compile/issue-2421_str.rs: New test.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r-- | gcc/testsuite/rust/compile/empty_file | 0 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2421_str.rs | 10 |
2 files changed, 10 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/empty_file b/gcc/testsuite/rust/compile/empty_file new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/gcc/testsuite/rust/compile/empty_file diff --git a/gcc/testsuite/rust/compile/issue-2421_str.rs b/gcc/testsuite/rust/compile/issue-2421_str.rs new file mode 100644 index 0000000..2616ccb --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2421_str.rs @@ -0,0 +1,10 @@ +#![feature(rustc_attrs)] + +#[rustc_builtin_macro] +macro_rules! include_str { + () => {{}}; +} + +fn main() { + include_str!("empty_file"); +} |