-
Notifications
You must be signed in to change notification settings - Fork 193
gccrs: Fix ICE in no input file #4240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
gccrs: Fix ICE in no input file #4240
Conversation
076a227 to
92edd40
Compare
92edd40 to
0e2e175
Compare
|
@dkm Please review the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| if (num_in_fnames == 0) | ||
| main_input_filename = "-"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Is it how the other frontends handle that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In grs_langhook_init, I'm covering the case when the global variable num_in_fnames is zero before main_input_filename is used.
This is like a safety check if the grs_langhook_post_options didnt catch the error.
| // check for input file | ||
| if (!*pfilename && num_in_fnames == 0) | ||
| *pfilename = "-"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In grs_langhook_post_options, I'm covering the case when no filename was passed in CLI and the filename pointer is null.
|
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. |
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>
1f210e3 to
948e559
Compare
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.