Skip to content

Commit d533f57

Browse files
committed
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 <[email protected]>
1 parent f942905 commit d533f57

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

gcc/rust/rust-lang.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ grs_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED)
286286
{
287287
// can be used to override other options if required
288288

289+
// check for input file
290+
if (!*pfilename && num_in_fnames == 0)
291+
*pfilename = "-";
292+
289293
// satisfies an assert in init_excess_precision in toplev.cc
290294
if (flag_excess_precision /*_cmdline*/ == EXCESS_PRECISION_DEFAULT)
291295
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+
static const char *stdin_file[] = {"-"};
403+
if (num_files == 0)
404+
{
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)