gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

gccrs: Fix ICE in no input file

Open shreyas-omkar opened this issue 2 months ago • 7 comments

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 avatar Oct 19 '25 11:10 shreyas-omkar

@dkm Please review the changes.

shreyas-omkar avatar Oct 19 '25 20:10 shreyas-omkar

The changes to grs_langhook_post_options and grs_langhook_init ensure the Rust frontend handles the “no input file” case the same way as other GCC frontends (e.g., D and Go).

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.

shreyas-omkar avatar Nov 01 '25 19:11 shreyas-omkar

can @dkm and @tschwinge review this, i am not sure how front ends are meant to respect pipe and no input files what do you think

philberty avatar Nov 13 '25 17:11 philberty

can @dkm and @tschwinge review this, i am not sure how front ends are meant to respect pipe and no input files what do you think

Yes, I should be able to review this one. Sorry for the delay!

dkm avatar Nov 19 '25 22:11 dkm

@dkm Screenshot from 2025-11-11 00-25-48

shreyas-omkar avatar Nov 20 '25 10:11 shreyas-omkar

@dkm Any Changes required??

shreyas-omkar avatar Nov 26 '25 14:11 shreyas-omkar

Hi @dkm, any changes in the PR?

shreyas-omkar avatar Dec 10 '25 15:12 shreyas-omkar