Bug 104619 - [10/11/12 Regression] ICE on list comprehension with default derived type constructor
Summary: [10/11/12 Regression] ICE on list comprehension with default derived type con...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.2.1
: P4 normal
Target Milestone: 10.4
Assignee: anlauf
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2022-02-21 19:29 UTC by Dominik Gronkiewicz
Modified: 2022-02-23 18:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-02-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominik Gronkiewicz 2022-02-21 19:29:54 UTC
This very short program produces an ICE with gfortran 11.2.1:

module m

    type :: item
        real :: x
    end type

    type :: container
        type(item) :: items(3)
    end type

end module

program p

    use m

    type(item), allocatable :: items(:)
    type(container) :: c

    items = [item(3.0), item(4.0), item(5.0)]
    ! ICE in the line below
    c = container(items=[(items(i), i = 1, size(items))])
    print *, c

end program
Comment 1 anlauf 2022-02-21 20:39:38 UTC
Confirmed.

Potential fix: skip shape check when shape is not available

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 266e41e25b1..451bc97df43 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -1472,6 +1472,8 @@ resolve_structure_cons (gfc_expr *expr, int init)
                  t = false;
                  break;
                };
+             if (cons->expr->shape == NULL)
+               continue;
              mpz_set_ui (len, 1);
              mpz_add (len, len, comp->as->upper[n]->value.integer);
              mpz_sub (len, len, comp->as->lower[n]->value.integer);
Comment 3 GCC Commits 2022-02-22 20:41:09 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r12-7351-gbc66b471d16ef2fd8cb66fd1131b41f80ecb9961
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Feb 21 22:49:05 2022 +0100

    Fortran: skip compile-time shape check if constructor shape is not known
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104619
            * resolve.cc (resolve_structure_cons): Skip shape check if shape
            of constructor cannot be determined at compile time.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104619
            * gfortran.dg/derived_constructor_comps_7.f90: New test.
Comment 4 GCC Commits 2022-02-23 18:51:05 UTC
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r11-9618-gd86949f5f55dbe0eb6f3044366101605882cd58e
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Feb 21 22:49:05 2022 +0100

    Fortran: skip compile-time shape check if constructor shape is not known
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104619
            * resolve.c (resolve_structure_cons): Skip shape check if shape
            of constructor cannot be determined at compile time.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104619
            * gfortran.dg/derived_constructor_comps_7.f90: New test.
    
    (cherry picked from commit bc66b471d16ef2fd8cb66fd1131b41f80ecb9961)
Comment 5 GCC Commits 2022-02-23 18:57:31 UTC
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:251061b82852bdebc6f13510b415ecb73a2f80ae

commit r10-10474-g251061b82852bdebc6f13510b415ecb73a2f80ae
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Feb 21 22:49:05 2022 +0100

    Fortran: skip compile-time shape check if constructor shape is not known
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104619
            * resolve.c (resolve_structure_cons): Skip shape check if shape
            of constructor cannot be determined at compile time.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104619
            * gfortran.dg/derived_constructor_comps_7.f90: New test.
    
    (cherry picked from commit bc66b471d16ef2fd8cb66fd1131b41f80ecb9961)
Comment 6 anlauf 2022-02-23 18:58:28 UTC
Fixed on mainline for gcc-12 and on affected branches.  Closing.

Thanks for the report!