Bug 95882 - [9/10/11 Regression] ICE in gfc_get_derived_type, at fortran/trans-types.c:2729
Summary: [9/10/11 Regression] ICE in gfc_get_derived_type, at fortran/trans-types.c:2729
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 9.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2020-06-24 18:57 UTC by G. Steinmetz
Modified: 2020-08-27 17:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-06-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2020-06-24 18:57:11 UTC
Changed between 20200517 and 20200524 :


$ cat z1.f90
module m
   type t
      character(((0)/0)) :: c
   end type
end


$ gfortran-11-20200517 -c z1.f90
z1.f90:3:22:

    3 |       character(((0)/0)) :: c
      |                      1
Error: Division by zero at (1)


$ gfortran-11-20200621 -c z1.f90
f951: internal compiler error: in gfc_get_derived_type, at fortran/trans-types.c:2729
0x784843 gfc_get_derived_type(gfc_symbol*, int)
        ../../gcc/fortran/trans-types.c:2729
0x784b68 gfc_typenode_for_spec(gfc_typespec*, int)
        ../../gcc/fortran/trans-types.c:1166
0x784dbe gfc_sym_type(gfc_symbol*)
        ../../gcc/fortran/trans-types.c:2247
0x729616 gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1769
0x72c888 gfc_create_module_variable
        ../../gcc/fortran/trans-decl.c:5302
0x6ebde2 do_traverse_symtree
        ../../gcc/fortran/symbol.c:4162
0x72d08b gfc_generate_module_vars(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:5801
0x707ca4 gfc_generate_module_code(gfc_namespace*)
        ../../gcc/fortran/trans.c:2238
0x6b4b01 translate_all_program_units
        ../../gcc/fortran/parse.c:6294
0x6b4b01 gfc_parse_file()
        ../../gcc/fortran/parse.c:6546
0x70098f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:212
Comment 1 G. Steinmetz 2020-06-24 18:57:33 UTC
Related, with different backtraces :


$ cat z2.f90
module m
   character(((0)/0)) :: c = '123456789'
end


$ cat z3.f90
subroutine s(c)
   character(((0)/0)) :: c
end


$ cat z4.f90
program p
   character(((0)/0)) :: c
   common /x/ c
end


$ cat z5.f90
program p
   character(((0)/0)) :: c = '123456789'
   common c
end
Comment 2 Martin Liška 2020-06-25 07:07:37 UTC
Started with r11-461-ge5abd1cb91606197.
Comment 3 GCC Commits 2020-08-27 14:12:49 UTC
The master branch has been updated by Mark Eggleston <markeggleston@gcc.gnu.org>:

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

commit r11-2907-gc336eda750d4e7a0827fedf995da955d6d88d5ca
Author: Mark Eggleston <markeggleston@gcc.gnu.org>
Date:   Fri Aug 21 06:39:30 2020 +0100

    Fortran  : ICE for division by zero in declaration PR95882
    
    A length expression containing a divide by zero in a character
    declaration will result in an ICE if the constant is anymore
    complicated that a contant divided by a constant.
    
    The cause was that char_len_param_value can return MATCH_YES
    even if a divide by zero was seen.  Prior to returning check
    whether a divide by zero was seen and if so set it to MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/fortran
    
            PR fortran/95882
            * decl.c (char_len_param_value): Check gfc_seen_div0 and
            if it is set return MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/testsuite/
    
            PR fortran/95882
            * gfortran.dg/pr95882_1.f90: New test.
            * gfortran.dg/pr95882_2.f90: New test.
            * gfortran.dg/pr95882_3.f90: New test.
            * gfortran.dg/pr95882_4.f90: New test.
            * gfortran.dg/pr95882_5.f90: New test.
Comment 4 GCC Commits 2020-08-27 16:03:49 UTC
The releases/gcc-10 branch has been updated by Mark Eggleston <markeggleston@gcc.gnu.org>:

https://gcc.gnu.org/g:8323d09e82345a1ca39f6630cdd22ccf4ef38a84

commit r10-8679-g8323d09e82345a1ca39f6630cdd22ccf4ef38a84
Author: Mark Eggleston <markeggleston@gcc.gnu.org>
Date:   Fri Aug 21 06:39:30 2020 +0100

    Fortran  : ICE for division by zero in declaration PR95882
    
    A length expression containing a divide by zero in a character
    declaration will result in an ICE if the constant is anymore
    complicated that a contant divided by a constant.
    
    The cause was that char_len_param_value can return MATCH_YES
    even if a divide by zero was seen.  Prior to returning check
    whether a divide by zero was seen and if so set it to MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/fortran
    
            PR fortran/95882
            * decl.c (char_len_param_value): Check gfc_seen_div0 and
            if it is set return MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/testsuite/
    
            PR fortran/95882
            * gfortran.dg/pr95882_1.f90: New test.
            * gfortran.dg/pr95882_2.f90: New test.
            * gfortran.dg/pr95882_3.f90: New test.
            * gfortran.dg/pr95882_4.f90: New test.
            * gfortran.dg/pr95882_5.f90: New test.
    
    (cherry picked from commit c336eda750d4e7a0827fedf995da955d6d88d5ca)
Comment 5 GCC Commits 2020-08-27 17:26:53 UTC
The releases/gcc-9 branch has been updated by Mark Eggleston <markeggleston@gcc.gnu.org>:

https://gcc.gnu.org/g:042c58a4b8ba48fdf26c9003154e9d3b83d4c568

commit r9-8836-g042c58a4b8ba48fdf26c9003154e9d3b83d4c568
Author: Mark Eggleston <markeggleston@gcc.gnu.org>
Date:   Fri Aug 21 06:39:30 2020 +0100

    Fortran  : ICE for division by zero in declaration PR95882
    
    A length expression containing a divide by zero in a character
    declaration will result in an ICE if the constant is anymore
    complicated that a contant divided by a constant.
    
    The cause was that char_len_param_value can return MATCH_YES
    even if a divide by zero was seen.  Prior to returning check
    whether a divide by zero was seen and if so set it to MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/fortran
    
            PR fortran/95882
            * decl.c (char_len_param_value): Check gfc_seen_div0 and
            if it is set return MATCH_ERROR.
    
    2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>
    
    gcc/testsuite/
    
            PR fortran/95882
            * gfortran.dg/pr95882_1.f90: New test.
            * gfortran.dg/pr95882_2.f90: New test.
            * gfortran.dg/pr95882_3.f90: New test.
            * gfortran.dg/pr95882_4.f90: New test.
            * gfortran.dg/pr95882_5.f90: New test.
    
    (cherry picked from commit c336eda750d4e7a0827fedf995da955d6d88d5ca)
Comment 6 markeggleston 2020-08-27 17:27:57 UTC
committed and backported.