gccrs: Fix ICE in no input file #4240
Open
+13
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.