From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0BA293858C66; Thu, 18 Jan 2024 09:34:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BA293858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705570496; bh=Ko4PEG+mmD0uBEtjqpH03bBOCh4s6OxaMFgLzLR40ik=; h=From:To:Subject:Date:From; b=vxTysh1ip9Fn61jXzfwvK7gc32XBWvHfkCr6wWiKj7kb0iIvaGRFa14lvKFnfKbBH 7Tp3/d7Awva6Zpcot7cqPIhaeH90XnblZkn5AyA45vo3JmWmsRzkUEx2qxgxL3i/Dj YdwT3OeJn8/iImeNu45qN1kBcoadPyfTDd+1GJlU= From: "juergen.reuter at desy dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/113471] New: [14 regression] wrong array bound check failure on valid code Date: Thu, 18 Jan 2024 09:34:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: juergen.reuter at desy dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113471 Bug ID: 113471 Summary: [14 regression] wrong array bound check failure on valid code Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: juergen.reuter at desy dot de Target Milestone: --- Created attachment 57136 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D57136&action=3Dedit Reproducer, 154 lines Very likely in the time period between March and late fall 2023 a regression appeared with flags in the following reproducer a Fortran runtime error (invalidly, I'd say): Fortran runtime error: Index '3' of dimension 1 of array 'cc' outside of expected range (1:2) The code is here and attached, needs to be compiled with -fcheck=3Dall or -fcheck=3Dbounds: module cs implicit none type :: c_t integer, dimension(2) :: c1 =3D 0, c2 =3D 0 contains generic :: init =3D> & c_init_trivial, & c_init_array, & c_init_arrays procedure, private :: c_init_trivial procedure, private :: c_init_array procedure, private :: c_init_arrays procedure :: init_col_acl =3D> c_init_col_acl procedure :: add_offset =3D> c_add_offset generic :: operator(.merge.) =3D> merge_cs procedure, private :: merge_cs end type c_t contains pure subroutine c_init_trivial (col) class(c_t), intent(inout) :: col col%c1 =3D 0 col%c2 =3D 0 end subroutine c_init_trivial pure subroutine c_init_array (col, c1) class(c_t), intent(inout) :: col integer, dimension(:), intent(in) :: c1 col%c1 =3D pack (c1, c1 /=3D 0, [0,0]) col%c2 =3D col%c1 end subroutine c_init_array pure subroutine c_init_arrays (col, c1, c2) class(c_t), intent(inout) :: col integer, dimension(:), intent(in) :: c1, c2 if (size (c1) =3D=3D size (c2)) then col%c1 =3D pack (c1, c1 /=3D 0, [0,0]) col%c2 =3D pack (c2, c2 /=3D 0, [0,0]) else if (size (c1) /=3D 0) then col%c1 =3D pack (c1, c1 /=3D 0, [0,0]) col%c2 =3D col%c1 else if (size (c2) /=3D 0) then col%c1 =3D pack (c2, c2 /=3D 0, [0,0]) col%c2 =3D col%c1 end if end subroutine c_init_arrays elemental subroutine c_init_col_acl (col, col_in, acl_in) class(c_t), intent(inout) :: col integer, intent(in) :: col_in, acl_in integer, dimension(0) :: null_array select case (col_in) case (0) select case (acl_in) case (0) call c_init_array (col, null_array) case default call c_init_array (col, [-acl_in]) end select case default select case (acl_in) case (0) call c_init_array (col, [col_in]) case default call c_init_array (col, [col_in, -acl_in]) end select end select end subroutine c_init_col_acl elemental subroutine c_add_offset (col, offset) class(c_t), intent(inout) :: col integer, intent(in) :: offset where (col%c1 /=3D 0) col%c1 =3D col%c1 + sign (offset, col%c1) where (col%c2 /=3D 0) col%c2 =3D col%c2 + sign (offset, col%c2) end subroutine c_add_offset elemental function merge_cs (col1, col2) result (col) type(c_t) :: col class(c_t), intent(in) :: col1, col2 call c_init_arrays (col, col1%c1, col2%c1) end function merge_cs function count_c_loops (col) result (count) integer :: count type(c_t), dimension(:), intent(in) :: col type(c_t), dimension(size(col)) :: cc integer :: i, n, offset, ii cc =3D col n =3D size (cc) offset =3D n call c_add_offset (cc, offset) count =3D 0 SCAN_LOOPS: do do i =3D 1, n if (any (cc(i)%c1 > offset)) then count =3D count + 1 ii =3D pick_new_line (cc(i)%c1, count, 1) cycle SCAN_LOOPS end if end do exit SCAN_LOOPS end do SCAN_LOOPS contains function pick_new_line (c, reset_val, sgn) result (line) integer :: line integer, dimension(:), intent(inout) :: c integer, intent(in) :: reset_val integer, intent(in) :: sgn integer :: i if (any (c =3D=3D count)) then line =3D count else do i =3D 1, size (c) if (sign (1, c(i)) =3D=3D sgn .and. abs (c(i)) > offset) then line =3D c(i) c(i) =3D reset_val return end if end do end if end function pick_new_line end function count_c_loops end module cs module cs_uti use cs implicit none private public :: c_1 contains subroutine c_1 (u) integer, intent(in) :: u type(c_t), dimension(4) :: col1, col2, col type(c_t), dimension(:), allocatable :: col3 type(c_t), dimension(:,:), allocatable :: col_array integer :: count, i call col1%init_col_acl ([1, 0, 2, 3], [0, 1, 3, 2]) col2 =3D col1 col =3D col1 .merge. col2 count =3D count_c_loops (col) end subroutine c_1 end module cs_uti program main_ut use cs_uti, only: c_1 implicit none call c_1 (6) end program main_ut=