https://gcc.gnu.org/g:079cd0326d9e198022e0d22f37c4398e80651d48
commit r17-6272-g079cd0326d9e198022e0d22f37c4398e80651d48 Author: Owen Avery <[email protected]> Date: Mon Nov 9 04:17:44 2026 -0500 gccrs: Fix linemap filename lifetimes 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]> Diff: --- 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 1461e523eaa9..01f2b93a2475 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 f5f2f4aa60da..31c78410bb27 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 0f4ba7257a1a..9d7dc0bbad36 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,
