Skip to content

Conversation

shreyas-omkar
Copy link

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 to lang_dependent_init and subsequently to lower-level functions like init_asm_output and lrealpath, which do not handle the NULL value and lead to a crash.

Solution

This patch introduces a check inside the lang_dependent_init function in gcc/toplevel.cc. The check verifies if the input filename is nullptr. If it is, the compiler now reports a fatal_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.

Screenshot_20251010_224635

Additionally, a full make check-rust was run successfully to ensure that no regressions were introduced by this change.


  • GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off. (DCO provided via --signoff).
  • Read contributing guidelines.
  • make check-rust passes locally.
  • Run clang-format on the changed file.
  • Added any relevant test cases to gcc/testsuite/rust/. (Manual test performed to confirm fix).

@shreyas-omkar shreyas-omkar marked this pull request as ready for review October 10, 2025 17:53
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch from 9f14789 to 801f9ac Compare October 10, 2025 19:24
@shreyas-omkar shreyas-omkar changed the title Fix: Prevent ICE on no input file gcc: Prevent ICE on no input file Oct 10, 2025
This patch adds a check in lang_dependent_init to detect when no input file is provided, issuing a fatal error instead of passing a NULL Pointer to downstream funcations.

Fixes Rust-GCC#3523

2025-10-11 shreyas-omkar  <shreyashegdeplus06@gmail.com>

	* gcc/toplev.cc (lang_dependent_init): Check for NULL filename and
	issue a fatal error.

Signed-off-by: shreyas-omkar <shreyashegdeplus06@gmail.com>
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch from 801f9ac to 5bd12d1 Compare October 10, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: segfault when no source file is passed

1 participant