From c5116601379fd3740cafcf4d2c4e949a57195140 Mon Sep 17 00:00:00 2001 From: shreyas-omkar Date: Sun, 19 Oct 2025 16:30:21 +0530 Subject: [PATCH] gccrs: Default Rust frontend to stdin when no input file is provided This fixes an Internal Compiler Error (ICE) where the `crab1` frontend would segmentation fault if run without any input source files. gcc/rust/ChangeLog: * rust-lang.cc (grs_langhook_post_options): Set pfilename to "-" if no input file is provided and num_in_fnames is 0. * rust-session-manager.cc (Session::handle_input_files): Handle num_files == 0 case explicitly by setting filename to "-". Signed-off-by: shreyas-omkar --- gcc/rust/rust-lang.cc | 7 +++++++ gcc/rust/rust-session-manager.cc | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc index 1088845497ef..7566fee73d0c 100644 --- a/gcc/rust/rust-lang.cc +++ b/gcc/rust/rust-lang.cc @@ -110,6 +110,9 @@ grs_langhook_init (void) using_eh_for_cleanups (); + if (num_in_fnames == 0) + main_input_filename = "-"; + // initialise compiler session Rust::Session::get_instance ().init (); @@ -286,6 +289,10 @@ grs_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED) { // can be used to override other options if required + // check for input file + if (!*pfilename && num_in_fnames == 0) + *pfilename = "-"; + // satisfies an assert in init_excess_precision in toplev.cc if (flag_excess_precision /*_cmdline*/ == EXCESS_PRECISION_DEFAULT) flag_excess_precision /*_cmdline*/ = EXCESS_PRECISION_STANDARD; diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 641811846832..23bcef9c3aa9 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -399,6 +399,12 @@ Session::enable_dump (std::string arg) void Session::handle_input_files (int num_files, const char **files) { + if (num_files == 0) + { + static const char *stdin_file[] = {"-"}; + files = stdin_file; + num_files = 1; + } if (num_files != 1) rust_fatal_error (UNDEF_LOCATION, "only one file may be specified on the command line");