gcc: Prevent ICE on no input file #4203
Open
+5
−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
Currently, invoking the
crab1
compiler front-end without providing an input source file results in an Internal Compiler Error (ICE) due to a segmentation fault.This occurs because a
NULL
pointer for the filename is passed tolang_dependent_init
and subsequently to lower-level functions likeinit_asm_output
andlrealpath
, which do not handle theNULL
value and lead to a crash.Solution
This patch introduces a check inside the
lang_dependent_init
function ingcc/toplevel.cc
. The check verifies if the input filename isnullptr
. If it is, the compiler now reports afatal_error("no input files")
and terminates gracefully.This new behavior is more robust, providing a clear error message to the user instead of an unexpected crash, and aligns better with the behavior of other GCC front-ends.
Testing
The fix was verified manually by running the compiler with no arguments and confirming that it now prints the fatal error message instead of segfaulting.
Additionally, a full
make check-rust
was run successfully to ensure that no regressions were introduced by this change.--signoff
).make check-rust
passes locally.clang-format
on the changed file.gcc/testsuite/rust/
. (Manual test performed to confirm fix).