gccrs: Fix ICE in no input file
Fixes #3523
Problem Description
Invoking the crab1 front-end without an input source file currently results in an Internal Compiler Error (ICE) due to a segmentation fault. This was caused by two different code paths attempting to process a NULL filename pointer.
Solution
This patch fixes both crash scenarios by making the Rust front-end gracefully default to reading from standard input (stdin), aligning its behavior with other GCC front-ends.
Session::handle_input_files(ingcc/rust/rust-session-manager.cc) is updated to handle thenum_files == 0case by setting the filename to"-"(stdin).grs_langhook_post_options(ingcc/rust/rust-lang.cc) is updated to check for cases where flags are present but no positional file is given, also setting the filename pointer to"-"to prevent the original crash ininit_asm_output.
Testing
The fix was verified by testing the two scenarios that previously caused a crash. Both now correctly default to stdin and exit gracefully without a segfault.
1. Running ./gcc/crab1 with no arguments:
(Shows the experimental compiler warning and exits safely)
2. Running ./gcc/crab1 with flags but no file:
(Correctly defaults to stdin and waits for input)
Regression testing by compiling a file normally (e.g., gccrs test.rs) was also performed and passed, confirming the fix does not break existing functionality. A full make check-rust also passes locally.
@dkm Please review the changes.
The changes to grs_langhook_post_options and grs_langhook_init ensure the Rust frontend handles the “no input file” case the same way as other GCC frontends (e.g., D and Go).
Both hooks are updated because GCC’s initialization sequence references these variables at different stages post_options handles the option-parsing phase, while init covers later setup before session creation.
If my approach isnt right, I am down for inputs.
can @dkm and @tschwinge review this, i am not sure how front ends are meant to respect pipe and no input files what do you think
can @dkm and @tschwinge review this, i am not sure how front ends are meant to respect pipe and no input files what do you think
Yes, I should be able to review this one. Sorry for the delay!
@dkm
@dkm Any Changes required??
Hi @dkm, any changes in the PR?