From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E549E385783F; Thu, 16 Mar 2023 13:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E549E385783F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678974566; bh=i/RX/2MV1JdOlu1258inIfjDufYeMoGcfRZ/G40QsUU=; h=From:To:Subject:Date:From; b=Hl0EETP9AxhDDgijcGdjEvtIW8WDTtOHPCDNJZW8eR+oe0DcufX5AuMEkFK3bHxdx bi4AbTrPxueakIq3jAnGLRPvIFHWZENEV0RwHJ20vNhEc6v3ETYbgq0k1MadpSGmvI vCXTSYf3/o8F031AZmN2tQ4d/8cnx4c6SvOPdBIU= From: "philippe.wautelet at aero dot obs-mip.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109157] New: -fbound-check: false positive Date: Thu, 16 Mar 2023 13:49:26 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: philippe.wautelet at aero dot obs-mip.fr 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 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=3D109157 Bug ID: 109157 Summary: -fbound-check: false positive Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: philippe.wautelet at aero dot obs-mip.fr Target Milestone: --- Hello, The following code triggers a wrong out of bound detection: > cat ndimlist.f90 program ndimlistbug implicit none integer, parameter :: FIELDSIZE=3D5 type :: tfieldmetadata_base integer, dimension(10) :: ndimlist =3D -2 end type tfieldmetadata_base type(tfieldmetadata_base), dimension(FIELDSIZE) :: tzfields call write_diachro_lfi( tzfields ) contains subroutine write_diachro_lfi( tpfields ) class(tfieldmetadata_base), dimension(:), intent(in) :: tpfields print *,tpfields(1)%ndimlist print *,tpfields(1)%ndimlist(8) end subroutine write_diachro_lfi end program ndimlistbug If compiled with gfortran 12.2.0 (but also 11.1.0, 11.2.0, 11.3.0 and 12.1.= 0), it gives: > gfortran -g -fbounds-check ndimlist.f90 > ./a.out=20 -2 -2 -2 -2 -2 -2=20= =20=20=20=20=20=20 -2 -2 -2 -2 At line 18 of file ndimlist.f90 Fortran runtime error: Index '8' of dimension 1 of array 'tpfields%_data%ndimlist' above upper bound of 5 Error termination. Backtrace: #0 0x400aec in write_diachro_lfi at /home/waup/F90/bug_gcc/ndimlist/ndimlist.f90:18 #1 0x4008ee in ndimlistbug at /home/waup/F90/bug_gcc/ndimlist/ndimlist.f90:11 #2 0x400b8f in main at /home/waup/F90/bug_gcc/ndimlist/ndimlist.f90:11 It seems there is a confusion between the size of tpfields and the size of tpfields()%ndimlist. This can be seen if FIELDSIZE is set to at least the s= ize of ndimlist. The bug is not present with versions of gfortran below 11.=