Bug 51052 - [OOP] Internal compiler error in gfc_conv_component
Summary: [OOP] Internal compiler error in gfc_conv_component
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-11-09 10:50 UTC by Arjen Markus
Modified: 2012-01-02 13:00 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-09 00:00:00


Attachments
Compressed tar file with two source files. (2.18 KB, application/x-gzip-compressed)
2011-11-09 10:50 UTC, Arjen Markus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arjen Markus 2011-11-09 10:50:05 UTC
Created attachment 25767 [details]
Compressed tar file with two source files.

The attached program source causes the compiler to stop with the message:

particles.f90: In function 'position_oil_particle':
particles.f90:142:0: internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:523
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

The version information of the compiler is:

Built by Equation Solution <http://www.Equation.com>.
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=d:/gcc4.6.2/bin/../libexec/gcc/i686-pc-mingw32/4.6.2/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ../gcc-4.6.2-mingw/configure --host=i686-pc-mingw32 --build=x86_64-unknown-linux-gnu --target=i686-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.6.2 --with-gcc --with-gnu-as --with-gnu-ld --with-host-libstdcxx='-lstdc++ -lsupc++ -lm' --with-ppl=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/ppl --with-cloog=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/cloog --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr --with-mpc=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpc --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.6.2 --disable-shared --disable-nls --disable-tls --disable-win32-registry --enable-libquadmath-support --enable-libquadmath --enable-languages=c,c++,fortran --enable-libgomp --enable-threads=win32 --enable-lto --enable-static --enable-shared=lto-plugin --enable-plugins --enable-ld=yes --enable-cloog-backend=ppl
Thread model: win32
gcc version 4.6.2 (GCC) 

The command I used to compile and link the program was:

gfortran -o particles points2d3d.f90 particles.f90
Comment 1 Tobias Burnus 2011-11-09 13:03:56 UTC
I can confirm the ICE - I get the same with 4.6 and 4.7.

Note, however, that with GCC 4.7 one has to fix the following coding problem before one can enjoy the internal error:

particles.f90:102.17:
        procedure, pass(particle) &
                 1
Error: Argument mismatch for the overriding procedure 'new_position' at (1): INTENT mismatch in argument 'particle'


The issue seems to occur for:

    position = position + deltt * velocity + &
               random_displacement

in subroutine position_oil_particle if particles.f90.


The ICE is in gfc_conv_component_ref for:

  if (DECL_FIELD_CONTEXT (field) != TREE_TYPE (decl))
    {
      tree f2 = c->norestrict_decl;
      if (!f2 || DECL_FIELD_CONTEXT (f2) != TREE_TYPE (decl))
        for (f2 = TYPE_FIELDS (TREE_TYPE (decl)); f2; f2 = DECL_CHAIN (f2))

and fails for "TYPE_FIELDS (TREE_TYPE (decl))" with: "internal compiler error: tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_conv_component_ref, at fortran/trans-expr.c:556"

This is called by gfc_conv_variable, which is called by get_proc_ptr_comp. The expression looks as follow

"position%__class_points2d3d_Point2d_p%__vtype_points2d3d_Point2d%__class_points2d3d_Point2d_a%__vtype_points2d3d_Point2d"

At least that's what I get when printing expr->symtree->n.sym->name and expr->ref{,->next,->next->next,...}->u.c.sym->name.
Comment 2 janus 2011-11-09 13:45:12 UTC
Here is an very much reduced (and corrected) test case. This is another case of "non-trivial polymorphic operands", cf. PR46262 and PR46328.

Arjen, why do you need those workarounds for 4.6?



module points2d3d

  implicit none

  type point2d
      real :: x, y
  contains
      procedure               :: add_vector_2d
      procedure               :: assign_2d
      generic                 :: operator(+)     => add_vector_2d
      generic                 :: assignment(=)   => assign_2d
  end type

contains

  subroutine assign_2d( point1, point2 )
    class(point2d), intent(inout) :: point1
    class(point2d), intent(in)    :: point2
    point1%x = point2%x
    point1%y = point2%y
  end subroutine

  function add_vector_2d( point, vector )
    class(point2d), intent(in)  :: point, vector
    class(point2d), allocatable :: add_vector_2d
    ! Workaround for gfortran 4.6
    if ( allocated( add_vector_2d ) ) then
        deallocate( add_vector_2d )
    endif
    allocate( add_vector_2d )
    add_vector_2d%x = point%x + vector%x
    add_vector_2d%y = point%y + vector%y
  end function

end module points2d3d



  use points2d3d
  implicit none

contains

  subroutine position_oil_particle()
    class(point2d), pointer      :: position
    type(point2d)                :: p1, p2
    position = position + p1 + p2
  end subroutine

end
Comment 3 Arjen Markus 2011-11-09 13:48:58 UTC
Hi Janus,

that may be from an older version of 4.6 (I now have 4.6.2,
previously 4.6.1). When running a program that used that
module, I got error messages about trying to allocate and
already allocated array.

Regards,

Arjen


On 2011-11-09 14:45, janus at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51052
> 
> janus at gcc dot gnu.org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |NEW
>    Last reconfirmed|                            |2011-11-09
>      Ever Confirmed|0                           |1
> 
> --- Comment #2 from janus at gcc dot gnu.org 2011-11-09 13:45:12 UTC ---
> Here is an very much reduced (and corrected) test case. This is another case of
> "non-trivial polymorphic operands", cf. PR46262 and PR46328.
> 
> Arjen, why do you need those workarounds for 4.6?
> 
> 
> 
> module points2d3d
> 
>   implicit none
> 
>   type point2d
>       real :: x, y
>   contains
>       procedure               :: add_vector_2d
>       procedure               :: assign_2d
>       generic                 :: operator(+)     => add_vector_2d
>       generic                 :: assignment(=)   => assign_2d
>   end type
> 
> contains
> 
>   subroutine assign_2d( point1, point2 )
>     class(point2d), intent(inout) :: point1
>     class(point2d), intent(in)    :: point2
>     point1%x = point2%x
>     point1%y = point2%y
>   end subroutine
> 
>   function add_vector_2d( point, vector )
>     class(point2d), intent(in)  :: point, vector
>     class(point2d), allocatable :: add_vector_2d
>     ! Workaround for gfortran 4.6
>     if ( allocated( add_vector_2d ) ) then
>         deallocate( add_vector_2d )
>     endif
>     allocate( add_vector_2d )
>     add_vector_2d%x = point%x + vector%x
>     add_vector_2d%y = point%y + vector%y
>   end function
> 
> end module points2d3d
> 
> 
> 
>   use points2d3d
>   implicit none
> 
> contains
> 
>   subroutine position_oil_particle()
>     class(point2d), pointer      :: position
>     type(point2d)                :: p1, p2
>     position = position + p1 + p2
>   end subroutine
> 
> end
> 
 

DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited.
The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.
Comment 4 Arjen Markus 2011-11-09 13:49:42 UTC
Hi Tobias,

On 2011-11-09 14:03, burnus at gcc dot gnu.org wrote:

> 
> Note, however, that with GCC 4.7 one has to fix the following coding problem
> before one can enjoy the internal error:
> 
> particles.f90:102.17:
>         procedure, pass(particle) &
>                  1
> Error: Argument mismatch for the overriding procedure 'new_position' at (1):
> INTENT mismatch in argument 'particle'
> 
> 

Hm, I will have to check that one. Thanks.

Regards,

Arjen
 

DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited.
The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.
Comment 5 janus 2011-11-09 13:56:39 UTC
(In reply to comment #3)
> that may be from an older version of 4.6 (I now have 4.6.2,
> previously 4.6.1). When running a program that used that
> module, I got error messages about trying to allocate and
> already allocated array.

ah, I guess that was PR50225 (which was fixed only in 4.7, so 4.6.2 probably does not help here).
Comment 6 Arjen Markus 2011-11-09 14:11:33 UTC
Hi Janus,

yes, that is the one :). I am really examining the borders of
gfortran at the moment.

On 2011-11-09 14:56, janus at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51052
> 
> --- Comment #5 from janus at gcc dot gnu.org 2011-11-09 13:56:39 UTC ---
> (In reply to comment #3)
>> that may be from an older version of 4.6 (I now have 4.6.2,
>> previously 4.6.1). When running a program that used that
>> module, I got error messages about trying to allocate and
>> already allocated array.
> 
> ah, I guess that was PR50225 (which was fixed only in 4.7, so 4.6.2 probably
> does not help here).
> 
 

DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited.
The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.
Comment 7 janus 2011-11-09 15:20:55 UTC
(In reply to comment #6)
> yes, that is the one :). I am really examining the borders of
> gfortran at the moment.

Right. Thanks for your continued bug reporting. That sort of user feedback helps us a lot.
Comment 8 Paul Thomas 2012-01-02 12:46:16 UTC
Author: pault
Date: Mon Jan  2 12:46:08 2012
New Revision: 182796

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182796
Log:
2012-01-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/51529
	* trans-array.c (gfc_array_allocate): Null allocated memory of
	newly allocted class arrays.

	PR fortran/46262
	PR fortran/46328
	PR fortran/51052
	* interface.c(build_compcall_for_operator): Add a type to the
	expression.
	* trans-expr.c (conv_base_obj_fcn_val): New function.
	(gfc_conv_procedure_call): Use base_expr to detect non-variable
	base objects and, ensuring that there is a temporary variable,
	build up the typebound call using conv_base_obj_fcn_val.
	(gfc_trans_class_assign): Pick out class procedure pointer
	assignments and do the assignment with no further prcessing.
	(gfc_trans_class_array_init_assign, gfc_trans_class_init_assign
	gfc_trans_class_assign): Move to top of file.
	* gfortran.h : Add 'base_expr' field to gfc_expr.
	* resolve.c (get_declared_from_expr): Add 'types' argument to
	switch checking of derived types on or off.
	(resolve_typebound_generic_call): Set the new argument.
	(resolve_typebound_function, resolve_typebound_subroutine):
	Set 'types' argument for get_declared_from_expr appropriately.
	Identify base expression, if not a variable, in the argument
	list of class valued calls. Assign it to the 'base_expr' field
	of the final expression. Strip away all references after the
	last class reference.


2012-01-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/46262
	PR fortran/46328
	PR fortran/51052
	* gfortran.dg/typebound_operator_7.f03: New.
	* gfortran.dg/typebound_operator_8.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_operator_7.f03
    trunk/gcc/testsuite/gfortran.dg/typebound_operator_8.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Paul Thomas 2012-01-02 13:00:36 UTC
Fixed on trunk.

Thanks for the report

Paul