Skip to content

Commit 076a227

Browse files
committed
gcc: 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/ChangeLog: * rust/rust-lang.cc (grs_langhook_post_options): Set pfilename to "-" if no input file is provided and num_in_fnames is 0. * rust/rust-session-manager.cc (Session::handle_input_files): Handle num_files == 0 case explicitly by setting filename to "-". Signed-off-by: shreyas-omkar <[email protected]>
1 parent ab68ca3 commit 076a227

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

gcc/rust/rust-lang.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ grs_langhook_init (void)
110110

111111
using_eh_for_cleanups ();
112112

113+
if (num_in_fnames == 0)
114+
main_input_filename = "-";
115+
113116
// initialise compiler session
114117
Rust::Session::get_instance ().init ();
115118

@@ -286,6 +289,10 @@ grs_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED)
286289
{
287290
// can be used to override other options if required
288291

292+
// check for input file
293+
if (!*pfilename && num_in_fnames == 0)
294+
*pfilename = "-";
295+
289296
// satisfies an assert in init_excess_precision in toplev.cc
290297
if (flag_excess_precision /*_cmdline*/ == EXCESS_PRECISION_DEFAULT)
291298
flag_excess_precision /*_cmdline*/ = EXCESS_PRECISION_STANDARD;

gcc/rust/rust-session-manager.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ Session::enable_dump (std::string arg)
399399
void
400400
Session::handle_input_files (int num_files, const char **files)
401401
{
402+
if (num_files == 0)
403+
{
404+
static const char *stdin_file[] = {"-"};
405+
files = stdin_file;
406+
num_files = 1;
407+
}
402408
if (num_files != 1)
403409
rust_fatal_error (UNDEF_LOCATION,
404410
"only one file may be specified on the command line");

0 commit comments

Comments
 (0)