Bug 20244 - internal compiler error: in fold_convert, at fold-const.c:2003
Summary: internal compiler error: in fold_convert, at fold-const.c:2003
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 24504 24673 24887 (view as bug list)
Depends on:
Blocks: 15502
  Show dependency treegraph
 
Reported: 2005-02-28 09:03 UTC by Luc Maisonobe
Modified: 2006-01-01 05:32 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-18 05:51:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Maisonobe 2005-02-28 09:03:44 UTC
the message "internal compiler error: in fold_convert, at fold-const.c:2003" is
triggered when compiling a fortran 90 snippet. It appears with the binary
version available from Bud Davis gfortran page on 2005-02-28, which displays
itself as:

GNU F95 version 4.0.0 20050224 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 4.0.0 20050223 (experimental).

It does not appear on the following older version:

gcc version 3.5.0 20040824 (experimental) (g95!) Dec 20 2004

I was able to reduce it to the following two files, but nothing shorter, and
nothing with one file only, sorry :-(


$ cat my_types.f90
module my_types
implicit none
  integer, parameter, public :: my_real = selected_real_kind(13)
type qr_type
   sequence
   real(my_real)                :: q
   real(my_real),dimension(1:3) :: r
end type qr_type
end module my_types
$ cat f.f90
subroutine f (a)
use my_types
implicit none
interface
   function g (u)
     use my_types
       real(my_real) , intent(in) :: u
       type(qr_type)              :: g
   end function g
end interface
real(my_real), dimension(3), intent(in) :: a
real(my_real) :: u
type(qr_type) :: v
v = g(u)
end subroutine f
$ gfortran -c my_types.f90 ; gfortran -v -c f.f90
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --enable-languages=c,f95
--prefix=/usr/work/2005055/irun
Thread model: posix
gcc version 4.0.0 20050224 (experimental)
 /home/luc/gfortran-tmp/irun/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.0/f951
f.f90 -quiet -dumpbase f.f90 -mtune=pentiumpro -auxbase f -version -o
/home/luc/tmp/ccFhx16T.s
GNU F95 version 4.0.0 20050224 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 4.0.0 20050223 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
f.f90: In function 'f':
f.f90:1: internal compiler error: in fold_convert, at fold-const.c:2003
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
$
Comment 1 Andrew Pinski 2005-02-28 13:26:48 UTC
Just a note the following version means something different:
gcc version 3.5.0 20040824 (experimental) (g95!) Dec 20 2004

That is g95 which is a different project from gfortran.

Confirmed, hmm, someone forgot about TYPE_VARIANTS.
Comment 2 Andrew Pinski 2005-10-24 16:53:25 UTC
*** Bug 24504 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2005-11-04 14:26:26 UTC
*** Bug 24673 has been marked as a duplicate of this bug. ***
Comment 4 Pierre-Matthieu Anglade 2005-11-04 14:54:45 UTC
Hi all,

Looking at the examples of failure due to this bug, I've observed that they are due  to user defined datatype. The function fold_convert seems to handle only intrinsic datatypes while the examples were using user defined one.

If user-defined datatypes are removed, the compilation just go through fine.

This feeling about datatype is confirmed by a meer look at fold-const.c. Which is switch/casing the datatypes.
Unfortunately I'm not a gcc expert and really don't know how this should be bug-fixed.
Comment 5 Andrew Pinski 2005-11-04 14:58:14 UTC
(In reply to comment #4)
> Unfortunately I'm not a gcc expert and really don't know how this should be
> bug-fixed.

The way this bug needs to be fixed is one of the following:
1. the types generated need to be in the exact location
2. The types need to be declared as TYPE variants of one another.
3. The fortran front-end needs to say that these types are compatible.

All of the above need to be fixed in the front-end and not in the middle-end where fold_convert resides.
Comment 6 Andrew Pinski 2005-11-04 14:59:23 UTC
(In reply to comment #5)
Oh and one more thing, the use of fold_convert is not the incorrect thing to do here.
Comment 7 Pierre-Matthieu Anglade 2005-11-04 15:31:58 UTC
I've simplified to it's (almost) simplest expression the test case:
module mtyp
  type t1
     integer::a
  end type t1
end module mtyp
module atest
  use mtyp
  type(t1)::ze
contains
  subroutine test(ze_in )
    use mtyp
    implicit none
    type(t1)::ze_in
    ze=ze_in
  end subroutine test
end module atest

I've try to backtrace the call up to the front-end. But I'm not able to do that since I really don't know the structure of gcc (and since ddd/gdb keeps busying me with stupid error message). 
I'd be glade to fix the bug if someone can introduce me a little bit more to the code. (any link for gcc beginners??)
Comment 8 Andreas Jaeger 2005-11-11 12:26:12 UTC
I got the same ICE with one of the SPEC2006 candidate benchmarks on x86_64-linux-gnu.
Comment 9 Andrew Pinski 2005-11-12 23:43:18 UTC
(In reply to comment #8)
> I got the same ICE with one of the SPEC2006 candidate benchmarks on
> x86_64-linux-gnu.

Was this before or after my fix for PR 18157 went in?  Because this and that bug had the same ICE but are really different bugs.
Comment 10 Andreas Jaeger 2005-11-13 08:03:48 UTC
I haven't tested SPEC for some time, so cannot tell when this happened first, the error is in current GCC with your patch applied.
Comment 11 Andrew Pinski 2005-11-16 15:24:16 UTC
*** Bug 24887 has been marked as a duplicate of this bug. ***
Comment 12 Dwarak Rajagopal 2005-11-17 17:30:46 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > I got the same ICE with one of the SPEC2006 candidate benchmarks on
> > x86_64-linux-gnu.
> 
> Was this before or after my fix for PR 18157 went in?  Because this and that
> bug had the same ICE but are really different bugs.
> 
Tried with gcc version 4.0.1 20050630 (prerelease) (without the patch) and the current head (with the patch).I see the same ICE for both before and after your patch in "wrf"(spec 2006). Tried with gcc version 4.0.1 20050630 (prerelease) (without the patch) and the current head (with the patch).

- Dwarak
Comment 13 Paul Thomas 2005-12-13 12:50:09 UTC
I am just now posting a patch for this bug.

Andrew,

I ignored your advice, "All of the above need to be fixed in the front-end and not in the middle-end where fold_convert resides." by doing the fixing in the middle end. I found that a front-end fix, in resolve_symbol, got more than a little bit cumbersome. The simplest, by far, was to attack trans-types(gfc_get_derived_type) and to use the host + use associated backend declarations for the derived type, rather than building afresh in the contained namespace.

Paul
Comment 14 Paul Thomas 2005-12-22 07:05:40 UTC
Subject: Bug 20244

Author: pault
Date: Thu Dec 22 07:05:22 2005
New Revision: 108943

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=108943
Log:
2005-12-22  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20889
	*resolve.c(resolve_structure_cons): Do not attempt to convert
	the type of mismatched pointer type components, except when
	the constructor component is BT_UNKNOWN; emit error instead.

	PR fortran/25029
	PR fortran/21256
	*resolve.c(check_assumed_size_reference): New function to check for upper
	bound in assumed size array references.
	(resolve_assumed_size_actual): New function to do a very restricted scan
	of actual argument expressions of those procedures for which incomplete
	assumed size array references are not allowed.
	(resolve_function, resolve_call): Switch off assumed size checking of
	actual arguments, except for elemental procedures and array valued
	intrinsics; excepting LBOUND.
	(resolve_variable): Call check_assumed_size_reference.

	PR fortran/19362
	PR fortran/20244
	PR fortran/20864
	PR fortran/25391
	*interface.c(gfc_compare_types): Broken into two.
	(gfc_compare_derived_types): Second half of gfc_compare_types with
	corrections for a missing check that module name is non-NULL and
	a check for private components.
	*symbol.c(gfc_free_dt_list): New function.
	(gfc_free_namespace): Call gfc_free_dt_list.
	*resolve.c(resolve_symbol): Build the list of derived types in the
	symbols namespace.
	*gfortran.h: Define the structure type gfc_dt_list.  Add a new field,
	derived_types to gfc_namespace.  Provide a prototye for the new
	function gfc_compare_derived_types.
	*trans_types.c(gfc_get_derived_type): Test for the derived type being
	available in the host namespace. In this case, the host backend
	declaration is used for the structure and its components.  If an
	unbuilt, equal structure that is not use associated is found in the
	host namespace, build it there and then.  On exit,traverse the
	namespace of the derived type to see if there are equal but unbuilt.
	If so, copy the structure and its component declarations.
	(copy_dt_decls_ifequal): New functions to copy declarations to other
	equal structure types.

	PR fortran/20862
	* io.c (gfc_match_format): Make the appearance of a format statement
	in a module specification block an error.

	PR fortran/23152
	* match.c (gfc_match_namelist): Set assumed shape arrays in
	namelists as std=GFC_STD_GNU and assumed size arrays as an
	unconditional error.

	PR fortran/25069
	* match.c (gfc_match_namelist): Set the respecification of a USE
	associated namelist group as std=GFC_STD_GNU.  Permit the concatenation
	on no error.

	PR fortran/25053
	PR fortran/25063
	PR fortran/25064
	PR fortran/25066
	PR fortran/25067
	PR fortran/25068
	PR fortran/25307
	* io.c (resolve_tag): Change std on IOSTAT != default integer to
	GFC_STD_GNU and change message accordingly.  Add same error for
	SIZE.
	(match_dt_element, gfortran.h): Add field err_where to gfc_dt and
	set it when tags are being matched.
	(gfc_resolve_dt): Remove tests that can be done before resolution
	and add some of the new ones here.
	(check_io_constraints): New function that checks for most of the
	data transfer constraints. Some of these were previously done in
	match_io, from where this function is called, and some were done
	in gfc_resolve_dt.
	(match_io): Remove most of the tests of constraints and add the
	call to check_io_constraints.

2005-12-22  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20889
	*gfortran.dg/pointer_component_type_1.f90: New test.

	PR fortran/25029
	PR fortran/21256
	*gfortran.dg/assumed_size_refs.f90: New test for the conditions that
	should give an error with assumed size array refernces and checks those
	that should not.
	*gfortran.dg/gfortran.dg/pr15140.f90: Give the assumed size array
	reference an upper bound so that it does not generate an error.

	PR fortran/19362
	PR fortran/20244
	PR fortran/20864
	PR fortran/25391
	*gfortran.dg/used_dummy_types_1.f90: New test.
	*gfortran.dg/used_dummy_types_2.f90: New test.
	*gfortran.dg/used_dummy_types_3.f90: New test.
	*gfortran.dg/used_dummy_types_4.f90: New test.
	*gfortran.dg/used_dummy_types_5.f90: New test.

	PR fortran/23152
	*gfortran.dg/namelist_use.f90: Add trap for warning on NAMELIST
	group already being USE associated.
	*gfortran.dg/assumed_shape_nml.f90: New test.
	*gfortran.dg/assumed_size_nml.f90: New test.

	PR fortran/20862
	PR fortran/25053
	PR fortran/25063
	PR fortran/25064
	PR fortran/25066
	PR fortran/25067
	PR fortran/25068
	PR fortran/25307
	* gfortran.dg/io_constraints_1.f90: New test.
	* gfortran.dg/io_constraints_1.f90: New test.
	* gfortran.dg/iostat_3.f90: Change wording of warning.
	 * gfortran.dg/g77/19981216-0.f:  the same.

Added:
    trunk/gcc/testsuite/gfortran.dg/assumed_shape_nml.f90
    trunk/gcc/testsuite/gfortran.dg/assumed_size_nml.f90
    trunk/gcc/testsuite/gfortran.dg/io_constraints_1.f90
    trunk/gcc/testsuite/gfortran.dg/io_constraints_2.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_component_type_1.f90
    trunk/gcc/testsuite/gfortran.dg/used_dummy_types_1.f90
    trunk/gcc/testsuite/gfortran.dg/used_dummy_types_2.f90
    trunk/gcc/testsuite/gfortran.dg/used_dummy_types_3.f90
    trunk/gcc/testsuite/gfortran.dg/used_dummy_types_4.f90
    trunk/gcc/testsuite/gfortran.dg/used_dummy_types_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/io.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/g77/19981216-0.f
    trunk/gcc/testsuite/gfortran.dg/initialization_1.f90
    trunk/gcc/testsuite/gfortran.dg/iostat_3.f90
    trunk/gcc/testsuite/gfortran.dg/namelist_use.f90
    trunk/gcc/testsuite/gfortran.dg/pr15140.f90

Comment 15 Paul Thomas 2005-12-26 09:07:45 UTC
Subject: Bug 20244

Author: pault
Date: Mon Dec 26 09:07:27 2005
New Revision: 109061

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109061
Log:
2005-12-26  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20889
	*resolve.c(resolve_structure_cons): Do not attempt to convert
	the type of mismatched pointer type components, except when
	the constructor component is BT_UNKNOWN; emit error instead.

	PR fortran/25018
	* expr.c (check_inquiry): Return FAILURE if there is no symtree to
	provide a name. Error/warning for assumed character length argument
	to LEN for an initialization expression, using GFC_GNU_STD. Add an
	argument to flag that the expression is not restricted.
	(check_init_expr): Improve the message for a failing variable.
	(gfc_match_init_expr): Call check_enquiry again to make sure that
	unsimplified expressions are not causing unnecessary errors.

	PR fortran/19362
	PR fortran/20244
	PR fortran/20864
	PR fortran/25391
	* interface.c (gfc_compare_types): Broken into two.
	(gfc_compare_derived_types): Second half of gfc_compare_types with
	corrections for a missing check that module name is non-NULL and
	a check for private components.
	* symbol.c (gfc_free_dt_list): New function.
	(gfc_free_namespace): Call gfc_free_dt_list.
	* resolve.c (resolve_symbol): Build the list of derived types in the
	symbols namespace.
	* gfortran.h: Define the structure type gfc_dt_list.  Add a new field,
	derived_types to gfc_namespace.  Provide a prototye for the new
	function gfc_compare_derived_types.
	* trans_types.c (gfc_get_derived_type): Test for the derived type being
	available in the host namespace. In this case, the host backend
	declaration is used for the structure and its components.  If an
	unbuilt, equal structure that is not use associated is found in the
	host namespace, build it there and then.  On exit,traverse the
	namespace of the derived type to see if there are equal but unbuilt.
	If so, copy the structure and its component declarations.
	(copy_dt_decls_ifequal): New functions to copy declarations to other
	equal structure types.

	PR fortran/20862
	* io.c (gfc_match_format): Make the appearance of a format statement
	in a module specification block an error.

	PR fortran/23152
	* match.c (gfc_match_namelist): Set assumed shape arrays in
	namelists as std=GFC_STD_GNU and assumed size arrays as an
	unconditional error.

	PR fortran/25069
	* match.c (gfc_match_namelist): Set the respecification of a USE
	associated namelist group as std=GFC_STD_GNU.  Permit the concatenation
	on no error.

	PR fortran/25053
	PR fortran/25063
	PR fortran/25064
	PR fortran/25066
	PR fortran/25067
	PR fortran/25068
	PR fortran/25307
	* io.c (resolve_tag): Change std on IOSTAT != default integer to
	GFC_STD_GNU and change message accordingly.  Add same error for
	SIZE.
	(match_dt_element, gfortran.h): Add field err_where to gfc_dt and
	set it when tags are being matched.
	(gfc_resolve_dt): Remove tests that can be done before resolution
	and add some of the new ones here.
	(check_io_constraints): New function that checks for most of the
	data transfer constraints. Some of these were previously done in
	match_io, from where this function is called, and some were done
	in gfc_resolve_dt.
	(match_io): Remove most of the tests of constraints and add the
	call to check_io_constraints.

2005-12-26  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20889
	* gfortran.dg/pointer_component_type_1.f90: New test.

	PR fortran/25018
	* gfortran.dg/initialization_1.f90: New test.
	* gfortran.dg/enum_5.f90: Change dg-error to new message.
	* gfortran.dg/g77/980616-0.f: The same.

	PR fortran/19362
	PR fortran/20244
	PR fortran/20864
	PR fortran/25391
	*gfortran.dg/used_dummy_types_1.f90: New test.
	*gfortran.dg/used_dummy_types_2.f90: New test.
	*gfortran.dg/used_dummy_types_3.f90: New test.
	*gfortran.dg/used_dummy_types_4.f90: New test.
	*gfortran.dg/used_dummy_types_5.f90: New test.

	PR fortran/23152
	* gfortran.dg/namelist_use.f90: Add trap for warning on NAMELIST
	group already being USE associated.
	* gfortran.dg/assumed_shape_nml.f90: New test.
	* gfortran.dg/assumed_size_nml.f90: New test.

	PR fortran/20862
	PR fortran/25053
	PR fortran/25063
	PR fortran/25064
	PR fortran/25066
	PR fortran/25067
	PR fortran/25068
	PR fortran/25307
	* gfortran.dg/io_constraints_1.f90: New test.
	* gfortran.dg/io_constraints_1.f90: New test.
	* gfortran.dg/iostat_3.f90: Change wording of warning.
	* gfortran.dg/g77/19981216-0.f:  the same.

Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/expr.c
    branches/gcc-4_1-branch/gcc/fortran/gfortran.h
    branches/gcc-4_1-branch/gcc/fortran/interface.c
    branches/gcc-4_1-branch/gcc/fortran/io.c
    branches/gcc-4_1-branch/gcc/fortran/match.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/symbol.c
    branches/gcc-4_1-branch/gcc/fortran/trans-types.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/enum_5.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/g77/19981216-0.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/g77/980616-0.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/namelist_use.f90

Comment 16 Paul Thomas 2005-12-26 09:10:52 UTC
fixed on trunk and 4.1
Comment 17 Paul Thomas 2005-12-29 06:18:37 UTC
Subject: Bug 20244

Author: pault
Date: Thu Dec 29 06:18:23 2005
New Revision: 109139

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109139
Log:
2005-12-29  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/25532
	* trans-types.c (copy_dt_decls_ifequal): Copy declarations for
	components of derived type components by recursing into
	gfc_get_derived_type.

2005-12-29  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/25532
	*gfortran.dg/host_used_types_1.f90: Check that host associated
	derived type components of derived types are properly declared
	in contained procedures.

	The following tests were not added on the 2005-12-26 commit.

	PR fortran/20889
	* gfortran.dg/pointer_component_type_1.f90: New test.

	PR fortran/25018
	* gfortran.dg/initialization_1.f90: New test.

	PR fortran/19362
	PR fortran/20244
	PR fortran/20864
	PR fortran/25391
	* gfortran.dg/used_dummy_types_1.f90: New test.
	* gfortran.dg/used_dummy_types_2.f90: New test.
	* gfortran.dg/used_dummy_types_3.f90: New test.
	* gfortran.dg/used_dummy_types_4.f90: New test.
	* gfortran.dg/used_dummy_types_5.f90: New test.

	PR fortran/23152
	* gfortran.dg/assumed_shape_nml.f90: New test.
	* gfortran.dg/assumed_size_nml.f90: New test.

	PR fortran/20862
	PR fortran/25053
	PR fortran/25063
	PR fortran/25064
	PR fortran/25066
	PR fortran/25067
	PR fortran/25068
	PR fortran/25307
	* gfortran.dg/io_constraints_1.f90: New test.
	* gfortran.dg/io_constraints_1.f90: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_shape_nml.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_size_nml.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/host_used_types_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/initialization_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/io_constraints_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/io_constraints_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/pointer_component_type_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_dummy_types_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_dummy_types_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_dummy_types_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_dummy_types_4.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_dummy_types_5.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/trans-types.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog