Bug 56765 - [OOP] compilation errors/ICE with polymorphic array
Summary: [OOP] compilation errors/ICE with polymorphic array
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-03-28 13:42 UTC by escout20
Modified: 2016-05-11 17:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-03-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description escout20 2013-03-28 13:42:48 UTC
When compiling following program:

program t_unlimited_2
    implicit none
    class(*), dimension(:), pointer :: u
    u => sub()
contains
    function sub() result(r)
        class(*), dimension(:), pointer :: r
        integer, dimension(3), target :: x = [1,2,3]
        r => x
    end function
end program

I get the output:
----------------------------------------------------------
$gfortran -Wall -Wextra t_unlimited_2.f90
t_unlimited_2.f90:4.4:

    u => sub()
    1
Error: Different ranks in pointer assignment at (1)
---------------------------------------------------------

u and sub are both of rank 1.

When compiling the following (u is scalar here):

program t_unlimited_3
    implicit none
    class(*), pointer :: u
    u => sub()
contains
    function sub() result(r)
        class(*), dimension(:), pointer :: r
        integer, dimension(3), target :: x = [1,2,3]
        r => x
    end function
end program  

I get an ICE:

------------------------------------------------------------
$gfortran -Wall -Wextra t_unlimited_3.f90
t_unlimited_3.f90: In function ‘t_unlimited_3’:
t_unlimited_3.f90:4:0: internal compiler error: in fold_convert_loc, at fold-const.c:1862
     u => sub()
 ^

t_unlimited_3.f90:4:0: internal compiler error: Abort trap
gfortran: internal compiler error: Abort trap (program f951)
Abort trap
-------------------------------------------------------------

Version:

$gfortran -v
Using built-in specs.
COLLECT_GCC=/xsw/gf48/bin/gfortran
COLLECT_LTO_WRAPPER=/xsw/gcc-4.8-20130321/install/libexec/gcc/x86_64-apple-darwin10.8.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin10.8.0
Configured with: ../src/configure --prefix=/xsw/gcc-4.8-20130321/install --enable-languages=c,fortran --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-libiconv-prefix=/opt/local
Thread model: posix
gcc version 4.8.0 20130321 (prerelease) (GCC) 


Running on Mac OS X 10.6.8
Comment 1 janus 2013-03-28 18:43:31 UTC
Confirmed with current trunk.
Comment 2 Tobias Burnus 2013-03-28 22:37:08 UTC
Regarding the rank error (and "expr->rank = "), it seems as if one has to review the following functions in result.c:  resolve_generic_f0, expression_rank, check_host_association, resolve_unknown_f, resolve_specific_f0, resolve_compcall,resolve_expr_ppc, resolve_assoc_var, add_comp_ref, resolve_structure_cons.
Comment 3 janus 2013-03-29 21:30:03 UTC
With this patch ...


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 196862)
+++ gcc/fortran/resolve.c	(working copy)
@@ -2538,7 +2538,9 @@ found:
     expr->ts = sym->ts;
   expr->value.function.name = sym->name;
   expr->value.function.esym = sym;
-  if (sym->as != NULL)
+  if (sym->result->ts.type == BT_CLASS && CLASS_DATA (sym->result)->as)
+    expr->rank = CLASS_DATA (sym->result)->as->rank;
+  else if (sym->as != NULL)
     expr->rank = sym->as->rank;
 
   return MATCH_YES;


... the behavior of the two test cases is swapped: The second one is (correctly) rejected, while the first one ends up with the ICE.
Comment 4 janus 2013-03-31 17:35:13 UTC
Btw, this bug does not require unlimited polymorphism, but also shows up with normal ('limited'?) CLASS definitions:


program t_limited
    implicit none
    type :: t
      integer :: i = 0
    end type
    class(t), dimension(:), pointer :: u
    u => sub()
contains
    function sub() result(r)
        class(t), dimension(:), pointer :: r
        type(t), dimension(3), target :: x = t(1)
        r => x
    end function
end program
Comment 5 janus 2013-04-13 12:31:42 UTC
Note: The patch in comment 3 regtests cleanly.
Comment 6 Gerhard Steinmetz 2016-05-11 17:21:28 UTC
On my environment, all tests compile now without an ICE.
(also tested with several other compile options)

$ gfortran-6 --version
GNU Fortran (SUSE Linux) 6.1.1 20160502 [gcc-6-branch revision 235698]


$ gfortran-6 -Wall -Wextra pr56765_comment0_t2.f90
$ a.out

$ gfortran-6 -Wall -Wextra pr56765_comment0_t3.f90
pr56765_comment0_t3.f90:4:4:

     u => sub()
    1
Error: Different ranks in pointer assignment at (1)

$ gfortran-6 -Wall -Wextra pr56765_comment4.f90
$ a.out