diff options
author | Nikos Alexandris <nikos-alexandris@protonmail.com> | 2023-03-02 03:14:46 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-03-02 09:19:00 +0000 |
commit | 6d25dac7370289ef8e44f1f8370572aebac6e8e4 (patch) | |
tree | 0d18cb3e16c6814673fd3016afb2de229eb2deba /gcc/rust/expand/rust-macro-builtins.cc | |
parent | 9ec974b93e7442b5babbea91683de64bf1b02dbd (diff) | |
download | gcc-6d25dac7370289ef8e44f1f8370572aebac6e8e4.zip gcc-6d25dac7370289ef8e44f1f8370572aebac6e8e4.tar.gz gcc-6d25dac7370289ef8e44f1f8370572aebac6e8e4.tar.bz2 |
Add location info when opening a file fails in include_str and include_bytes. Resolves issue #1872
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (load_file_bytes): Add location parameter.
(MacroBuiltin::include_bytes_handler): Pass location to load_file_bytes.
(MacroBuiltin::include_str_handler): Pass location to load_file_bytes.
gcc/testsuite/ChangeLog:
* rust/compile/builtin_macro_include_bytes_location_info.rs: New test.
* rust/compile/builtin_macro_include_str_location_info.rs: New test.
Signed-off-by: Nikos Alexandris <nikos-alexandris@protonmail.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index d7f1578..5f317a0 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -308,12 +308,12 @@ source_relative_path (std::string path, Location locus) FIXME: platform specific. */ std::vector<uint8_t> -load_file_bytes (const char *filename) +load_file_bytes (Location invoc_locus, const char *filename) { RAIIFile file_wrap (filename); if (file_wrap.get_raw () == nullptr) { - rust_error_at (Location (), "cannot open filename %s: %m", filename); + rust_error_at (invoc_locus, "cannot open filename %s: %m", filename); return std::vector<uint8_t> (); } @@ -326,7 +326,7 @@ load_file_bytes (const char *filename) if (fread (&buf[0], fsize, 1, f) != 1) { - rust_error_at (Location (), "error reading file %s: %m", filename); + rust_error_at (invoc_locus, "error reading file %s: %m", filename); return std::vector<uint8_t> (); } @@ -391,7 +391,8 @@ MacroBuiltin::include_bytes_handler (Location invoc_locus, std::string target_filename = source_relative_path (lit_expr->as_string (), invoc_locus); - std::vector<uint8_t> bytes = load_file_bytes (target_filename.c_str ()); + std::vector<uint8_t> bytes + = load_file_bytes (invoc_locus, target_filename.c_str ()); /* Is there a more efficient way to do this? */ std::vector<std::unique_ptr<AST::Expr>> elts; @@ -455,7 +456,8 @@ MacroBuiltin::include_str_handler (Location invoc_locus, std::string target_filename = source_relative_path (lit_expr->as_string (), invoc_locus); - std::vector<uint8_t> bytes = load_file_bytes (target_filename.c_str ()); + std::vector<uint8_t> bytes + = load_file_bytes (invoc_locus, target_filename.c_str ()); /* FIXME: reuse lexer */ int expect_single = 0; |