Bug 101349 - ICE in gfc_get_descriptor_field, at fortran/trans-array.c:140
Summary: ICE in gfc_get_descriptor_field, at fortran/trans-array.c:140
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2021-07-06 17:35 UTC by G. Steinmetz
Modified: 2021-09-03 19:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-07-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2021-07-06 17:35:32 UTC
With a missing attribute allocatable or pointer :
(affects version down to r6)


$ cat z1.f90
subroutine s(x)
   class(*) :: x(:)
   allocate (x, source=['abc'])
end


$ cat z2.f90   # ok
subroutine s(x)
   class(*), allocatable :: x(:)
   allocate (x, source=['abc'])
end


$ gfortran-12-20210704 -c z1.f90
z1.f90:3:31:

    3 |    allocate (x, source=['abc'])
      |                               1
internal compiler error: in gfc_get_descriptor_field, at fortran/trans-array.c:140
0x7ad4f0 gfc_get_descriptor_field
        ../../gcc/fortran/trans-array.c:140
0x7ae7bf gfc_conv_descriptor_dtype(tree_node*)
        ../../gcc/fortran/trans-array.c:215
0x7b46d0 gfc_array_init_size
        ../../gcc/fortran/trans-array.c:5562
0x7b46d0 gfc_array_allocate(gfc_se*, gfc_expr*, tree_node*, tree_node*, tree_node*, tree_node*, tree_node*, tree_node**, gfc_expr*, tree_node*, bool)
        ../../gcc/fortran/trans-array.c:5982
0x8256b7 gfc_trans_allocate(gfc_code*)
        ../../gcc/fortran/trans-stmt.c:6736
0x7acb47 trans_code
        ../../gcc/fortran/trans.c:2090
0x7d31a4 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6898
0x759926 translate_all_program_units
        ../../gcc/fortran/parse.c:6464
0x759926 gfc_parse_file()
        ../../gcc/fortran/parse.c:6733
0x7a5c4f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:216
Comment 1 kargls 2021-07-06 18:32:22 UTC
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 45c3ad387ac..8365eb4caa8 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -7820,8 +7820,9 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec)
 	}
     }
 
-  /* Check for F08:C628.  */
-  if (allocatable == 0 && pointer == 0 && !unlimited)
+  /* F08:C628.  (R632) Each allocate-object shall be a data pointer or
+     an allocatable variable.  */
+  if (allocatable == 0 && pointer == 0)
     {
       gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
 		 &e->where);
Comment 2 anlauf 2021-08-30 19:31:17 UTC
Steve,

are you going to submit your patch?
Comment 3 Steve Kargl 2021-08-30 20:03:41 UTC
On Mon, Aug 30, 2021 at 07:31:17PM +0000, anlauf at gcc dot gnu.org wrote:
> 
> --- Comment #2 from anlauf at gcc dot gnu.org ---
> Steve,
> 
> are you going to submit your patch?
> 

I submitted the patch to bugzilla.  Whether
it makes it into the repository is predicated
on new volunteers stepping into gfortran world.
Comment 4 GCC Commits 2021-08-30 20:42:56 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:9213ff13247739d6d335064a6b568278a872a991

commit r12-3230-g9213ff13247739d6d335064a6b568278a872a991
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Aug 30 22:41:01 2021 +0200

    Fortran - correct check for constraint F2008:C628 / F2018:C932
    
    gcc/fortran/ChangeLog:
    
            PR fortran/101349
            * resolve.c (resolve_allocate_expr): An unlimited polymorphic
            argument to ALLOCATE must be ALLOCATABLE or a POINTER.  Fix the
            corresponding check.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/101349
            * gfortran.dg/unlimited_polymorphic_33.f90: New test.
Comment 5 anlauf 2021-08-30 20:49:24 UTC
Committed as obvious.  Fixed.
Comment 6 GCC Commits 2021-09-03 19:18:01 UTC
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:f826c257b6fb64868fd12a52291d1b6f85e1689a

commit r11-8958-gf826c257b6fb64868fd12a52291d1b6f85e1689a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Aug 30 22:41:01 2021 +0200

    Fortran - correct check for constraint F2008:C628 / F2018:C932
    
    gcc/fortran/ChangeLog:
    
            PR fortran/101349
            * resolve.c (resolve_allocate_expr): An unlimited polymorphic
            argument to ALLOCATE must be ALLOCATABLE or a POINTER.  Fix the
            corresponding check.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/101349
            * gfortran.dg/unlimited_polymorphic_33.f90: New test.
    
    (cherry picked from commit 9213ff13247739d6d335064a6b568278a872a991)