From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 50A50386F819; Wed, 6 May 2020 23:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50A50386F819 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588807600; bh=ZRYZ7VtYVKuTMd97DYM0n+gMp1PitoIPKUMDp+JufIQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Jmyfzgi8wBRc92MPqs78uLODJvuVoosHOiL5vegpEBYm+fIcTZnZAQF56Y+3CheJK tAYeX79PckjxaYURa1VYalw0PLxwST+OkEZj15W2Xcrdpw6ej7DnVPwamvJf9JkNjq sNcZTon5eB2xrx6ijS07QR6og8luKDj/c2T9buqI= From: "foreese at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" Date: Wed, 06 May 2020 23:26:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 8.4.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: foreese at gcc dot gnu.org 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: Message-ID: In-Reply-To: References: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 May 2020 23:26:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94978 --- Comment #1 from Fritz Reese --- The regression is caused by r253156, which introduces the warning in the fi= rst place. The relevant code is in frontend-passes.c (do_subscript). Apparently, the FE is aware that when there is a conditional it cannot correctly simpli= fy the subscript bounds. However, in the testcase there is an inner DO-loop wh= ich, when the bounds are reduced to the empty set, prevents the code from becomi= ng invalid. Therefore no warning should be issued. The warning can be bypassed by guarding the inner DO-loop with any conditio= nal, including a vacuously true one: $ diff -auw pascal.f03 pascal2.f03 --- pascal.f03 2020-05-06 19:14:50.966646632 -0400 +++ pascal2.f03 2020-05-06 19:23:48.209569659 -0400 @@ -9,9 +9,11 @@ do i =3D 0, 8 pascal(i,0) =3D 1 + if (.true.) then do j =3D 1, i-1 pascal(i,j) =3D pascal(i-1,j) + pascal(i-1,j-1) enddo + endif do j =3D i, 8 pascal(i,j) =3D 0 enddo $ gfortran pascal2.f03 Normally the warning can be suppressed with -Wno-do-subscript, but the code= in do_subscript() determines that this is "definitely" an issue and therefore moves the warning to category 0. (An interesting note: moving the code in the testcase into a subroutine, ra= ther than the main program, suppresses the warning for GCC 8, but not GCC 9, 10,= or 11.)=