Bug 25392 - ICEs with -ff2c
Summary: ICEs with -ff2c
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.1.3
Assignee: Tobias Schlüter
URL:
Keywords: ice-on-valid-code, monitored
: 26440 30979 (view as bug list)
Depends on:
Blocks: 19292 26440
  Show dependency treegraph
 
Reported: 2005-12-13 14:06 UTC by Jakub Jelinek
Modified: 2007-02-27 19:21 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-11-23 20:52:22


Attachments
gcc41-pr25392.patch (1.54 KB, patch)
2007-02-27 16:21 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2005-12-13 14:06:03 UTC
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.
Comment 1 Andrew Pinski 2005-12-30 06:48:32 UTC
Confirmed.
Comment 2 Andrew Pinski 2006-01-02 03:42:50 UTC
  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;
Comment 3 Andrew Pinski 2006-02-24 17:40:05 UTC
*** Bug 26440 has been marked as a duplicate of this bug. ***
Comment 4 Francois-Xavier Coudert 2006-05-11 11:36:23 UTC
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
Comment 5 Francois-Xavier Coudert 2006-06-30 08:54:46 UTC
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.
Comment 6 Richard Biener 2006-07-04 12:18:11 UTC
Of course it is - see my analysis in PR26440 - but it is a mess.
Comment 7 Tobias Schlüter 2006-12-14 01:18:57 UTC
I have a patch, but it adds another ugly layer of code, I'll try to clean this mess up and then submit.
Comment 8 Tobias Schlüter 2006-12-21 03:05:00 UTC
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

Comment 9 Tobias Schlüter 2006-12-21 03:17:25 UTC
Keeping this open, until the fix is also in 4.2.
Comment 10 Tobias Schlüter 2006-12-29 18:54:51 UTC
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

Comment 11 Tobias Schlüter 2006-12-29 18:56:10 UTC
Fixed in 4.2 and trunk.
Comment 12 Andrew Pinski 2007-02-27 15:28:28 UTC
*** Bug 30979 has been marked as a duplicate of this bug. ***
Comment 13 Tobias Schlüter 2007-02-27 16:10:45 UTC
Should I backport this to 4.1?  I guess it makes sense since this can be considered a regressions WRT g77.
Comment 14 Jakub Jelinek 2007-02-27 16:21:51 UTC
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).
Comment 15 Tobias Schlüter 2007-02-27 19:20:34 UTC
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

Comment 16 Tobias Schlüter 2007-02-27 19:21:36 UTC
The patch has moved into its new home on the 4.1 branch.