gccrs: Fix ICE in no input file#4240
Conversation
076a227 to
92edd40
Compare
92edd40 to
0e2e175
Compare
|
@dkm Please review the changes. |
CohenArthur
left a comment
There was a problem hiding this comment.
The changes look okay to me but I'm not sure I understand all of them. I don't see why we have to modify grs_langhook_post_options and grs_langhook_init - could you explain how you arrived to these changes? Did you take inspiration from other frontends? Why are those particular changes?
The changes to handle_input_files seem completely fine
|
The changes to 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. |
1f210e3 to
948e559
Compare
948e559 to
c511660
Compare
philberty
left a comment
There was a problem hiding this comment.
Not sure i understand this PR have you tried it? like use the stdin stream ?
echo 'fn main() {}' | gccrs -
does that actually work?
philberty
left a comment
There was a problem hiding this comment.
Are you sure you dont just need to do handle_input_files if num_in_fnames == 0?
|
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! |
c511660 to
2538f6a
Compare
d533f57 to
a3c4d7b
Compare
|
@dkm Any Changes required?? |
a3c4d7b to
7cb88ce
Compare
|
Hi @dkm, any changes in the PR? |
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 <shreyashegdeplus06@gmail.com>
7cb88ce to
bc42b6a
Compare
|
Hi @dkm, any changes in the PR? |

Fixes #3523
Problem Description
Invoking the
crab1front-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 aNULLfilename 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
stdinand exit gracefully without a segfault.1. Running

./gcc/crab1with no arguments:(Shows the experimental compiler warning and exits safely)
2. Running


./gcc/crab1with 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 fullmake check-rustalso passes locally.