real function foo (x, y) real x, y foo = y - x do while (foo .gt. 180.) foo = foo - 360. enddo do while (foo .le. -180.) foo = foo + 360. enddo end ICEs in various places depending on the exact -O level and target. The problem is that __result_foo variable is given type not corresponding to its kind which leads e.g. on i?86 -m32 to emit_move_insn ICE (trying to copy a SFmode constant to DFmode var). I'd say __result_foo should still use SFmode type, only return type of the function should be DFmode and in the RETURN_EXPR widen it.
Confirmed.
D.784 = __result_foo > 1.8e+2f; D.786 = __result_foo - 3.6e+2f; D.788 = __result_foo <= -1.8e+2f; D.790 = __result_foo + 3.6e+2f;
*** Bug 26440 has been marked as a duplicate of this bug. ***
File entry-4.f90 from the gfortran testsuite also ICEs with -ff2c: $ gfortran -c entry_4.f90 -ff2c src/entry_4.f90: In function ‘f2’: src/entry_4.f90:12: internal compiler error: in make_decl_rtl, at varasm.c:1002
Reduced testcase: real function foo () if (foo .gt. 0) call abort end I'm almost sure it's a type mismatch problem. The above code generates the following tree dump: foo () { real8 __result_foo; if (__result_foo > 0.0) { _gfortran_abort (); } else { (void) 0; } return __result_foo; } but I think foo is not declared a real8 but simply as real4. If I change the Fortran code to explicitly declare foo as "real*8 function foo ()" then the ICE disappears.
Of course it is - see my analysis in PR26440 - but it is a mess.
I have a patch, but it adds another ugly layer of code, I'll try to clean this mess up and then submit.
Subject: Bug 25392 Author: tobi Date: Thu Dec 21 03:04:43 2006 New Revision: 120099 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120099 Log: PR fortran/25392 fortran/ * trans-stmt.c (gfc_trans_return): Fix comment formatting. * trans-types.c (gfc_sym_type): Don't return early for functions. Remove special handling for -ff2c. (gfc_get_function_type): Add special handling for -ff2c. * trans-decl.c (gfc_create_function_decl): Fix comment formatting. (gfc_get_fake_result_decl): Make sure we get the right type for functions. (gfc_generate_function_code): Convert type of result variable to type of function. testsuite/ * gfortran.dg/f2c_8.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/f2c_8.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-stmt.c trunk/gcc/fortran/trans-types.c trunk/gcc/testsuite/ChangeLog
Keeping this open, until the fix is also in 4.2.
Subject: Bug 25392 Author: tobi Date: Fri Dec 29 18:54:41 2006 New Revision: 120274 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120274 Log: Backport from trunk: fortran/ PR fortran/25392 * trans-stmt.c (gfc_trans_return): Fix comment formatting. * trans-types.c (gfc_sym_type): Don't return early for functions. Remove special handling for -ff2c. (gfc_get_function_type): Add special handling for -ff2c. * trans-decl.c (gfc_create_function_decl): Fix comment formatting. (gfc_get_fake_result_decl): Make sure we get the right type for functions. (gfc_generate_function_code): Convert type of result variable to type of function. testsuite/ PR fortran/25392 * gfortran.dg/f2c_8.f90: New test. Added: branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/f2c_8.f90 Modified: branches/gcc-4_2-branch/gcc/fortran/ChangeLog branches/gcc-4_2-branch/gcc/fortran/trans-decl.c branches/gcc-4_2-branch/gcc/fortran/trans-stmt.c branches/gcc-4_2-branch/gcc/fortran/trans-types.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Fixed in 4.2 and trunk.
*** Bug 30979 has been marked as a duplicate of this bug. ***
Should I backport this to 4.1? I guess it makes sense since this can be considered a regressions WRT g77.
Created attachment 13120 [details] gcc41-pr25392.patch Yes, I think so. Attached is what we have in Red Hat gcc 4.1.x tree for a few days already (and have been bootstrapped/regtested several times).
Subject: Bug 25392 Author: tobi Date: Tue Feb 27 19:20:21 2007 New Revision: 122382 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122382 Log: 2006-12-29 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> PR fortran/25392 * trans-types.c (gfc_sym_type): Don't return early for functions. Remove special handling for -ff2c. (gfc_get_function_type): Add special handling for -ff2c. * trans-decl.c (gfc_create_function_decl): Fix comment formatting. (gfc_get_fake_result_decl): Make sure we get the right type for functions. (gfc_generate_function_code): Convert type of result variable to type of function. * gfortran.dg/f2c_8.f90: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/f2c_8.f90 - copied unchanged from r120099, trunk/gcc/testsuite/gfortran.dg/f2c_8.f90 Modified: branches/gcc-4_1-branch/gcc/fortran/ChangeLog branches/gcc-4_1-branch/gcc/fortran/trans-decl.c branches/gcc-4_1-branch/gcc/fortran/trans-stmt.c branches/gcc-4_1-branch/gcc/fortran/trans-types.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
The patch has moved into its new home on the 4.1 branch.