When compiling a program with -fmax-errors=n and the n-th error is encountered, an internal compiler error occurs and the gfortran command exits with status 4. Expected result is: the compiler should report the abortion and exit with the status code according to the error encountered, like the C compiler does. Example: $ echo x > test.f $ gfortran -fmax-errors=1 test.f test.f:1.1: x 1 Error: Non-numeric character in statement label at (1) Fatal Error: Error count reached limit of 1. gfortran.exe: internal compiler error: Aborted (program f951) Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. $ echo $? 4
This seems to be a Windows / MinGW specific problem caused by the way gfortran returns when a fatal error occurs. gfortran just calls exit(3); which according to Kai matches Windows' abort status code. The proper way seems to use the system.h's exit codes: FATAL_EXIT_CODE, EXIT_SUCCESS and EXIT_FAILURE instead of hard-coded error codes. The error message itself is printed by the driver (gcc.c, gfortran.exe) and not by the proper compiler (f951.exe). Draft patch: diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index 3092828..8520e2a 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -941,3 +941,3 @@ gfc_error_now (const char *gmsgid, ...) if (flag_fatal_errors) - exit (1); + exit (EXIT_FAILURE); } @@ -958,3 +958,3 @@ gfc_fatal_error (const char *gmsgid, ...) - exit (3); + exit (FATAL_EXIT_CODE); } @@ -1021,3 +1021,3 @@ gfc_error_check (void) if (flag_fatal_errors) - exit (1); + exit (EXIT_FAILURE); } diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index c226bae..d4388e0 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -1870,3 +1870,3 @@ include_line (gfc_char_t *line) if (load_file (filename, NULL, false) == FAILURE) - exit (1); + exit (EXIT_FAILURE); @@ -2074,3 +2074,3 @@ gfc_new_file (void) - exit (0); + exit (EXIT_SUCCESS); #endif
Author: burnus Date: Fri Jan 21 20:33:10 2011 New Revision: 169104 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169104 Log: 2011-01-21 Tobias Burnus <burnus@net-b.de> PR fortran/47394 * error.c (gfc_error_now, gfc_fatal_error, gfc_error_check): Use defined instead of magic number exit status codes. * scanner.c (include_line, gfc_new_file): Ditto. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/error.c trunk/gcc/fortran/scanner.c
Author: burnus Date: Fri Jan 21 22:38:55 2011 New Revision: 169109 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169109 Log: 2011-01-21 Tobias Burnus <burnus@net-b.de> PR fortran/47394 * error.c (gfc_error_now, gfc_fatal_error, gfc_error_check): Use defined instead of magic number exit status codes. * scanner.c (include_line, gfc_new_file): Ditto. * gfortranspec.c (lang_specific_driver): Ditto. Modified: branches/gcc-4_5-branch/gcc/fortran/ChangeLog branches/gcc-4_5-branch/gcc/fortran/error.c branches/gcc-4_5-branch/gcc/fortran/gfortranspec.c branches/gcc-4_5-branch/gcc/fortran/scanner.c
FIXED on the trunk (4.6) and on the 4.5 branch. Thanks for the report!
*** Bug 50231 has been marked as a duplicate of this bug. ***