Bug 57142 - [4.7/4.8/4.9 Regression] SIZE/SHAPE overflow despite kind=8
Summary: [4.7/4.8/4.9 Regression] SIZE/SHAPE overflow despite kind=8
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, wrong-code
Depends on:
Blocks:
 
Reported: 2013-05-02 11:44 UTC by Tobias Burnus
Modified: 2013-05-07 17:29 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2013-05-02 11:44:44 UTC
The following program should print:
  1 k=8 / 4294967300 k=8
  1 k=8 / 2147483650 k=8

However, it prints:
  1 k=8 / 4 k=8
  1 k=8 / -2147483646 k=8

Expected:
* kind=8 is properly handled
* With kind=4, a warning/error is printed that the value exceeds huge(1_4)

NOTE: shape has the same issue; ubound/lbound are okay (in both regards). The run-time version is fine.


!integer :: A(huge(1)+2_8), B(2,3)
integer :: A(1), B(huge(1)+3_8,2_8)
print '(4(i0,a))', size(A,kind=8),' k=', kind(size(A,kind=8)),' / ', &
                   size(B,kind=8),' k=', kind(size(B,kind=8))
print '(4(i0,a))', size(A,dim=1,kind=8),' k=', kind(size(A,dim=1,kind=8)), &
      ' / ',       size(B,dim=1,kind=8),' k=', kind(size(B,dim=1,kind=8))
end
Comment 1 Dominique d'Humieres 2013-05-02 11:53:45 UTC
When compiled with gfortran 4.5.3 or older, the output is the one you expect:

1 k=8 / 4294967300 k=8
1 k=8 / 2147483650 k=8

From 4.6.4 to trunk the outputs is

1 k=8 / 4 k=8
1 k=8 / -2147483646 k=8
Comment 2 Dominique d'Humieres 2013-05-02 12:58:20 UTC
The change is due to revision 158253.
Comment 3 Tobias Burnus 2013-05-02 16:29:59 UTC
Author: burnus
Date: Thu May  2 16:29:14 2013
New Revision: 198549

URL: http://gcc.gnu.org/viewcvs?rev=198549&root=gcc&view=rev
Log:
2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * simplify.c (gfc_simplify_size): Renamed from
        simplify_size; fix kind=8 handling.
        (gfc_simplify_size): New function.
        (gfc_simplify_shape): Add range check.
        * resolve.c (resolve_function): Fix handling
        for ISYM_SIZE.

2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * gfortran.dg/size_kind_2.f90: New.
        * gfortran.dg/size_kind_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/size_kind_2.f90
    trunk/gcc/testsuite/gfortran.dg/size_kind_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Tobias Burnus 2013-05-07 17:26:40 UTC
Author: burnus
Date: Tue May  7 16:36:48 2013
New Revision: 198687

URL: http://gcc.gnu.org/viewcvs?rev=198687&root=gcc&view=rev
Log:
2013-05-07  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * simplify.c (gfc_simplify_size): Renamed from
        simplify_size; fix kind=8 handling.
        (gfc_simplify_size): New function.
        (gfc_simplify_shape): Add range check.

2013-05-07  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * gfortran.dg/size_kind_2.f90: New.
        * gfortran.dg/size_kind_3.f90: New.


Added:
    branches/gcc-4_8-branch/gcc/testsuite/gfortran.dg/size_kind_2.f90
    branches/gcc-4_8-branch/gcc/testsuite/gfortran.dg/size_kind_3.f90
Modified:
    branches/gcc-4_8-branch/gcc/fortran/ChangeLog
    branches/gcc-4_8-branch/gcc/fortran/resolve.c
    branches/gcc-4_8-branch/gcc/fortran/simplify.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 5 Tobias Burnus 2013-05-07 17:28:51 UTC
Author: burnus
Date: Tue May  7 17:28:12 2013
New Revision: 198690

URL: http://gcc.gnu.org/viewcvs?rev=198690&root=gcc&view=rev
Log:
2013-05-07  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * simplify.c (gfc_simplify_size): Renamed from
        simplify_size; fix kind=8 handling.
        (gfc_simplify_size): New function.
        (gfc_simplify_shape): Add range check.

2013-05-07  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2013-05-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57142
        * gfortran.dg/size_kind_2.f90: New.
        * gfortran.dg/size_kind_3.f90: New.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/size_kind_2.f90
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/size_kind_3.f90
Modified:
    branches/gcc-4_7-branch/gcc/fortran/ChangeLog
    branches/gcc-4_7-branch/gcc/fortran/resolve.c
    branches/gcc-4_7-branch/gcc/fortran/simplify.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 6 Tobias Burnus 2013-05-07 17:29:22 UTC
FIXED on the trunk (4.9) and on the 4.7/4.8 branch.