Bug 108501 - [13 Regression] ICE in get_expr_storage_size, at fortran/interface.cc:2941
Summary: [13 Regression] ICE in get_expr_storage_size, at fortran/interface.cc:2941
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: 13.0
Assignee: anlauf
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2023-01-23 17:47 UTC by G. Steinmetz
Modified: 2023-02-05 18:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-01-23 00:00:00


Attachments
Patch for the ICE in get_expr_storage_size (417 bytes, patch)
2023-01-23 19:44 UTC, anlauf
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2023-01-23 17:47:09 UTC
Started between 20221218 and 20230108 :


$ cat z1.f90
program p
   real, parameter :: n = 2
   real :: a(1,(n),2)
   call s(a(:,:,1))
end
subroutine s(x)
   real :: x(2)
end


$ gfortran-13-20230122 -c z1.f90
z1.f90:3:15:

    3 |    real :: a(1,(n),2)
      |               1
Error: Expression at (1) must be of INTEGER type, found REAL
z1.f90:3:21:

    3 |    real :: a(1,(n),2)
      |                     1
Error: The module or main program array 'a' at (1) must have constant shape
f951: internal compiler error: Segmentation fault
0xf8a79f crash_signal
        ../../gcc/toplev.cc:314
0x848fd9 get_expr_storage_size
        ../../gcc/fortran/interface.cc:2941
0x848fd9 gfc_compare_actual_formal(gfc_actual_arglist**, gfc_formal_arglist*, int, int, bool, locus*)
        ../../gcc/fortran/interface.cc:3327
0x9b3136 check_externals_procedure
        ../../gcc/fortran/frontend-passes.cc:5742
0x9b7e29 gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*)
        ../../gcc/fortran/frontend-passes.cc:5352
0x9b968b gfc_check_externals0
        ../../gcc/fortran/frontend-passes.cc:5861
0x9ba614 gfc_check_externals(gfc_namespace*)
        ../../gcc/fortran/frontend-passes.cc:5883
0x89f2c0 gfc_parse_file()
        ../../gcc/fortran/parse.cc:6942
0x8edd9f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.cc:229
Comment 1 anlauf 2023-01-23 19:43:32 UTC
First, I think the code is actually valid, adjusting keywords.

Furthermore, there are two issues here, an underlying one, namely that
we reject the following:

program p
  real, parameter :: n = 2
  real :: a(1,(n),2)
end

pr108501.f90:3:14:

    3 |   real :: a(1,(n),2)
      |              1
Error: Expression at (1) must be of INTEGER type, found REAL
pr108501.f90:3:20:

    3 |   real :: a(1,(n),2)
      |                    1
Error: The module or main program array 'a' at (1) must have constant shape

This is already present in gcc-7, so although it is a nasty bug, it's not
a regression.

The other issue is likely exposed by this misbehavior, leading to an ICE
when checking the argument of the call in get_expr_storage_size.
This issue is also present in all versions down to at least gcc-7,
so arguably not really a regression.

I have a patch for the latter.
Comment 2 anlauf 2023-01-23 19:44:28 UTC
Created attachment 54330 [details]
Patch for the ICE in get_expr_storage_size
Comment 3 anlauf 2023-01-23 19:48:06 UTC
(In reply to anlauf from comment #1)
> First, I think the code is actually valid, adjusting keywords.

Oops, I cannot read, and Intel accepted the code when forgetting to
enfore standard conformance checking.

Putting a brown bag over my head.  Fixing keywords again...
Comment 5 GCC Commits 2023-01-23 21:08:34 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:771d793df1622a476e1cf8d05f0a6aee350fa56b

commit r13-5312-g771d793df1622a476e1cf8d05f0a6aee350fa56b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 23 21:19:03 2023 +0100

    Fortran: avoid ICE on invalid array subscript triplets [PR108501]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108501
            * interface.cc (get_expr_storage_size): Check array subscript triplets
            that we actually have integer values before trying to extract with
            mpz_get_si.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108501
            * gfortran.dg/pr108501.f90: New test.
Comment 6 Richard Biener 2023-01-24 09:07:29 UTC
Fixed I assume.
Comment 7 GCC Commits 2023-01-28 21:45:11 UTC
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r12-9076-gdaa4c49a4773f274b7a784cedd7b0e0b3c59523b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 23 21:19:03 2023 +0100

    Fortran: avoid ICE on invalid array subscript triplets [PR108501]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108501
            * interface.cc (get_expr_storage_size): Check array subscript triplets
            that we actually have integer values before trying to extract with
            mpz_get_si.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108501
            * gfortran.dg/pr108501.f90: New test.
    
    (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)
Comment 8 GCC Commits 2023-02-04 15:43:28 UTC
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:76a6f8470c8c786b271cb0d897de891fe0d4043f

commit r11-10504-g76a6f8470c8c786b271cb0d897de891fe0d4043f
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 23 21:19:03 2023 +0100

    Fortran: avoid ICE on invalid array subscript triplets [PR108501]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108501
            * interface.c (get_expr_storage_size): Check array subscript triplets
            that we actually have integer values before trying to extract with
            mpz_get_si.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108501
            * gfortran.dg/pr108501.f90: New test.
    
    (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)
Comment 9 GCC Commits 2023-02-05 18:55:21 UTC
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r10-11196-gd4bb7751af090736fb4a3bd7278d7094f35e02e4
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 23 21:19:03 2023 +0100

    Fortran: avoid ICE on invalid array subscript triplets [PR108501]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108501
            * interface.c (get_expr_storage_size): Check array subscript triplets
            that we actually have integer values before trying to extract with
            mpz_get_si.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108501
            * gfortran.dg/pr108501.f90: New test.
    
    (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)