From: Owen Avery <[email protected]>
Leaks filenames so that they live as long as the linemap does (until
exit?).
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-include.cc
(MacroBuiltin::include_handler): Remove include_extra_file
usage.
* lex/rust-lex.cc (Lexer::Lexer): Copy and leak filename
parameter.
* rust-session-manager.h (Session::extra_files): Remove member
variable.
(Session::include_extra_file): Remove member function.
Signed-off-by: Owen Avery <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/5b5d1e0b5f5970c5099808feffb9774d17dd5317
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/5070
gcc/rust/expand/rust-macro-builtins-include.cc | 3 +--
gcc/rust/lex/rust-lex.cc | 4 +++-
gcc/rust/rust-session-manager.h | 13 -------------
3 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/gcc/rust/expand/rust-macro-builtins-include.cc
b/gcc/rust/expand/rust-macro-builtins-include.cc
index 1461e523e..01f2b93a2 100644
--- a/gcc/rust/expand/rust-macro-builtins-include.cc
+++ b/gcc/rust/expand/rust-macro-builtins-include.cc
@@ -227,8 +227,7 @@ MacroBuiltin::include_handler (location_t invoc_locus,
std::string filename
= source_relative_path (lit_expr->as_string (), invoc_locus);
- auto target_filename
- = Rust::Session::get_instance ().include_extra_file (std::move (filename));
+ const char *target_filename = filename.c_str ();
RAIIFile target_file (target_filename);
Linemap *linemap = Session::get_instance ().linemap;
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index f5f2f4aa6..31c78410b 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -163,8 +163,10 @@ Lexer::Lexer (const char *filename, RAIIFile file_input,
Linemap *linemap,
input_queue{*raw_input_source}, token_queue (TokenSource (this))
{
// inform line_table that file is being entered and is in line 1
+ // TODO: filename needs to live ~forever, is there a better way than xstrdup?
+ // ^ (as long as the linemap does)
if (linemap)
- line_map->start_file (filename, current_line);
+ line_map->start_file (xstrdup (filename), current_line);
}
Lexer::~Lexer ()
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 0f4ba7257..9d7dc0bba 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -418,10 +418,6 @@ struct Session
std::string injected_crate_name;
std::map<std::string, std::string> extern_crates;
- /* extra files get included during late stages of compilation (e.g. macro
- * expansion) */
- std::vector<std::string> extra_files;
-
// backend linemap
Linemap *linemap;
@@ -450,15 +446,6 @@ public:
void init_options ();
void handle_crate_name (const char *filename, const AST::Crate
&parsed_crate);
- /* This function saves the filename data into the session manager using the
- * `move` semantics, and returns a C-style string referencing the input
- * std::string */
- inline const char *include_extra_file (std::string filename)
- {
- extra_files.push_back (std::move (filename));
- return extra_files.back ().c_str ();
- }
-
struct LoadedCrate
{
LoadedCrate (std::string name, NodeId node_id,
base-commit: 8b4f3e924201f70ee8e552531a008be655d660d3
--
2.56.0