Bug 103716 - [11/12/13 Regression] ICE in gimplify_expr, at gimplify.c:15964 since r9-3803-ga5fbc2f36a291cbe
Summary: [11/12/13 Regression] ICE in gimplify_expr, at gimplify.c:15964 since r9-3803...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.0
: P4 normal
Target Milestone: 11.5
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2021-12-14 18:11 UTC by G. Steinmetz
Modified: 2024-04-26 19:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-15 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-12-14 18:11:35 UTC
Started with r10 (before 20190505) :


$ cat z1.f90
function f(x)
   character(*) :: x(*)
   print *, g(x%len)
end


$ cat z2.f90
function f(x)
   character(*) :: x(3)
   print *, g(x%len)
end


$ gfortran-9 -c z1.f90
$
$ gfortran-12-20211212 -c z1.f90
gimplification failed:
(integer(kind=4)) _x <nop_expr 0x7fa0eb2defa0
    type <integer_type 0x7fa0eb11e5e8 integer(kind=4) sizes-gimplified public SI
        size <integer_cst 0x7fa0eb107e40 constant 32>
        unit-size <integer_cst 0x7fa0eb107e58 constant 4>
        align:32 warn_if_not_align:0 symtab:0 alias-set 3 canonical-type 0x7fa0eb11e5e8 precision:32 min <integer_cst 0x7fa0eb107df8 -2147483648> max <integer_cst 0x7fa0eb107e10 2147483647>
        pointer_to_this <pointer_type 0x7fa0eb126a80>>
    readonly
    arg:0 <parm_decl 0x7fa0eb2e7200 _x
        type <integer_type 0x7fa0eb11e738 integer(kind=8) public DI
            size <integer_cst 0x7fa0eb107c00 constant 64>
            unit-size <integer_cst 0x7fa0eb107c18 constant 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fa0eb11e738 precision:64 min <integer_cst 0x7fa0eb107e88 -9223372036854775808> max <integer_cst 0x7fa0eb107ea0 9223372036854775807>
            pointer_to_this <pointer_type 0x7fa0eb153738>>
        readonly used DI z1.f90:1:0 size <integer_cst 0x7fa0eb107c00 64> unit-size <integer_cst 0x7fa0eb107c18 8>
        align:64 warn_if_not_align:0 context <function_decl 0x7fa0eb2f8e00 f> arg-type <integer_type 0x7fa0eb11e738 integer(kind=8)>>>
z1.f90:3:20:

    3 |    print *, g(x%len)
      |                    ^
internal compiler error: gimplification failed
0xbe3308 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15964
0xbf1777 gimplify_modify_expr
        ../../gcc/gimplify.c:5975
0xbe20a7 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14951
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
0xbe19db gimplify_statement_list
        ../../gcc/gimplify.c:2014
0xbe19db gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15396
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
0xbe1d4c gimplify_and_add(tree_node*, gimple**)
        ../../gcc/gimplify.c:495
0xbe1d4c gimplify_loop_expr
        ../../gcc/gimplify.c:1988
0xbe1d4c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15156
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
0xbe19db gimplify_statement_list
        ../../gcc/gimplify.c:2014
0xbe19db gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15396
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
0xbe6d03 gimplify_bind_expr
        ../../gcc/gimplify.c:1427
0xbe268a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15152
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
0xbe19db gimplify_statement_list
        ../../gcc/gimplify.c:2014
0xbe19db gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:15396
0xbe6378 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:7026
Comment 1 Martin Liška 2021-12-15 11:16:40 UTC
Started with r9-3803-ga5fbc2f36a291cbe.
Comment 2 anlauf 2021-12-15 19:56:29 UTC
No ICE for

  print *, g((x%len))

Furthermore, adding an interface

  interface 
     function g(x)
       integer, intent(in) :: x
     end function g
  end interface

in the original testcase gives the error:

pr103716-z1.f90:11:13:

   11 |   print *, g(x%len)
      |             1
Error: Rank mismatch in argument 'x' at (1) (scalar and rank-1)

This is wrong: x%len is actually a scalar.

* * *

I am not happy that this is marked as a regression, as the %len inquiry did
not exist before the commit in the subject.  If somebody else agrees, we should
remove that.
Comment 3 G. Steinmetz 2021-12-16 08:57:20 UTC
On my environment(s) the history for r9 is as follows :

       <= 20181028 : Error: Unexpected '%' for nonderived-type variable 'x' at (1)
20181104..20190824 : ICE in check_assumed_size_reference/gfc_format_decoder
20191005..20200125 : ICE in gimplify_expr
       >= 20200508 : accepted, no Error, no ICE

(sorry for the sparse coverage with r9 binaries between 20200125 and 20200508)
Comment 4 anlauf 2021-12-16 17:23:58 UTC
(In reply to G. Steinmetz from comment #3)
> On my environment(s) the history for r9 is as follows :
> 
>        <= 20181028 : Error: Unexpected '%' for nonderived-type variable 'x'
> at (1)
> 20181104..20190824 : ICE in check_assumed_size_reference/gfc_format_decoder
> 20191005..20200125 : ICE in gimplify_expr
>        >= 20200508 : accepted, no Error, no ICE
> 
> (sorry for the sparse coverage with r9 binaries between 20200125 and
> 20200508)

OK, I checked again, and find top-of-the-branch r9 generating questionable code.

  print *, g(x%len)

generates

      D.3874 = g (&(integer(kind=4)) _x, _x);

(note the 2 arguments), while

  print *, g(len(x))

generates

      D.3876 = (integer(kind=4)) _x;
      D.3877 = g (&D.3876);

which is how it should have been.
Comment 5 anlauf 2021-12-16 21:32:33 UTC
The following partial revert of r10-7334 avoids the ICE and restores the bug
in gcc-9:

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index bff1b35446f..245c4e1683f 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -5436,7 +5436,7 @@ gfc_resolve_ref (gfc_expr *expr)
        case REF_INQUIRY:
          /* Implement requirement in note 9.7 of F2018 that the result of the
             LEN inquiry be a scalar.  */
-         if (ref->u.i == INQUIRY_LEN && array_ref && expr->ts.deferred)
+         if (ref->u.i == INQUIRY_LEN && array_ref)
            {
              array_ref->u.ar.type = AR_ELEMENT;
              expr->rank = 0;
Comment 6 Jakub Jelinek 2022-06-28 10:47:28 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 7 GCC Commits 2023-05-23 05:46:47 UTC
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:842a432b02238361ecc601d301ac400a7f30f4fa

commit r14-1082-g842a432b02238361ecc601d301ac400a7f30f4fa
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue May 23 06:46:37 2023 +0100

    Fortran: Fix assumed length chars and len inquiry [PR103716]
    
    2023-05-23  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/103716
            * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
            element should be done for all characters without a len expr,
            not just deferred lens, and for integer expressions.
            * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
            set the se string_length to NULL_TREE.
    
    gcc/testsuite/
            PR fortran/103716
            * gfortran.dg/pr103716.f90 : New test.
Comment 8 Richard Biener 2023-07-07 10:41:48 UTC
GCC 10 branch is being closed.
Comment 9 GCC Commits 2024-03-28 15:53:15 UTC
The releases/gcc-13 branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:48d23749534ca96b3f0883579b44700a17e83d15

commit r13-8503-g48d23749534ca96b3f0883579b44700a17e83d15
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue May 23 06:46:37 2023 +0100

    Fortran: Fix assumed length chars and len inquiry [PR103716]
    
    2023-05-23  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/103716
            * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
            element should be done for all characters without a len expr,
            not just deferred lens, and for integer expressions.
            * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
            set the se string_length to NULL_TREE.
    
    gcc/testsuite/
            PR fortran/103716
            * gfortran.dg/pr103716.f90 : New test.
    
    (cherry picked from commit 842a432b02238361ecc601d301ac400a7f30f4fa)
Comment 10 Paul Thomas 2024-03-28 15:56:49 UTC
Fixed on 13- and 14-branches. Closing.

Thanks for the report

Paul
Comment 11 GCC Commits 2024-04-26 19:16:11 UTC
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r12-10398-gb482968801158116dd8ba3b15a4c29143b2a423a
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue May 23 06:46:37 2023 +0100

    Fortran: Fix assumed length chars and len inquiry [PR103716]
    
    2023-05-23  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/103716
            * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
            element should be done for all characters without a len expr,
            not just deferred lens, and for integer expressions.
            * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
            set the se string_length to NULL_TREE.
    
    gcc/testsuite/
            PR fortran/103716
            * gfortran.dg/pr103716.f90 : New test.
    
    (cherry picked from commit 842a432b02238361ecc601d301ac400a7f30f4fa)