Bug 95979 - [10/11 Regression] ICE in get_kind, at fortran/simplify.c:129
Summary: [10/11 Regression] ICE in get_kind, at fortran/simplify.c:129
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 10.3
Assignee: anlauf
URL:
Keywords: ice-on-invalid-code, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-06-29 17:52 UTC by G. Steinmetz
Modified: 2020-10-23 19:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.4.1, 8.4.1, 9.3.1
Known to fail: 10.2.1, 11.0
Last reconfirmed: 2020-06-29 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-29 17:52:19 UTC
Changed between 20191215 and 20200105 :


$ cat z1.f90
program p
   integer :: a = index('abcd', 'c', [.true.], kind=1)
end


$ cat z2.f90
program p
   integer :: a = index('abcd', 'c', [.true.], kind=4)
end


$ cat z3.f90
program p
   integer :: a(1) = index('abcd', 'c', [.true.])
   integer :: b(1) = index('abcd', 'c', [.true.], kind=1)
   print *, a
   print *, b
end


$ gfortran-10-20191215 -c z1.f90
z1.f90:2:15:

    2 |    integer :: a = index('abcd', 'c', [.true.], kind=1)
      |               1
Error: Incompatible ranks 0 and 1 in assignment at (1)


$ gfortran-11-20200628 -c z1.f90
0xbd215f crash_signal
        ../../gcc/toplev.c:328
0x65730f gfc_format_decoder
        ../../gcc/fortran/error.c:981
0x1504fce pp_format(pretty_printer*, text_info*)
        ../../gcc/pretty-print.c:1475
0x14f96df diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../gcc/diagnostic.c:1159
0x657489 gfc_report_diagnostic
        ../../gcc/fortran/error.c:782
0x65759b gfc_error_opt
        ../../gcc/fortran/error.c:1352
0x658aa0 gfc_error(char const*, ...)
        ../../gcc/fortran/error.c:1381
0x6db27a get_kind
        ../../gcc/fortran/simplify.c:129
0x6e4ce1 gfc_simplify_index(gfc_expr*, gfc_expr*, gfc_expr*, gfc_expr*)
        ../../gcc/fortran/simplify.c:3479
0x66c997 do_simplify
        ../../gcc/fortran/intrinsic.c:4634
0x677178 gfc_intrinsic_func_interface(gfc_expr*, int)
        ../../gcc/fortran/intrinsic.c:4899
0x65d5f9 gfc_simplify_expr(gfc_expr*, int)
        ../../gcc/fortran/expr.c:2180
0x65e03a scalarize_intrinsic_call
        ../../gcc/fortran/expr.c:2422
0x65c82b gfc_check_init_expr(gfc_expr*)
        ../../gcc/fortran/expr.c:2934
0x65cb07 gfc_reduce_init_expr(gfc_expr*)
        ../../gcc/fortran/expr.c:3087
0x65fd70 gfc_match_init_expr(gfc_expr**)
        ../../gcc/fortran/expr.c:3133
0x64b5f4 variable_decl
        ../../gcc/fortran/decl.c:2886
0x64b5f4 gfc_match_data_decl()
        ../../gcc/fortran/decl.c:6197
0x6ae0a3 match_word
        ../../gcc/fortran/parse.c:65
0x6ae0a3 decode_statement
        ../../gcc/fortran/parse.c:376
Comment 1 Dominique d'Humieres 2020-06-29 20:35:11 UTC
I don't see the ICE on a standard GCC11, but its instrumented version gives

../../work/gcc/fortran/simplify.c:127:10: runtime error: load of value 4294967295, which is not a valid value for type 'expr_t'
../../work/gcc/fortran/error.c:970:2: runtime error: member access within misaligned address 0x000000000002 for type 'struct gfc_linebuf', which requires 8 byte alignment
0x000000000002: note: pointer points here
<memory cannot be printed>
../../work/gcc/fortran/error.c:971:46: runtime error: member access within misaligned address 0x000000000002 for type 'struct gfc_linebuf', which requires 8 byte alignment
0x000000000002: note: pointer points here
<memory cannot be printed>
../../work/gcc/fortran/error.c:979:42: runtime error: member access within misaligned address 0x000000000002 for type 'struct gfc_linebuf', which requires 8 byte alignment
0x000000000002: note: pointer points here

The instrumented GCC9 and 10 give the expected error.
Comment 2 Richard Biener 2020-07-23 06:52:00 UTC
GCC 10.2 is released, adjusting target milestone.
Comment 3 anlauf 2020-08-25 20:44:20 UTC
Only examples z1 and z2 are invalid code, z3 is actually valid code.
Adjusting keywords.

Maybe the issue is related to PR87711, where the optional KIND argument
causes havoc with the elementalness of an intrinsic. (There it is LEN_TRIM).
Comment 4 anlauf 2020-10-05 20:09:28 UTC
(In reply to anlauf from comment #3)
> Maybe the issue is related to PR87711, where the optional KIND argument
> causes havoc with the elementalness of an intrinsic. (There it is LEN_TRIM).

Replying to myself: it seems to be that simplification fails when one of
the arguments to INDEX is array-valued.  Might be a general issue.
Comment 6 GCC Commits 2020-10-16 20:18:22 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:02629b116eed7c6911ef0eb2ef97e1883e9fb1de

commit r11-4020-g02629b116eed7c6911ef0eb2ef97e1883e9fb1de
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Oct 16 22:17:46 2020 +0200

    PR fortran/95979 - ICE in get_kind, at fortran/simplify.c:129
    
    Simplification of the elemental intrinsic INDEX with constant array-valued
    arguments failed with an ICE or did not reduce to a constant array, depending
    also on the presence of the optional KIND argument.  Add a further attempt of
    simplification in the case of elemental intrinsics, and make sure the KIND
    argument is not removed prematurely during simplification of INDEX.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/95979
            * expr.c (gfc_check_init_expr): Fix check of return code from
            gfc_intrinsic_func_interface.
            * intrinsic.c (gfc_intrinsic_func_interface): Add further attempt
            of simplification of elemental intrinsics with array arguments.
            * iresolve.c (gfc_resolve_index_func): Keep optional KIND argument
            for simplification of elemental use of INDEX.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/95979
            * gfortran.dg/index_4.f90: New test.
Comment 7 GCC Commits 2020-10-22 20:41:44 UTC
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:90b83a25b3499ff50a9b7afc0e84e1355191c220

commit r10-8939-g90b83a25b3499ff50a9b7afc0e84e1355191c220
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Oct 16 22:17:46 2020 +0200

    PR fortran/95979 - ICE in get_kind, at fortran/simplify.c:129
    
    Simplification of the elemental intrinsic INDEX with constant array-valued
    arguments failed with an ICE or did not reduce to a constant array, depending
    also on the presence of the optional KIND argument.  Add a further attempt of
    simplification in the case of elemental intrinsics, and make sure the KIND
    argument is not removed prematurely during simplification of INDEX.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/95979
            * expr.c (gfc_check_init_expr): Fix check of return code from
            gfc_intrinsic_func_interface.
            * intrinsic.c (gfc_intrinsic_func_interface): Add further attempt
            of simplification of elemental intrinsics with array arguments.
            * iresolve.c (gfc_resolve_index_func): Keep optional KIND argument
            for simplification of elemental use of INDEX.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/95979
            * gfortran.dg/index_4.f90: New test.
    
    (cherry picked from commit 02629b116eed7c6911ef0eb2ef97e1883e9fb1de)
Comment 8 anlauf 2020-10-23 19:51:06 UTC
Fixed on master for gcc-11, and on 10-branch.  Closing.

Thanks for the report!