Skip to content

Conversation

@shreyas-omkar
Copy link

Fixes #3523

Problem Description

Invoking the crab1 front-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 a NULL filename 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.

  1. Session::handle_input_files (in gcc/rust/rust-session-manager.cc) is updated to handle the num_files == 0 case by setting the filename to "-" (stdin).
  2. grs_langhook_post_options (in gcc/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 in init_asm_output.

Testing

The fix was verified by testing the two scenarios that previously caused a crash. Both now correctly default to stdin and exit gracefully without a segfault.

1. Running ./gcc/crab1 with no arguments:
(Shows the experimental compiler warning and exits safely)
image

2. Running ./gcc/crab1 with flags but no file:
(Correctly defaults to stdin and waits for input)
image
image

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 full make check-rust also passes locally.

@shreyas-omkar shreyas-omkar changed the title gcc: Default Rust frontend to stdin when no input file is provided gcc: Fix ICE in no input file Oct 19, 2025
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch 4 times, most recently from 076a227 to 92edd40 Compare October 19, 2025 14:12
@shreyas-omkar shreyas-omkar marked this pull request as ready for review October 19, 2025 15:30
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>
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch from 92edd40 to 0e2e175 Compare October 19, 2025 18:51
@shreyas-omkar
Copy link
Author

@dkm Please review the changes.

@shreyas-omkar shreyas-omkar changed the title gcc: Fix ICE in no input file gccrs: Fix ICE in no input file Oct 19, 2025
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